Spatial Database
Spatial Databases store geographic information in the relational format including coordinates and topologies(vectors and raster forms). There are two ways to represent data i.e. vectors and raster. Vector is high-quality geographical data, raster used to show patterns, made available large sets of data.
PostGIS
PostGIS is a spatial database and an extension of PostgreSQL. It is used to perform CRUD operations on GIS data. PostGIS extends PostgreSQL by adding three new features: spatial indexes, spatial types, and spatial functions.
Installing PostGIS
- Go to https://www.pgadmin.org/ and download the latest version of pgAdmin for your system
- Download PostgreSQL from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
- Follow downloading steps from https://postgis.net/workshops/postgis-intro/installation.html.
Gather some data
- Go to https://overpass-turbo.eu/
- Select data of your choice. (Like buildings=*)
- Download data in the form of GeoJson
- Place anywhere in you local storage.
- Query for our course https://overpass-turbo.eu/s/1l0U to download lahore's neighbourhoods
Creating Server and databases
- Install OGR2OG. (Using brew on Mac.) (On Windows)
- Open pgAdmin.
- Create Database.
- Type your password of the master user you created while installing
- Right Click on servers > Register > Server...
Download some data
ogr2ogr -f "PostgreSQL" PG:"dbname=lahore_db user=postgres password=1234" path/lahore-neighbourhoods.geojson -nln lahore_neighbourhoods
Path in above command is used for complete path like C:/Downloads/data.geojson/
Query data
- Open pgadmin
- Refresh your database
- Check the newly created table
- Open the query tool
- Query your data