desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Returns whether this coordinate sequence is 3D. This property value is inherited from the parent Geometry.'
@property def hasz(self):
return self._z
'Clones this coordinate sequence.'
def clone(self):
return GEOSCoordSeq(capi.cs_clone(self.ptr), self.hasz)
'Returns the KML representation for the coordinates.'
@property def kml(self):
if self.hasz: substr = '%s,%s,%s ' else: substr = '%s,%s,0 ' return ('<coordinates>%s</coordinates>' % ''.join([(substr % self[i]) for i in xrange(len(self))]).strip())
'Returns a tuple version of this coordinate sequence.'
@property def tuple(self):
n = self.size if (n == 1): return self[0] else: return tuple([self[i] for i in xrange(n)])
'Initializes on the given sequence -- may take lists, tuples, NumPy arrays of X,Y pairs, or Point objects. If Point objects are used, ownership is _not_ transferred to the LineString object. Examples: ls = LineString((1, 1), (2, 2)) ls = LineString([(1, 1), (2, 2)]) ls = LineString(array([(1, 1), (2, 2)])) ls = LineSt...
def __init__(self, *args, **kwargs):
if (len(args) == 1): coords = args[0] else: coords = args if isinstance(coords, (tuple, list)): ncoords = len(coords) if coords: ndim = len(coords[0]) else: raise TypeError('Cannot initialize on empty sequence.') self._check...
'Allows iteration over this LineString.'
def __iter__(self):
for i in xrange(len(self)): (yield self[i])
'Returns the number of points in this LineString.'
def __len__(self):
return len(self._cs)
'Returns a tuple version of the geometry from the coordinate sequence.'
@property def tuple(self):
return self._cs.tuple
'Internal routine that returns a sequence (list) corresponding with the given function. Will return a numpy array if possible.'
def _listarr(self, func):
lst = [func(i) for i in xrange(len(self))] if numpy: return numpy.array(lst) else: return lst
'Returns a numpy array for the LineString.'
@property def array(self):
return self._listarr(self._cs.__getitem__)
'Returns the line merge of this LineString.'
@property def merged(self):
return self._topology(capi.geos_linemerge(self.ptr))
'Returns a list or numpy array of the X variable.'
@property def x(self):
return self._listarr(self._cs.getX)
'Returns a list or numpy array of the Y variable.'
@property def y(self):
return self._listarr(self._cs.getY)
'Returns a list or numpy array of the Z variable.'
@property def z(self):
if (not self.hasz): return None else: return self._listarr(self._cs.getZ)
'Returns a GEOSGeometry for the given WKB buffer.'
def read(self, wkb):
return GEOSGeometry(super(WKBReader, self).read(wkb))
'Returns a GEOSGeometry for the given WKT string.'
def read(self, wkt):
return GEOSGeometry(super(WKTReader, self).read(wkt))
'Testing Geometry GEOSIndexError'
def test00_GEOSIndexException(self):
p = Point(1, 2) for i in range((-2), 2): p._checkindex(i) self.assertRaises(GEOSIndexError, p._checkindex, 2) self.assertRaises(GEOSIndexError, p._checkindex, (-3))
'Testing Point mutations'
def test01_PointMutations(self):
for p in (Point(1, 2, 3), fromstr('POINT (1 2 3)')): self.assertEqual(p._get_single_external(1), 2.0, 'Point _get_single_external') p._set_single(0, 100) self.assertEqual(p.coords, (100.0, 2.0, 3.0), 'Point _set_single') p._set_list(2, (50, 3141)) self.assertEq...
'Testing Point exceptions'
def test02_PointExceptions(self):
self.assertRaises(TypeError, Point, range(1)) self.assertRaises(TypeError, Point, range(4))
'Testing Point API'
def test03_PointApi(self):
q = Point(4, 5, 3) for p in (Point(1, 2, 3), fromstr('POINT (1 2 3)')): p[0:2] = [4, 5] for f in geos_function_tests: self.assertEqual(f(q), f(p), ('Point ' + f.__name__))
'Testing LineString mutations'
def test04_LineStringMutations(self):
for ls in (LineString((1, 0), (4, 1), (6, (-1))), fromstr('LINESTRING (1 0,4 1,6 -1)')): self.assertEqual(ls._get_single_external(1), (4.0, 1.0), 'LineString _get_single_external') ls._set_single(0, ((-50), 25)) self.assertEqual(ls.coords, (((-50.0), 25.0), (4.0, 1.0), (6.0, (...
'Testing Polygon mutations'
def test05_Polygon(self):
for pg in (Polygon(((1, 0), (4, 1), (6, (-1)), (8, 10), (1, 0)), ((5, 4), (6, 4), (6, 3), (5, 4))), fromstr('POLYGON ((1 0,4 1,6 -1,8 10,1 0),(5 4,6 4,6 3,5 4))')): self.assertEqual(pg._get_single_external(0), LinearRing((1, 0), (4, 1), (6, (-1)), (8, 10), (1, 0)), 'Polygon ...
'Testing Collection mutations'
def test06_Collection(self):
for mp in (MultiPoint(*map(Point, ((3, 4), ((-1), 2), (5, (-4)), (2, 8)))), fromstr('MULTIPOINT (3 4,-1 2,5 -4,2 8)')): self.assertEqual(mp._get_single_external(2), Point(5, (-4)), 'Collection _get_single_external') mp._set_list(3, map(Point, ((5, 5), (3, (-2)), (8, 1)))) s...
'Slice retrieval'
def test01_getslice(self):
(pl, ul) = self.lists_of_len() for i in self.limits_plus(1): self.assertEqual(pl[i:], ul[i:], ('slice [%d:]' % i)) self.assertEqual(pl[:i], ul[:i], ('slice [:%d]' % i)) for j in self.limits_plus(1): self.assertEqual(pl[i:j], ul[i:j], ('slice [%d:%d]' % (i, j))) ...
'Slice assignment'
def test02_setslice(self):
def setfcn(x, i, j, k, L): x[i:j:k] = range(L) (pl, ul) = self.lists_of_len() for slen in range((self.limit + 1)): ssl = nextRange(slen) ul[:] = ssl pl[:] = ssl self.assertEqual(pl, ul[:], 'set slice [:]') for i in self.limits_plus(1): ssl = ...
'Delete slice'
def test03_delslice(self):
for Len in range(self.limit): (pl, ul) = self.lists_of_len(Len) del pl[:] del ul[:] self.assertEqual(pl[:], ul[:], 'del slice [:]') for i in range(((- Len) - 1), (Len + 1)): (pl, ul) = self.lists_of_len(Len) del pl[i:] del ul[i:] ...
'Get/set/delete single item'
def test04_get_set_del_single(self):
(pl, ul) = self.lists_of_len() for i in self.limits_plus(0): self.assertEqual(pl[i], ul[i], ('get single item [%d]' % i)) for i in self.limits_plus(0): (pl, ul) = self.lists_of_len() pl[i] = 100 ul[i] = 100 self.assertEqual(pl[:], ul[:], ('set single it...
'Out of range exceptions'
def test05_out_of_range_exceptions(self):
def setfcn(x, i): x[i] = 20 def getfcn(x, i): return x[i] def delfcn(x, i): del x[i] (pl, ul) = self.lists_of_len() for i in (((-1) - self.limit), self.limit): self.assertRaises(IndexError, setfcn, ul, i) self.assertRaises(IndexError, getfcn, ul, i) se...
'List methods'
def test06_list_methods(self):
(pl, ul) = self.lists_of_len() pl.append(40) ul.append(40) self.assertEqual(pl[:], ul[:], 'append') pl.extend(range(50, 55)) ul.extend(range(50, 55)) self.assertEqual(pl[:], ul[:], 'extend') pl.reverse() ul.reverse() self.assertEqual(pl[:], ul[:], 'reverse') for i in self.lim...
'Type-restricted list'
def test07_allowed_types(self):
(pl, ul) = self.lists_of_len() ul._allowed = (int, long) ul[1] = 50 ul[:2] = [60, 70, 80] def setfcn(x, i, v): x[i] = v self.assertRaises(TypeError, setfcn, ul, 2, 'hello') self.assertRaises(TypeError, setfcn, ul, slice(0, 3, 2), ('hello', 'goodbye'))
'Length limits'
def test08_min_length(self):
(pl, ul) = self.lists_of_len() ul._minlength = 1 def delfcn(x, i): del x[:i] def setfcn(x, i): x[:i] = [] for i in range(((self.limit - ul._minlength) + 1), (self.limit + 1)): self.assertRaises(ValueError, delfcn, ul, i) self.assertRaises(ValueError, setfcn, ul, i) ...
'Error on assigning non-iterable to slice'
def test09_iterable_check(self):
(pl, ul) = self.lists_of_len((self.limit + 1)) def setfcn(x, i, v): x[i] = v self.assertRaises(TypeError, setfcn, ul, slice(0, 3, 2), 2)
'Index check'
def test10_checkindex(self):
(pl, ul) = self.lists_of_len() for i in self.limits_plus(0): if (i < 0): self.assertEqual(ul._checkindex(i), (i + self.limit), '_checkindex(neg index)') else: self.assertEqual(ul._checkindex(i), i, '_checkindex(pos index)') for i in (((- self.limit) - 1), self.l...
'Sorting'
def test_11_sorting(self):
(pl, ul) = self.lists_of_len() pl.insert(0, pl.pop()) ul.insert(0, ul.pop()) pl.sort() ul.sort() self.assertEqual(pl[:], ul[:], 'sort') mid = pl[(len(pl) / 2)] pl.sort(key=(lambda x: ((mid - x) ** 2))) ul.sort(key=(lambda x: ((mid - x) ** 2))) self.assertEqual(pl[:], ul[:], 'sort...
'Arithmetic'
def test_12_arithmetic(self):
(pl, ul) = self.lists_of_len() al = range(10, 14) self.assertEqual(list((pl + al)), list((ul + al)), 'add') self.assertEqual(type(ul), type((ul + al)), 'type of add result') self.assertEqual(list((al + pl)), list((al + ul)), 'radd') self.assertEqual(type(al), type((al + ul)), 'type o...
'Returns the proper null SRID depending on the GEOS version. See the comments in `test15_srid` for more details.'
@property def null_srid(self):
info = geos_version_info() if ((info['version'] == '3.0.0') and info['release_candidate']): return (-1) else: return None
'Tests out the GEOSBase class.'
def test00_base(self):
class FakeGeom1(GEOSBase, ): pass c_float_p = ctypes.POINTER(ctypes.c_float) class FakeGeom2(GEOSBase, ): ptr_type = c_float_p fg1 = FakeGeom1() fg2 = FakeGeom2() fg1.ptr = ctypes.c_void_p() fg1.ptr = None fg2.ptr = c_float_p(ctypes.c_float(5.23)) fg2.ptr = None f...
'Testing WKT output.'
def test01a_wkt(self):
for g in self.geometries.wkt_out: geom = fromstr(g.wkt) self.assertEqual(g.ewkt, geom.wkt)
'Testing HEX output.'
def test01b_hex(self):
for g in self.geometries.hex_wkt: geom = fromstr(g.wkt) self.assertEqual(g.hex, geom.hex)
'Testing (HEX)EWKB output.'
def test01b_hexewkb(self):
from binascii import a2b_hex ogc_hex = '01010000000000000000000000000000000000F03F' hexewkb_2d = '0101000020E61000000000000000000000000000000000F03F' hexewkb_3d = '01010000A0E61000000000000000000000000000000000F03F0000000000000040' pnt_2d = Point(0, 1, srid=4326) pnt_3d = Point(0, 1, 2, srid=432...
'Testing KML output.'
def test01c_kml(self):
for tg in self.geometries.wkt_out: geom = fromstr(tg.wkt) kml = getattr(tg, 'kml', False) if kml: self.assertEqual(kml, geom.kml)
'Testing the Error handlers.'
def test01d_errors(self):
print '\nBEGIN - expecting GEOS_ERROR; safe to ignore.\n' for err in self.geometries.errors: try: g = fromstr(err.wkt) except (GEOSException, ValueError): pass self.assertRaises(GEOSException, GEOSGeometry, buffer('0')) print '\nEND - expec...
'Testing WKB output.'
def test01e_wkb(self):
from binascii import b2a_hex for g in self.geometries.hex_wkt: geom = fromstr(g.wkt) wkb = geom.wkb self.assertEqual(b2a_hex(wkb).upper(), g.hex)
'Testing creation from HEX.'
def test01f_create_hex(self):
for g in self.geometries.hex_wkt: geom_h = GEOSGeometry(g.hex) geom_t = fromstr(g.wkt) self.assertEqual(geom_t.wkt, geom_h.wkt)
'Testing creation from WKB.'
def test01g_create_wkb(self):
from binascii import a2b_hex for g in self.geometries.hex_wkt: wkb = buffer(a2b_hex(g.hex)) geom_h = GEOSGeometry(wkb) geom_t = fromstr(g.wkt) self.assertEqual(geom_t.wkt, geom_h.wkt)
'Testing EWKT.'
def test01h_ewkt(self):
srid = 32140 for p in self.geometries.polygons: ewkt = ('SRID=%d;%s' % (srid, p.wkt)) poly = fromstr(ewkt) self.assertEqual(srid, poly.srid) self.assertEqual(srid, poly.shell.srid) self.assertEqual(srid, fromstr(poly.ewkt).srid)
'Testing GeoJSON input/output (via GDAL).'
def test01i_json(self):
if ((not gdal) or (not gdal.GEOJSON)): return for g in self.geometries.json_geoms: geom = GEOSGeometry(g.wkt) if (not hasattr(g, 'not_equal')): self.assertEqual(g.json, geom.json) self.assertEqual(g.json, geom.geojson) self.assertEqual(GEOSGeometry(g.wkt),...
'Testing the fromfile() factory.'
def test01k_fromfile(self):
from StringIO import StringIO ref_pnt = GEOSGeometry('POINT(5 23)') wkt_f = StringIO() wkt_f.write(ref_pnt.wkt) wkb_f = StringIO() wkb_f.write(str(ref_pnt.wkb)) for fh in (wkt_f, wkb_f): fh.seek(0) pnt = fromfile(fh) self.assertEqual(ref_pnt, pnt)
'Testing equivalence.'
def test01k_eq(self):
p = fromstr('POINT(5 23)') self.assertEqual(p, p.wkt) self.assertNotEqual(p, 'foo') ls = fromstr('LINESTRING(0 0, 1 1, 5 5)') self.assertEqual(ls, ls.wkt) self.assertNotEqual(p, 'bar') for g in (p, ls): self.assertNotEqual(g, None) self.assertNotEqual(g, {'f...
'Testing Point objects.'
def test02a_points(self):
prev = fromstr('POINT(0 0)') for p in self.geometries.points: pnt = fromstr(p.wkt) self.assertEqual(pnt.geom_type, 'Point') self.assertEqual(pnt.geom_typeid, 0) self.assertEqual(p.x, pnt.x) self.assertEqual(p.y, pnt.y) self.assertEqual(True, (pnt == fromstr(p.w...
'Testing MultiPoint objects.'
def test02b_multipoints(self):
for mp in self.geometries.multipoints: mpnt = fromstr(mp.wkt) self.assertEqual(mpnt.geom_type, 'MultiPoint') self.assertEqual(mpnt.geom_typeid, 4) self.assertAlmostEqual(mp.centroid[0], mpnt.centroid.tuple[0], 9) self.assertAlmostEqual(mp.centroid[1], mpnt.centroid.tuple[1], ...
'Testing LineString objects.'
def test03a_linestring(self):
prev = fromstr('POINT(0 0)') for l in self.geometries.linestrings: ls = fromstr(l.wkt) self.assertEqual(ls.geom_type, 'LineString') self.assertEqual(ls.geom_typeid, 1) self.assertEqual(ls.empty, False) self.assertEqual(ls.ring, False) if hasattr(l, 'centroid'):...
'Testing MultiLineString objects.'
def test03b_multilinestring(self):
prev = fromstr('POINT(0 0)') for l in self.geometries.multilinestrings: ml = fromstr(l.wkt) self.assertEqual(ml.geom_type, 'MultiLineString') self.assertEqual(ml.geom_typeid, 5) self.assertAlmostEqual(l.centroid[0], ml.centroid.x, 9) self.assertAlmostEqual(l.centroid[1...
'Testing LinearRing objects.'
def test04_linearring(self):
for rr in self.geometries.linearrings: lr = fromstr(rr.wkt) self.assertEqual(lr.geom_type, 'LinearRing') self.assertEqual(lr.geom_typeid, 2) self.assertEqual(rr.n_p, len(lr)) self.assertEqual(True, lr.valid) self.assertEqual(False, lr.empty) self.assertEqual(l...
'Testing Polygon objects.'
def test05a_polygons(self):
bbox = ((-180), (-90), 180, 90) p = Polygon.from_bbox(bbox) self.assertEqual(bbox, p.extent) prev = fromstr('POINT(0 0)') for p in self.geometries.polygons: poly = fromstr(p.wkt) self.assertEqual(poly.geom_type, 'Polygon') self.assertEqual(poly.geom_typeid, 3) self...
'Testing MultiPolygon objects.'
def test05b_multipolygons(self):
print '\nBEGIN - expecting GEOS_NOTICE; safe to ignore.\n' prev = fromstr('POINT (0 0)') for mp in self.geometries.multipolygons: mpoly = fromstr(mp.wkt) self.assertEqual(mpoly.geom_type, 'MultiPolygon') self.assertEqual(mpoly.geom_typeid, 6) self.asse...
'Testing Geometry __del__() on rings and polygons.'
def test06a_memory_hijinks(self):
poly = fromstr(self.geometries.polygons[1].wkt) ring1 = poly[0] ring2 = poly[1] del ring1 del ring2 ring1 = poly[0] ring2 = poly[1] del poly (s1, s2) = (str(ring1), str(ring2))
'Testing Coordinate Sequence objects.'
def test08_coord_seq(self):
for p in self.geometries.polygons: if p.ext_ring_cs: poly = fromstr(p.wkt) cs = poly.exterior_ring.coord_seq self.assertEqual(p.ext_ring_cs, cs.tuple) self.assertEqual(len(p.ext_ring_cs), len(cs)) for i in xrange(len(p.ext_ring_cs)): ...
'Testing relate() and relate_pattern().'
def test09_relate_pattern(self):
g = fromstr('POINT (0 0)') self.assertRaises(GEOSException, g.relate_pattern, 0, 'invalid pattern, yo') for rg in self.geometries.relate_geoms: a = fromstr(rg.wkt_a) b = fromstr(rg.wkt_b) self.assertEqual(rg.result, a.relate_pattern(b, rg.pattern)) self.assertEqua...
'Testing intersects() and intersection().'
def test10_intersection(self):
for i in xrange(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) i1 = fromstr(self.geometries.intersect_geoms[i].wkt) self.assertEqual(True, a.intersects(b)) i2 = a.intersection(b) ...
'Testing union().'
def test11_union(self):
for i in xrange(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) u1 = fromstr(self.geometries.union_geoms[i].wkt) u2 = a.union(b) self.assertEqual(u1, u2) self.assertEqual(u...
'Testing difference().'
def test12_difference(self):
for i in xrange(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) d1 = fromstr(self.geometries.diff_geoms[i].wkt) d2 = a.difference(b) self.assertEqual(d1, d2) self.assertEqu...
'Testing sym_difference().'
def test13_symdifference(self):
for i in xrange(len(self.geometries.topology_geoms)): a = fromstr(self.geometries.topology_geoms[i].wkt_a) b = fromstr(self.geometries.topology_geoms[i].wkt_b) d1 = fromstr(self.geometries.sdiff_geoms[i].wkt) d2 = a.sym_difference(b) self.assertEqual(d1, d2) self.asse...
'Testing buffer().'
def test14_buffer(self):
for bg in self.geometries.buffer_geoms: g = fromstr(bg.wkt) exp_buf = fromstr(bg.buffer_wkt) quadsegs = bg.quadsegs width = bg.width self.assertRaises(ctypes.ArgumentError, g.buffer, width, float(quadsegs)) buf = g.buffer(width, quadsegs) self.assertEqual(exp_...
'Testing the SRID property and keyword.'
def test15_srid(self):
pnt = Point(5, 23, srid=4326) self.assertEqual(4326, pnt.srid) pnt.srid = 3084 self.assertEqual(3084, pnt.srid) self.assertRaises(ctypes.ArgumentError, pnt.set_srid, '4326') poly = fromstr(self.geometries.polygons[1].wkt, srid=4269) self.assertEqual(4269, poly.srid) for ring in poly: ...
'Testing the mutability of Polygons and Geometry Collections.'
def test16_mutable_geometries(self):
for p in self.geometries.polygons: poly = fromstr(p.wkt) self.assertRaises(TypeError, poly.__setitem__, 0, LineString((1, 1), (2, 2))) shell_tup = poly.shell.tuple new_coords = [] for point in shell_tup: new_coords.append(((point[0] + 500.0), (point[1] + 500.0))) ...
'Testing three-dimensional geometries.'
def test17_threed(self):
pnt = Point(2, 3, 8) self.assertEqual((2.0, 3.0, 8.0), pnt.coords) self.assertRaises(TypeError, pnt.set_coords, (1.0, 2.0)) pnt.coords = (1.0, 2.0, 3.0) self.assertEqual((1.0, 2.0, 3.0), pnt.coords) ls = LineString((2.0, 3.0, 8.0), (50.0, 250.0, (-117.0))) self.assertEqual(((2.0, 3.0, 8.0), ...
'Testing the distance() function.'
def test18_distance(self):
pnt = Point(0, 0) self.assertEqual(0.0, pnt.distance(Point(0, 0))) self.assertEqual(1.0, pnt.distance(Point(0, 1))) self.assertAlmostEqual(1.41421356237, pnt.distance(Point(1, 1)), 11) ls1 = LineString((0, 0), (1, 1), (2, 2)) ls2 = LineString((5, 2), (6, 1), (7, 0)) self.assertEqual(3, ls1.d...
'Testing the length property.'
def test19_length(self):
pnt = Point(0, 0) self.assertEqual(0.0, pnt.length) ls = LineString((0, 0), (1, 1)) self.assertAlmostEqual(1.41421356237, ls.length, 11) poly = Polygon(LinearRing((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))) self.assertEqual(4.0, poly.length) mpoly = MultiPolygon(poly.clone(), poly) self.ass...
'Testing empty geometries and collections.'
def test20a_emptyCollections(self):
gc1 = GeometryCollection([]) gc2 = fromstr('GEOMETRYCOLLECTION EMPTY') pnt = fromstr('POINT EMPTY') ls = fromstr('LINESTRING EMPTY') poly = fromstr('POLYGON EMPTY') mls = fromstr('MULTILINESTRING EMPTY') mpoly1 = fromstr('MULTIPOLYGON EMPTY') mpoly2 = MultiPolygon(()) ...
'Testing GeometryCollection handling of other collections.'
def test20b_collections_of_collections(self):
coll = [mp.wkt for mp in self.geometries.multipolygons if mp.valid] coll.extend([mls.wkt for mls in self.geometries.multilinestrings]) coll.extend([p.wkt for p in self.geometries.polygons]) coll.extend([mp.wkt for mp in self.geometries.multipoints]) gc_wkt = ('GEOMETRYCOLLECTION(%s)' % ','.join(coll...
'Testing `ogr` and `srs` properties.'
def test21_test_gdal(self):
if (not gdal.HAS_GDAL): return g1 = fromstr('POINT(5 23)') self.assertEqual(True, isinstance(g1.ogr, gdal.OGRGeometry)) self.assertEqual(g1.srs, None) g2 = fromstr('LINESTRING(0 0, 5 5, 23 23)', srid=4326) self.assertEqual(True, isinstance(g2.ogr, gdal.OGRGeometry)) ...
'Testing use with the Python `copy` module.'
def test22_copy(self):
import django.utils.copycompat as copy poly = GEOSGeometry('POLYGON((0 0, 0 23, 23 23, 23 0, 0 0), (5 5, 5 10, 10 10, 10 5, 5 5))') cpy1 = copy.copy(poly) cpy2 = copy.deepcopy(poly) self.assertNotEqual(poly._ptr, cpy1._ptr) self.assertNotE...
'Testing `transform` method.'
def test23_transform(self):
if (not gdal.HAS_GDAL): return orig = GEOSGeometry('POINT (-104.609 38.255)', 4326) trans = GEOSGeometry('POINT (992385.4472045 481455.4944650)', 2774) (t1, t2, t3) = (orig.clone(), orig.clone(), orig.clone()) t1.transform(trans.srid) t2.transform(gdal.SpatialReference('EPSG:...
'Testing `extent` method.'
def test24_extent(self):
mp = MultiPoint(Point(5, 23), Point(0, 0), Point(10, 50)) self.assertEqual((0.0, 0.0, 10.0, 50.0), mp.extent) pnt = Point(5.23, 17.8) self.assertEqual((5.23, 17.8, 5.23, 17.8), pnt.extent) poly = fromstr(self.geometries.polygons[3].wkt) ring = poly.shell (x, y) = (ring.x, ring.y) (xmin, ...
'Testing pickling and unpickling support.'
def test25_pickle(self):
import pickle, cPickle def get_geoms(lst, srid=None): return [GEOSGeometry(tg.wkt, srid) for tg in lst] tgeoms = get_geoms(self.geometries.points) tgeoms.extend(get_geoms(self.geometries.multilinestrings, 4326)) tgeoms.extend(get_geoms(self.geometries.polygons, 3084)) tgeoms.extend(get_g...
'Testing PreparedGeometry support.'
def test26_prepared(self):
if (not GEOS_PREPARE): return mpoly = GEOSGeometry('MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5)))') prep = mpoly.prepared pnts = [Point(5, 5), Point(7.5, 7.5), Point(2.5, 7.5)] covers = [True, True, False] for (pnt, c) in zip(pnts, covers...
'Testing line merge support'
def test26_line_merge(self):
ref_geoms = (fromstr('LINESTRING(1 1, 1 1, 3 3)'), fromstr('MULTILINESTRING((1 1, 3 3), (3 3, 4 2))')) ref_merged = (fromstr('LINESTRING(1 1, 3 3)'), fromstr('LINESTRING (1 1, 3 3, 4 2)')) for (geom, merged) in zip(ref_geoms, ref_merged): ...
'The base constructor for GEOS geometry objects, and may take the following inputs: * strings: - WKT - HEXEWKB (a PostGIS-specific canonical form) - GeoJSON (requires GDAL) * buffer: - WKB The `srid` keyword is used to specify the Source Reference Identifier (SRID) number for this Geometry. If not set, the SRID will b...
def __init__(self, geo_input, srid=None):
if isinstance(geo_input, basestring): if isinstance(geo_input, unicode): geo_input = geo_input.encode('ascii') wkt_m = wkt_regex.match(geo_input) if wkt_m: if wkt_m.group('srid'): srid = int(wkt_m.group('srid')) g = wkt_r().read(wkt_m.group...
'Helper routine for performing post-initialization setup.'
def _post_init(self, srid):
if (srid and isinstance(srid, int)): self.srid = srid self.__class__ = GEOS_CLASSES[self.geom_typeid] self._set_cs()
'Destroys this Geometry; in other words, frees the memory used by the GEOS C++ object.'
def __del__(self):
if self._ptr: capi.destroy_geom(self._ptr)
'Returns a clone because the copy of a GEOSGeometry may contain an invalid pointer location if the original is garbage collected.'
def __copy__(self):
return self.clone()
'The `deepcopy` routine is used by the `Node` class of django.utils.tree; thus, the protocol routine needs to be implemented to return correct copies (clones) of these GEOS objects, which use C pointers.'
def __deepcopy__(self, memodict):
return self.clone()
'WKT is used for the string representation.'
def __str__(self):
return self.wkt
'Short-hand representation because WKT may be very large.'
def __repr__(self):
return ('<%s object at %s>' % (self.geom_type, hex(addressof(self.ptr))))
'Equivalence testing, a Geometry may be compared with another Geometry or a WKT representation.'
def __eq__(self, other):
if isinstance(other, basestring): return (self.wkt == other) elif isinstance(other, GEOSGeometry): return self.equals_exact(other) else: return False
'The not equals operator.'
def __ne__(self, other):
return (not (self == other))
'Returns the union of this Geometry and the other.'
def __or__(self, other):
return self.union(other)
'Returns the intersection of this Geometry and the other.'
def __and__(self, other):
return self.intersection(other)
'Return the difference this Geometry and the other.'
def __sub__(self, other):
return self.difference(other)
'Return the symmetric difference of this Geometry and the other.'
def __xor__(self, other):
return self.sym_difference(other)
'Returns True if this Geometry has a coordinate sequence, False if not.'
@property def has_cs(self):
if isinstance(self, (Point, LineString, LinearRing)): return True else: return False
'Sets the coordinate sequence for this Geometry.'
def _set_cs(self):
if self.has_cs: self._cs = GEOSCoordSeq(capi.get_cs(self.ptr), self.hasz) else: self._cs = None
'Returns a clone of the coordinate sequence for this Geometry.'
@property def coord_seq(self):
if self.has_cs: return self._cs.clone()
'Returns a string representing the Geometry type, e.g. \'Polygon\''
@property def geom_type(self):
return capi.geos_type(self.ptr)
'Returns an integer representing the Geometry type.'
@property def geom_typeid(self):
return capi.geos_typeid(self.ptr)
'Returns the number of geometries in the Geometry.'
@property def num_geom(self):
return capi.get_num_geoms(self.ptr)
'Returns the number of coordinates in the Geometry.'
@property def num_coords(self):
return capi.get_num_coords(self.ptr)
'Returns the number points, or coordinates, in the Geometry.'
@property def num_points(self):
return self.num_coords
'Returns the dimension of this Geometry (0=point, 1=line, 2=surface).'
@property def dims(self):
return capi.get_dims(self.ptr)