16 | | Thus, the Python {{{ctypes}}} package was used to wrap the [http://geos.refractions.net/ro/doxygen_docs/html/geos__c_8h-source.html GEOS C API] to bring the rich capabilities of GEOS to Python and GeoDjango. |
| 16 | Thus, the Python {{{ctypes}}} package was used to wrap the [http://geos.refractions.net/ro/doxygen_docs/html/geos__c_8h-source.html GEOS C API] to bring the rich capabilities of GEOS to Python and !GeoDjango. |
| 17 | |
| 18 | ''Features'': |
| 19 | * A BSD licensed interface to the GEOS geometry routines, implemented purely in Python using {{{ctypes}}}. |
| 20 | * Loosely-coupled to !GeoDjango, ''e.g.'', GEOS geometry objects may be used outside a django project/application (no need have {{{DJANGO_SETTINGS_MODULE}}} set). |
| 21 | * Mutability. GEOS Geometry objects may be modified, and memory is safely re-used when possible. |
| 22 | * Cross-platform and tested. !GeoDjango GEOS geometries are well-tested and compatible with Windows, Linux, Solaris, and Mac OSX platforms. |
26 | | === LinearRing === |
| 38 | === !LineString === |
| 39 | |
| 40 | Initializes on the given sequence, for example, the constructor may take lists, tuples, !NumPy arrays of X,Y[,Z] pairs, or {{{Point}}} objects. If {{{Point}}} objects are used, ownership of the points is ''not'' transferred to the {{{LineString}}} object. Examples: |
| 41 | |
| 42 | {{{ |
| 43 | #!python |
| 44 | >>> from django.contrib.gis.geos import LineString, Point |
| 45 | >>> ls = LineString((1, 1), (2, 2)) |
| 46 | >>> ls = LineString([(1, 1), (2, 2)]) |
| 47 | >>> ls = LineString(Point(1, 1), Point(2, 2)) |
| 48 | >>> from numpy import array |
| 49 | >>> ls = LineString(array([(1, 1), (2, 2)])) |
| 50 | }}} |
| 51 | |
| 52 | === !LinearRing === |
| 69 | |
| 70 | GEOS geometry objects may be created from strings using the {{{fromstr()}}} factory, or using the constructor for each geometry object (as described above). |
| 71 | {{{ |
| 72 | #!python |
| 73 | >>> from django.contrib.gis.geos import fromstr |
| 74 | >>> pnt = fromstr('POINT(-90.5 29.5)', srid=4326) |
| 75 | }}} |
| 76 | The {{{srid}}} keyword may be used to set the spatial reference system identifier number for the geometry. This will be used to conduct any needed transformations for spatial lookups and geographic model creation. It should be noted that {{{fromstr}}} is a shortcut to the constructor for the base {{{GEOSGeometry}}} object. |
| 77 | |
| 78 | === Output Properties === |
| 79 | * {{{wkt}}}: Returns the Well-Known Text of the geometry (an OGC standard). |
| 80 | * {{{hex}}}: Returns the HEXEWKB PostGIS canonical representation of the geometry. This representation is specific to PostGIS, and is not a standard. |
| 81 | * {{{kml}}}: Returns a KML (Keyhole Markup Language) representation of the geometry. Should only be used for geometries with an SRID of 4326 (WGS84), but this restriction is not enforced. |