Skip to content

Commit

Permalink
Cleanup handling for FlatGeobuf driver
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-ward committed Apr 1, 2021
1 parent dcc2b90 commit 3c91e59
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

## 0.2.0 (unreleased)
## 0.2.0

### Major enhancements

Expand All @@ -18,6 +18,7 @@
- Addition of `pyogrio.__gdal_version__` attribute to return GDAL version tuple
and `__gdal_version_string__` to return string version.
- Addition of `list_drivers` function to list all available GDAL drivers.
- Addition of read and write support for `FlatGeobuf` driver when available in GDAL.

## 0.1.0

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ information.
You can certainly try to read or write using unsupported drivers that are
available in your installation, but you may encounter errors.

Note: different drivers have different tolerance for mixed geometry types, e.g.,
MultiPolygon and Polygon in the same dataset. You will get exceptions if you
attempt to write mixed geometries to a driver that doesn't support them.

### Listing layers

To list layers available in a data source:
Expand Down
4 changes: 2 additions & 2 deletions pyogrio/_io.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,10 @@ def ogr_write(str path, str layer, str driver, geometry, field_data, fields,
layer_b = layer.encode('UTF-8')
layer_c = layer_b

# if shapefile or GeoJSON, always delete first
# if shapefile, GeoJSON, or FlatGeobuf, always delete first
# for other types, check if we can create layers
# GPKG might be the only multi-layer writeable type. TODO: check this
if driver in ('ESRI Shapefile', 'GeoJSON', 'GeoJSONSeq') and os.path.exists(path):
if driver in ('ESRI Shapefile', 'GeoJSON', 'GeoJSONSeq', 'FlatGeobuf') and os.path.exists(path):
os.unlink(path)

# TODO: invert this: if exists then try to update it, if that doesn't work then always create
Expand Down
7 changes: 6 additions & 1 deletion pyogrio/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from pyogrio._io import ogr_read, ogr_read_info, ogr_list_layers, ogr_write


DRIVERS = {".gpkg": "GPKG", ".shp": "ESRI Shapefile", ".json": "GeoJSON"}
DRIVERS = {
".gpkg": "GPKG",
".shp": "ESRI Shapefile",
".json": "GeoJSON",
".fgb": "FlatGeobuf",
}


def read(
Expand Down

0 comments on commit 3c91e59

Please sign in to comment.