Exemplo n.º 1
0
    def geometry_column(self):
        "Returns the GeometryColumn model associated with the geographic column."
        from django.contrib.gis.models import GeometryColumns
        # Use the `get_field_by_name` on the model's options so that we
        # get the correct model if there's model inheritance -- otherwise
        # the returned model is None.
        opts = self.model._meta
        fld, model, direct, m2m = opts.get_field_by_name(self.geom_field)
        if model is None: model = self.model

        # Trying to get the `GeometryColumns` object that corresponds to the
        # the geometry field.
        try:
            db_table = model._meta.db_table
            geo_col = fld.column

            if SpatialBackend.oracle:
                # Making upper case for Oracle.
                db_table = db_table.upper()
                geo_col = geo_col.upper()

            gc_kwargs = {
                GeometryColumns.table_name_col(): db_table,
                GeometryColumns.geom_col_name(): geo_col,
            }
            return GeometryColumns.objects.get(**gc_kwargs)
        except Exception, msg:
            raise LayerMapError(
                'Geometry column does not exist for model. (did you run syncdb?):\n %s'
                % msg)
Exemplo n.º 2
0
    def geometry_column(self):
        "Returns the GeometryColumn model associated with the geographic column."
        from django.contrib.gis.models import GeometryColumns
        # Use the `get_field_by_name` on the model's options so that we
        # get the correct model if there's model inheritance -- otherwise
        # the returned model is None.
        opts = self.model._meta
        fld, model, direct, m2m = opts.get_field_by_name(self.geom_field)
        if model is None: model = self.model

        # Trying to get the `GeometryColumns` object that corresponds to the
        # the geometry field.
        try:
            db_table = model._meta.db_table
            geo_col = fld.column

            if SpatialBackend.oracle:
                # Making upper case for Oracle.
                db_table = db_table.upper()
                geo_col = geo_col.upper()

            gc_kwargs = { GeometryColumns.table_name_col() : db_table,
                          GeometryColumns.geom_col_name() : geo_col,
                         }
            return GeometryColumns.objects.get(**gc_kwargs)
        except Exception, msg:
            raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)
Exemplo n.º 3
0
    def test_add_gis_field(self):
        """
        Tests the AddField operation with a GIS-enabled column.
        """
        project_state = self.set_up_test_model()
        operation = migrations.AddField(
            "Neighborhood",
            "path",
            fields.LineStringField(srid=4326, null=True, blank=True),
        )
        new_state = project_state.clone()
        operation.state_forwards("gis", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("gis", editor, project_state,
                                        new_state)
        self.assertColumnExists("gis_neighborhood", "path")

        # Test GeometryColumns when available
        if HAS_GEOMETRY_COLUMNS:
            self.assertEqual(
                GeometryColumns.objects.filter(
                    **{
                        GeometryColumns.table_name_col(): "gis_neighborhood"
                    }).count(), 2)
        self.current_state = new_state
Exemplo n.º 4
0
 def geometry_column(self):
     "Returns the GeometryColumn model associated with the geographic column."
     # Getting the GeometryColumn object.
     try:
         db_table = self.model._meta.db_table
         geo_col = self.geom_field
         if SpatialBackend.name == 'oracle':
             # Making upper case for Oracle.
             db_table = db_table.upper()
             geo_col = geo_col.upper()
         gc_kwargs = {GeometryColumns.table_name_col() : db_table,
                      GeometryColumns.geom_col_name() : geo_col,
                      }
         return GeometryColumns.objects.get(**gc_kwargs)
     except Exception, msg:
         raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)
Exemplo n.º 5
0
 def geometry_column(self):
     "Returns the GeometryColumn model associated with the geographic column."
     from django.contrib.gis.models import GeometryColumns
     # Getting the GeometryColumn object.
     try:
         db_table = self.model._meta.db_table
         geo_col = self.geom_field
         if SpatialBackend.oracle:
             # Making upper case for Oracle.
             db_table = db_table.upper()
             geo_col = geo_col.upper()
         gc_kwargs = {GeometryColumns.table_name_col() : db_table,
                      GeometryColumns.geom_col_name() : geo_col,
                      }
         return GeometryColumns.objects.get(**gc_kwargs)
     except Exception, msg:
         raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)
