question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GeoJSONSeq append to file

See original GitHub issue

Expected behavior and actual behavior.

Appending to a GeoJSON newline-delimited file is not currently supported.

https://github.com/Toblerity/Fiona/blob/2ec38d087fea72c8bd0e7696d8ac1a6203df8851/fiona/drvsupport.py#L54

I can’t find any other issues mentioning appending using GeoJSONSeq, and given the nature of the format, it seems like that should be possible. Where would a PR to enable that take place?

Steps to reproduce the problem.

import fiona
import geopandas as gpd
from geopandas.io.file import infer_schema
from shapely.geometry import Point

gdf = gpd.GeoDataFrame(geometry=[Point([0, 1])])
schema = infer_schema(gdf)
with fiona.open('test.geojson', "w", driver='GeoJSONSeq', schema=schema) as colxn:
    colxn.writerecords(gdf.iterfeatures())

gdf = gpd.GeoDataFrame(geometry=[Point([2, 2])])
schema = infer_schema(gdf)
with fiona.open('test.geojson', "a", driver='GeoJSONSeq', schema=schema) as colxn:
    colxn.writerecords(gdf.iterfeatures())
---------------------------------------------------------------------------
DriverError                               Traceback (most recent call last)
<ipython-input-26-01e338412202> in <module>
----> 1 with fiona.open('test.geojson', "a", driver='GeoJSONSeq', schema=schema) as colxn:
      2 
      3     colxn.writerecords(gdf.iterfeatures())
      4 

~/local/anaconda3/envs/create-database/lib/python3.7/site-packages/fiona/env.py in wrapper(*args, **kwargs)
    405             with Env.from_defaults(session=session):
    406                 log.debug("Credentialized: {!r}".format(getenv()))
--> 407                 return f(*args, **kwargs)
    408     return wrapper
    409 

~/local/anaconda3/envs/create-database/lib/python3.7/site-packages/fiona/__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    252         if mode in ('a', 'r'):
    253             c = Collection(path, mode, driver=driver, encoding=encoding,
--> 254                            layer=layer, enabled_drivers=enabled_drivers, **kwargs)
    255         elif mode == 'w':
    256             if schema:

~/local/anaconda3/envs/create-database/lib/python3.7/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
    161 
    162         if self.session is not None:
--> 163             self.guard_driver_mode()
    164 
    165         if self.mode in ("a", "w"):

~/local/anaconda3/envs/create-database/lib/python3.7/site-packages/fiona/collection.py in guard_driver_mode(self)
    180             raise DriverError("unsupported driver: %r" % driver)
    181         if self.mode not in supported_drivers[driver]:
--> 182             raise DriverError("unsupported mode: %r" % self.mode)
    183 
    184     @property

DriverError: unsupported mode: 'a'

Operating system

For example: Mac OS X 10.15.1

Fiona and GDAL version and provenance

Fiona 1.8.11, from Conda Gdal 3.0.2, from Conda

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
sgilliescommented, Dec 3, 2019

@kannes thank you. This not good: the raison d’être for GeoJSON sequences is to allow incremental parsing and appending. It’s not a write once format.

2reactions
kylebarroncommented, Dec 3, 2019

Yeah, agreed. I’m a little surprised it wasn’t supported by default when the functionality was added. I don’t know C/C++ or else I’d try to make a PR to GDAL. In any case, I’ll see what responses I get on the GDAL issue, linked above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GeoJSONSeq: sequence of GeoJSON features - GDAL
The driver automatically reprojects geometries to WGS84 longitude, latitude, if the layer is created with another SRS. Appending to an existing file is ......
Read more >
Append to geosjon file and save as .js file - Stack Overflow
I want to append "var data =" to geojson file and save it as .js but the file is created with "var data...
Read more >
Command line-tool to convert geojson file to line-delimited ...
I'm loving the ndjson-cli tools for working with newline-delimited GeoJSON files. But I can't seem to find a tool that converts a standard ......
Read more >
14.3. Exploring Data Formats and Fields - QGIS Documentation
Storing geometry information in delimited text files ... and click on Table ▻ Edit table, go to Indexes tab and click on Add...
Read more >
Fiona 2.0dev documentation
Fiona reads and writes geographic data files and thereby helps Python programmers ... Missing GDAL support for TopoJSON, GeoJSONSeq, and ESRIJSON has been ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found