#!/bin/bash # Copyright (c) 2026 Elizabeth Cray SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $SCRIPT_DIR/.env if ! command -v ogr2ogr >/dev/null 2>&1; then echo "ogr2ogr is not installed. Please install it and try again." exit 1 fi if ! command -v curl >/dev/null 2>&1; then echo "curl is not installed. Please install it and try again." exit 1 fi if ! command -v node >/dev/null 2>&1; then echo "Node.js is not installed. Please install it and try again." exit 1 fi if [ -f "$SCRIPT_DIR/osm_data.json" ]; then rm "$SCRIPT_DIR/osm_data.json" fi curl --connect-timeout 950 --location --globoff "$OSM_QUERY" --output "$SCRIPT_DIR/osm_data.json" if [ -f "$SCRIPT_DIR/osm_data.json" ]; then echo "OSM data downloaded to $SCRIPT_DIR/osm_data.json" RESULTLINE=`head -n1 $SCRIPT_DIR/osm_data.json` if [ -z "$RESULTLINE" ]; then echo "OSM data file is empty." exit 1 fi if [[ $RESULTLINE == "" ]]; then echo "OSM data file contains an error." exit 1 fi if [ -f "$SCRIPT_DIR/osm_data.geojson" ]; then rm "$SCRIPT_DIR/osm_data.geojson" fi node "$SCRIPT_DIR/convert_osm.js" echo "OSM data converted to GeoJSON at $SCRIPT_DIR/osm_data.geojson" ogr2ogr -f "PostgreSQL" PG:"$PGSQL_URL" "$SCRIPT_DIR/osm_data.geojson" -nln "$LAYER_NAME" -overwrite echo "OSM data imported into PostgreSQL layer $LAYER_NAME" else echo "Failed to download OSM data." exit 1 fi