I have a GeoDataFrame with plenty of info, including a 'geometry' column. Some of the rows have no geometry data... I simply don't have it. I decided to leave those rows as 'None' or 'NoneType' in the geometry column. This would be a representation of my GeoDataFrame:

   person  job         geometry
1  bob     Musician    POINT(1234.1234123 1234123.234)
2  john    Accountant  None
3  Sandra  Banker      POINT(234234.2343 23423.234)

I have tried with this:

engine = db.create_engine('postgresql://{}:{}@{}:5432/{}'.format(user, password, host, database))


But of course, Python complaints:

AttributeError: 'NoneType' object has no attribute '_geom'

How can I still upload the GeoDataFrame? I do not want to get rid of those customers without coordinates as they still have valuable info + I could obtain it later in time.

  • This might be useful. You may need to assign empty geometry in you dataframe for the missing geometry. geopandas.org/docs/user_guide/missing_empty.html
    – jbalk
    Sep 3 '21 at 19:28
  • I don't have an environment where I can test it right now, so this answer may not be perfect, but give it a try. Change None of GeodataFrame geometry to Polygon(None) using shapely. from shapely.geometry import Polygon ; gdf.loc[gdf['geometry'].isna(), 'geometry'] = Polygon(None);
    – Urban87
    Sep 8 '21 at 4:41

So thanks to the comments I was able to find an answer. The simplest way to create a 'geometry nonetype' is by creating an empty geometry. This is a representation of what I did:

from shapely.geometry import Point

gdf['geometry'][0] = Point()

That creates an empty geometry value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.