Skip to content

Instantly share code, notes, and snippets.

@krishnaglodha
Created February 13, 2024 05:42
Show Gist options
  • Save krishnaglodha/079dfb7aaef5bb785d43657be0fa7931 to your computer and use it in GitHub Desktop.
Save krishnaglodha/079dfb7aaef5bb785d43657be0fa7931 to your computer and use it in GitHub Desktop.
Send GeoJSON to existing postgis table
#!/bin/bash
# Set the variables
PGHOST=""
PGDATABASE=""
PGUSER=""
PGPASSWORD=""
PGPORT=""
TABLE_NAME=""
GEOJSON_FILE=""
SCHEMA_NAME=""
# Use ogr2ogr to append GeoJSON data to the existing table in PostgreSQL
ogr2ogr -f "PostgreSQL" PG:"host=$PGHOST dbname=$PGDATABASE user=$PGUSER password=$PGPASSWORD port=$PGPORT" \
-nln "$SCHEMA_NAME.$TABLE_NAME" -progress -append $GEOJSON_FILE
# Check if the ogr2ogr command was successful
if [ $? -eq 0 ]; then
echo "GeoJSON data appended to the PostgreSQL table successfully."
else
echo "Error: Unable to append GeoJSON data to the PostgreSQL table."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment