101 | | |
102 | | A model with geometry fields will get the following methods, substitute {{{GEOM}}} with the name of the geometry field. |
103 | | |
104 | | '''Update:''' All of the extra instance methods below (except {{{get_GEOM_ogr}}} and {{{get_GEOM_srs}}}) have been deprecated in r5657 due to lazy geometry support. In other words, these properties may be directly accessed as attributes from the geometry field. As part of the deprecation process, [http://docs.python.org/lib/module-warnings.html warnings] are issued when such methods are invoked so that users have notice to change their code before these methods disappear in the future. |
105 | | |
106 | | == get_GEOM_ogr == |
107 | | Returns a {{{OGRGeometry}}} instance for the geometry. For example, using the {{{Zip}}} model, as above: |
108 | | |
109 | | {{{ |
110 | | #!python |
111 | | >>> from django.contrib.gis.gdal import OGRGeometry # Where to import from |
112 | | >>> z = Zip.objects.get(code='77096') |
113 | | >>> geom = z.get_poly_ogr() |
114 | | >>> print geom |
115 | | POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10)) |
116 | | >>> for ring in poly: |
117 | | ... print ring |
118 | | ... for point in ring: |
119 | | ... print point |
120 | | ... |
121 | | LINEARRING (10 10,10 20,20 20,20 15,10 10) |
122 | | (10.0, 10.0) |
123 | | (10.0, 20.0) |
124 | | (20.0, 20.0) |
125 | | (20.0, 15.0) |
126 | | (10.0, 10.0) |
127 | | }}} |
128 | | |
129 | | == get_GEOM_srs == |
130 | | |
131 | | Returns the OGR {{{SpatialReference}}} object for this geometry. |
132 | | |
133 | | {{{ |
134 | | #!python |
135 | | >>> from django.contrib.gis.gdal import SpatialReference # Where these related classes reside |
136 | | >>> z = Zip.objects.get(code='77096') |
137 | | >>> srs = z.get_poly_srs() |
138 | | >>> print srs |
139 | | GEOGCS["WGS 84", |
140 | | DATUM["WGS_1984", |
141 | | SPHEROID["WGS 84",6378137,298.257223563, |
142 | | AUTHORITY["EPSG","7030"]], |
143 | | TOWGS84[0,0,0,0,0,0,0], |
144 | | AUTHORITY["EPSG","6326"]], |
145 | | PRIMEM["Greenwich",0, |
146 | | AUTHORITY["EPSG","8901"]], |
147 | | UNIT["degree",0.01745329251994328, |
148 | | AUTHORITY["EPSG","9122"]], |
149 | | AUTHORITY["EPSG","4326"]] |
150 | | >>> print srs.semi_major, srs.semi_minor, srs.inverse_flattening |
151 | | 6378137.0 6356752.31425 298.257223563 |
152 | | >>> print srs.geographic |
153 | | True |
154 | | }}} |
155 | | |
156 | | == get_GEOM_geos == |
157 | | '''Update:''' This extra instance method was deprecated in r5657 -- and may now be accessed directly through the attribute name of the geometry field -- ''e.g.'', {{{dist.poly}}} returns a {{{GEOSGeometry}}} instance for the {{{PolygonField}}} of the {{{District}}} model. |
158 | | |
159 | | Returns a {{{GEOSGeometry}}} instance for the geometry. For example (using the {{{District}}} model from the [wiki:GeoDjango#Example example]): |
160 | | |
161 | | {{{ |
162 | | #!python |
163 | | >>> from django.contrib.gis.geos import GEOSGeometry # Where to import from |
164 | | >>> dist = District.objects.get(name='Houston ISD') |
165 | | >>> geom = dist.get_poly_geos() |
166 | | >>> print geom.centroid.wkt |
167 | | POINT(-95.231713 29.723235) |
168 | | >>> print geom.area |
169 | | 0.08332 |
170 | | >>> print geom.geom_type |
171 | | Polygon |
172 | | >>> print geom.centroid.geom_type |
173 | | Point |
174 | | >>> print geom.intersects(GEOSGeometry('POINT(-95.395223 29.798088)')) |
175 | | False |
176 | | }}} |
177 | | |
178 | | == get_GEOM_srid == |
179 | | |
180 | | '''Update:''' This extra instance method was deprecated in r5657 -- and may now be accessed directly through the attribute name of the geometry field -- ''e.g.'', {{{dist.poly.srid}}}. |
181 | | |
182 | | Returns the SRID (source reference identifier) for the geometry. |
183 | | |
184 | | == get_GEOM_wkt == |
185 | | |
186 | | '''Update:''' This extra instance method was deprecated in r5657 -- and may now be accessed directly through the attribute name of the geometry field -- ''e.g.'', {{{skool.point.wkt}}}, or simply {{{str(skool.point)}}}. |
187 | | |
188 | | Returns the OGC WKT (Well Known Text) for the geometry. For example (using the {{{School}}} model from the [wiki:GeoDjango#Example example]): |
189 | | |
190 | | {{{ |
191 | | #!python |
192 | | >>> skool = School.objects.get(name='PSAS') |
193 | | >>> print skool.get_point_wkt() |
194 | | POINT(-95.460822 29.745463) |
195 | | }}} |
196 | | |
197 | | == get_GEOM_centroid == |
198 | | |
199 | | '''Update:''' This extra instance method was deprecated in r5657 -- and may now be accessed directly through the attribute name of the geometry field -- ''e.g.'', {{{dist.poly.centroid.wkt}}}. |
200 | | |
201 | | This routine will return the centroid of the geometry. For example (using the {{{District}}} model from above): |
202 | | |
203 | | {{{ |
204 | | #!python |
205 | | >>> dist = District.objects.get(name='Houston ISD') |
206 | | >>> print dist.get_poly_centroid() |
207 | | POINT(-95.231713 29.723235) |
208 | | }}} |
209 | | |
210 | | == get_GEOM_area == |
211 | | |
212 | | '''Update:''' This extra instance method was deprecated in r5657 -- and may now be accessed directly through the attribute name of the geometry field -- ''e.g.'', {{{dist.poly.area}}}. |
213 | | |
214 | | This routine will return the area of the geometry field. |
215 | | |
216 | | {{{ |
217 | | #!python |
218 | | >>> dist = District.objects.get(name='Houston ISD') |
219 | | >>> print dist.get_poly_area() |
220 | | 0.08332 |
221 | | }}} |
222 | | |
223 | | '''Note''': Units are in the projected units of the coordinate system. In the example above, the units are in degrees since we're using WGS84. |
| 101 | '''Update:''' All of the extra instance methods haave been deprecated as of r6467 because lazy geometry support includes all of their functionality (including OGR geometries and OSR spatial references with the `ogr` and `srs` properties, respectively). In other words, these properties may be directly accessed as attributes from the geometry field. |