I’m working with a MongoDB database containing city polygon data. I’ve successfully connected to it from Python and downloaded the data. However, when I convert it into a GeoDataFrame, the geometry column doesn’t seem to be recognized correctly. How can I ensure GeoPandas can utilize the geometry data?
The following code demonstrates the process:
query = {
'properties.PROVINCIA': 'Ciudad'
}
consult = collection.find(query)
df_result = pd.DataFrame(consult)
df = pd.DataFrame.from_records(df_result['properties'].tolist())
df['geometry'] = df_result['geometry']
df.head()
Thanks!!
2
Answers
I think you need to use a geopandas.GeoDataFrame()
Something like this:
I have no experience in converting data from MongoDB to GeoPandas … but I would try to replace
pd.DataFrame.from_records()
withgeopandas.GeoDataFrame.from_records()
.