diff --git a/.justfile b/.justfile new file mode 100644 index 0000000..47b44fc --- /dev/null +++ b/.justfile @@ -0,0 +1,13 @@ +extract input output: + quackosm {{input}} --osm-tags-filter-file tags.json --silent --compact --output {{output}} + +download region output: + quackosm --geom-filter-geocode {{region}} --osm-extract-source Geofabrik --osm-tags-filter-file tags.json --compact --output {{output}} + +convert input output: + python3 slice.py --input {{input}} --output {{output}} + +plot file: + #!/usr/bin/env bash + stem=$(basename {{file}} .parquet) + python3 plot.py -i {{file}} -o ${stem}.png \ No newline at end of file diff --git a/import_osm.py b/import_osm.py deleted file mode 100644 index f253f5f..0000000 --- a/import_osm.py +++ /dev/null @@ -1,58 +0,0 @@ -import json -import psycopg2 -from shapely.geometry import shape - -def import_geojson(filepath): - conn = psycopg2.connect( - dbname="gis_data", - user="osm", - password="osm", - host="localhost" - ) - cur = conn.cursor() - - try: - with open(filepath) as f: - data = json.load(f) - - if data["type"] != "FeatureCollection": - raise ValueError("GeoJSON must be a FeatureCollection") - - for idx, feature in enumerate(data["features"]): - try: - geom_type = feature["geometry"]["type"] - properties = feature["properties"] - geom = shape(feature["geometry"]) - wkt = geom.wkt - - # Insert lines - if geom_type == "LineString": - cur.execute(""" - INSERT INTO osm_lines (geometry, tags) - VALUES (ST_GeomFromText(%s, 4326), %s) - """, (wkt, json.dumps(properties))) - - # Insert polygons AND multipolygons - elif geom_type in ("Polygon", "MultiPolygon"): - cur.execute(""" - INSERT INTO osm_polygons (geometry, tags) - VALUES (ST_GeomFromText(%s, 4326), %s) - """, (wkt, json.dumps(properties))) - - else: - print(f"Skipping unsupported geometry type: {geom_type}") - - except Exception as e: - print(f"Error processing feature {idx}: {e}") - continue - - conn.commit() - - except json.JSONDecodeError: - print("Invalid JSON file. Ensure filtered.geojson is correctly generated.") - finally: - cur.close() - conn.close() - -if __name__ == "__main__": - import_geojson("israel.geojson") diff --git a/install.txt b/install.txt index 5892977..30375af 100644 --- a/install.txt +++ b/install.txt @@ -1,30 +1,4 @@ ## packages -sudo dnf install postgresql-server postgresql-contrib postgis osmium-tool jq python3-devel pip +sudo dnf install osmium-tool jq python3-devel pip -pip install quackosm[cli] psycopg2-binary pyosmium geoalchemy2 geojson shapely - -## PostgreSQL setup -sudo postgresql-setup --initdb -sudo -u postgres psql - -CREATE USER osm WITH PASSWORD 'osm'; -CREATE DATABASE gis_data OWNER osm; -\q -sudo -u postgres psql -d gis_data - -CREATE TABLE osm_lines ( - id SERIAL PRIMARY KEY, - geometry GEOMETRY(LINESTRING, 4326), - tags JSONB -); - -CREATE TABLE osm_polygons ( - id SERIAL PRIMARY KEY, - geometry GEOMETRY(POLYGON, 4326), - tags JSONB -); - -CREATE INDEX idx_osm_lines_geometry ON osm_lines USING GIST(geometry); -CREATE INDEX idx_osm_polygons_geometry ON osm_polygons USING GIST(geometry); -CREATE INDEX idx_osm_lines_tags ON osm_lines USING GIN(tags); -CREATE INDEX idx_osm_polygons_tags ON osm_polygons USING GIN(tags); +pip install quackosm[cli] psycopg2-binary pyosmium geoalchemy2 geojson shapely \ No newline at end of file