1

I'm attempting to pull a set of building footprints from open street map using a shapefile boundary. I have success getting the buildings into a geodataframe, but when I attempt to write them out to a shapefile I get the following error:

ValueError: Invalid field type class 'list'

Here's my code

import osmnx as ox
import shapefile
import geopandas
from shapely.geometry import shape

shp = shapefile.Reader("StudyArea.shp")
feature = shp.shapeRecords()[0]
first = feature.shape.__geo_interface__

#convert to shapely shape
shp_geom = shape(first)

fprints = ox.footprints.footprints_from_polygon(shp_geom, 
footprint_type ='building')
ox.plot_shape(ox.project_gdf(fprints))
type(fprints)
fprints.to_file('footprints.shp', driver='ESRI Shapefile')

Everything works except the last line when I attempt to write the file. It actually writes a shapefile but it writes an empty polyline shapefile (based on the icon in ArcCatalog) I've read about others who've had issues with the datatype conversion of some of the footprint attribute info but am new to geopandas and didn't find a clear solution.

  • 1
    One of the columns in your fprint dataframe has lists in it, and such a data type is not supported by ESRI Shapefiles. – joris Dec 4 '19 at 20:11
  • I think I found the problem. The Nodes column is of type Series. I'm more of an R guy. Is there something similar to R subset in Python? I don't really need that column and would like to eliminate it from the dataframe before importing – jport Dec 4 '19 at 20:40
0

Open StreetMap building footprints include a 'nodes' column that is of datatype list. I ended up using this code to drop the column and afterwards the shapefile was written correctly

fprints.drop(['nodes'], axis = 1)

Thanks to joris for getting me on the right track

| improve this answer | |
  • Note, one other option is that you can stringify your column of lists to retain that data (in string form) in the shapefile. – gboeing Jul 4 at 20:45

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.