Merged in patch from Aryeh Leib Taurog for #9877, adapting as necessary.
1 from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
2 from django.contrib.gis.geos.point import Point
3 from django.contrib.gis.geos.linestring import LineString, LinearRing
4 from django.contrib.gis.geos.polygon import Polygon
5 from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
6 from django.contrib.gis.geos.error import GEOSException, GEOSIndexError
7 from django.contrib.gis.geos.libgeos import geos_version, geos_version_info, GEOS_PREPARE
9 def fromfile(file_name):
11 Given a string file name, returns a GEOSGeometry. The file may contain WKB,
14 fh = open(file_name, 'rb')
17 if wkt_regex.match(buf) or hex_regex.match(buf):
18 return GEOSGeometry(buf)
20 return GEOSGeometry(buffer(buf))
22 def fromstr(wkt_or_hex, **kwargs):
23 "Given a string value (wkt or hex), returns a GEOSGeometry object."
24 return GEOSGeometry(wkt_or_hex, **kwargs)
27 "Converts HEXEWKB into WKT."
28 return GEOSGeometry(hex).wkt
31 "Converts WKT into HEXEWKB."
32 return GEOSGeometry(wkt).hex
35 "Returns the centroid of the geometry (given in HEXEWKB)."
36 return GEOSGeometry(input).centroid.wkt
39 "Returns the area of the geometry (given in HEXEWKB)."
40 return GEOSGeometry(input).area