| 173 | |
| 174 | = Model API = |
| 175 | == Field Keywords == |
| 176 | * Field keywords are used during model creation, for example: |
| 177 | {{{ |
| 178 | class Zip(models.Model): |
| 179 | code = models.IntegerField() |
| 180 | poly = models.PolygonField(srid=-1, index=True) |
| 181 | }}} |
| 182 | |
| 183 | * {{{srid}}} |
| 184 | * Sets the SRID of geometry to the value. Defaults to 4326 (WGS84) |
| 185 | * {{{index}}} |
| 186 | * If set to True, will create an index for the given geometry. |
| 187 | * '''Disabled.''' Implemented, but there's a bug and won't allow syncdb to execute. |
| 188 | |
| 189 | == Fields == |
| 190 | |
| 191 | The following geometry-enabled fields are available: |
| 192 | * {{{PointField}}} |
| 193 | * {{{LineStringField}}} (bug in current version has this as {{{LineString}}}, will be fixed) |
| 194 | * {{{PolygonField}}} |
| 195 | * {{{MultiPointField}}} |
| 196 | * {{{MultiLineStringField}}} |
| 197 | * {{{MultiPolygonField}}} |
| 198 | * {{{GeometryCollectionField}}} |
| 199 | |
| 200 | == Creating a Geometry Object and Saving == |
| 201 | Here is an example of how to create a geometry object (assuming the {{{Zip}}} model example above). Geometries can be represented in either the WKT (Well Known Text) format, or in HEXEWKB (PostGIS specific, essentially a WKB geometry in hexadecimal). ''See'' Open GIS Consortium, Inc., ''[http://portal.opengeospatial.org/files/?artifact_id=829&ei=Z5oGRv6aCZ-IwQKh2LXwAw&usg=__4YgoHsbqjocl8Z01SwMAyN84aW0=&sig2=4DpSpm83ZDEIBKSivWcYGQ OpenGIS Simple Feature Specification For SQL]'', Document 99-049 (May 5, 1999), at Ch. 3.2.5 (SQL Textual Representation of Geometry, pg. 53); ''see also'' [http://postgis.refractions.net/docs/ch04.html#id2904792 "PostGIS EWKB, EWKT and Canonical Forms"], PostGIS documentation at Ch. 4.1.2]. |
| 202 | {{{ |
| 203 | >>> from zipcode.models import Zip |
| 204 | >>> z = Zip(code=77096, poly='POLYGON(( 10 10, 10 20, 20 20, 20 15, 10 10))') |
| 205 | >>> z.save() |
| 206 | }}} |