How insert FeatureCollection to postgis?

Viewed 11

I've created table scheme with sqlalchemy.\

class Calculation(Base):
    __tablename__ = "calculations"

    calculation_id = sa.Column(UUID(as_uuid=True), default=uuid4, primary_key=True)
    tle = sa.Column(sa.String, nullable=False)
    shape = sa.Column(Geometry(from_text="ST_GeomFromGeoJSON", srid=4326), nullable=False)

And I have geojson with multiple features.

I tried different ways for convert geojson to dataframe, dataseries and insert to database. Not working.

For example:

js = '''
{
  "type": "FeatureCollection",
...
...
'''

gdf = gpd.GeoDataFrame.from_features(js["features"])
    calc = Calculation(tle='1', shape=func.ST_GeomFromGeoJSON(gs))

    db.add(sat)
    db.commit()

It takes error

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'GeoDataFrame'
0 Answers
Related