def test_create_extent(self):

        package = factories.Dataset()

        geojson = json.loads(self.geojson_examples['point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package['id'],
                                       the_geom=WKTElement(shape.wkt,
                                                           self.db_srid))
        package_extent.save()

        assert_equals(package_extent.package_id, package['id'])
        if legacy_geoalchemy:
            assert_equals(Session.scalar(package_extent.the_geom.x),
                          geojson['coordinates'][0])
            assert_equals(Session.scalar(package_extent.the_geom.y),
                          geojson['coordinates'][1])
            assert_equals(Session.scalar(package_extent.the_geom.srid),
                          self.db_srid)
        else:
            from sqlalchemy import func
            assert_equals(
                Session.query(func.ST_X(package_extent.the_geom)).first()[0],
                geojson['coordinates'][0])
            assert_equals(
                Session.query(func.ST_Y(package_extent.the_geom)).first()[0],
                geojson['coordinates'][1])
            assert_equals(package_extent.the_geom.srid, self.db_srid)
    def test_create_extent(self):

        package = factories.Dataset()

        geojson = json.loads(self.geojson_examples['point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package['id'],
                                       the_geom=WKTElement(
                                           shape.wkt, self.db_srid))
        package_extent.save()

        assert_equals(package_extent.package_id, package['id'])
        if legacy_geoalchemy:
            assert_equals(Session.scalar(package_extent.the_geom.x),
                          geojson['coordinates'][0])
            assert_equals(Session.scalar(package_extent.the_geom.y),
                          geojson['coordinates'][1])
            assert_equals(Session.scalar(package_extent.the_geom.srid),
                          self.db_srid)
        else:
            from sqlalchemy import func
            assert_equals(
                Session.query(func.ST_X(package_extent.the_geom)).first()[0],
                geojson['coordinates'][0])
            assert_equals(
                Session.query(func.ST_Y(package_extent.the_geom)).first()[0],
                geojson['coordinates'][1])
            assert_equals(package_extent.the_geom.srid, self.db_srid)
Example #3
0
    def test_update_extent(self):

        package = Package.get('annakarenina')

        geojson = json.loads(self.geojson_examples['point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package.id,
                                       the_geom=WKTSpatialElement(
                                           shape.wkt, self.db_srid))
        package_extent.save()
        assert Session.scalar(
            package_extent.the_geom.geometry_type) == 'ST_Point'

        # Update the geometry (Point -> Polygon)
        geojson = json.loads(self.geojson_examples['polygon'])

        shape = asShape(geojson)
        package_extent.the_geom = WKTSpatialElement(shape.wkt, self.db_srid)
        package_extent.save()

        assert package_extent.package_id == package.id
        assert Session.scalar(
            package_extent.the_geom.geometry_type) == 'ST_Polygon'
        assert Session.scalar(package_extent.the_geom.srid) == self.db_srid
Example #4
0
    def test_create_extent(self):

        package = factories.Dataset()

        geojson = json.loads(self.geojson_examples["point"])

        shape = asShape(geojson)
        package_extent = PackageExtent(
            package_id=package["id"],
            the_geom=WKTElement(shape.wkt, self.db_srid),
        )
        package_extent.save()

        assert (package_extent.package_id == package["id"])
        if legacy_geoalchemy:
            assert (Session.scalar(
                package_extent.the_geom.x) == geojson["coordinates"][0])
            assert (Session.scalar(
                package_extent.the_geom.y) == geojson["coordinates"][1])
            assert (Session.scalar(
                package_extent.the_geom.srid) == self.db_srid)
        else:
            from sqlalchemy import func

            assert (Session.query(func.ST_X(package_extent.the_geom)).first()
                    [0] == geojson["coordinates"][0])
            assert (Session.query(func.ST_Y(package_extent.the_geom)).first()
                    [0] == geojson["coordinates"][1])
            assert (package_extent.the_geom.srid == self.db_srid)
Example #5
0
    def test_update_extent(self):

        package = factories.Dataset()

        geojson = json.loads(self.geojson_examples["point"])

        shape = asShape(geojson)
        package_extent = PackageExtent(
            package_id=package["id"],
            the_geom=WKTElement(shape.wkt, self.db_srid),
        )
        package_extent.save()
        if legacy_geoalchemy:
            assert(
                Session.scalar(package_extent.the_geom.geometry_type) ==
                "ST_Point"
            )
        else:
            from sqlalchemy import func

            assert(
                Session.query(
                    func.ST_GeometryType(package_extent.the_geom)
                ).first()[0] ==
                "ST_Point"
            )

        # Update the geometry (Point -> Polygon)
        geojson = json.loads(self.geojson_examples["polygon"])

        shape = asShape(geojson)
        package_extent.the_geom = WKTElement(shape.wkt, self.db_srid)
        package_extent.save()

        assert(package_extent.package_id == package["id"])
        if legacy_geoalchemy:
            assert(
                Session.scalar(package_extent.the_geom.geometry_type) ==
                "ST_Polygon"
            )
            assert(
                Session.scalar(package_extent.the_geom.srid) == self.db_srid
            )
        else:
            assert(
                Session.query(
                    func.ST_GeometryType(package_extent.the_geom)
                ).first()[0] ==
                "ST_Polygon"
            )
            assert(package_extent.the_geom.srid == self.db_srid)
Example #6
0
    def test_create_extent(self):
        package = Package.get('annakarenina')
        assert package

        geojson = json.loads(self.geojson_examples['point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package.id,the_geom=WKTSpatialElement(shape.wkt, self.db_srid))
        package_extent.save()

        assert package_extent.package_id == package.id
        assert Session.scalar(package_extent.the_geom.x) == geojson['coordinates'][0]
        assert Session.scalar(package_extent.the_geom.y) == geojson['coordinates'][1]
        assert Session.scalar(package_extent.the_geom.srid) == self.db_srid
Example #7
0
    def test_update_extent(self):
        ''' '''

        package = factories.Dataset()

        geojson = json.loads(self.geojson_examples[u'point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package[u'id'],
                                       the_geom=WKTElement(shape.wkt,
                                                           self.db_srid))
        package_extent.save()
        if legacy_geoalchemy:
            assert_equals(
                Session.scalar(package_extent.the_geom.geometry_type),
                u'ST_Point')
        else:
            from sqlalchemy import func
            assert_equals(
                Session.query(
                    func.ST_GeometryType(package_extent.the_geom)).first()[0],
                u'ST_Point')

        # Update the geometry (Point -> Polygon)
        geojson = json.loads(self.geojson_examples[u'polygon'])

        shape = asShape(geojson)
        package_extent.the_geom = WKTElement(shape.wkt, self.db_srid)
        package_extent.save()

        assert_equals(package_extent.package_id, package[u'id'])
        if legacy_geoalchemy:
            assert_equals(
                Session.scalar(package_extent.the_geom.geometry_type),
                u'ST_Polygon')
            assert_equals(
                Session.scalar(package_extent.the_geom.srid),
                self.db_srid)
        else:
            assert_equals(
                Session.query(
                    func.ST_GeometryType(package_extent.the_geom)).first()[0],
                u'ST_Polygon')
            assert_equals(package_extent.the_geom.srid, self.db_srid)
    def test_update_extent(self):

        package = factories.Dataset()

        geojson = json.loads(self.geojson_examples['point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package['id'],
                                       the_geom=WKTElement(shape.wkt,
                                                           self.db_srid))
        package_extent.save()
        if legacy_geoalchemy:
            assert_equals(
                Session.scalar(package_extent.the_geom.geometry_type),
                'ST_Point')
        else:
            from sqlalchemy import func
            assert_equals(
                Session.query(
                    func.ST_GeometryType(package_extent.the_geom)).first()[0],
                'ST_Point')

        # Update the geometry (Point -> Polygon)
        geojson = json.loads(self.geojson_examples['polygon'])

        shape = asShape(geojson)
        package_extent.the_geom = WKTElement(shape.wkt, self.db_srid)
        package_extent.save()

        assert_equals(package_extent.package_id, package['id'])
        if legacy_geoalchemy:
            assert_equals(
                Session.scalar(package_extent.the_geom.geometry_type),
                'ST_Polygon')
            assert_equals(
                Session.scalar(package_extent.the_geom.srid),
                self.db_srid)
        else:
            assert_equals(
                Session.query(
                    func.ST_GeometryType(package_extent.the_geom)).first()[0],
                'ST_Polygon')
            assert_equals(package_extent.the_geom.srid, self.db_srid)
    def test_update_extent(self):

        package = Package.get('annakarenina')

        geojson = json.loads(self.geojson_examples['point'])

        shape = asShape(geojson)
        package_extent = PackageExtent(package_id=package.id,the_geom=WKTSpatialElement(shape.wkt, self.db_srid))
        package_extent.save()
        assert Session.scalar(package_extent.the_geom.geometry_type) == 'ST_Point'

        # Update the geometry (Point -> Polygon)
        geojson = json.loads(self.geojson_examples['polygon'])

        shape = asShape(geojson)
        package_extent.the_geom=WKTSpatialElement(shape.wkt, self.db_srid)
        package_extent.save()

        assert package_extent.package_id == package.id
        assert Session.scalar(package_extent.the_geom.geometry_type) == 'ST_Polygon'
        assert Session.scalar(package_extent.the_geom.srid) == self.db_srid