Skip to content

Instantly share code, notes, and snippets.

@daniel-j-h
Created February 21, 2023 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-j-h/837641870fbf47115806bc7aff654a53 to your computer and use it in GitHub Desktop.
Save daniel-j-h/837641870fbf47115806bc7aff654a53 to your computer and use it in GitHub Desktop.
LUCAS 2018 dataset as a GeoJSON file for simple and easy visualization - https://esdac.jrc.ec.europa.eu/content/lucas-2018-topsoil-data
#!/usr/bin/env python3
import sys
import csv
import json
import argparse
from pathlib import Path
def main(args):
print("reading csv from {}".format(args.input), file=sys.stderr)
geo = { "type": "FeatureCollection", "features": [] }
with args.input.open() as src:
reader = csv.DictReader(src)
for row in reader:
lat, lng = row["TH_LAT"], row["TH_LONG"]
geo["features"] += [{
"type": "Feature",
"properties": row,
"geometry": {
"coordinates": [ lng, lat ],
"type": "Point",
}
}]
print("writing geojson to {}".format(args.out), file=sys.stderr)
with args.out.open("w") as dst:
json.dump(geo, dst, indent=2)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("input", type=Path, help="path to lucas2018 .csv file")
parser.add_argument("-o", "--out", type=Path, required=True, help="path to .geojson output file")
main(parser.parse_args())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment