def test_poly_multi(self): 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_poly_multi(self): 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_poly_multi(self): 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(%s)' % self.expected_srid, 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) srid = '-1' if GDAL_VERSION < (2, 3) else '31253' self.assertIn('geom = models.MultiLineStringField(srid=%s)' % srid, model_def)
def test_poly_multi(self): 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()", 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) srid = "-1" if GDAL_VERSION < (2, 3) else "31253" self.assertIn("geom = models.MultiLineStringField(srid=%s)" % srid, model_def)
def test_time_field(self): # Only possible to test this on PostGIS at the momemnt. MySQL # complains about permissions, and SpatiaLite/Oracle are # insanely difficult to get support compiled in for in GDAL. if not connections["default"].ops.postgis: return # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: return # writing shapefules via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect(ogr_db, "Measurement", layer_key=AllOGRFields._meta.db_table, decimal=["f_decimal"]) expected = [ "# This is an auto-generated Django model module created by ogrinspect.", "from django.contrib.gis.db import models", "", "class Measurement(models.Model):", " f_decimal = models.DecimalField(max_digits=0, decimal_places=0)", " f_int = models.IntegerField()", " f_datetime = models.DateTimeField()", " f_time = models.TimeField()", " f_float = models.FloatField()", " f_char = models.CharField(max_length=10)", " f_date = models.DateField()", " geom = models.PolygonField()", " objects = models.GeoManager()", ] self.assertEqual(model_def, "\n".join(expected))
def test_time_field(self): # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: self.skipTest("Unable to setup an OGR connection to your database") try: # Writing shapefiles via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect(ogr_db, 'Measurement', layer_key=AllOGRFields._meta.db_table, decimal=['f_decimal']) except OGRException: self.skipTest("Unable to setup an OGR connection to your database") self.assertTrue(model_def.startswith( '# This is an auto-generated Django model module created by ogrinspect.\n' 'from django.contrib.gis.db import models\n' '\n' 'class Measurement(models.Model):\n' )) # The ordering of model fields might vary depending on several factors (version of GDAL, etc.) self.assertIn(' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def) self.assertIn(' f_int = models.IntegerField()', model_def) self.assertIn(' f_datetime = models.DateTimeField()', model_def) self.assertIn(' f_time = models.TimeField()', model_def) self.assertIn(' f_float = models.FloatField()', model_def) self.assertIn(' f_char = models.CharField(max_length=10)', model_def) self.assertIn(' f_date = models.DateField()', model_def) self.assertIsNotNone(re.search( r' geom = models.PolygonField\(([^\)])*\)\n' # Some backends may have srid=-1 r' objects = models.GeoManager\(\)', model_def))
def test_time_field(self): # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: self.skipTest("Unable to setup an OGR connection to your database") try: # Writing shapefiles via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect(ogr_db, 'Measurement', layer_key=AllOGRFields._meta.db_table, decimal=['f_decimal']) except GDALException: self.skipTest("Unable to setup an OGR connection to your database") self.assertTrue(model_def.startswith( '# This is an auto-generated Django model module created by ogrinspect.\n' 'from django.contrib.gis.db import models\n' '\n' 'class Measurement(models.Model):\n' )) # The ordering of model fields might vary depending on several factors (version of GDAL, etc.) self.assertIn(' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def) self.assertIn(' f_int = models.IntegerField()', model_def) self.assertIn(' f_datetime = models.DateTimeField()', model_def) self.assertIn(' f_time = models.TimeField()', model_def) self.assertIn(' f_float = models.FloatField()', model_def) self.assertIn(' f_char = models.CharField(max_length=10)', model_def) self.assertIn(' f_date = models.DateField()', model_def) # Some backends may have srid=-1 self.assertIsNotNone(re.search(r' geom = models.PolygonField\(([^\)])*\)', model_def))
def test_time_field(self): # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: self.skipTest("Unable to setup an OGR connection to your database") try: # Writing shapefiles via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect( ogr_db, "Measurement", layer_key=AllOGRFields._meta.db_table, decimal=["f_decimal"], ) except GDALException: self.skipTest("Unable to setup an OGR connection to your database") self.assertTrue( model_def.startswith( "# This is an auto-generated Django model module created by " "ogrinspect.\n" "from django.contrib.gis.db import models\n" "\n" "\n" "class Measurement(models.Model):\n")) # The ordering of model fields might vary depending on several factors # (version of GDAL, etc.). if connection.vendor == "sqlite" and GDAL_VERSION < (3, 4): # SpatiaLite introspection is somewhat lacking on GDAL < 3.4 (#29461). self.assertIn(" f_decimal = models.CharField(max_length=0)", model_def) else: self.assertIn( " f_decimal = models.DecimalField(max_digits=0, decimal_places=0)", model_def, ) self.assertIn(" f_int = models.IntegerField()", model_def) if not connection.ops.mariadb: # Probably a bug between GDAL and MariaDB on time fields. self.assertIn(" f_datetime = models.DateTimeField()", model_def) self.assertIn(" f_time = models.TimeField()", model_def) if connection.vendor == "sqlite" and GDAL_VERSION < (3, 4): self.assertIn(" f_float = models.CharField(max_length=0)", model_def) else: self.assertIn(" f_float = models.FloatField()", model_def) max_length = 0 if connection.vendor == "sqlite" else 10 self.assertIn( " f_char = models.CharField(max_length=%s)" % max_length, model_def) self.assertIn(" f_date = models.DateField()", model_def) # Some backends may have srid=-1 self.assertIsNotNone( re.search(r" geom = models.PolygonField\(([^\)])*\)", model_def))
def test_time_field(self): # Only possible to test this on PostGIS at the momemnt. MySQL # complains about permissions, and SpatiaLite/Oracle are # insanely difficult to get support compiled in for in GDAL. if not connections['default'].ops.postgis: return # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: return # writing shapefules via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect(ogr_db, 'Measurement', layer_key=AllOGRFields._meta.db_table, decimal=['f_decimal']) expected = [ '# This is an auto-generated Django model module created by ogrinspect.', 'from django.contrib.gis.db import models', '', 'class Measurement(models.Model):', ' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', ] if GDAL_VERSION < (1, 9, 0): # Prior to GDAL 1.9, the order of the model fields was not # the same as the columns in the database. expected.extend([ ' f_int = models.IntegerField()', ' f_datetime = models.DateTimeField()', ' f_time = models.TimeField()', ' f_float = models.FloatField()', ' f_char = models.CharField(max_length=10)', ' f_date = models.DateField()', ]) else: expected.extend([ ' f_float = models.FloatField()', ' f_int = models.IntegerField()', ' f_char = models.CharField(max_length=10)', ' f_date = models.DateField()', ' f_datetime = models.DateTimeField()', ' f_time = models.TimeField()', ]) expected.extend([ ' geom = models.PolygonField()', ' objects = models.GeoManager()', ]) self.assertEqual(model_def, '\n'.join(expected))
def test_poly(self): shp_file = os.path.join(TEST_DATA, 'test_poly', 'test_poly.shp') model_def = ogrinspect(shp_file, 'MyModel') expected = [ '# This is an auto-generated Django model module created by ogrinspect.', 'from django.contrib.gis.db import models', '', 'class MyModel(models.Model):', ' float = models.FloatField()', ' int = models.{}()'.format('BigIntegerField' if GDAL_VERSION >= (2, 0) else 'FloatField'), ' str = models.CharField(max_length=80)', ' geom = models.PolygonField(srid=-1)', ] self.assertEqual(model_def, '\n'.join(expected))
def test_poly(self): shp_file = os.path.join(TEST_DATA, "test_poly", "test_poly.shp") model_def = ogrinspect(shp_file, "MyModel") expected = [ "# This is an auto-generated Django model module created by ogrinspect.", "from django.contrib.gis.db import models", "", "class MyModel(models.Model):", " float = models.FloatField()", " int = models.FloatField()", " str = models.CharField(max_length=80)", " geom = models.PolygonField(srid=-1)", " objects = models.GeoManager()", ] self.assertEqual(model_def, "\n".join(expected))
def test_poly(self): shp_file = os.path.join(TEST_DATA, "test_poly", "test_poly.shp") model_def = ogrinspect(shp_file, "MyModel") expected = [ "# This is an auto-generated Django model module created by ogrinspect.", "from django.contrib.gis.db import models", "", "", "class MyModel(models.Model):", " float = models.FloatField()", " int = models.BigIntegerField()", " str = models.CharField(max_length=80)", " geom = models.PolygonField()", ] self.assertEqual(model_def, "\n".join(expected))
def test_date_field(self): shp_file = os.path.join(TEST_DATA, 'cities', 'cities.shp') model_def = ogrinspect(shp_file, 'City') expected = [ '# This is an auto-generated Django model module created by ogrinspect.', 'from django.contrib.gis.db import models', '', 'class City(models.Model):', ' name = models.CharField(max_length=80)', ' population = models.{}()'.format('BigIntegerField' if GDAL_VERSION >= (2, 0) else 'FloatField'), ' density = models.FloatField()', ' created = models.DateField()', ' geom = models.PointField(srid=-1)', ] self.assertEqual(model_def, '\n'.join(expected))
def test_date_field(self): shp_file = os.path.join(TEST_DATA, "cities", "cities.shp") model_def = ogrinspect(shp_file, "City") expected = [ "# This is an auto-generated Django model module created by ogrinspect.", "from django.contrib.gis.db import models", "", "class City(models.Model):", " name = models.CharField(max_length=80)", " population = models.FloatField()", " density = models.FloatField()", " created = models.DateField()", " geom = models.PointField(srid=-1)", " objects = models.GeoManager()", ] self.assertEqual(model_def, "\n".join(expected))
def test_date_field(self): shp_file = os.path.join(TEST_DATA, "cities", "cities.shp") model_def = ogrinspect(shp_file, "City") expected = [ "# This is an auto-generated Django model module created by ogrinspect.", "from django.contrib.gis.db import models", "", "", "class City(models.Model):", " name = models.CharField(max_length=80)", " population = models.BigIntegerField()", " density = models.FloatField()", " created = models.DateField()", " geom = models.PointField()", ] self.assertEqual(model_def, "\n".join(expected))
def test_time_field(self): # Only possible to test this on PostGIS at the momemnt. MySQL # complains about permissions, and SpatiaLite/Oracle are # insanely difficult to get support compiled in for in GDAL. if not connections['default'].ops.postgis: self.skipTest("This database does not support 'ogrinspect'ion") # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: self.skipTest( "Your GDAL installation does not support PostGIS databases") # Writing shapefiles via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect(ogr_db, 'Measurement', layer_key=AllOGRFields._meta.db_table, decimal=['f_decimal']) self.assertTrue( model_def.startswith( '# This is an auto-generated Django model module created by ogrinspect.\n' 'from django.contrib.gis.db import models\n' '\n' 'class Measurement(models.Model):\n')) # The ordering of model fields might vary depending on several factors (version of GDAL, etc.) self.assertIn( ' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def) self.assertIn(' f_int = models.IntegerField()', model_def) self.assertIn(' f_datetime = models.DateTimeField()', model_def) self.assertIn(' f_time = models.TimeField()', model_def) self.assertIn(' f_float = models.FloatField()', model_def) self.assertIn(' f_char = models.CharField(max_length=10)', model_def) self.assertIn(' f_date = models.DateField()', model_def) self.assertTrue( model_def.endswith(' geom = models.PolygonField()\n' ' objects = models.GeoManager()'))
def test_time_field(self): # Only possible to test this on PostGIS at the momemnt. MySQL # complains about permissions, and SpatiaLite/Oracle are # insanely difficult to get support compiled in for in GDAL. if not connections['default'].ops.postgis: return # Getting the database identifier used by OGR, if None returned # GDAL does not have the support compiled in. ogr_db = get_ogr_db_string() if not ogr_db: return # writing shapefules via GDAL currently does not support writing OGRTime # fields, so we need to actually use a database model_def = ogrinspect(ogr_db, 'Measurement', layer_key=AllOGRFields._meta.db_table, decimal=['f_decimal']) self.assertTrue(model_def.startswith( '# This is an auto-generated Django model module created by ogrinspect.\n' 'from django.contrib.gis.db import models\n' '\n' 'class Measurement(models.Model):\n' )) # The ordering of model fields might vary depending on several factors (version of GDAL, etc.) self.assertIn(' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def) self.assertIn(' f_int = models.IntegerField()', model_def) self.assertIn(' f_datetime = models.DateTimeField()', model_def) self.assertIn(' f_time = models.TimeField()', model_def) self.assertIn(' f_float = models.FloatField()', model_def) self.assertIn(' f_char = models.CharField(max_length=10)', model_def) self.assertIn(' f_date = models.DateField()', model_def) self.assertTrue(model_def.endswith( ' geom = models.PolygonField()\n' ' objects = models.GeoManager()' ))
def test_poly_multi(self): 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)