1

I am trying to export a geodatabase I created via the OMSNX package. ()

When I attempt to convert the file from a geodatabase to shapefile I get an error "ValueError: Invalid field type <class 'list'>". This is because the geodatabase has some formats that are not compatible with shapefiles as mentioned here under the spatial data section.

How do I convert the geodataframe to allow for an export as a shapefile? My code and attached error are below.

import geopandas as gpd
import osmnx as ox
import fiona as fi
print(fi.supported_drivers)
%matplotlib inline
ox.__version__

place = "Dickinson, Texas"
tags = {"building": True}
gdf = ox.geometries_from_place(place, tags)
gdf.shape



fig, ax = ox.plot_footprints(gdf, figsize=(8, 8))
gdf.shape
gdf.to_file('testgalvy.gpkg',driver='GPKG')

Error Message

1

1 Answer 1

3

Whenever I get "ValueError: Invalid field type <class 'list'>". it is when I am trying to convert a geodataframe which has a string/object field with lists in it to shapefile. Do you have lists in a column?

You can convert them to strings by doing:

import pandas as pd
df = pd.DataFrame({'a':[1,2,3],'b':[['a','list','in','the','column'],'b','c']}) #Create some test data


   a                           b
0  1  [a, list, in, the, column]
1  2                           b
2  3                           c

df['b'] = df['b'].apply(lambda x: ' '.join(x)) #Join the list into a string

   a                     b
0  1  a list in the column
1  2                     b
2  3                     c

If you have alot of data you can check all columns like this:

for col in df.columns:
    if any(isinstance(val, list) for val in df[col]):
        print('Column: {0}, has a list in it'.format(col))
Column: b, has a list in it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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