Last active
March 4, 2024 02:48
-
-
Save jrmontag/1f46b64d986b04603b105ca3979a7afe to your computer and use it in GitHub Desktop.
shotspotter geojson (building on https://github.com/kevee/shotspotter-locations ) - map sometimes takes some refreshes
This file contains hidden or 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
import json | |
import logging | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s [%(levelname)s] %(message)s", | |
) | |
def main(input_file, output_file) -> None: | |
with open(input_file, "r") as f: | |
data: dict = json.load(f) | |
events = data["events"] | |
features = [] | |
for idx, event in enumerate(events): | |
lat = float(event["lat"]) | |
lon = float(event["lon"]) | |
metadata = event["metadata"] | |
# geojson spec: | |
# https://datatracker.ietf.org/doc/html/rfc7946 | |
geometry = {"type": "Point", "coordinates": [lon, lat]} | |
properties = {"metadata": ":".join(metadata)} | |
feature = {"type": "Feature", "geometry": geometry, "properties": properties} | |
features.append(feature) | |
if idx % 1000 == 0: | |
logging.info(f"Processed {idx} events") | |
geojson = {"type": "FeatureCollection", "features": features} | |
with open(output_file, "w") as f: | |
json.dump(geojson, f) | |
if __name__ == "__main__": | |
input_file = "shots.json" | |
output_file = "shots.geojson" | |
logging.info(f"Reading: {input_file}; writing: {output_file}") | |
main(input_file, output_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment