MCPcopy
hub / github.com/django/django / test05_geography_layermapping

Method test05_geography_layermapping

tests/gis_tests/geogapp/tests.py:85–115  ·  view source on GitHub ↗

Testing LayerMapping support on models with geography fields.

(self)

Source from the content-addressed store, hash-verified

83 self.assertIn(f"{point_field} ~=", ctx.captured_queries[0]["sql"])
84
85 def test05_geography_layermapping(self):
86 "Testing LayerMapping support on models with geography fields."
87 # There is a similar test in `layermap` that uses the same data set,
88 # but the County model here is a bit different.
89 from django.contrib.gis.utils import LayerMapping
90
91 # Getting the shapefile and mapping dictionary.
92 shp_path = os.path.realpath(
93 os.path.join(os.path.dirname(__file__), "..", "data")
94 )
95 co_shp = os.path.join(shp_path, "counties", "counties.shp")
96 co_mapping = {
97 "name": "Name",
98 "state": "State",
99 "mpoly": "MULTIPOLYGON",
100 }
101 # Reference county names, number of polygons, and state names.
102 names = ["Bexar", "Galveston", "Harris", "Honolulu", "Pueblo"]
103 num_polys = [1, 2, 1, 19, 1] # Number of polygons for each.
104 st_names = ["Texas", "Texas", "Texas", "Hawaii", "Colorado"]
105
106 lm = LayerMapping(County, co_shp, co_mapping, source_srs=4269, unique="name")
107 lm.save(silent=True, strict=True)
108
109 for c, name, num_poly, state in zip(
110 County.objects.order_by("name"), names, num_polys, st_names
111 ):
112 self.assertEqual(4326, c.mpoly.srid)
113 self.assertEqual(num_poly, len(c.mpoly))
114 self.assertEqual(name, c.name)
115 self.assertEqual(state, c.state)
116
117
118class GeographyFunctionTests(FuncTestMixin, TestCase):

Callers

nothing calls this directly

Calls 4

saveMethod · 0.95
LayerMappingClass · 0.90
order_byMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected