0

I'm trying to pass a GeoJson response that comes from a function called db.session.query(func.ST_AsGeoJSON(self.geometry)).first(), using GeoAlchemy and PostGres. When printing, shows:

('{"type":"Polygon","coordinates":[[[-38.4105,-12.9232],[-38.4205,-12.9232],[-38.4305,-12.9232],[-38.4505,-12.9232],[-38.4105,-12.9232]]]}',)

But when i try to add this to other Json, like that:

    geojson = {
        'geometry': db.session.query(func.ST_AsGeoJSON(self.geometry)).first(),
        'type': 'Feature',
        'properties': {
            'Nome': 'Default',
            'Qualidade': 'Default'
        },
    }

The response that comes to the website is full of backslashes:

enter image description here

I need to properly pass the geometry response to the geojson.

  • That happened to me in Java, when I did .string() to a property that is already an string, check if you are not doing same mistake, dont convert to a string something that is already string – BugsOverflow Feb 18 '21 at 19:34
  • Sadly, i'm not converting to string :( – Gabriel Reis Feb 18 '21 at 19:40
  • 1
    However, the database query returns a string. It is possible to deserialize the str back into a dict. Look [here](https://docs.python.org/3/library/json.html#json.loads). – Detlef Feb 19 '21 at 00:30

0 Answers0