Created
February 21, 2023 21:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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