desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Testing the `distance` GeoQuerySet method on geodetic coordnate systems.'
| @no_spatialite
def test03b_distance_method(self):
| if oracle:
tol = 2
else:
tol = 5
ls = LineString(((150.902, (-34.4245)), (150.87, (-34.5789))))
if (oracle or connection.ops.geography):
distances = [1120954.92533513, 140575.720018241, 640396.662906304, 60580.9693849269, 972807.955955075, 568451.8357838, 40435.4335201384, 0, 682... |
'Testing the `distance` GeoQuerySet method used with `transform` on a geographic field.'
| @no_oracle
def test03c_distance_method(self):
| if (not connection.ops.geography):
self.assertRaises(ValueError, CensusZipcode.objects.distance, self.stx_pnt)
z = SouthTexasZipcode.objects.get(name='77005')
dists_m = [3553.30384972258, 1243.18391525602, 2186.15439472242]
buf1 = z.poly.centroid.buffer(100)
buf2 = buf1.transform(4269, clone... |
'Testing the `distance_lt`, `distance_gt`, `distance_lte`, and `distance_gte` lookup types.'
| def test04_distance_lookups(self):
| qs1 = SouthTexasCity.objects.filter(point__distance_gte=(self.stx_pnt, D(km=7))).filter(point__distance_lte=(self.stx_pnt, D(km=20)))
if (spatialite or oracle):
dist_qs = (qs1,)
else:
qs2 = SouthTexasCityFt.objects.filter(point__distance_gte=(self.stx_pnt, D(km=7))).filter(point__distance_lt... |
'Testing distance lookups on geodetic coordinate systems.'
| def test05_geodetic_distance_lookups(self):
| line = GEOSGeometry('LINESTRING(144.9630 -37.8143,151.2607 -33.8870)', 4326)
dist_qs = AustraliaCity.objects.filter(point__distance_lte=(line, D(km=100)))
if (oracle or connection.ops.geography):
self.assertEqual(9, dist_qs.count())
self.assertEqual(['Batemans Bay', 'Canberra', 'Hil... |
'Testing the `area` GeoQuerySet method.'
| def test06_area(self):
| area_sq_m = [5437908.90234375, 10183031.4389648, 11254471.0073242, 9881708.91772461]
tol = 2
for (i, z) in enumerate(SouthTexasZipcode.objects.area()):
self.assertAlmostEqual(area_sq_m[i], z.area.sq_m, tol)
|
'Testing the `length` GeoQuerySet method.'
| def test07_length(self):
| len_m1 = 473504.769553813
len_m2 = 4617.668
if spatialite:
self.assertRaises(ValueError, Interstate.objects.length)
else:
qs = Interstate.objects.length()
if oracle:
tol = 2
else:
tol = 5
self.assertAlmostEqual(len_m1, qs[0].length.m, tol)
... |
'Testing the `perimeter` GeoQuerySet method.'
| @no_spatialite
def test08_perimeter(self):
| perim_m = [18404.3550889361, 15627.2108551001, 20632.5588368978, 17094.5996143697]
if oracle:
tol = 2
else:
tol = 7
for (i, z) in enumerate(SouthTexasZipcode.objects.perimeter()):
self.assertAlmostEqual(perim_m[i], z.perimeter.m, tol)
for (i, c) in enumerate(SouthTexasCity.ob... |
'Testing the measurement GeoQuerySet methods on fields with NULL values.'
| def test09_measurement_null_fields(self):
| SouthTexasZipcode.objects.create(name='78212')
htown = SouthTexasCity.objects.get(name='Downtown Houston')
z = SouthTexasZipcode.objects.distance(htown.point).area().get(name='78212')
self.assertEqual(None, z.distance)
self.assertEqual(None, z.area)
|
'Test the creation of 3D models.'
| def test01_3d(self):
| for (name, pnt_data) in city_data:
(x, y, z) = pnt_data
pnt = Point(x, y, z, srid=4326)
City3D.objects.create(name=name, point=pnt)
city = City3D.objects.get(name=name)
self.assertTrue(city.point.hasz)
self.assertEqual(z, city.point.z)
for (name, line, exp_z) in i... |
'Testing LayerMapping on 3D models.'
| def test01a_3d_layermapping(self):
| from models import Point2D, Point3D
point_mapping = {'point': 'POINT'}
mpoint_mapping = {'mpoint': 'MULTIPOINT'}
lm = LayerMapping(Point2D, vrt_file, point_mapping, transform=False)
lm.save()
self.assertEqual(3, Point2D.objects.count())
self.assertRaises(LayerMapError, LayerMapping, Point3D,... |
'Test GeoQuerySet.kml() with Z values.'
| def test02a_kml(self):
| h = City3D.objects.kml(precision=6).get(name='Houston')
ref_kml_regex = re.compile('^<Point><coordinates>-95.363\\d+,29.763\\d+,18</coordinates></Point>$')
self.assertTrue(ref_kml_regex.match(h.kml))
|
'Test GeoQuerySet.geojson() with Z values.'
| def test02b_geojson(self):
| h = City3D.objects.geojson(precision=6).get(name='Houston')
ref_json_regex = re.compile('^{"type":"Point","coordinates":\\[-95.363151,29.763374,18(\\.0+)?\\]}$')
self.assertTrue(ref_json_regex.match(h.geojson))
|
'Testing the Union aggregate of 3D models.'
| def test03a_union(self):
| ref_ewkt = 'SRID=4326;MULTIPOINT(-123.305196 48.462611 15,-104.609252 38.255001 1433,-97.521157 34.464642 380,-96.801611 32.782057 147,-95.363151 29.763374 18,-95.23506 38.971823 251,-87.650175 41.850385 181,174.783117 -41.315268 14)'
ref_union = GEOSGeometry(ref_... |
'Testing the Extent3D aggregate for 3D models.'
| def test03b_extent(self):
| ref_extent3d = ((-123.305196), (-41.315268), 14, 174.783117, 48.462611, 1433)
extent1 = City3D.objects.aggregate(Extent3D('point'))['point__extent3d']
extent2 = City3D.objects.extent3d()
def check_extent3d(extent3d, tol=6):
for (ref_val, ext_val) in zip(ref_extent3d, extent3d):
self.... |
'Testing GeoQuerySet.perimeter() on 3D fields.'
| def test04_perimeter(self):
| ref_perim_3d = 76859.2620451
ref_perim_2d = 76859.2577803
tol = 6
self.assertAlmostEqual(ref_perim_2d, Polygon2D.objects.perimeter().get(name='2D BBox').perimeter.m, tol)
self.assertAlmostEqual(ref_perim_3d, Polygon3D.objects.perimeter().get(name='3D BBox').perimeter.m, tol)
|
'Testing GeoQuerySet.length() on 3D fields.'
| def test05_length(self):
| tol = 3
ref_length_2d = 4368.1721949481
ref_length_3d = 4368.62547052088
self.assertAlmostEqual(ref_length_2d, Interstate2D.objects.length().get(name='I-45').length.m, tol)
self.assertAlmostEqual(ref_length_3d, Interstate3D.objects.length().get(name='I-45').length.m, tol)
ref_length_2d = 4367.71... |
'Testing GeoQuerySet.scale() on Z values.'
| def test06_scale(self):
| zscales = ((-3), 4, 23)
for zscale in zscales:
for city in City3D.objects.scale(1.0, 1.0, zscale):
self.assertEqual((city_dict[city.name][2] * zscale), city.scale.z)
|
'Testing GeoQuerySet.translate() on Z values.'
| def test07_translate(self):
| ztranslations = (5.23, 23, (-17))
for ztrans in ztranslations:
for city in City3D.objects.translate(0, 0, ztrans):
self.assertEqual((city_dict[city.name][2] + ztrans), city.translate.z)
|
'Testing GeoIP initialization.'
| def test01_init(self):
| g1 = GeoIP()
path = settings.GEOIP_PATH
g2 = GeoIP(path, 0)
g3 = GeoIP.open(path, 0)
for g in (g1, g2, g3):
self.assertEqual(True, bool(g._country))
self.assertEqual(True, bool(g._city))
city = os.path.join(path, 'GeoLiteCity.dat')
cntry = os.path.join(path, 'GeoIP.dat')
... |
'Testing GeoIP query parameter checking.'
| def test02_bad_query(self):
| cntry_g = GeoIP(city='<foo>')
self.assertRaises(GeoIPException, cntry_g.city, 'google.com')
self.assertRaises(GeoIPException, cntry_g.coords, 'yahoo.com')
self.assertRaises(TypeError, cntry_g.country_code, 17)
self.assertRaises(TypeError, cntry_g.country_name, GeoIP)
|
'Testing GeoIP country querying methods.'
| def test03_country(self):
| g = GeoIP(city='<foo>')
fqdn = 'www.google.com'
addr = '12.215.42.19'
for query in (fqdn, addr):
for func in (g.country_code, g.country_code_by_addr, g.country_code_by_name):
self.assertEqual('US', func(query))
for func in (g.country_name, g.country_name_by_addr, g.country_na... |
'Testing GeoIP city querying methods.'
| def test04_city(self):
| g = GeoIP(country='<foo>')
addr = '130.80.29.3'
fqdn = 'chron.com'
for query in (fqdn, addr):
for func in (g.country_code, g.country_code_by_addr, g.country_code_by_name):
self.assertEqual('US', func(query))
for func in (g.country_name, g.country_name_by_addr, g.country_name_... |
'Ensure geography features loaded properly.'
| def test01_fixture_load(self):
| self.assertEqual(8, City.objects.count())
|
'Testing GeoQuerySet distance lookup support on non-point geography fields.'
| def test02_distance_lookup(self):
| z = Zipcode.objects.get(code='77002')
cities1 = list(City.objects.filter(point__distance_lte=(z.poly, D(mi=500))).order_by('name').values_list('name', flat=True))
cities2 = list(City.objects.filter(point__dwithin=(z.poly, D(mi=500))).order_by('name').values_list('name', flat=True))
for cities in [cities... |
'Testing GeoQuerySet.distance() support on non-point geography fields.'
| def test03_distance_method(self):
| htown = City.objects.get(name='Houston')
qs = Zipcode.objects.distance(htown.point)
|
'Ensuring exceptions are raised for operators & functions invalid on geography fields.'
| def test04_invalid_operators_functions(self):
| z = Zipcode.objects.get(code='77002')
self.assertRaises(ValueError, City.objects.filter(point__within=z.poly).count)
self.assertRaises(ValueError, City.objects.filter(point__contained=z.poly).count)
htown = City.objects.get(name='Houston')
self.assertRaises(ValueError, City.objects.get, point__exact... |
'Testing LayerMapping support on models with geography fields.'
| def test05_geography_layermapping(self):
| if (not gdal.HAS_GDAL):
return
from django.contrib.gis.utils import LayerMapping
shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
co_mapping = {'name': 'Name', 'state': 'State', 'mpoly': 'MULTIPOLYG... |
'Testing that Area calculations work on geography columns.'
| def test06_geography_area(self):
| from django.contrib.gis.measure import A
ref_area = 5439084.70637573
tol = 5
z = Zipcode.objects.area().get(code='77002')
self.assertAlmostEqual(z.area.sq_m, ref_area, tol)
|
'Testing retrieval of SpatialRefSys model objects.'
| @no_mysql
def test01_retrieve(self):
| for sd in test_srs:
srs = SpatialRefSys.objects.get(srid=sd['srid'])
self.assertEqual(sd['srid'], srs.srid)
(auth_name, oracle_flag) = sd['auth_name']
if (postgis or (oracle and oracle_flag)):
self.assertEqual(True, srs.auth_name.startswith(auth_name))
self.assert... |
'Testing getting OSR objects from SpatialRefSys model objects.'
| @no_mysql
def test02_osr(self):
| for sd in test_srs:
sr = SpatialRefSys.objects.get(srid=sd['srid'])
self.assertEqual(True, sr.spheroid.startswith(sd['spheroid']))
self.assertEqual(sd['geographic'], sr.geographic)
self.assertEqual(sd['projected'], sr.projected)
if (not (spatialite and (not sd['spatialite']))... |
'Testing the ellipsoid property.'
| @no_mysql
def test03_ellipsoid(self):
| for sd in test_srs:
ellps1 = sd['ellipsoid']
prec = sd['eprec']
srs = SpatialRefSys.objects.get(srid=sd['srid'])
ellps2 = srs.ellipsoid
for i in range(3):
param1 = ellps1[i]
param2 = ellps2[i]
self.assertAlmostEqual(ellps1[i], ellps2[i], pr... |
'Taken from regressiontests/syndication/tests.py.'
| def assertChildNodes(self, elem, expected):
| actual = set([n.nodeName for n in elem.childNodes])
expected = set(expected)
self.assertEqual(actual, expected)
|
'Tests geographic feeds using GeoRSS over RSSv2.'
| def test_geofeed_rss(self):
| doc1 = minidom.parseString(self.client.get('/feeds/rss1/').content)
doc2 = minidom.parseString(self.client.get('/feeds/rss2/').content)
(feed1, feed2) = (doc1.firstChild, doc2.firstChild)
self.assertChildNodes(feed2.getElementsByTagName('channel')[0], ['title', 'link', 'description', 'language', 'lastBu... |
'Testing geographic feeds using GeoRSS over Atom.'
| def test_geofeed_atom(self):
| doc1 = minidom.parseString(self.client.get('/feeds/atom1/').content)
doc2 = minidom.parseString(self.client.get('/feeds/atom2/').content)
(feed1, feed2) = (doc1.firstChild, doc2.firstChild)
self.assertChildNodes(feed2, ['title', 'link', 'id', 'updated', 'entry', 'georss:box'])
for feed in [feed1, fe... |
'Testing geographic feeds using W3C Geo.'
| def test_geofeed_w3c(self):
| doc = minidom.parseString(self.client.get('/feeds/w3cgeo1/').content)
feed = doc.firstChild
self.assertEqual(feed.getAttribute(u'xmlns:geo'), u'http://www.w3.org/2003/01/geo/wgs84_pos#')
chan = feed.getElementsByTagName('channel')[0]
items = chan.getElementsByTagName('item')
self.assertEqual(len... |
'Taken from regressiontests/syndication/tests.py.'
| def assertChildNodes(self, elem, expected):
| actual = set([n.nodeName for n in elem.childNodes])
expected = set(expected)
self.assertEqual(actual, expected)
|
'Tests geographic sitemap index.'
| def test_geositemap_index(self):
| doc = minidom.parseString(self.client.get('/sitemap.xml').content)
index = doc.firstChild
self.assertEqual(index.getAttribute(u'xmlns'), u'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(3, len(index.getElementsByTagName('sitemap')))
|
'Tests KML/KMZ geographic sitemaps.'
| def test_geositemap_kml(self):
| for kml_type in ('kml', 'kmz'):
doc = minidom.parseString(self.client.get(('/sitemaps/%s.xml' % kml_type)).content)
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute(u'xmlns'), u'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(urlset.getAttribute(u'xmlns:geo... |
'Tests GeoRSS geographic sitemaps.'
| def test_geositemap_georss(self):
| from feeds import feed_dict
doc = minidom.parseString(self.client.get('/sitemaps/georss.xml').content)
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute(u'xmlns'), u'http://www.sitemaps.org/schemas/sitemap/0.9')
self.assertEqual(urlset.getAttribute(u'xmlns:geo'), u'http://www.google.com/g... |
'Testing geographic model initialization from fixtures.'
| def test01_fixtures(self):
| self.assertEqual(2, Country.objects.count())
self.assertEqual(8, City.objects.count())
self.assertEqual(2, State.objects.count())
|
'Testing Lazy-Geometry support (using the GeometryProxy).'
| def test02_proxy(self):
| pnt = Point(0, 0)
nullcity = City(name='NullCity', point=pnt)
nullcity.save()
for bad in [5, 2.0, LineString((0, 0), (1, 1))]:
try:
nullcity.point = bad
except TypeError:
pass
else:
self.fail('Should throw a TypeError')
new = Point... |
'Testing KML output from the database using GeoQuerySet.kml().'
| def test03a_kml(self):
| if (not postgis):
self.assertRaises(NotImplementedError, State.objects.all().kml, field_name='poly')
return
qs = City.objects.all()
self.assertRaises(TypeError, qs.kml, 'name')
if (connection.ops.spatial_version >= (1, 3, 3)):
ref_kml = '<Point><coordinates>-104.609252,38.255001<... |
'Testing GML output from the database using GeoQuerySet.gml().'
| def test03b_gml(self):
| if (mysql or spatialite):
self.assertRaises(NotImplementedError, Country.objects.all().gml, field_name='mpoly')
return
qs = City.objects.all()
self.assertRaises(TypeError, qs.gml, field_name='name')
ptown1 = City.objects.gml(field_name='point', precision=9).get(name='Pueblo')
ptown2 ... |
'Testing GeoJSON output from the database using GeoQuerySet.geojson().'
| def test03c_geojson(self):
| if (not connection.ops.geojson):
self.assertRaises(NotImplementedError, Country.objects.all().geojson, field_name='mpoly')
return
if (connection.ops.spatial_version >= (1, 4, 0)):
pueblo_json = '{"type":"Point","coordinates":[-104.609252,38.255001]}'
houston_json = '{"type":"Poin... |
'Testing SVG output using GeoQuerySet.svg().'
| def test03d_svg(self):
| if (mysql or oracle):
self.assertRaises(NotImplementedError, City.objects.svg)
return
self.assertRaises(TypeError, City.objects.svg, precision='foo')
svg1 = 'cx="-104.609252" cy="-38.255001"'
svg2 = svg1.replace('c', '')
self.assertEqual(svg1, City.objects.svg().get(name='Pueblo')... |
'Testing the transform() GeoManager method.'
| @no_mysql
def test04_transform(self):
| htown = fromstr('POINT(1947516.83115183 6322297.06040572)', srid=3084)
ptown = fromstr('POINT(992363.390841912 481455.395105533)', srid=2774)
prec = 3
if (not oracle):
h = City.objects.transform(htown.srid).get(name='Houston')
self.assertEqual(3084, h.point.srid)
self.asser... |
'Testing the `extent` GeoQuerySet method.'
| @no_mysql
@no_spatialite
def test05_extent(self):
| expected = ((-96.8016128540039), 29.7633724212646, (-95.3631439208984), 32.78205871582)
qs = City.objects.filter(name__in=('Houston', 'Dallas'))
extent = qs.extent()
for (val, exp) in zip(extent, expected):
self.assertAlmostEqual(exp, val, 4)
|
'Testing the `make_line` GeoQuerySet method.'
| @no_mysql
@no_oracle
@no_spatialite
def test06_make_line(self):
| self.assertRaises(TypeError, State.objects.make_line)
self.assertRaises(TypeError, Country.objects.make_line)
ref_line = GEOSGeometry('LINESTRING(-95.363151 29.763374,-96.801611 32.782057,-97.521157 34.464642,174.783117 -41.315268,-104.609252 38.255001,-95.23506 38.971823,-87.650175 41.... |
'Testing the `disjoint` lookup type.'
| @no_mysql
def test09_disjoint(self):
| ptown = City.objects.get(name='Pueblo')
qs1 = City.objects.filter(point__disjoint=ptown.point)
self.assertEqual(7, qs1.count())
qs2 = State.objects.filter(poly__disjoint=ptown.point)
self.assertEqual(1, qs2.count())
self.assertEqual('Kansas', qs2[0].name)
|
'Testing the \'contained\', \'contains\', and \'bbcontains\' lookup types.'
| def test10_contains_contained(self):
| texas = Country.objects.get(name='Texas')
if (not oracle):
qs = City.objects.filter(point__contained=texas.mpoly)
self.assertEqual(3, qs.count())
cities = ['Houston', 'Dallas', 'Oklahoma City']
for c in qs:
self.assertEqual(True, (c.name in cities))
houston = C... |
'Testing automatic transform for lookups and inserts.'
| @no_mysql
def test11_lookup_insert_transform(self):
| sa_4326 = 'POINT (-98.493183 29.424170)'
wgs_pnt = fromstr(sa_4326, srid=4326)
if oracle:
nad_wkt = 'POINT (300662.034646583 5416427.45974934)'
nad_srid = 41157
else:
nad_wkt = 'POINT (1645978.362408288754523 6276356.025927528738976)'
nad_srid = 3084
... |
'Testing NULL geometry support, and the `isnull` lookup type.'
| @no_mysql
def test12_null_geometries(self):
| State.objects.create(name='Puerto Rico')
nullqs = State.objects.filter(poly__isnull=True)
validqs = State.objects.filter(poly__isnull=False)
self.assertEqual(1, len(nullqs))
self.assertEqual('Puerto Rico', nullqs[0].name)
self.assertEqual(2, len(validqs))
state_names = [s.name for s in... |
'Testing the \'left\' and \'right\' lookup types.'
| @no_mysql
@no_oracle
@no_spatialite
def test13_left_right(self):
| co_border = State.objects.get(name='Colorado').poly
ks_border = State.objects.get(name='Kansas').poly
cities = ['Houston', 'Dallas', 'Oklahoma City', 'Lawrence', 'Chicago', 'Wellington']
qs = City.objects.filter(point__right=co_border)
self.assertEqual(6, len(qs))
for c in qs:
self.as... |
'Testing the \'same_as\' and \'equals\' lookup types.'
| def test14_equals(self):
| pnt = fromstr('POINT (-95.363151 29.763374)', srid=4326)
c1 = City.objects.get(point=pnt)
c2 = City.objects.get(point__same_as=pnt)
c3 = City.objects.get(point__equals=pnt)
for c in [c1, c2, c3]:
self.assertEqual('Houston', c.name)
|
'Testing the \'relate\' lookup type.'
| @no_mysql
def test15_relate(self):
| pnt1 = fromstr('POINT (649287.0363174 4177429.4494686)', srid=2847)
pnt2 = fromstr('POINT(-98.4919715741052 29.4333344025053)', srid=4326)
self.assertRaises(ValueError, Country.objects.filter, mpoly__relate=(23, 'foo'))
for (bad_args, e) in [((pnt1, 0), ValueError), ((pnt2, 'T*T***FF*', 0), Val... |
'Testing creating a model instance and the geometry being None'
| def test16_createnull(self):
| c = City()
self.assertEqual(c.point, None)
|
'Testing the `unionagg` (aggregate union) GeoManager method.'
| @no_mysql
def test17_unionagg(self):
| tx = Country.objects.get(name='Texas').mpoly
union1 = fromstr('MULTIPOINT(-96.801611 32.782057,-95.363151 29.763374)')
union2 = fromstr('MULTIPOINT(-96.801611 32.782057,-95.363151 29.763374)')
qs = City.objects.filter(point__within=tx)
self.assertRaises(TypeError, qs.unionagg, 'name')
... |
'Testing the general GeometryField.'
| @no_spatialite
def test18_geometryfield(self):
| Feature(name='Point', geom=Point(1, 1)).save()
Feature(name='LineString', geom=LineString((0, 0), (1, 1), (5, 5))).save()
Feature(name='Polygon', geom=Polygon(LinearRing((0, 0), (0, 5), (5, 5), (5, 0), (0, 0)))).save()
Feature(name='GeometryCollection', geom=GeometryCollection(Point(2, 2), LineString((0... |
'Testing the `centroid` GeoQuerySet method.'
| @no_mysql
def test19_centroid(self):
| qs = State.objects.exclude(poly__isnull=True).centroid()
if oracle:
tol = 0.1
elif spatialite:
tol = 1e-06
else:
tol = 1e-09
for s in qs:
self.assertEqual(True, s.poly.centroid.equals_exact(s.centroid, tol))
|
'Testing the `point_on_surface` GeoQuerySet method.'
| @no_mysql
def test20_pointonsurface(self):
| if oracle:
ref = {'New Zealand': fromstr('POINT (174.616364 -36.100861)', srid=4326), 'Texas': fromstr('POINT (-103.002434 36.500397)', srid=4326)}
elif (postgis or spatialite):
ref = {'New Zealand': Country.objects.get(name='New Zealand').mpoly.point_on_surface, 'Texas': Co... |
'Testing the `scale` GeoQuerySet method.'
| @no_mysql
@no_oracle
def test21_scale(self):
| (xfac, yfac) = (2, 3)
tol = 5
qs = Country.objects.scale(xfac, yfac, model_att='scaled')
for c in qs:
for (p1, p2) in zip(c.mpoly, c.scaled):
for (r1, r2) in zip(p1, p2):
for (c1, c2) in zip(r1.coords, r2.coords):
self.assertAlmostEqual((c1[0] * xf... |
'Testing the `translate` GeoQuerySet method.'
| @no_mysql
@no_oracle
def test22_translate(self):
| (xfac, yfac) = (5, (-23))
qs = Country.objects.translate(xfac, yfac, model_att='translated')
for c in qs:
for (p1, p2) in zip(c.mpoly, c.translated):
for (r1, r2) in zip(p1, p2):
for (c1, c2) in zip(r1.coords, r2.coords):
self.assertAlmostEqual((c1[0] ... |
'Testing the `num_geom` GeoQuerySet method.'
| @no_mysql
def test23_numgeom(self):
| for c in Country.objects.num_geom():
self.assertEqual(2, c.num_geom)
for c in City.objects.filter(point__isnull=False).num_geom():
if postgis:
self.assertEqual(None, c.num_geom)
else:
self.assertEqual(1, c.num_geom)
|
'Testing the `num_points` GeoQuerySet method.'
| @no_mysql
@no_spatialite
def test24_numpoints(self):
| for c in Country.objects.num_points():
self.assertEqual(c.mpoly.num_points, c.num_points)
if (not oracle):
for c in City.objects.num_points():
self.assertEqual(1, c.num_points)
|
'Testing the `difference`, `intersection`, `sym_difference`, and `union` GeoQuerySet methods.'
| @no_mysql
def test25_geoset(self):
| geom = Point(5, 23)
tol = 1
qs = Country.objects.all().difference(geom).sym_difference(geom).union(geom)
if spatialite:
qs = qs.exclude(name='Texas')
else:
qs = qs.intersection(geom)
for c in qs:
if oracle:
pass
else:
self.assertEqual(c.mpo... |
'Test GeoQuerySet methods on inherited Geometry fields.'
| @no_mysql
def test26_inherited_geofields(self):
| mansfield = PennsylvaniaCity.objects.create(name='Mansfield', county='Tioga', point='POINT(-77.071445 41.823881)')
qs = PennsylvaniaCity.objects.transform(32128)
self.assertEqual(1, qs.count())
for pc in qs:
self.assertEqual(32128, pc.point.srid)
|
'Testing GeoQuerySet.snap_to_grid().'
| @no_mysql
@no_oracle
@no_spatialite
def test27_snap_to_grid(self):
| for bad_args in ((), range(3), range(5)):
self.assertRaises(ValueError, Country.objects.snap_to_grid, *bad_args)
for bad_args in (('1.0',), (1.0, None), tuple(map(unicode, range(4)))):
self.assertRaises(TypeError, Country.objects.snap_to_grid, *bad_args)
wkt = 'MULTIPOLYGON(((12.41580 43.... |
'Testing GeoQuerySet.reverse_geom().'
| @no_mysql
@no_spatialite
def test28_reverse(self):
| coords = [((-95.363151), 29.763374), ((-95.448601), 29.713803)]
Track.objects.create(name='Foo', line=LineString(coords))
t = Track.objects.reverse_geom().get(name='Foo')
coords.reverse()
self.assertEqual(tuple(coords), t.reverse_geom.coords)
if oracle:
self.assertRaises(TypeError, State... |
'Testing GeoQuerySet.force_rhr().'
| @no_mysql
@no_oracle
@no_spatialite
def test29_force_rhr(self):
| rings = (((0, 0), (5, 0), (0, 5), (0, 0)), ((1, 1), (1, 3), (3, 1), (1, 1)))
rhr_rings = (((0, 0), (0, 5), (5, 0), (0, 0)), ((1, 1), (3, 1), (1, 3), (1, 1)))
State.objects.create(name='Foo', poly=Polygon(*rings))
s = State.objects.force_rhr().get(name='Foo')
self.assertEqual(rhr_rings, s.force_rhr.c... |
'Testing GeoQuerySet.geohash().'
| @no_mysql
@no_oracle
@no_spatialite
def test30_geohash(self):
| if (not connection.ops.geohash):
return
ref_hash = '9vk1mfq8jx0c8e0386z6'
h1 = City.objects.geohash().get(name='Houston')
h2 = City.objects.geohash(precision=5).get(name='Houston')
self.assertEqual(ref_hash, h1.geohash)
self.assertEqual(ref_hash[:5], h2.geohash)
|
'Testing GeoQuerySet.update(), see #10411.'
| def test01_update(self):
| pnt = City.objects.get(name='Pueblo').point
bak = pnt.clone()
pnt.y += 0.005
pnt.x += 0.005
City.objects.filter(name='Pueblo').update(point=pnt)
self.assertEqual(pnt, City.objects.get(name='Pueblo').point)
City.objects.filter(name='Pueblo').update(point=bak)
self.assertEqual(bak, City.ob... |
'Testing `render_to_kmz` with non-ASCII data, see #11624.'
| def test02_kmz(self):
| name = '\xc3\x85land Islands'.decode('iso-8859-1')
places = [{'name': name, 'description': name, 'kml': '<Point><coordinates>5.0,23.0</coordinates></Point>'}]
kmz = render_to_kmz('gis/kml/placemarks.kml', {'places': places})
|
'Testing `extent` on a table with a single point, see #11827.'
| @no_spatialite
@no_mysql
def test03_extent(self):
| pnt = City.objects.get(name='Pueblo').point
ref_ext = (pnt.x, pnt.y, pnt.x, pnt.y)
extent = City.objects.filter(name='Pueblo').extent()
for (ref_val, val) in zip(ref_ext, extent):
self.assertAlmostEqual(ref_val, val, 4)
|
'Testing dates are converted properly, even on SpatiaLite, see #16408.'
| def test04_unicode_date(self):
| founded = datetime(1857, 5, 23)
mansfield = PennsylvaniaCity.objects.create(name='Mansfield', county='Tioga', point='POINT(-77.071445 41.823881)', founded=founded)
self.assertEqual(founded, PennsylvaniaCity.objects.dates('founded', 'day')[0])
|
'Testing LayerMapping initialization.'
| def test01_init(self):
| bad1 = copy(city_mapping)
bad1['foobar'] = 'FooField'
bad2 = copy(city_mapping)
bad2['name'] = 'Nombre'
bad3 = copy(city_mapping)
bad3['point'] = 'CURVE'
for bad_map in (bad1, bad2, bad3):
try:
lm = LayerMapping(City, city_shp, bad_map)
except LayerMapError:
... |
'Test LayerMapping import of a simple point shapefile.'
| def test02_simple_layermap(self):
| lm = LayerMapping(City, city_shp, city_mapping)
lm.save()
self.assertEqual(3, City.objects.count())
ds = DataSource(city_shp)
layer = ds[0]
for feat in layer:
city = City.objects.get(name=feat['Name'].value)
self.assertEqual(feat['Population'].value, city.population)
self... |
'Testing the `strict` keyword, and import of a LineString shapefile.'
| def test03_layermap_strict(self):
| try:
lm = LayerMapping(Interstate, inter_shp, inter_mapping)
lm.save(silent=True, strict=True)
except InvalidDecimal:
if mysql:
Interstate.objects.all().delete()
else:
self.fail('Should have failed on strict import with invalid decimal v... |
'Helper function for ensuring the integrity of the mapped County models.'
| def county_helper(self, county_feat=True):
| for (name, n, st) in zip(NAMES, NUMS, STATES):
c = County.objects.get(name=name)
self.assertEqual(n, len(c.mpoly))
self.assertEqual(st, c.state.name)
if county_feat:
qs = CountyFeat.objects.filter(name=name)
self.assertEqual(n, qs.count())
|
'Testing the `unique`, and `transform`, geometry collection conversion, and ForeignKey mappings.'
| def test04_layermap_unique_multigeometry_fk(self):
| try:
lm = LayerMapping(County, co_shp, co_mapping, transform=False)
lm = LayerMapping(County, co_shp, co_mapping, source_srs=4269)
lm = LayerMapping(County, co_shp, co_mapping, source_srs='NAD83')
for arg in ('name', ('name', 'mpoly')):
lm = LayerMapping(County, co_shp, c... |
'Tests the `fid_range` keyword and the `step` keyword of .save().'
| def test05_test_fid_range_step(self):
| def clear_counties():
County.objects.all().delete()
lm = LayerMapping(County, co_shp, co_mapping, transform=False, unique='name')
clear_counties()
bad_ranges = (5.0, 'foo', co_shp)
for bad in bad_ranges:
self.assertRaises(TypeError, lm.save, fid_range=bad)
fr = (3, 5)
self.as... |
'Tests LayerMapping on inherited models. See #12093.'
| def test06_model_inheritance(self):
| icity_mapping = {'name': 'Name', 'population': 'Population', 'density': 'Density', 'point': 'POINT', 'dt': 'Created'}
lm1 = LayerMapping(ICity1, city_shp, icity_mapping)
lm1.save()
lm2 = LayerMapping(ICity2, city_shp, icity_mapping)
lm2.save()
self.assertEqual(6, ICity1.objects.count())
self... |
'Tests LayerMapping on invalid geometries. See #15378.'
| def test07_invalid_layer(self):
| invalid_mapping = {'point': 'POINT'}
lm = LayerMapping(Invalid, invalid_shp, invalid_mapping, source_srs=4326)
lm.save(silent=True)
|
'Testing initialisation from valid units'
| def testInit(self):
| d = Distance(m=100)
self.assertEqual(d.m, 100)
(d1, d2, d3) = (D(m=100), D(meter=100), D(metre=100))
for d in (d1, d2, d3):
self.assertEqual(d.m, 100)
d = D(nm=100)
self.assertEqual(d.m, 185200)
(y1, y2, y3) = (D(yd=100), D(yard=100), D(Yard=100))
for d in (y1, y2, y3):
s... |
'Testing initialisation from invalid units'
| def testInitInvalid(self):
| self.assertRaises(AttributeError, D, banana=100)
|
'Testing access in different units'
| def testAccess(self):
| d = D(m=100)
self.assertEqual(d.km, 0.1)
self.assertAlmostEqual(d.ft, 328.084, 3)
|
'Testing access in invalid units'
| def testAccessInvalid(self):
| d = D(m=100)
self.failIf(hasattr(d, 'banana'))
|
'Test addition & subtraction'
| def testAddition(self):
| d1 = D(m=100)
d2 = D(m=200)
d3 = (d1 + d2)
self.assertEqual(d3.m, 300)
d3 += d1
self.assertEqual(d3.m, 400)
d4 = (d1 - d2)
self.assertEqual(d4.m, (-100))
d4 -= d1
self.assertEqual(d4.m, (-200))
try:
d5 = (d1 + 1)
except TypeError as e:
pass
else:
... |
'Test multiplication & division'
| def testMultiplication(self):
| d1 = D(m=100)
d3 = (d1 * 2)
self.assertEqual(d3.m, 200)
d3 = (2 * d1)
self.assertEqual(d3.m, 200)
d3 *= 5
self.assertEqual(d3.m, 1000)
d4 = (d1 / 2)
self.assertEqual(d4.m, 50)
d4 /= 5
self.assertEqual(d4.m, 10)
a5 = (d1 * D(m=10))
self.assertTrue(isinstance(a5, Area))... |
'Testing default units during maths'
| def testUnitConversions(self):
| d1 = D(m=100)
d2 = D(km=1)
d3 = (d1 + d2)
self.assertEqual(d3._default_unit, 'm')
d4 = (d2 + d1)
self.assertEqual(d4._default_unit, 'km')
d5 = (d1 * 2)
self.assertEqual(d5._default_unit, 'm')
d6 = (d1 / 2)
self.assertEqual(d6._default_unit, 'm')
|
'Testing comparisons'
| def testComparisons(self):
| d1 = D(m=100)
d2 = D(km=1)
d3 = D(km=0)
self.assertTrue((d2 > d1))
self.assertTrue((d1 == d1))
self.assertTrue((d1 < d2))
self.failIf(d3)
|
'Testing conversion to strings'
| def testUnitsStr(self):
| d1 = D(m=100)
d2 = D(km=3.5)
self.assertEqual(str(d1), '100.0 m')
self.assertEqual(str(d2), '3.5 km')
self.assertEqual(repr(d1), 'Distance(m=100.0)')
self.assertEqual(repr(d2), 'Distance(km=3.5)')
|
'Testing the `unit_attname` class method'
| def testUnitAttName(self):
| unit_tuple = [('Yard', 'yd'), ('Nautical Mile', 'nm'), ('German legal metre', 'german_m'), ('Indian yard', 'indian_yd'), ('Chain (Sears)', 'chain_sears'), ('Chain', 'chain')]
for (nm, att) in unit_tuple:
self.assertEqual(att, D.unit_attname(nm))
|
'Testing initialisation from valid units'
| def testInit(self):
| a = Area(sq_m=100)
self.assertEqual(a.sq_m, 100)
a = A(sq_m=100)
self.assertEqual(a.sq_m, 100)
a = A(sq_mi=100)
self.assertEqual(a.sq_m, 258998811.0336)
|
'Testing initialisation from invalid units'
| def testInitInvaliA(self):
| self.assertRaises(AttributeError, A, banana=100)
|
'Testing access in different units'
| def testAccess(self):
| a = A(sq_m=100)
self.assertEqual(a.sq_km, 0.0001)
self.assertAlmostEqual(a.sq_ft, 1076.391, 3)
|
'Testing access in invalid units'
| def testAccessInvaliA(self):
| a = A(sq_m=100)
self.failIf(hasattr(a, 'banana'))
|
'Test addition & subtraction'
| def testAddition(self):
| a1 = A(sq_m=100)
a2 = A(sq_m=200)
a3 = (a1 + a2)
self.assertEqual(a3.sq_m, 300)
a3 += a1
self.assertEqual(a3.sq_m, 400)
a4 = (a1 - a2)
self.assertEqual(a4.sq_m, (-100))
a4 -= a1
self.assertEqual(a4.sq_m, (-200))
try:
a5 = (a1 + 1)
except TypeError as e:
pa... |
'Test multiplication & division'
| def testMultiplication(self):
| a1 = A(sq_m=100)
a3 = (a1 * 2)
self.assertEqual(a3.sq_m, 200)
a3 = (2 * a1)
self.assertEqual(a3.sq_m, 200)
a3 *= 5
self.assertEqual(a3.sq_m, 1000)
a4 = (a1 / 2)
self.assertEqual(a4.sq_m, 50)
a4 /= 5
self.assertEqual(a4.sq_m, 10)
try:
a5 = (a1 * A(sq_m=1))
exce... |
'Testing default units during maths'
| def testUnitConversions(self):
| a1 = A(sq_m=100)
a2 = A(sq_km=1)
a3 = (a1 + a2)
self.assertEqual(a3._default_unit, 'sq_m')
a4 = (a2 + a1)
self.assertEqual(a4._default_unit, 'sq_km')
a5 = (a1 * 2)
self.assertEqual(a5._default_unit, 'sq_m')
a6 = (a1 / 2)
self.assertEqual(a6._default_unit, 'sq_m')
|
'Testing comparisons'
| def testComparisons(self):
| a1 = A(sq_m=100)
a2 = A(sq_km=1)
a3 = A(sq_km=0)
self.assertTrue((a2 > a1))
self.assertTrue((a1 == a1))
self.assertTrue((a1 < a2))
self.failIf(a3)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.