Spatial database
Spatial database
management system?
Introduction to Spatial • We often need to store the information regarding the geometry
of a system.
Databases • Conventional RDBMS will need multiple tables to store
information of the things like points, lines and polygons.
-A simple square is represented in 16 rows across 3 tables
• This makes operations very complex and slow as many tables
then need to be handled simultaneously.
• The introduction of ORDBMS (Object Relational Database
Management System) removed these problems.
• Thus, spatial databases uses geometrical objects to store the
information of these new datatypes and new operations like
distance and area can be defined upon them.
• Insurance Risk Manager: Which homes are most likely to be affected in the
next great flood on the Mississippi?
• Medical Doctor: Based on this patient's MRI, have we treated somebody with a
An Industry Grade SDBMS
similar condition? PostGIS is an extension for PostgreSQL (which is a powerful open-source
• Molecular Biologist: Is the topology of the amino acid biosynthesis gene in the relational database).
genome found in any other sequence feature map in the database? It adds support for geographic objects, allowing you to store, query, and
• Astronomer: Find all blue galaxies within 2 arcmin of quasars manipulate spatial (location-based) data.
In simple words:
🔹 PostgreSQL = normal database for regular data (like numbers, text)
🔹 PostGIS = upgrade that lets the database understand maps, shapes, and geography
(like points, lines, and polygons)
1
Some Common Data Types -- To allow usage of PostGIS module
CREATE EXTENSION postgis;
in PostGIS: --Defining a relation
CREATE TABLE parks (
•POINT – a single location (e.g., a house’s id SERIAL PRIMARY KEY,
location) name VARCHAR(100),
•LINESTRING – a path (e.g., a road or river) location GEOMETRY(Point, 4326)
•POLYGON – an area (e.g., a park, a city );
boundary) --Find parks within 1 km of a given point (latitude 28.6,
•MULTIPOLYGON, MULTILINESTRING, etc. – longitude 77.1)
for complex shapes SELECT name
•GEOGRAPHY – special type that considers the FROM parks
WHERE ST_DWithin(location, ST_MakePoint(77.1,
Earth’s curvature (important for global data) 28.6)::geography, 1000);