sqlalchemy.func.ST_X - python examples

Here are the examples of the python api sqlalchemy.func.ST_X taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

0 View Complete Implementation : test_package.py
Copyright GNU General Public License v3.0
Author : italia
    def test_spatial_extra(self):
        app = self._get_test_app()

        user = factories.User()
        env = {'REMOTE_USER': user['name'].encode('ascii')}
        dataset = factories.Dataset(user=user)

        offset = url_for(controller='package', action='edit', id=dataset['id'])
        res = app.get(offset, extra_environ=env)

        form = res.forms[1]
        form['extras__0__key'] = u'spatial'
        form['extras__0__value'] = self.geojson_examples['point']

        res = helpers.submit_and_follow(app, form, env, 'save')

        astert 'Error' not in res, res

        package_extent = Session.query(PackageExtent) \
            .filter(PackageExtent.package_id == dataset['id']).first()

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

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

0 View Complete Implementation : test_package_extent.py
Copyright GNU General Public License v3.0
Author : italia
    def test_create_extent(self):

        package = factories.Dataset()

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

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

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