Changes between Version 1 and Version 2 of GeoDjangoDatabaseAPI
 Timestamp:
 06/10/07 01:13:05 (8 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

GeoDjangoDatabaseAPI
v1 v2 1 [[TOC ]]1 [[TOC(GeoDjangoDatabaseAPI)]] 2 2 = Database API = 3 3 4 '''Note:''' The following database lookup types can only be used with on geographic fields with {{{filter()}}}. Filters on 'normal' fields (e.g. {{{CharField}}}) may be chained with those on geographic fields. Thus, geographic queries take the following form (assuming the {{{Zip}}} model used in the [ GeoDjangoModelAPI GeoDjango Model API docs]:4 '''Note:''' The following database lookup types can only be used with on geographic fields with {{{filter()}}}. Filters on 'normal' fields (e.g. {{{CharField}}}) may be chained with those on geographic fields. Thus, geographic queries take the following form (assuming the {{{Zip}}} model used in the [wiki:GeoDjangoModelAPI GeoDjango Model API docs]: 5 5 {{{ 6 6 #!python … … 79 79 * Returns 1 (TRUE) if the Geometries are "spatially disjoint". 80 80 * PostGIS equivalent {{{Disjoint(geometry, geometry)}}} 81 * {{{intersects}}}82 * PostGIS equivalent {{{Intersects(geometry, geometry)}}}83 81 * {{{touches}}} 82 * Returns 1 (TRUE) if the Geometries "spatially touch". 84 83 * PostGIS equivalent {{{Touches(geometry, geometry)}}} 85 84 * {{{crosses}}} 85 * Returns 1 (TRUE) if the Geometries "spatially cross". 86 86 * PostGIS equivalent {{{Crosses(geometry, geometry)}}} 87 * {{{within}}} 88 * Returns 1 (TRUE) if Geometry A is "spatially within" Geometry B. 89 * PostGIS equivalent {{{Within(geometry, geometry)}}} 87 90 * {{{overlaps}}} 91 * Returns 1 (TRUE) if the Geometries "spatially overlap". 88 92 * PostGIS equivalent {{{Overlaps(geometry, geometry)}}} 89 93 * {{{contains}}} 94 * Returns 1 (TRUE) if Geometry A "spatially contains" Geometry B. 90 95 * PostGIS equivalent {{{Contains(geometry, geometry)}}} 91 * {{{intersects}}}92 * PostGIS equivalent {{{Intersects(geometry, geometry)}}}93 96 * {{{relate}}} 97 * Returns the DE9IM (dimensionally extended nineintersection matrix) between the two geometries. 94 98 * PostGIS equivelent {{{Relate(geometry, geometry)}}} 95 99 … … 99 103 100 104 == get_GEOM_ogr == 101 Returns a {{{OGRGeometry}}} instance for the geometry. 105 Returns a {{{OGRGeometry}}} instance for the geometry. For example, using the {{{Zip}}} model, as above: 106 107 {{{ 108 #!python 109 >>> from django.contrib.gis.gdal import OGRGeometry # Where to import from 110 >>> z = Zip.objects.get(code='77096') 111 >>> geom = z.get_poly_ogr() 112 >>> print geom 113 POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10)) 114 >>> for ring in poly: 115 ... print ring 116 ... for point in ring: 117 ... print point 118 ... 119 LINEARRING (10 10,10 20,20 20,20 15,10 10) 120 (10.0, 10.0) 121 (10.0, 20.0) 122 (20.0, 20.0) 123 (20.0, 15.0) 124 (10.0, 10.0) 125 }}} 102 126 103 127 == get_GEOM_geos == 104 Returns a {{{GEOSGeometry}}} instance for the geometry. For example (using the {{{District}}} model from above):105 106 {{{ 107 #!python 108 >>> from django.contrib.gis.geos import GEOSGeometry 128 Returns a {{{GEOSGeometry}}} instance for the geometry. For example (using the {{{District}}} model from the [wiki:GeoDjango#Example example]): 129 130 {{{ 131 #!python 132 >>> from django.contrib.gis.geos import GEOSGeometry # Where to import from 109 133 >>> dist = District.objects.get(name='Houston ISD') 110 134 >>> geom = dist.get_poly_geos() … … 121 145 }}} 122 146 147 == get_GEOM_srid == 148 149 Returns the SRID (source reference identifier) for the geometry. 150 151 == get_GEOM_srs == 152 153 Returns the OGR {{{SpatialReference}}} object for this geometry. 154 155 {{{ 156 #!python 157 >>> from django.contrib.gis.gdal import SpatialReference # Where these related classes reside 158 >>> z = Zip.objects.get(code='77096') 159 >>> srs = z.get_poly_srs() 160 >>> print srs 161 GEOGCS["WGS 84", 162 DATUM["WGS_1984", 163 SPHEROID["WGS 84",6378137,298.257223563, 164 AUTHORITY["EPSG","7030"]], 165 TOWGS84[0,0,0,0,0,0,0], 166 AUTHORITY["EPSG","6326"]], 167 PRIMEM["Greenwich",0, 168 AUTHORITY["EPSG","8901"]], 169 UNIT["degree",0.01745329251994328, 170 AUTHORITY["EPSG","9122"]], 171 AUTHORITY["EPSG","4326"]] 172 >>> print srs.semi_major, srs.semi_minor, srs.inverse_flattening 173 6378137.0 6356752.31425 298.257223563 174 >>> print srs.geographic 175 True 176 }}} 177 123 178 == get_GEOM_wkt == 124 179 125 Returns the OGC WKT (Well Known Text) for the geometry. For example (using the {{{School}}} model from above):180 Returns the OGC WKT (Well Known Text) for the geometry. For example (using the {{{School}}} model from the [wiki:GeoDjango#Example example]): 126 181 127 182 {{{