def test_ST_AsGeoJson(self):
        lake_id = self._create_one_lake()
        lake = session.query(Lake).get(lake_id)

        # Test geometry
        s1 = select([func.ST_AsGeoJSON(Lake.__table__.c.geom)])
        r1 = session.execute(s1).scalar()
        assert loads(r1) == {
            "type": "LineString",
            "coordinates": [[0, 0], [1, 1]]
        }

        # Test geometry ORM
        s1_orm = lake.geom.ST_AsGeoJSON()
        r1_orm = session.execute(s1_orm).scalar()
        assert loads(r1_orm) == {
            "type": "LineString",
            "coordinates": [[0, 0], [1, 1]]
        }

        # Test with function inside
        s1_func = select(
            [func.ST_AsGeoJSON(func.ST_MakeValid(Lake.__table__.c.geom))])
        r1_func = session.execute(s1_func).scalar()
        assert loads(r1_func) == {
            "type": "LineString",
            "coordinates": [[0, 0], [1, 1]]
        }
Esempio n. 2
0
 def test_nested_funcs(self):
     stmt = select([func.ST_AsGeoJSON(func.ST_MakeValid(func.ST_MakePoint(1, 2)))])
     self._assert_stmt(
         stmt,
         'SELECT '
         'ST_AsGeoJSON(ST_MakeValid('
         'ST_MakePoint(:ST_MakePoint_1, :ST_MakePoint_2)'
         ')) AS "ST_AsGeoJSON_1"',
     )