Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBOX - ValueError: Invalid field type <type 'list'> #447

Closed
snowman2 opened this issue Jun 2, 2017 · 1 comment
Closed

BBOX - ValueError: Invalid field type <type 'list'> #447

snowman2 opened this issue Jun 2, 2017 · 1 comment

Comments

@snowman2
Copy link
Contributor

snowman2 commented Jun 2, 2017

Here is the dataframe printout:

   COAST  DIST_MAIN  DIST_SINK  ENDO    HYBAS_ID    MAIN_BAS  NEXT_DOWN  \
0      0          0          0     0  2060072430  2060072430          0   

    NEXT_SINK  ORDER  PFAF_ID  SORT  SUB_AREA  UP_AREA  \
0  2060072430      1   293508  1469   10302.2  10302.2   

                                                bbox  \
0  [6326657.72675, 3117746.64584, 6444470.85451, ...   

                                            geometry  
0  (POLYGON ((57.53750000000003 28.1791666666667,...  

Here is the error when dumping to shapefile:

Invalid field type <type 'list'>
Traceback (most recent call last):
  File "/Users/rdchlads/tethys/src/tethys_apps/tethysapp/gssha_model_builder/controllers.py", line 321, in create_model
    gpd.iloc[[0]].to_file(watershed_shapefile_path)
  File "/Users/rdchlads/tethys/miniconda/envs/tethys/lib/python2.7/site-packages/geopandas/geodataframe.py", line 343, in to_file
    to_file(self, filename, driver, schema, **kwargs)
  File "/Users/rdchlads/tethys/miniconda/envs/tethys/lib/python2.7/site-packages/geopandas/io/file.py", line 63, in to_file
    c.write(feature)
  File "/Users/rdchlads/tethys/miniconda/envs/tethys/lib/python2.7/site-packages/fiona/collection.py", line 341, in write
    self.writerecords([record])
  File "/Users/rdchlads/tethys/miniconda/envs/tethys/lib/python2.7/site-packages/fiona/collection.py", line 335, in writerecords
    self.session.writerecs(records, self)
  File "fiona/ogrext.pyx", line 1029, in fiona.ogrext.WritingSession.writerecs (fiona/ogrext.c:18014)
  File "fiona/ogrext.pyx", line 325, in fiona.ogrext.OGRFeatureBuilder.build (fiona/ogrext.c:7057)
ValueError: Invalid field type <type 'list'>

SOLUTION: Remove the bbox column.

print(gpd.bbox)
print(gpd[['HYBAS_ID', 'geometry']])
gpd[['HYBAS_ID', 'geometry']].to_file(watershed_shapefile_path)
0    [6326657.72675, 3117746.64584, 6444470.85451, ...
Name: bbox, dtype: object
     HYBAS_ID                                           geometry
0  2060072430  (POLYGON ((57.53750000000003 28.1791666666667,...
@jdmcbr
Copy link
Member

jdmcbr commented Sep 5, 2017

@snowman2 Lists are not supported data types to store in shapefiles. If you need to store the bounding box in columns, calling the frame gdf (using gpd as the name of your frame is discouraged, since gpd is the standard shorthand name used on import for geopandas), then you can you can do:

 gdf = pd.merge(gdf, gdf.bounds, left_index=True, right_index=True)

@jdmcbr jdmcbr closed this as completed Sep 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants