Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save an empty layer to GeoJSON drop all fields #26260

Closed
qgib opened this issue Mar 7, 2018 · 2 comments
Closed

Save an empty layer to GeoJSON drop all fields #26260

qgib opened this issue Mar 7, 2018 · 2 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers

Comments

@qgib
Copy link
Contributor

qgib commented Mar 7, 2018

Author Name: Etienne Trimaille (@Gustry)
Original Redmine Issue: 18370
Affected QGIS version: 3.1(master)
Redmine category:data_provider


I could replicate this issue on both QGIS 2.18 and 3.1, with Python script and using the UI.

If I create an empty memory layer and if I save to geojson, then all my fields are lost:

The python code shows the problem:

v = QgsVectorLayer('Point?crs=epsg:4326&field=id:integer&field=name:string(20)', 'test', 'memory')
print(v.isValid())
print(v.fields().count())

path = '/tmp/test_geojson.geojson'
QgsVectorFileWriter.writeAsVectorFormat(v, path, 'utf-8', v.crs(), 'GeoJSON')
export_layer = QgsVectorLayer(path, 'exported', 'ogr')
print(export_layer.isValid())
print(export_layer.fields().count())

It will output on both QGIS 2 and 3:

True
2
True
0

I hope it's not some layer/dataset creation option. I looked in the OGR documentation too. Nothing I could notice.

This is an issue because I expect to have the same attribute table.


@qgib
Copy link
Contributor Author

qgib commented Mar 7, 2018

Author Name: Etienne Trimaille (@Gustry)


Well, it seems it's not a bug. Because attributes in GeoJSON are defined at the feature level, not at the layer level. So obviously, if no features, then no attribute table.

@qgib
Copy link
Contributor Author

qgib commented Mar 7, 2018

Author Name: Nyall Dawson (@nyalldawson)


  • resolution was changed from to invalid
  • status_id was changed from Open to Closed

@qgib qgib closed this as completed Mar 7, 2018
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers
Projects
None yet
Development

No branches or pull requests

1 participant