Skip to content

Instantly share code, notes, and snippets.

@simonw
Created November 20, 2024 06:01
Show Gist options
  • Save simonw/1e2a170b7368932ebd3922cb5d234924 to your computer and use it in GitHub Desktop.
Save simonw/1e2a170b7368932ebd3922cb5d234924 to your computer and use it in GitHub Desktop.
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.
@simonw
Copy link
Author

simonw commented Nov 20, 2024

Created from this file like this: https://gist.github.com/simonw/53ad57ad42c7efe75e2028d975907180

import json

# Load the JSON data from the file
file_path = '/mnt/data/places.json'
with open(file_path, 'r') as file:
    data = [json.loads(line) for line in file]

# Convert to GeoJSON manually
geojson_data = {
    "type": "FeatureCollection",
    "features": []
}

for place in data:
    feature = {
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [place['longitude'], place['latitude']]
        },
        "properties": {k: v for k, v in place.items() if k not in ['latitude', 'longitude']}
    }
    geojson_data["features"].append(feature)

# Save the GeoJSON data to a file
output_path = '/mnt/data/places.geojson'
with open(output_path, 'w') as geojson_file:
    json.dump(geojson_data, geojson_file)

output_path

Code by ChatGPT Code Interpreter: https://chatgpt.com/share/673d7b92-0b4c-8006-a442-c5e6c2713d9c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment