Fiona: Allow overwrite/clobbering of GeoJSON files

Created on 3 Apr 2017  路  4Comments  路  Source: Toblerity/Fiona

Expected behavior and actual behavior.

fiona.open('existing.json', 'w', driver='GeoJSON', ...) should clobber the existing file just like Python's builtin open() does. Instead, we get an opaque ValueError: null layer inside session.start(). See also #436 and #437.

Steps to reproduce the problem.

Modification of tests/test_geojson.py's WriteTest.test_json() demonstrates the issue.

Operating system

Any.

Fiona version and provenance

1.7.5 and earlier. All distributions.

bug expert

Most helpful comment

As this bit me today here is a minimal example to reproduce this and the error message I got for googlability. Python 3 with pip packages GDAL==2.2.2 and Fiona==1.7.9.post1.

import fiona
from fiona.crs import from_epsg
from shapely.geometry import Point, mapping

schema = {
    "geometry": "Point",
    "properties": {"id": "int"}
}

feature = {
    "geometry": mapping(Point(0,0)),
    "properties": {"id": "0"}
}

for i in range(2):
    with fiona.open("/tmp/test.geojson", "w", 
                    driver="GeoJSON",
                    schema=schema, 
                    crs=from_epsg(4326)) as sink:
        sink.write(feature)
        print(f"Write #{i+1} succeeded")

CPLE_NotSupportedError: GeoJSON driver doesn't support creating a layer on a read-only datasource
...
During handling of the above exception, another exception occurred:
...
DriverIOError: GeoJSON driver doesn't support creating a layer on a read-only datasource

All 4 comments

Dataset and layer overwriting is complicated in GDAL. It's better in versions 2+ where it's easier to test driver capabilities.

As this bit me today here is a minimal example to reproduce this and the error message I got for googlability. Python 3 with pip packages GDAL==2.2.2 and Fiona==1.7.9.post1.

import fiona
from fiona.crs import from_epsg
from shapely.geometry import Point, mapping

schema = {
    "geometry": "Point",
    "properties": {"id": "int"}
}

feature = {
    "geometry": mapping(Point(0,0)),
    "properties": {"id": "0"}
}

for i in range(2):
    with fiona.open("/tmp/test.geojson", "w", 
                    driver="GeoJSON",
                    schema=schema, 
                    crs=from_epsg(4326)) as sink:
        sink.write(feature)
        print(f"Write #{i+1} succeeded")

CPLE_NotSupportedError: GeoJSON driver doesn't support creating a layer on a read-only datasource
...
During handling of the above exception, another exception occurred:
...
DriverIOError: GeoJSON driver doesn't support creating a layer on a read-only datasource

I'm using fiona-git and still getting:

ERROR Fiona CPLE_NotSupported in b'The GeoJSON driver does not overwrite existing files.'

@eigenwillig Please can you provide some more information:

  • Which platform are you running on? (OS, Python version, GDAL version)
  • Can you confirm the exact version you are running (commit hash)?
  • Do the tests pass (especially test_geojson.py::test_overwrite_json)?
Was this page helpful?
0 / 5 - 0 ratings

Related issues

klonuo picture klonuo  路  3Comments

SeanDS picture SeanDS  路  3Comments

sgillies picture sgillies  路  4Comments

jamesmyatt picture jamesmyatt  路  4Comments

mattijn picture mattijn  路  8Comments