Skip to content

Instantly share code, notes, and snippets.

@kevin-deyoungster
Created July 14, 2020 15:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevin-deyoungster/11d3412dc86939d63290b6ab6e20a0f6 to your computer and use it in GitHub Desktop.
Save kevin-deyoungster/11d3412dc86939d63290b6ab6e20a0f6 to your computer and use it in GitHub Desktop.
QGIS script to export selected features to GeoJSON (separately)
import json
layer = qgis.utils.iface.activeLayer()
for i, elem in enumerate(layer.selectedFeatures()):
attrs = elem.__geo_interface__
filename = attrs["properties"]["DISTRICT"] # change this to whatever you want to be filename
with open(f"{filename}.geojson", "w") as geo_json_output:
json.dump(attrs, geo_json_output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment