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

Support for list-like feature properties #435

Open
egorf opened this issue Mar 29, 2017 · 2 comments
Open

Support for list-like feature properties #435

egorf opened this issue Mar 29, 2017 · 2 comments

Comments

@egorf
Copy link
Contributor

egorf commented Mar 29, 2017

Expected behavior and actual behavior.

Instead of writing a triplet property, I get the following exception:

Warning 6: dataset /Users/egor/Documents/reach-surveying/surveying/gdf.geojson does not support layer creation option ENCODING
Traceback (most recent call last):
  File "project.py", line 118, in <module>
    gdf.to_file("gdf.geojson", driver="GeoJSON")
  File "/Users/egor/Documents/reach-surveying/venv/lib/python2.7/site-packages/geopandas/geodataframe.py", line 343, in to_file
    to_file(self, filename, driver, schema, **kwargs)
  File "/Users/egor/Documents/reach-surveying/venv/lib/python2.7/site-packages/geopandas/io/file.py", line 63, in to_file
    c.write(feature)
  File "/Users/egor/Documents/reach-surveying/venv/lib/python2.7/site-packages/fiona/collection.py", line 339, in write
    self.writerecords([record])
  File "/Users/egor/Documents/reach-surveying/venv/lib/python2.7/site-packages/fiona/collection.py", line 333, in writerecords
    self.session.writerecs(records, self)
  File "fiona/ogrext.pyx", line 1019, in fiona.ogrext.WritingSession.writerecs (fiona/ogrext2.c:17895)
  File "fiona/ogrext.pyx", line 326, in fiona.ogrext.OGRFeatureBuilder.build (fiona/ogrext2.c:7195)
ValueError: Invalid field type <type 'tuple'>

I can see this data type is not supported, nor the lists are mentioned in FIELD_TYPES_MAP and FIELD_TYPES. Is there a potential way to work around this problem?

Steps to reproduce the problem.

    gs = geopandas.GeoSeries({
        "name": "name",
        "triplet_data": (0, 1, 2),
        "geometry": shapely.geometry.Point((0.0, 0.0, 0.0))
    })

    gdf = geopandas.GeoDataFrame()
    gdf = gdf.append(gs, ignore_index=True)
    gdf = gdf.append(gs, ignore_index=True)
    gdf = gdf.append(gs, ignore_index=True)
    gdf.to_file("gdf.geojson", driver="GeoJSON")

Operating system

Mac OS X 10.12.3

Fiona version and provenance

Fiona==1.7.5, installed as a pip dependency to geopandas

@sgillies
Copy link
Member

@egorf you are right, there is currenty no support in Fiona for tuple or list properties. The work arounds are to explode these tuples into three separate properties or to encode them in a string using a microformat specific to your application.

The blocker for Fiona is that the GDAL/OGR libraries lack support for arbitrary Python collections. In the list at http://www.gdal.org/ogr__core_8h.html#a787194bea637faf12d61643124a7c9fc you'll see there is no support for dicts or heterogeneous lists or tuples, only array-like lists. Supporting arrays of a single element type would not be very hard, though we might find that they are not supported in certain data formats.

@egorf
Copy link
Contributor Author

egorf commented Mar 30, 2017

Ok, I see. Theoretically, there may be check, that all data inside the list is the right type, then create an OFTList, raise ValueError otherwise. I will look into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants