0

I am attempting to load geojson from a file into mssql express using sqlalchemy for the insert and geopandas to load and read the file. sqlserver examples seems to be hard to find, but below is what i was able to scrape together at this point, which doesn't work.

geodataframe = geopandas.read_file(fname)
geodataframe['geom'] = geodataframe['geometry'].apply(lambda x: WKTElement(x.wkt, srid=4326))
geodataframe.drop('geometry', 1, inplace=True)
geodataframe.to_sql('geo', engine, if_exists='append', index=False,dtype={'geom': Geometry('POINT', srid= 4326)})

does anyone have a working example of loading geojson into Sql Server sqlexpress with python?

Messak
  • 423
  • 1
  • 3
  • 16
  • geopandas dispatches to fiona to write data. As the docs say, check `import fiona; fiona.supported_drivers` to see if that's even available. – Paul H Dec 19 '17 at 15:55
  • Actually, i said i was using sqlalchemy/geoalchemy to post the data to mssql, not fiona per this post, I just cant find a mssql example https://stackoverflow.com/questions/38361336/write-geodataframe-into-sql-database – Messak Dec 19 '17 at 17:49
  • You may feed GeoJSON into GeoAlchemy by the means of [`shapely.geometry.shape`](https://shapely.readthedocs.io/en/latest/manual.html#shapely.geometry.shape): `geoalchemy2.shape.from_shape(shapely.geometry.shape(json.loads('geojson_string')))` – bartolo-otrit Feb 12 '22 at 10:40

0 Answers0