no PGSQL
This commit is contained in:
parent
9902419b41
commit
7d24fb338a
3 changed files with 15 additions and 86 deletions
13
.justfile
Normal file
13
.justfile
Normal file
|
|
@ -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
|
||||||
|
|
@ -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")
|
|
||||||
30
install.txt
30
install.txt
|
|
@ -1,30 +1,4 @@
|
||||||
## packages
|
## 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
|
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);
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue