Browse files

Refactored the GEOS interface. Improvements include:

* Geometries now allow list-like manipulation, e.g., can add, insert, delete vertexes (or other geometries in collections) like Python lists.  Thanks, Aryeh Leib Taurog.
* Added support for GEOS prepared geometries via `prepared` property.  Prepared geometries significantly speed up certain operations.
* Added support for GEOS cascaded union as `MultiPolygon.cascaded_union` property.
* Added support for GEOS line merge as `merged` property on `LineString`, and `MultiLineString` geometries.  Thanks, Paul Smith.
* No longer use the deprecated C API for serialization to/from WKB and WKT.  Now use the GEOS I/O classes, which are now exposed as `WKTReader`, `WKTWriter`, `WKBReader`, and `WKBWriter` (which supports 3D and SRID inclusion)
* Moved each type of geometry to their own module, eliminating the cluttered ``.
* Internally, all C API methods are explicitly called from a module rather than a star import.

Fixed #9557, #9877, #10222

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 4246c83 commit 66e1670efae34d721e374788e4c3f8b5fe5fa481 @jbronn jbronn committed Mar 24, 2009
@@ -1,4 +1,4 @@
-Copyright (c) 2007, Justin Bronn
+Copyright (c) 2007-2009 Justin Bronn
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@@ -1,69 +1,14 @@
- The goal of this module is to be a ctypes wrapper around the GEOS library
- that will work on both *NIX and Windows systems. Specifically, this uses
- the GEOS C api.
- I have several motivations for doing this:
- (1) The GEOS SWIG wrapper is no longer maintained, and requires the
- installation of SWIG.
- (2) The PCL implementation is over 2K+ lines of C and would make
- PCL a requisite package for the GeoDjango application stack.
- (3) Windows and Mac compatibility becomes substantially easier, and does not
- require the additional compilation of PCL or GEOS and SWIG -- all that
- is needed is a Win32 or Mac compiled GEOS C library (dll or dylib)
- in a location that Python can read (e.g. 'C:\Python25').
- In summary, I wanted to wrap GEOS in a more maintainable and portable way using
- only Python and the excellent ctypes library (now standard in Python 2.5).
- In the spirit of loose coupling, this library does not require Django or
- GeoDjango. Only the GEOS C library and ctypes are needed for the platform
- of your choice.
- For more information about GEOS:
- For more info about PCL and the discontinuation of the Python GEOS
- library see Sean Gillies' writeup (and subsequent update) at:
+The GeoDjango GEOS module. Please consult the GeoDjango documentation
+for more details:
-from django.contrib.gis.geos.base import GEOSGeometry, wkt_regex, hex_regex
-from django.contrib.gis.geos.geometries import Point, LineString, LinearRing, Polygon, HAS_NUMPY
+from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
+from django.contrib.gis.geos.point import Point
+from django.contrib.gis.geos.linestring import LineString, LinearRing
+from django.contrib.gis.geos.polygon import Polygon
from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
-from django.contrib.gis.geos.libgeos import geos_version, geos_version_info
-def fromfile(file_name):
- """
- Given a string file name, returns a GEOSGeometry. The file may contain WKB,
- WKT, or HEX.
- """
- fh = open(file_name, 'rb')
- buf =
- fh.close()
- if wkt_regex.match(buf) or hex_regex.match(buf):
- return GEOSGeometry(buf)
- else:
- return GEOSGeometry(buffer(buf))
-def fromstr(wkt_or_hex, **kwargs):
- "Given a string value (wkt or hex), returns a GEOSGeometry object."
- return GEOSGeometry(wkt_or_hex, **kwargs)
-def hex_to_wkt(hex):
- "Converts HEXEWKB into WKT."
- return GEOSGeometry(hex).wkt
-def wkt_to_hex(wkt):
- "Converts WKT into HEXEWKB."
- return GEOSGeometry(wkt).hex
-def centroid(input):
- "Returns the centroid of the geometry (given in HEXEWKB)."
- return GEOSGeometry(input).centroid.wkt
-def area(input):
- "Returns the area of the geometry (given in HEXEWKB)."
- return GEOSGeometry(input).area
+from import WKTReader, WKTWriter, WKBReader, WKBWriter
+from django.contrib.gis.geos.factory import fromfile, fromstr
+from django.contrib.gis.geos.libgeos import geos_version, geos_version_info, GEOS_PREPARE
Oops, something went wrong.

0 comments on commit 66e1670

Please sign in to comment.