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 `geometries.py`.
* Internally, all C API methods are explicitly called from a module rather than a star import.
Fixed #9557, #9877, #10222
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24 08:12:21 +08:00
|
|
|
from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
|
|
|
|
|
|
|
|
def fromfile(file_h):
|
|
|
|
"""
|
|
|
|
Given a string file name, returns a GEOSGeometry. The file may contain WKB,
|
|
|
|
WKT, or HEX.
|
|
|
|
"""
|
|
|
|
# If given a file name, get a real handle.
|
|
|
|
if isinstance(file_h, basestring):
|
2012-05-05 20:01:38 +08:00
|
|
|
with open(file_h, 'rb') as file_h:
|
|
|
|
buf = file_h.read()
|
|
|
|
else:
|
|
|
|
buf = file_h.read()
|
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 `geometries.py`.
* Internally, all C API methods are explicitly called from a module rather than a star import.
Fixed #9557, #9877, #10222
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24 08:12:21 +08:00
|
|
|
|
|
|
|
# If we get WKB need to wrap in buffer(), so run through regexes.
|
|
|
|
if wkt_regex.match(buf) or hex_regex.match(buf):
|
|
|
|
return GEOSGeometry(buf)
|
|
|
|
else:
|
|
|
|
return GEOSGeometry(buffer(buf))
|
|
|
|
|
|
|
|
def fromstr(string, **kwargs):
|
|
|
|
"Given a string value, returns a GEOSGeometry object."
|
|
|
|
return GEOSGeometry(string, **kwargs)
|