diff --git a/django/contrib/gis/gdal/geomtype.py b/django/contrib/gis/gdal/geomtype.py index abb184e2f9..0c672e4227 100644 --- a/django/contrib/gis/gdal/geomtype.py +++ b/django/contrib/gis/gdal/geomtype.py @@ -85,3 +85,11 @@ class OGRGeomType(object): elif s == 'Unknown': s = 'Geometry' return s + 'Field' + + def to_multi(self): + """ + Transform Point, LineString, Polygon, and their 25D equivalents + to their Multi... counterpart. + """ + if self.name.startswith(('Point', 'LineString', 'Polygon')): + self.num += 3 diff --git a/django/contrib/gis/utils/ogrinspect.py b/django/contrib/gis/utils/ogrinspect.py index 9c9a4c7f8c..c4697fe242 100644 --- a/django/contrib/gis/utils/ogrinspect.py +++ b/django/contrib/gis/utils/ogrinspect.py @@ -43,11 +43,9 @@ def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False): mfield += 'field' _mapping[mfield] = field gtype = data_source[layer_key].geom_type - if multi_geom and gtype.num in (1, 2, 3): - prefix = 'MULTI' - else: - prefix = '' - _mapping[geom_name] = prefix + str(gtype).upper() + if multi_geom: + gtype.to_multi() + _mapping[geom_name] = str(gtype).upper() return _mapping @@ -210,10 +208,9 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non # TODO: Autodetection of multigeometry types (see #7218). gtype = layer.geom_type - if multi_geom and gtype.num in (1, 2, 3): - geom_field = 'Multi%s' % gtype.django - else: - geom_field = gtype.django + if multi_geom: + gtype.to_multi() + geom_field = gtype.django # Setting up the SRID keyword string. if srid is None: diff --git a/tests/gis_tests/data/gas_lines/gas_leitung.dbf b/tests/gis_tests/data/gas_lines/gas_leitung.dbf new file mode 100644 index 0000000000..6d660b9fe2 Binary files /dev/null and b/tests/gis_tests/data/gas_lines/gas_leitung.dbf differ diff --git a/tests/gis_tests/data/gas_lines/gas_leitung.prj b/tests/gis_tests/data/gas_lines/gas_leitung.prj new file mode 100644 index 0000000000..d9a43f4357 --- /dev/null +++ b/tests/gis_tests/data/gas_lines/gas_leitung.prj @@ -0,0 +1 @@ +PROJCS["MGI_Ferro_Austria_GK_East",GEOGCS["GCS_MGI_Ferro",DATUM["D_MGI",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Ferro",-17.66666666666667],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",-5000000.0],PARAMETER["Central_Meridian",34.0],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/tests/gis_tests/data/gas_lines/gas_leitung.shp b/tests/gis_tests/data/gas_lines/gas_leitung.shp new file mode 100644 index 0000000000..6eb9df876a Binary files /dev/null and b/tests/gis_tests/data/gas_lines/gas_leitung.shp differ diff --git a/tests/gis_tests/data/gas_lines/gas_leitung.shx b/tests/gis_tests/data/gas_lines/gas_leitung.shx new file mode 100644 index 0000000000..273a6c91ef Binary files /dev/null and b/tests/gis_tests/data/gas_lines/gas_leitung.shx differ diff --git a/tests/gis_tests/inspectapp/tests.py b/tests/gis_tests/inspectapp/tests.py index f13390aa19..ca2dce72de 100644 --- a/tests/gis_tests/inspectapp/tests.py +++ b/tests/gis_tests/inspectapp/tests.py @@ -91,6 +91,10 @@ class OGRInspectTest(TestCase): shp_file = os.path.join(TEST_DATA, 'test_poly', 'test_poly.shp') model_def = ogrinspect(shp_file, 'MyModel', multi_geom=True) self.assertIn('geom = models.MultiPolygonField(srid=-1)', model_def) + # Same test with a 25D-type geometry field + shp_file = os.path.join(TEST_DATA, 'gas_lines', 'gas_leitung.shp') + model_def = ogrinspect(shp_file, 'MyModel', multi_geom=True) + self.assertIn('geom = models.MultiLineStringField(srid=-1)', model_def) def test_date_field(self): shp_file = os.path.join(TEST_DATA, 'cities', 'cities.shp')