File: fiona_to_pyogrio.rst

package info (click to toggle)
python-geopandas 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,848 kB
  • sloc: python: 26,022; makefile: 147; sh: 25
file content (73 lines) | stat: -rw-r--r-- 2,503 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
.. currentmodule:: geopandas

.. ipython:: python
   :suppress:

   import geopandas

Migration from the Fiona to the Pyogrio read/write engine
=========================================================

Since version 0.11, GeoPandas started supporting two engines to read and write files:
`Fiona <https://fiona.readthedocs.io>`__ and
`Pyogrio <https://pyogrio.readthedocs.io>`__.

It became possible to choose the engine using the ``engine=`` parameter in
:func:`geopandas.read_file` and :func:`geopandas.GeoDataFrame.to_file`. It became also
possible to change the default engine globally with:

.. code-block:: python

    geopandas.options.io_engine = "pyogrio"

For Geopandas versions <1.0, GeoPandas defaulted to use Fiona. Starting from GeoPandas
version 1.0, the global default has changed from Fiona to Pyogrio.

The main reason for this change is performance. Pyogrio is optimized for the use case
relevant for GeoPandas: reading and writing in bulk. Because of this, in many cases
speedups >5-20x can be observed.

This guide outlines the (known) functional differences between both, so you can account
for them when switching to Pyogrio.


Write an attribute table to a file
----------------------------------

Using the Fiona engine, it was possible to write an attribute table (a table without
geometry column) to a file using the ``schema`` parameter to specify that the "geometry"
column of a GeoDataFrame should be ignored.

With Pyogrio you can write an attribute table by using :func:`pyogrio.write_dataframe`
and passing a pandas DataFrame to it:

.. code-block:: python

    >>> import pyogrio
    >>> df = pd.DataFrame({"data_column": [1, 2, 3]})
    >>> pyogrio.write_dataframe(df, "test_attribute_table.gpkg")


No support for ``schema`` parameter to write files
--------------------------------------------------

Pyogrio does not support specifying the `schema` parameter to write files. This means
it is not possible to specify the types of attributes being written explicitly.


Writing EMPTY geometries
------------------------

Pyogrio writes EMPTY and None geometries as such to e.g. GPKG files, Fiona writes both
as None.

.. ipython:: python
    :okwarning:

    import shapely
    
    gdf = geopandas.GeoDataFrame(geometry=[shapely.Polygon(), None], crs=31370)
    gdf.to_file("test_fiona.gpkg", engine="fiona")
    gdf.to_file("test_pyogrio.gpkg", engine="pyogrio")
    geopandas.read_file("test_fiona.gpkg").head()
    geopandas.read_file("test_pyogrio.gpkg").head()