Changes between Version 53 and Version 54 of GeoDjango
- Timestamp:
- Mar 31, 2007, 1:57:18 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GeoDjango
v53 v54 21 21 * [GeoDjango#PostGISOperatorFieldLookupTypes PostGIS Operator Field Lookup Types] 22 22 * [GeoDjango#PostGISGEOSFunctionFieldLookupTypes PostGIS GEOS Function Field Lookup Types] 23 * [GeoDjango#ExtraInstanceMethods Extra Instance Methods] 23 24 24 25 = Background = … … 95 96 from django.contrib.gis.db import models 96 97 97 class District(models.Model ):98 class District(models.Model, models.GeoMixin): 98 99 name = models.CharField(maxlength=35) 99 100 num = models.IntegerField() … … 102 103 objects = models.GeoManager() 103 104 104 class School(models.Model ):105 class School(models.Model, models.GeoMixin): 105 106 name = models.CharField(maxlength=35) 106 point = models.PointField( )107 point = models.PointField(index=True) 107 108 108 109 objects = models.GeoManager() 109 110 }}} 111 112 '''Notes''': The {{{GeoMixin}}} class allows for [GeoDjango#ExtraInstanceMethods extra instance methods]. The {{{index}}} keyword is used to indicate that a GiST index be created for the School {{{PointField}}}s fields. 110 113 111 114 Use the {{{manage.py}}} just like you normally would: … … 123 126 ); 124 127 SELECT AddGeometryColumn('geo_app_school', 'point', 4326, 'POINT', 2); 128 CREATE INDEX "geo_app_school_point_id" ON "geo_app_school" USING GIST ( "point" GIST_GEOMETRY_OPS ); 125 129 SELECT AddGeometryColumn('geo_app_district', 'poly', 4326, 'MULTIPOLYGON', 2); 126 130 COMMIT; … … 212 216 The following geometry-enabled fields are available: 213 217 * {{{PointField}}} 214 * {{{LineStringField}}} (bug in current version has this as {{{LineString}}}, will be fixed)218 * {{{LineStringField}}} 215 219 * {{{PolygonField}}} 216 220 * {{{MultiPointField}}} … … 224 228 from django.contrib.gis.db import models 225 229 226 class Zip(models.Model ):230 class Zip(models.Model, models.GeoMixin): 227 231 code = models.IntegerField() 228 232 poly = models.PolygonField(srid=-1, index=True) 233 234 object = models.GeoManager() 229 235 }}} 230 236 … … 232 238 * Sets the SRID of geometry to the value. Defaults to 4326 (WGS84) 233 239 * {{{index}}} 234 * If set to True, will create an index for the given geometry. 235 * '''Disabled.''' Implemented, but there's a bug and won't allow syncdb to execute. 240 * If set to True, will create a GiST index for the given geometry. Update the index with the PostgreSQL command {{{VACUUM ANALYZE}}} (may take a while to execute depending on how large your geographic-enabled tables are). 236 241 237 242 == Creating and Saving Models with Geometry Fields == … … 314 319 * Requires GEOS 315 320 * Returns 1 (TRUE) if the Geometries are "spatially disjoint". 316 *317 321 * PostGIS equivalent {{{Disjoint(geometry, geometry)}}} 318 322 * {{{intersects}}} … … 331 335 * PostGIS equivelent {{{Relate(geometry, geometry)}}} 332 336 333 337 == Extra Instance Methods == 338 339 A model with geometry fields will get the following methods: 340 341 == get_FOO_wkt == 342 343 For every geometry field, the model object will have a {{{get_FOO_wkt}}} method, where {{{FOO}}} is the name of the geometry field. For example (using the {{{School}}} model from above): 344 345 {{{ 346 >>> skool = School.objects.get(name='PSAS') 347 >>> print skool.get_point_wkt() 348 POINT(-95.460822 29.745463) 349 }}} 350 351 == get_FOO_centroid == 352 353 For every geometry field, the model object will have a {{{get_FOO_centroid}}} method, where {{{FOO}}} is the name of the geometry field. This routine will return the centroid of the geometry. For example (using the {{{District}}} model from above): 354 355 {{{ 356 >>> dist = District.objects.get(name='Houston ISD') 357 >>> print dist.get_poly_centroid() 358 POINT(-95.231713 29.723235) 359 }}} 360 361 == get_FOO_area == 362 363 For every geometry field, the model object will have a {{{get_FOO_area}}} method, where {{{FOO}} is the name of the geometry field. This routine will return the area of the geometry. 364 365 {{{ 366 >>> dist = District.objects.get(name='Houston ISD') 367 >>> print dist.get_poly_area() 368 0.08332 369 }}} 370 371 '''Note''': Units need to be figured out here.