geopandas / pyogrio

Vectorized vector I/O using OGR
https://pyogrio.readthedocs.io
MIT License
272 stars 22 forks source link

ENH: Passing driver options to ogr when reading #216

Closed jtmiclat closed 1 year ago

jtmiclat commented 1 year ago

First off i want to say thank you for a super cool library!

I was wondering if pyogrio can pass optional driver arguments when using read_dataframe .

For example, we have a geojson named test.geojson


{
  "type": "FeatureCollection",
  "features":
  [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [ 2.000000001, 49.000000001 ]
      },
      "properties": {
        "a_property": "foo",
        "some_object": {
          "a_property": 1,
          "another_property": 2
        }
      }
    }
  ]
}

Ideally reading it with the option FLATTEN_NESTED_ATTRIBUTES="YES" would return


+------------------------------------------------------------------------------------------------+
 | a_property | some_object_a_property | some_object_another_property | geometry                 |
+------------------------------------------------------------------------------------------------+
| foo          | 1                      | 2                            | POINT (2.00000 49.00000)|
+------------------------------------------------------------------------------------------------+

but when running it gives the following error

In [1]:  pyogrio.read_dataframe("test.geojson", FLATTEN_NESTED_ATTRIBUTES="YES")
----> 1 pyogrio.read_dataframe("test.geojson", FLATTEN_NESTED_ATTRIBUTES="YES")

TypeError: read_dataframe() got an unexpected keyword argument 'FLATTEN_NESTED_ATTRIBUTES'

Interestingly enough write_dataframe already supports optional drivers https://github.com/geopandas/pyogrio/blob/a0b658509f191dece282d6b198099505e9510349/pyogrio/raw.py#L314-L328

brendan-ward commented 1 year ago

Yes, we should support driver and layer options where appropriate, just like for writing. Thanks for the suggestion!