Skip to content

Instantly share code, notes, and snippets.

@jrmontag
Last active March 4, 2024 02:48
Show Gist options
  • Save jrmontag/1f46b64d986b04603b105ca3979a7afe to your computer and use it in GitHub Desktop.
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
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)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment