mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #24207 -- Added 25D-type geometry field support to ogrinspect
Thanks Michael Diener for the report and sample data, and Tim Graham for the review.
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.dbf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.dbf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										1
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.prj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.prj
									
									
									
									
									
										Normal file
									
								
							| @@ -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]] | ||||
							
								
								
									
										
											BIN
										
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.shp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.shp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.shx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/gis_tests/data/gas_lines/gas_leitung.shx
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -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') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user