desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Testing the combination of two GeoQuerySets. See #10807.'
def test10_combine(self):
buf1 = City.objects.get(name='Aurora').location.point.buffer(0.1) buf2 = City.objects.get(name='Kecksburg').location.point.buffer(0.1) qs1 = City.objects.filter(location__point__within=buf1) qs2 = City.objects.filter(location__point__within=buf2) combined = (qs1 | qs2) names = [c.name for c in c...
'Ensuring GeoQuery objects are unpickled correctly. See #10839.'
def test11_geoquery_pickle(self):
import pickle from django.contrib.gis.db.models.sql import GeoQuery qs = City.objects.all() q_str = pickle.dumps(qs.query) q = pickle.loads(q_str) self.assertEqual(GeoQuery, q.__class__)
'Testing `Count` aggregate use with the `GeoManager` on geo-fields.'
@no_oracle def test12a_count(self):
dallas = City.objects.get(name='Dallas') loc = Location.objects.annotate(num_cities=Count('city')).get(id=dallas.location.id) self.assertEqual(2, loc.num_cities)
'Testing `Count` aggregate use with the `GeoManager` on non geo-fields. See #11087.'
def test12b_count(self):
qs = Author.objects.annotate(num_books=Count('books')).filter(num_books__gt=1) vqs = Author.objects.values('name').annotate(num_books=Count('books')).filter(num_books__gt=1) self.assertEqual(1, len(qs)) self.assertEqual(3, qs[0].num_books) self.assertEqual(1, len(vqs)) self.assertEqual(3, vqs[0]...
'Testing `Count` aggregate with `.values()`. See #15305.'
def test13c_count(self):
qs = Location.objects.filter(id=5).annotate(num_cities=Count('city')).values('id', 'point', 'num_cities') self.assertEqual(1, len(qs)) self.assertEqual(2, qs[0]['num_cities']) self.assertTrue(isinstance(qs[0]['point'], GEOSGeometry))
'Testing `select_related` on a nullable ForeignKey via `GeoManager`. See #11381.'
@no_oracle def test13_select_related_null_fk(self):
no_author = Book.objects.create(title='Without Author') b = Book.objects.select_related('author').get(title='Without Author') self.assertEqual(None, b.author)
'Testing the `collect` GeoQuerySet method and `Collect` aggregate.'
@no_mysql @no_oracle @no_spatialite def test14_collect(self):
ref_geom = GEOSGeometry('MULTIPOINT(-97.516111 33.058333,-96.801611 32.782057,-95.363151 29.763374,-96.801611 32.782057)') c1 = City.objects.filter(state='TX').collect(field_name='location__point') c2 = City.objects.filter(state='TX').aggregate(Collect('location__point'))['location__point__colle...
'Testing doing select_related on the related name manager of a unique FK. See #13934.'
def test15_invalid_select_related(self):
qs = Article.objects.select_related('author__article') sql = str(qs.query)
'Ensure annotated date querysets work if spatial backend is used. See #14648.'
def test16_annotated_date_queryset(self):
birth_years = [dt.year for dt in list(Author.objects.annotate(num_books=Count('books')).dates('dob', 'year'))] birth_years.sort() self.assertEqual([1950, 1974], birth_years)
'Testing GeometryField initialization with defaults.'
def test00_init(self):
fld = forms.GeometryField() for bad_default in ('blah', 3, 'FoO', None, 0): self.assertRaises(ValidationError, fld.clean, bad_default)
'Testing GeometryField with a SRID set.'
def test01_srid(self):
fld = forms.GeometryField(srid=4326) geom = fld.clean('POINT(5 23)') self.assertEqual(4326, geom.srid) fld = forms.GeometryField(srid=32140) tol = 1e-07 xform_geom = GEOSGeometry('POINT (951640.547328465 4219369.26171664)', srid=32140) cleaned_geom = fld.clean('SRID=4326;POINT (-...
'Testing GeometryField\'s handling of null (None) geometries.'
def test02_null(self):
fld = forms.GeometryField() self.assertRaises(forms.ValidationError, fld.clean, None) fld = forms.GeometryField(required=False, null=False) self.assertRaises(forms.ValidationError, fld.clean, None) fld = forms.GeometryField(required=False) self.assertEqual(None, fld.clean(None))
'Testing GeometryField\'s handling of different geometry types.'
def test03_geom_type(self):
fld = forms.GeometryField() for wkt in ('POINT(5 23)', 'MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 'LINESTRING(0 0, 1 1)'): self.assertEqual(GEOSGeometry(wkt), fld.clean(wkt)) pnt_fld = forms.GeometryField(geom_type='POINT') self.assertEqual(GEOSGeometry('...
'Validates that the input value can be converted to a Geometry object (which is returned). A ValidationError is raised if the value cannot be instantiated as a Geometry.'
def clean(self, value):
if (not value): if (self.null and (not self.required)): return None else: raise forms.ValidationError(self.error_messages['no_geom']) try: geom = GEOSGeometry(value) except: raise forms.ValidationError(self.error_messages['invalid_geom']) if ((str(...
'Builds the map options hash for the OpenLayers template.'
def map_options(self):
def ol_bounds(extent): return ('new OpenLayers.Bounds(%s)' % str(extent)) def ol_projection(srid): return ('new OpenLayers.Projection("EPSG:%s")' % srid) map_types = [('srid', 'projection', 'srid'), ('display_srid', 'displayProjection', 'srid'), ('units', 'units', str), ('max_resolutio...
'Injects OpenLayers JavaScript into the admin.'
@property def media(self):
media = super(GeoModelAdmin, self).media media.add_js([self.openlayers_url]) media.add_js(self.extra_js) return media
'Overloaded from ModelAdmin so that an OpenLayersWidget is used for viewing/editing GeometryFields.'
def formfield_for_dbfield(self, db_field, **kwargs):
if isinstance(db_field, models.GeometryField): request = kwargs.pop('request', None) kwargs['widget'] = self.get_map_widget(db_field) return db_field.formfield(**kwargs) else: return super(GeoModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
'Returns a subclass of the OpenLayersWidget (or whatever was specified in the `widget` attribute) using the settings from the attributes set in this class.'
def get_map_widget(self, db_field):
is_collection = (db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION')) if is_collection: if (db_field.geom_type == 'GEOMETRYCOLLECTION'): collection_type = 'Any' else: collection_type = OGRGeomType(db_field.geom_type.replace('MULTI...
'Initializes on an exterior ring and a sequence of holes (both instances may be either LinearRing instances, or a tuple/list that may be constructed into a LinearRing). Examples of initialization, where shell, hole1, and hole2 are valid LinearRing geometries: >>> poly = Polygon(shell, hole1, hole2) >>> poly = Polygon(s...
def __init__(self, *args, **kwargs):
if (not args): raise TypeError('Must provide at least one LinearRing, or a tuple, to initialize a Polygon.') ext_ring = args[0] init_holes = args[1:] n_holes = len(init_holes) if ((n_holes == 1) and isinstance(init_holes[0], (tuple, list))): if (le...
'Iterates over each ring in the polygon.'
def __iter__(self):
for i in xrange(len(self)): (yield self[i])
'Returns the number of rings in this Polygon.'
def __len__(self):
return (self.num_interior_rings + 1)
'Constructs a Polygon from a bounding box (4-tuple).'
@classmethod def from_bbox(cls, bbox):
(x0, y0, x1, y1) = bbox return GEOSGeometry(('POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' % (x0, y0, x0, y1, x1, y1, x1, y0, x0, y0)))
'Helper routine for trying to construct a ring from the given parameter.'
def _construct_ring(self, param, msg='Parameter must be a sequence of LinearRings or objects that can initialize to LinearRings'):
if isinstance(param, LinearRing): return param try: ring = LinearRing(param) return ring except TypeError: raise TypeError(msg)
'Returns the ring at the specified index. The first index, 0, will always return the exterior ring. Indices > 0 will return the interior ring at the given index (e.g., poly[1] and poly[2] would return the first and second interior ring, respectively). CAREFUL: Internal/External are not the same as Interior/Exterior! ...
def _get_single_internal(self, index):
if (index == 0): return capi.get_extring(self.ptr) else: return capi.get_intring(self.ptr, (index - 1))
'Returns the number of interior rings.'
@property def num_interior_rings(self):
return capi.get_nrings(self.ptr)
'Gets the exterior ring of the Polygon.'
def _get_ext_ring(self):
return self[0]
'Sets the exterior ring of the Polygon.'
def _set_ext_ring(self, ring):
self[0] = ring
'Gets the tuple for each ring in this Polygon.'
@property def tuple(self):
return tuple([self[i].tuple for i in xrange(len(self))])
'Returns the KML representation of this Polygon.'
@property def kml(self):
inner_kml = ''.join([('<innerBoundaryIs>%s</innerBoundaryIs>' % self[(i + 1)].kml) for i in xrange(self.num_interior_rings)]) return ('<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>' % (self[0].kml, inner_kml))
'Initializes from a GEOS pointer.'
def __init__(self, ptr, z=False):
if (not isinstance(ptr, CS_PTR)): raise TypeError('Coordinate sequence should initialize with a CS_PTR.') self._ptr = ptr self._z = z
'Iterates over each point in the coordinate sequence.'
def __iter__(self):
for i in xrange(self.size): (yield self[i])
'Returns the number of points in the coordinate sequence.'
def __len__(self):
return int(self.size)
'Returns the string representation of the coordinate sequence.'
def __str__(self):
return str(self.tuple)
'Returns the coordinate sequence value at the given index.'
def __getitem__(self, index):
coords = [self.getX(index), self.getY(index)] if ((self.dims == 3) and self._z): coords.append(self.getZ(index)) return tuple(coords)
'Sets the coordinate sequence value at the given index.'
def __setitem__(self, index, value):
if isinstance(value, (list, tuple)): pass elif (numpy and isinstance(value, numpy.ndarray)): pass else: raise TypeError('Must set coordinate with a sequence (list, tuple, or numpy array).') if ((self.dims == 3) and self._z): n_args = 3 ...
'Checks the given index.'
def _checkindex(self, index):
sz = self.size if ((sz < 1) or (index < 0) or (index >= sz)): raise GEOSIndexError(('invalid GEOS Geometry index: %s' % str(index)))
'Checks the given dimension.'
def _checkdim(self, dim):
if ((dim < 0) or (dim > 2)): raise GEOSException(('invalid ordinate dimension "%d"' % dim))
'Returns the value for the given dimension and index.'
def getOrdinate(self, dimension, index):
self._checkindex(index) self._checkdim(dimension) return capi.cs_getordinate(self.ptr, index, dimension, byref(c_double()))
'Sets the value for the given dimension and index.'
def setOrdinate(self, dimension, index, value):
self._checkindex(index) self._checkdim(dimension) capi.cs_setordinate(self.ptr, index, dimension, value)
'Get the X value at the index.'
def getX(self, index):
return self.getOrdinate(0, index)
'Set X with the value at the given index.'
def setX(self, index, value):
self.setOrdinate(0, index, value)
'Get the Y value at the given index.'
def getY(self, index):
return self.getOrdinate(1, index)
'Set Y with the value at the given index.'
def setY(self, index, value):
self.setOrdinate(1, index, value)
'Get Z with the value at the given index.'
def getZ(self, index):
return self.getOrdinate(2, index)
'Set Z with the value at the given index.'
def setZ(self, index, value):
self.setOrdinate(2, index, value)
'Returns the size of this coordinate sequence.'
@property def size(self):
return capi.cs_getsize(self.ptr, byref(c_uint()))
'Returns the dimensions of this coordinate sequence.'
@property def dims(self):
return capi.cs_getdims(self.ptr, byref(c_uint()))
'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):
srids = ((-1), 32140) for srid in srids: 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...
'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...