Changes between Version 53 and Version 54 of GeoDjango


Ignore:
Timestamp:
Mar 31, 2007, 1:57:18 AM (17 years ago)
Author:
jbronn
Comment:

updated api, fixed some typgraphical errors

Legend:

Unmodified
Added
Removed
Modified
  • GeoDjango

    v53 v54  
    2121   * [GeoDjango#PostGISOperatorFieldLookupTypes PostGIS Operator Field Lookup Types]
    2222   * [GeoDjango#PostGISGEOSFunctionFieldLookupTypes PostGIS GEOS Function Field Lookup Types]
     23   * [GeoDjango#ExtraInstanceMethods Extra Instance Methods]
    2324
    2425= Background =
     
    9596from django.contrib.gis.db import models
    9697
    97 class District(models.Model):
     98class District(models.Model, models.GeoMixin):
    9899    name = models.CharField(maxlength=35)
    99100    num  = models.IntegerField()
     
    102103    objects = models.GeoManager()
    103104
    104 class School(models.Model):
     105class School(models.Model, models.GeoMixin):
    105106    name  = models.CharField(maxlength=35)
    106     point = models.PointField()
     107    point = models.PointField(index=True)
    107108
    108109    objects = models.GeoManager()
    109110}}}
     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.
    110113
    111114Use the {{{manage.py}}} just like you normally would:
     
    123126);
    124127SELECT AddGeometryColumn('geo_app_school', 'point', 4326, 'POINT', 2);
     128CREATE INDEX "geo_app_school_point_id" ON "geo_app_school" USING GIST ( "point" GIST_GEOMETRY_OPS );
    125129SELECT AddGeometryColumn('geo_app_district', 'poly', 4326, 'MULTIPOLYGON', 2);
    126130COMMIT;
     
    212216The following geometry-enabled fields are available:
    213217 * {{{PointField}}}
    214  * {{{LineStringField}}}  (bug in current version has this as {{{LineString}}}, will be fixed)
     218 * {{{LineStringField}}}
    215219 * {{{PolygonField}}}
    216220 * {{{MultiPointField}}}
     
    224228from django.contrib.gis.db import models
    225229
    226 class Zip(models.Model):
     230class Zip(models.Model, models.GeoMixin):
    227231  code = models.IntegerField()
    228232  poly = models.PolygonField(srid=-1, index=True)
     233
     234  object = models.GeoManager()
    229235}}}
    230236
     
    232238   * Sets the SRID of geometry to the value.  Defaults to 4326 (WGS84)
    233239 * {{{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).
    236241
    237242== Creating and Saving Models with Geometry Fields ==
     
    314319   * Requires GEOS
    315320   * Returns 1 (TRUE) if the Geometries are "spatially disjoint".
    316    *
    317321   * PostGIS equivalent {{{Disjoint(geometry, geometry)}}}
    318322 * {{{intersects}}}
     
    331335   * PostGIS equivelent {{{Relate(geometry, geometry)}}}
    332336
    333 
     337== Extra Instance Methods ==
     338
     339A model with geometry fields will get the following methods:
     340
     341== get_FOO_wkt ==
     342
     343For 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()
     348POINT(-95.460822 29.745463)
     349}}}
     350
     351== get_FOO_centroid ==
     352
     353For 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()
     358POINT(-95.231713 29.723235)
     359}}}
     360
     361== get_FOO_area ==
     362
     363For 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()
     3680.08332
     369}}}
     370
     371'''Note''': Units need to be figured out here.
Back to Top