Exemplo n.º 6
0
 def assertGeometryColumnsCount(self, expected_count):
     table_name = "gis_neighborhood"
     if connection.features.uppercases_column_names:
         table_name = table_name.upper()
     self.assertEqual(
         GeometryColumns.objects.filter(
             **{
                 GeometryColumns.table_name_col(): table_name,
             }).count(), expected_count)
Exemplo n.º 7
0
 def assertGeometryColumnsCount(self, expected_count):
     table_name = "gis_neighborhood"
     if connection.features.uppercases_column_names:
         table_name = table_name.upper()
     self.assertEqual(
         GeometryColumns.objects.filter(**{
             GeometryColumns.table_name_col(): table_name,
         }).count(),
         expected_count
     )
Exemplo n.º 8
0
 def geometry_column(self):
     "Returns the GeometryColumn model associated with the geographic column."
     # Getting the GeometryColumn object.
     try:
         db_table = self.model._meta.db_table
         if SpatialBackend.name == 'oracle': db_table = db_table.upper()
         gc_kwargs = {GeometryColumns.table_name_col() : db_table}
         return GeometryColumns.objects.get(**gc_kwargs)
     except Exception, msg:
         raise LayerMapError('Geometry column does not exist for model. (did you run syncdb?):\n %s' % msg)
Exemplo n.º 9
0
 def tearDown(self):
     # Delete table after testing
     with connection.cursor() as cursor:
         try:
             cursor.execute("DROP TABLE %s" % connection.ops.quote_name("gis_neighborhood"))
         except DatabaseError:
             pass
         else:
             if HAS_GEOMETRY_COLUMNS:
                 cursor.execute("DELETE FROM geometry_columns WHERE %s = %%s" % (
                     GeometryColumns.table_name_col(),), ["gis_neighborhood"])
     super(OperationTests, self).tearDown()
Exemplo n.º 10
0
    def test_remove_gis_field(self):
        """
        Tests the RemoveField operation with a GIS-enabled column.
        """
        project_state = self.set_up_test_model()
        operation = migrations.RemoveField("Neighborhood", "geom")
        new_state = project_state.clone()
        operation.state_forwards("gis", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("gis", editor, project_state, new_state)
        self.assertColumnNotExists("gis_neighborhood", "geom")

        # Test GeometryColumns when available
        if HAS_GEOMETRY_COLUMNS:
            self.assertEqual(
                GeometryColumns.objects.filter(**{GeometryColumns.table_name_col(): "gis_neighborhood"}).count(),
                0
            )
Exemplo n.º 11
0
    def test_remove_gis_field(self):
        """
        Tests the RemoveField operation with a GIS-enabled column.
        """
        project_state = self.set_up_test_model()
        operation = migrations.RemoveField("Neighborhood", "geom")
        new_state = project_state.clone()
        operation.state_forwards("gis", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("gis", editor, project_state,
                                        new_state)
        self.assertColumnNotExists("gis_neighborhood", "geom")

        # Test GeometryColumns when available
        if HAS_GEOMETRY_COLUMNS:
            self.assertEqual(
                GeometryColumns.objects.filter(
                    **{
                        GeometryColumns.table_name_col(): "gis_neighborhood"
                    }).count(), 0)
        self.current_state = new_state
Exemplo n.º 12
0
    def test_add_gis_field(self):
        """
        Tests the AddField operation with a GIS-enabled column.
        """
        project_state = self.set_up_test_model()
        operation = migrations.AddField(
            "Neighborhood",
            "path",
            fields.LineStringField(srid=4326, null=True, blank=True),
        )
        new_state = project_state.clone()
        operation.state_forwards("gis", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("gis", editor, project_state, new_state)
        self.assertColumnExists("gis_neighborhood", "path")

        # Test GeometryColumns when available
        if HAS_GEOMETRY_COLUMNS:
            self.assertEqual(
                GeometryColumns.objects.filter(**{GeometryColumns.table_name_col(): "gis_neighborhood"}).count(),
                2
            )