SlideShare a Scribd company logo
© 2018 EnterpriseDB® Corporation. All rights reserved. 1
DISCOVER POSTGIS
1
Mansur Shaikh
CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2019. All rights reserved.
CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2018. All rights reserved.
THE DATABASE PLATFORM COMPANY FOR DIGITAL
BUSINESS
EnterpriseDB (EDB) delivers the premier open source-based, multi-model data platform for new
applications, cloud re-platforming, application modernization, and legacy migration.
2
© Copyright EnterpriseDB Corporation, 2018. All rights reserved.
Who is EDB?
© Copyright EnterpriseDB Corporation, 2018. All rights reserved.
WHO IS EDB?
Founded in 2004
Customer base > 4000
500+ employees in offices worldwide
Recognized RDBMS leader
Gartner
Forrester
Largest PostgreSQL community leader:
• EDB Postgres Technology Platform
• Services, Training & RDBA
• Community PostgreSQL Experts
• Community contributions and influence
• Partner ecosystem
The world leader in open-source based
Postgres software and services.
© 2018 EnterpriseDB® Corporation. All rights reserved. 5
CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2019. All rights reserved.
5
Customers working SMARTER, reducing RISK and being more PRODUCTIVE with EDB.
OVER 4,000 CUSTOMERS
U.S Customers
EMEA Customers APAC Customers
102
of the
Fortune 500
337
of the Forbes
Global 2000
WORLDWIDE PRESENCE
CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2019. All rights reserved.6
CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2018. All rights reserved.
ONLY OPEN
SOURCE RDBMS IN
GARTNER MQ
EDB Recognized
7 Years In A Row on
Gartner’s Magic
Quadrant
© 2015 EnterpriseDB Corporation. All rights reserved. 8
Getting started with PostGIS
© 2018 EnterpriseDB® Corporation. All rights reserved. 9
About PostGIS
• Refractions Research released first version in 2001 under
the GNU license
• Follows the Simple Features for SQL specification from the
Open Geospatial Consortium (OGC)
• Over 300 spatial operators and spatial functions
− Processing and analytical functions
• Spatial data types
• Spatial indexing
• Spatial reprojection
• Import / Export shapefiles (command line and GUI)
• Commands for importing raster data
• SQL commands to render and import data from multiple
formats such GeoJSON, KML, GML, and WTK
9
© 2018 EnterpriseDB® Corporation. All rights reserved. 10
PostGIS : Getting started with spatial databases
• QGIS
− Open Source desktop GIS
• Enterprise GIS
− An integrated GIS system that is accessible throughout your organization
• Spatial database
− A centralized location for storing spatial data
− Spatial features for dealing with spatial data and analysis
• PostGIS
− A specific implementation of a spatial database built on the PostgreSQl database
© 2018 EnterpriseDB® Corporation. All rights reserved. 11
PostGIS Data Types
Geometry
Geography
Raster Topology
© 2018 EnterpriseDB® Corporation. All rights reserved. 12
PostGIS Data subtypes
Point
Linestring
Polygon
Multipoint
Multilinestring
Multipolygon
© 2018 EnterpriseDB® Corporation. All rights reserved. 13
Spatial Definitions Examples (1 of 5)
Boundary
© 2018 EnterpriseDB® Corporation. All rights reserved. 14
Spatial Definitions Examples (2 of 5)
© 2018 EnterpriseDB® Corporation. All rights reserved. 15
Spatial Definitions Examples (3 of 5)
© 2018 EnterpriseDB® Corporation. All rights reserved. 16
Spatial Definitions Examples (4 of 5)
Equals
© 2018 EnterpriseDB® Corporation. All rights reserved. 17
Getting started (loading data…)
17
INSERT into events_geo(eventname,geom,date)
SELECT eventname,
st_setsrid(st_makepoint(lon,lat),4326) as geom,date
FROM events;
Events Table
eventname character varying
lat double precision
lon double precision
Date timestamp with time zone
events_geo Table
eventname character varying
lat double precision
Lon double precision
Date timestamp with time zone
© 2018 EnterpriseDB® Corporation. All rights reserved. 18
Getting started (visual inspection)
18
© 2018 EnterpriseDB® Corporation. All rights reserved. 19
Getting started (visual inspection)
19
© 2018 EnterpriseDB® Corporation. All rights reserved. 20
Getting started (Geometry Input and Output)
20
Example Input function
Insert into cities (name,state,geom)
Values (‘Bedford’,’MA’,
ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
© 2018 EnterpriseDB® Corporation. All rights reserved. 21
Getting started (Power of GIS & SQL)
Create a route from a collection of waypoints captured in sequence
Write a function to tell whether a given lat/lon pair is
within a Point-Radius ring
© 2018 EnterpriseDB® Corporation. All rights reserved. 22
Getting started (Power of GIS & SQL)
34, 9
70, 12
Simple distance query between two points
SELECT ST_Distance
(ST_GeomFromText('POINT(34 9)’,4629),
ST_GeomFromText('POINT(70 12)’,4629));
© 2018 EnterpriseDB® Corporation. All rights reserved. 23
Getting started (Power of GIS & SQL)
Create a route from a collection of waypoints captured in sequence
Write a function to tell whether a given lat/lon pair is
within a Point-Radius ring
© 2018 EnterpriseDB® Corporation. All rights reserved. 24
Getting started (Power of GIS & SQL)
All the powerful tools of the RDBMS are available to you
Insert into cities (name,state,geom)
Values (‘Bedford’,’MA’,
ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
© 2018 EnterpriseDB® Corporation. All rights reserved. 25
Getting started (Power of GIS & SQL)
Answer powerful questions with a simple query
Example Input function
Insert into cities (name,state,geom)
Values (‘Bedford’,’MA’,
ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
© 2018 EnterpriseDB® Corporation. All rights reserved. 26
Getting started (Power of GIS & SQL)
© 2018 EnterpriseDB® Corporation. All rights reserved. 27
What exactly is a spatial database ?
• Simple features standard (SFS) developed by Open Geospatial
Consortium
− Storage
− Geometry-BLOB Field
− Spatial functions (buffer, intersect, etc)
− PostGIS- ST_buffer(geom,400)
− SQL Server-geom.STBuffer(400)
− SQL/MM Spatial-extends SFS
• Spatial Indexes
© 2018 EnterpriseDB® Corporation. All rights reserved. 28
Simple SQL Statement
• Select nest_id, recentstat, ST_Distance(geom, home) from raptor_nests
• Where recentspec=‘RTHA’
• Order by recentstat, nest_id;
• Why use SQl – Standard, Text based, store in database, backups in plain
text format, sent from web pages
© 2015 EnterpriseDB Corporation. All rights reserved. 29
PostGIS Installation
© 2018 EnterpriseDB® Corporation. All rights reserved. 30
Installing PostGIS on your Local Computer
https://www.enterprisedb.com/downloads/postgis
© 2018 EnterpriseDB® Corporation. All rights reserved. 31
PgAdmin4
Open PgAdmin4
Select on server and create server
Right click on database and create database -> sdb_course
Select sdb_course-> verify extensions and schemas and functions
Add PostGIS extension
Select sdb_course
Open query tool-> create extension postgis;
Verify functions, extensions and public schema
spatial_ref_sys
© 2018 EnterpriseDB® Corporation. All rights reserved. 32
Installing QGIS : DEMO
• Download link
https://qgis.org/en/site/forusers/download.html
© 2018 EnterpriseDB® Corporation. All rights reserved. 33
Loading Spatial data into PostGIS
− Resource file :- sdb_data.zip
− Loading shapefile
− Using PostGIS shapefile and dbf exporter
− Command line :- c:programefilespostgresql11bin
− raster2pgsql , shp2pgsql
− Open Postgres shapefile import/export manager
− View connection detail-> import->add file
− Goto S DB_DATA folder -> load baea-nests.shp and bowl_habitat.shp
− Give special reference id is 4326
© 2018 EnterpriseDB® Corporation. All rights reserved. 34
Loading Spatial data into PostGIS using QGIS
• Load into QGIS and then put into PostGIS
− Any type of vector data you can load and view – ESRIGeo, or Jeojson, GPS file
− Select SDB_DATA folder from browser panel and drag and paste layers panel
− Select three file GBH_Rookeries.shp, Linear_Projects.shp, Raptor_Nests-shp
− First make connection
− Select database-> Dbmanager ->
− Make a connection with postgis from Browser panel -> provide connection information
− Click on basic for authentication and click on store -> Test connection
− List tables with no geometry
− Click on ok
− Click on import
− Give input file GBH_Rookeries, Linear_projects, Raptor_nests one by one
Go to PGAdmin4 and verify sdb_course with these five tables
© 2018 EnterpriseDB® Corporation. All rights reserved. 35
Accessing PostGIS from the commandline, the pgAdmin, QGIS
− C:programefilepostgresql11binshp2pgsql
− C:programefilepostgresql11binraster2pgsql
− pgAdmin4
− Open query tools
 Select * from baue_nests
Some other tables with geometry column
© 2018 EnterpriseDB® Corporation. All rights reserved. 36
4. Making SQL Spatial
• The PostGIS Vector Geometry model
• The Spatial reference ID
• The Geometry field
• Geometry vs Geography data type
• Spatial queries-working with Geometries
• Spatial queries-Measurement
• Spatial queries – Accessing the geometry
© 2018 EnterpriseDB® Corporation. All rights reserved. 37
4. Vector Geometry Model
• Conforms to the OGC SFS standard
• Basic data structure is a Point
− 2 dimension –X and Y values. (longitude and latitude), projection
− 3 Dimension value- z values
• Line String is an array of points
• Polygon is an array of closed LineString’s
− First Linestring is an exterior ring
− Each following LineString is an interior ring
© 2018 EnterpriseDB® Corporation. All rights reserved. 38
4. Vector Geometry Model. Cont..
• Multi-Part geometries
− Array of individual geometries
− Multipoint
− MultiLinestring
− MultiPolygon
• Features
− Geometry
− Attributes(field, properties,etc)
© 2018 EnterpriseDB® Corporation. All rights reserved. 39
Spatial Reference ID
• Unique identifier for a coordinate reference system
− Coordinate System :- based in angles based on earth
− Projection
− Zone
− Datum
• In PostGIS you indicate the Spatial Reference by a number
• That number corresponds to well known Text
• Individual Geometries can have a spatial reference
• Geometry columns have a spatial reference
© 2018 EnterpriseDB® Corporation. All rights reserved. 40
The Geometry field
• The geometry field is what makes a table spatial
• Its just a column in the database that can store a feature geometry
• It includes the SRID, the geometry type, and the actual coordinates in
binary form
• We can’t interpret the binary data but PostGIS provides a number of
functions that can output the geometry in human readable format
binary data could be picture, shape any things
These are functions that can output geometry as human redable text
• ST_AsText(), ST_AsEWKT(), ST_AsGeoJSON, etc.
• The combination of a geometry and the attribute that describes that
geometry is known as features
© 2018 EnterpriseDB® Corporation. All rights reserved. 41
Geometry vs Geography
• Two different ways to store a features spatial information
− Geometry (data type). Based on plain surface
− Geography. (data type). Based on circular earth , math behind calculation is
complicated
• Geometry
− Based on planner surface
− Can be in a variety of coordinates reference systems defined by OGC
− Are mathematically simple
− Rich set of functions available
− OGC standard , GEOS libraries, etc.
− Accuracy declines as spatial extent increases.
© 2018 EnterpriseDB® Corporation. All rights reserved. 42
Geometry vs Geography cont ..
• Geography
− Based on round earth
− Can only be in geographic coordinates system (latitude/longitude)
− Are mathematically complex
− Only support a fraction of the functions that are available for geometries
− Accurate measurements
− Which should you use ??
− Scale of your data and if larger distance use geography
− Availability of functions that you need
− performance
© 2018 EnterpriseDB® Corporation. All rights reserved. 43
Working with Geometries
• What can we do with Geometries in PostGIS
− Get information about it
− GeometryType(geom) what type point, line or polygon
− ST_CoordDIM(geom). How many coordinate associate with each points
− ST_Dimension(geom). Like if line then it is one dimenstional, polygon is area which is two
dimensional
− ST_SRID(geom). :- special reference id for geometry
− ST_IsCollection(geom) :- returns true if geometry is single point or multipoint polygon
− ST_NumGeometries(geom),ST_NuminteriorRings(geom),ST_NumPoints(geom)
− ST_IsSimple(geom),ST_IsEmpty(geom),ST_IsClosed(geom),ST_isRing(geom)
− ST_IsValid(geom), ST_IsValidReason(geom)
• Change it’s spatial reference
• ST_SetSRID(geom,SRID) changes special reference id associated with that geometry
• ST_Transform(geom,SRID) converts one coordinate reference system to another
© 2018 EnterpriseDB® Corporation. All rights reserved. 44
Spatial Queries :- Measurements
• What we can do with geometry ?
− Measure it
− ST_Length(line)
− Geometry- Cartesian length in SRID units
− Geography-length in meters over the spheroid
− ST_3DLength(line)
- Geometry-3D cartesian length using SRID
- Geography - Not supported
− ST_LengthSpheroid(line, spheroid)
− ST_Area(polygon)
− Geometry- cartesian area in SRID units
− Geography-area in square meters over the spheroid
− ST_Perimeter(polygon), ST_3DPerimeter(polygon)
© 2018 EnterpriseDB® Corporation. All rights reserved. 45
Spatial Queries :- Accessing the Geometries
• What we can do with geometry ?
− Calculate distance from other geometries
− ST_Distance(geom1,geom2)
Geometry-cartesian distance in SRID units
Geography – length in meters over the spheroid
− ST_3DDistance(geom1,geom2)
- Geometry- cartesian distance using SRID in units
- Geography - Not supported
ST_DistanceSphere(geom1,geom2)
Geometry-cartesian area in SRID units squre degrees
Geography:- area in squre meters over the spheroid
ST_Perimeter(polygon), ST3DPerimeter(polygon)
© 2018 EnterpriseDB® Corporation. All rights reserved. 46
Spatial Queries :- Accessing the Geometries
• What we can do with geometry ?
− Calculate distance from other geometries
− See it’s coordinate in text form
− ST_AsText(geom), ST_AsWKT(geom)
− ST_AsGeoJSON(geom)
− ST_AsGML(geom), ST_AsKML(geom)
− ST_AsMVT(table)
− Access it’s Coordinates
- ST_X(point), ST_Y(point), ST_Z(point), ST_M(point)
- ST_StartPoint(geom0, ST_EndPoint(geom)
− ST_PointN(geom,n), ST_LineinterpolatePoint(geom,proportion)
− ST_GeometryN(geom,n)
− ST_ExteriorRing(geom), ST_interiorRingN(geom,n)
© 2018 EnterpriseDB® Corporation. All rights reserved. 47
• Docs - http://www.postgis.org/docs/
• PostGIS in Action, 2nd Edition
− http://www.amazon.com/gp/search?index=books&linkCode=qs&keywords=9781617291395
Resources:
© 2018 EnterpriseDB® Corporation. All rights reserved. 48
48
Postgres Vision Goes Virtual in 2020.
APJ Track on 24th June
Time: 8.30am – 11.45am IST/
11.00am – 2.45pm Singapore/1.00pm to 4.45pm AU EST
Attend from the comfort of your home. Learn:
• how organizations are using PostgreSQL to reduce cost & increase innovation
• the tools and technology that PostgreSQL experts are using
• how developers are using PostgreSQL databases
• about the of future of PostgreSQL and much more
REGISTER NOW
© 2018 EnterpriseDB® Corporation. All rights reserved. 49
THANK YOU
info@enterprisedb.com
www.enterprisedb.com
CONFIDENTIAL © Copyright EnterpriseDB

More Related Content

What's hot (20)

PDF
Land Use/Land Cover Mapping Of Allahabad City by Using Remote Sensing & GIS
IJMER
 
PPTX
GIS User to Web-GIS Developer Journey
Tek Kshetri
 
PPTX
NOSQL vs SQL
Mohammed Fazuluddin
 
PPTX
Sql vs NoSQL-Presentation
Shubham Tomar
 
PPT
Introduction to GIS systems
Vivek Srivastava
 
PPTX
Oracle Spatial de la A a la Z - Unidad 3
Jorge Ulises
 
PPT
Arcgis training day_1
yashasweesharma
 
PDF
Introduction to ArcGIS 10.1
Claudio Montoni
 
PPT
Chap1 introduction to geographic information system (gis)
Mweemba Hachita
 
PPT
Google Earth Basics
teedawg12
 
PPTX
Spatial Database and Database Management System
Lal Mohammad
 
PDF
What is GIS
Esri
 
PPTX
GIS and spatial-modelling
Julian Swindell
 
PPT
Google Earth
bananagrl6913
 
PDF
SQL vs. NoSQL Databases
Osama Jomaa
 
PPT
Web mapping
Sareuon Soum
 
PDF
Open Source GIS
Iwan Setiawan
 
PDF
SQL-Server Database.pdf
ShehryarSH1
 
PPTX
Mastering Security with GeoServer and GeoFence - FOSS4G EU 2017
GeoSolutions
 
PPTX
ElasticSearch : Architecture et Développement
Mohamed hedi Abidi
 
Land Use/Land Cover Mapping Of Allahabad City by Using Remote Sensing & GIS
IJMER
 
GIS User to Web-GIS Developer Journey
Tek Kshetri
 
NOSQL vs SQL
Mohammed Fazuluddin
 
Sql vs NoSQL-Presentation
Shubham Tomar
 
Introduction to GIS systems
Vivek Srivastava
 
Oracle Spatial de la A a la Z - Unidad 3
Jorge Ulises
 
Arcgis training day_1
yashasweesharma
 
Introduction to ArcGIS 10.1
Claudio Montoni
 
Chap1 introduction to geographic information system (gis)
Mweemba Hachita
 
Google Earth Basics
teedawg12
 
Spatial Database and Database Management System
Lal Mohammad
 
What is GIS
Esri
 
GIS and spatial-modelling
Julian Swindell
 
Google Earth
bananagrl6913
 
SQL vs. NoSQL Databases
Osama Jomaa
 
Web mapping
Sareuon Soum
 
Open Source GIS
Iwan Setiawan
 
SQL-Server Database.pdf
ShehryarSH1
 
Mastering Security with GeoServer and GeoFence - FOSS4G EU 2017
GeoSolutions
 
ElasticSearch : Architecture et Développement
Mohamed hedi Abidi
 

Similar to Discover PostGIS: Add Spatial functions to PostgreSQL (20)

PPT
Building a Spatial Database in PostgreSQL
Sohail Akbar Goheer
 
PPTX
FOSS4G 2017 Spatial Sql for Rookies
Todd Barr
 
PDF
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
GIS in the Rockies
 
PDF
Leicester 2010 notes
Joanne Cook
 
PDF
Building A Spatial Database In Postgresql (Ppt).pdf
ssuser0ab1a4
 
PDF
Osgis 2010 notes
Joanne Cook
 
PDF
Building Location Aware Apps - Get Started with PostGIS, PART I
lasmasi
 
PDF
Pg intro part1-theory_slides
lasmasi
 
PPT
Building a Spatial Database in PostgreSQL
Kudos S.A.S
 
PDF
Post gispguk
lbtlsystems
 
PDF
Postgis for Enterprise
GeoLivre Conference
 
PDF
map3d_mapguide_postgis
Prasad PANDIT
 
PPT
Getting started with PostGIS geographic database
EDINA, University of Edinburgh
 
PPT
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
JISC GECO
 
PPT
PostGIS Workshop: a comprehensive tutorial.ppt
LonJames2
 
PPTX
Lecture 1 - Introduction to GIS and SDI.pptx
sinonabdoulwali
 
PPT
Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
ACSG Section Montréal
 
PPT
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
Steven Pousty
 
PPTX
Why is postgis awesome?
Kasper Van Lombeek
 
PPTX
design_doc
Aman Gill
 
Building a Spatial Database in PostgreSQL
Sohail Akbar Goheer
 
FOSS4G 2017 Spatial Sql for Rookies
Todd Barr
 
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
GIS in the Rockies
 
Leicester 2010 notes
Joanne Cook
 
Building A Spatial Database In Postgresql (Ppt).pdf
ssuser0ab1a4
 
Osgis 2010 notes
Joanne Cook
 
Building Location Aware Apps - Get Started with PostGIS, PART I
lasmasi
 
Pg intro part1-theory_slides
lasmasi
 
Building a Spatial Database in PostgreSQL
Kudos S.A.S
 
Post gispguk
lbtlsystems
 
Postgis for Enterprise
GeoLivre Conference
 
map3d_mapguide_postgis
Prasad PANDIT
 
Getting started with PostGIS geographic database
EDINA, University of Edinburgh
 
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
JISC GECO
 
PostGIS Workshop: a comprehensive tutorial.ppt
LonJames2
 
Lecture 1 - Introduction to GIS and SDI.pptx
sinonabdoulwali
 
Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
ACSG Section Montréal
 
LinuxFest NW - Using Postgis To Add Some Spatial Flavor To Your App
Steven Pousty
 
Why is postgis awesome?
Kasper Van Lombeek
 
design_doc
Aman Gill
 
Ad

More from EDB (20)

PDF
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
PDF
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
PDF
Migre sus bases de datos Oracle a la nube
EDB
 
PDF
EFM Office Hours - APJ - July 29, 2021
EDB
 
PDF
Benchmarking Cloud Native PostgreSQL
EDB
 
PDF
Las Variaciones de la Replicación de PostgreSQL
EDB
 
PDF
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
PDF
Is There Anything PgBouncer Can’t Do?
EDB
 
PDF
Data Analysis with TensorFlow in PostgreSQL
EDB
 
PDF
Practical Partitioning in Production with Postgres
EDB
 
PDF
A Deeper Dive into EXPLAIN
EDB
 
PDF
IOT with PostgreSQL
EDB
 
PDF
A Journey from Oracle to PostgreSQL
EDB
 
PDF
Psql is awesome!
EDB
 
PDF
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
PPTX
Comment sauvegarder correctement vos données
EDB
 
PDF
Cloud Native PostgreSQL - Italiano
EDB
 
PDF
New enhancements for security and usability in EDB 13
EDB
 
PPTX
Best Practices in Security with PostgreSQL
EDB
 
PDF
Cloud Native PostgreSQL - APJ
EDB
 
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
EDB
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
EDB
 
Migre sus bases de datos Oracle a la nube
EDB
 
EFM Office Hours - APJ - July 29, 2021
EDB
 
Benchmarking Cloud Native PostgreSQL
EDB
 
Las Variaciones de la Replicación de PostgreSQL
EDB
 
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
Is There Anything PgBouncer Can’t Do?
EDB
 
Data Analysis with TensorFlow in PostgreSQL
EDB
 
Practical Partitioning in Production with Postgres
EDB
 
A Deeper Dive into EXPLAIN
EDB
 
IOT with PostgreSQL
EDB
 
A Journey from Oracle to PostgreSQL
EDB
 
Psql is awesome!
EDB
 
EDB 13 - New Enhancements for Security and Usability - APJ
EDB
 
Comment sauvegarder correctement vos données
EDB
 
Cloud Native PostgreSQL - Italiano
EDB
 
New enhancements for security and usability in EDB 13
EDB
 
Best Practices in Security with PostgreSQL
EDB
 
Cloud Native PostgreSQL - APJ
EDB
 
Ad

Recently uploaded (20)

PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Digital Circuits, important subject in CS
contactparinay1
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 

Discover PostGIS: Add Spatial functions to PostgreSQL

  • 1. © 2018 EnterpriseDB® Corporation. All rights reserved. 1 DISCOVER POSTGIS 1 Mansur Shaikh CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2019. All rights reserved.
  • 2. CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2018. All rights reserved. THE DATABASE PLATFORM COMPANY FOR DIGITAL BUSINESS EnterpriseDB (EDB) delivers the premier open source-based, multi-model data platform for new applications, cloud re-platforming, application modernization, and legacy migration. 2
  • 3. © Copyright EnterpriseDB Corporation, 2018. All rights reserved. Who is EDB?
  • 4. © Copyright EnterpriseDB Corporation, 2018. All rights reserved. WHO IS EDB? Founded in 2004 Customer base > 4000 500+ employees in offices worldwide Recognized RDBMS leader Gartner Forrester Largest PostgreSQL community leader: • EDB Postgres Technology Platform • Services, Training & RDBA • Community PostgreSQL Experts • Community contributions and influence • Partner ecosystem The world leader in open-source based Postgres software and services.
  • 5. © 2018 EnterpriseDB® Corporation. All rights reserved. 5 CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2019. All rights reserved. 5 Customers working SMARTER, reducing RISK and being more PRODUCTIVE with EDB. OVER 4,000 CUSTOMERS U.S Customers EMEA Customers APAC Customers 102 of the Fortune 500 337 of the Forbes Global 2000
  • 6. WORLDWIDE PRESENCE CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2019. All rights reserved.6
  • 7. CONFIDENTIAL © Copyright EnterpriseDB Corporation, 2018. All rights reserved. ONLY OPEN SOURCE RDBMS IN GARTNER MQ EDB Recognized 7 Years In A Row on Gartner’s Magic Quadrant
  • 8. © 2015 EnterpriseDB Corporation. All rights reserved. 8 Getting started with PostGIS
  • 9. © 2018 EnterpriseDB® Corporation. All rights reserved. 9 About PostGIS • Refractions Research released first version in 2001 under the GNU license • Follows the Simple Features for SQL specification from the Open Geospatial Consortium (OGC) • Over 300 spatial operators and spatial functions − Processing and analytical functions • Spatial data types • Spatial indexing • Spatial reprojection • Import / Export shapefiles (command line and GUI) • Commands for importing raster data • SQL commands to render and import data from multiple formats such GeoJSON, KML, GML, and WTK 9
  • 10. © 2018 EnterpriseDB® Corporation. All rights reserved. 10 PostGIS : Getting started with spatial databases • QGIS − Open Source desktop GIS • Enterprise GIS − An integrated GIS system that is accessible throughout your organization • Spatial database − A centralized location for storing spatial data − Spatial features for dealing with spatial data and analysis • PostGIS − A specific implementation of a spatial database built on the PostgreSQl database
  • 11. © 2018 EnterpriseDB® Corporation. All rights reserved. 11 PostGIS Data Types Geometry Geography Raster Topology
  • 12. © 2018 EnterpriseDB® Corporation. All rights reserved. 12 PostGIS Data subtypes Point Linestring Polygon Multipoint Multilinestring Multipolygon
  • 13. © 2018 EnterpriseDB® Corporation. All rights reserved. 13 Spatial Definitions Examples (1 of 5) Boundary
  • 14. © 2018 EnterpriseDB® Corporation. All rights reserved. 14 Spatial Definitions Examples (2 of 5)
  • 15. © 2018 EnterpriseDB® Corporation. All rights reserved. 15 Spatial Definitions Examples (3 of 5)
  • 16. © 2018 EnterpriseDB® Corporation. All rights reserved. 16 Spatial Definitions Examples (4 of 5) Equals
  • 17. © 2018 EnterpriseDB® Corporation. All rights reserved. 17 Getting started (loading data…) 17 INSERT into events_geo(eventname,geom,date) SELECT eventname, st_setsrid(st_makepoint(lon,lat),4326) as geom,date FROM events; Events Table eventname character varying lat double precision lon double precision Date timestamp with time zone events_geo Table eventname character varying lat double precision Lon double precision Date timestamp with time zone
  • 18. © 2018 EnterpriseDB® Corporation. All rights reserved. 18 Getting started (visual inspection) 18
  • 19. © 2018 EnterpriseDB® Corporation. All rights reserved. 19 Getting started (visual inspection) 19
  • 20. © 2018 EnterpriseDB® Corporation. All rights reserved. 20 Getting started (Geometry Input and Output) 20 Example Input function Insert into cities (name,state,geom) Values (‘Bedford’,’MA’, ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
  • 21. © 2018 EnterpriseDB® Corporation. All rights reserved. 21 Getting started (Power of GIS & SQL) Create a route from a collection of waypoints captured in sequence Write a function to tell whether a given lat/lon pair is within a Point-Radius ring
  • 22. © 2018 EnterpriseDB® Corporation. All rights reserved. 22 Getting started (Power of GIS & SQL) 34, 9 70, 12 Simple distance query between two points SELECT ST_Distance (ST_GeomFromText('POINT(34 9)’,4629), ST_GeomFromText('POINT(70 12)’,4629));
  • 23. © 2018 EnterpriseDB® Corporation. All rights reserved. 23 Getting started (Power of GIS & SQL) Create a route from a collection of waypoints captured in sequence Write a function to tell whether a given lat/lon pair is within a Point-Radius ring
  • 24. © 2018 EnterpriseDB® Corporation. All rights reserved. 24 Getting started (Power of GIS & SQL) All the powerful tools of the RDBMS are available to you Insert into cities (name,state,geom) Values (‘Bedford’,’MA’, ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
  • 25. © 2018 EnterpriseDB® Corporation. All rights reserved. 25 Getting started (Power of GIS & SQL) Answer powerful questions with a simple query Example Input function Insert into cities (name,state,geom) Values (‘Bedford’,’MA’, ST_GeomFromText(‘POINT(-71.248063 42.510547)’,4326));
  • 26. © 2018 EnterpriseDB® Corporation. All rights reserved. 26 Getting started (Power of GIS & SQL)
  • 27. © 2018 EnterpriseDB® Corporation. All rights reserved. 27 What exactly is a spatial database ? • Simple features standard (SFS) developed by Open Geospatial Consortium − Storage − Geometry-BLOB Field − Spatial functions (buffer, intersect, etc) − PostGIS- ST_buffer(geom,400) − SQL Server-geom.STBuffer(400) − SQL/MM Spatial-extends SFS • Spatial Indexes
  • 28. © 2018 EnterpriseDB® Corporation. All rights reserved. 28 Simple SQL Statement • Select nest_id, recentstat, ST_Distance(geom, home) from raptor_nests • Where recentspec=‘RTHA’ • Order by recentstat, nest_id; • Why use SQl – Standard, Text based, store in database, backups in plain text format, sent from web pages
  • 29. © 2015 EnterpriseDB Corporation. All rights reserved. 29 PostGIS Installation
  • 30. © 2018 EnterpriseDB® Corporation. All rights reserved. 30 Installing PostGIS on your Local Computer https://www.enterprisedb.com/downloads/postgis
  • 31. © 2018 EnterpriseDB® Corporation. All rights reserved. 31 PgAdmin4 Open PgAdmin4 Select on server and create server Right click on database and create database -> sdb_course Select sdb_course-> verify extensions and schemas and functions Add PostGIS extension Select sdb_course Open query tool-> create extension postgis; Verify functions, extensions and public schema spatial_ref_sys
  • 32. © 2018 EnterpriseDB® Corporation. All rights reserved. 32 Installing QGIS : DEMO • Download link https://qgis.org/en/site/forusers/download.html
  • 33. © 2018 EnterpriseDB® Corporation. All rights reserved. 33 Loading Spatial data into PostGIS − Resource file :- sdb_data.zip − Loading shapefile − Using PostGIS shapefile and dbf exporter − Command line :- c:programefilespostgresql11bin − raster2pgsql , shp2pgsql − Open Postgres shapefile import/export manager − View connection detail-> import->add file − Goto S DB_DATA folder -> load baea-nests.shp and bowl_habitat.shp − Give special reference id is 4326
  • 34. © 2018 EnterpriseDB® Corporation. All rights reserved. 34 Loading Spatial data into PostGIS using QGIS • Load into QGIS and then put into PostGIS − Any type of vector data you can load and view – ESRIGeo, or Jeojson, GPS file − Select SDB_DATA folder from browser panel and drag and paste layers panel − Select three file GBH_Rookeries.shp, Linear_Projects.shp, Raptor_Nests-shp − First make connection − Select database-> Dbmanager -> − Make a connection with postgis from Browser panel -> provide connection information − Click on basic for authentication and click on store -> Test connection − List tables with no geometry − Click on ok − Click on import − Give input file GBH_Rookeries, Linear_projects, Raptor_nests one by one Go to PGAdmin4 and verify sdb_course with these five tables
  • 35. © 2018 EnterpriseDB® Corporation. All rights reserved. 35 Accessing PostGIS from the commandline, the pgAdmin, QGIS − C:programefilepostgresql11binshp2pgsql − C:programefilepostgresql11binraster2pgsql − pgAdmin4 − Open query tools  Select * from baue_nests Some other tables with geometry column
  • 36. © 2018 EnterpriseDB® Corporation. All rights reserved. 36 4. Making SQL Spatial • The PostGIS Vector Geometry model • The Spatial reference ID • The Geometry field • Geometry vs Geography data type • Spatial queries-working with Geometries • Spatial queries-Measurement • Spatial queries – Accessing the geometry
  • 37. © 2018 EnterpriseDB® Corporation. All rights reserved. 37 4. Vector Geometry Model • Conforms to the OGC SFS standard • Basic data structure is a Point − 2 dimension –X and Y values. (longitude and latitude), projection − 3 Dimension value- z values • Line String is an array of points • Polygon is an array of closed LineString’s − First Linestring is an exterior ring − Each following LineString is an interior ring
  • 38. © 2018 EnterpriseDB® Corporation. All rights reserved. 38 4. Vector Geometry Model. Cont.. • Multi-Part geometries − Array of individual geometries − Multipoint − MultiLinestring − MultiPolygon • Features − Geometry − Attributes(field, properties,etc)
  • 39. © 2018 EnterpriseDB® Corporation. All rights reserved. 39 Spatial Reference ID • Unique identifier for a coordinate reference system − Coordinate System :- based in angles based on earth − Projection − Zone − Datum • In PostGIS you indicate the Spatial Reference by a number • That number corresponds to well known Text • Individual Geometries can have a spatial reference • Geometry columns have a spatial reference
  • 40. © 2018 EnterpriseDB® Corporation. All rights reserved. 40 The Geometry field • The geometry field is what makes a table spatial • Its just a column in the database that can store a feature geometry • It includes the SRID, the geometry type, and the actual coordinates in binary form • We can’t interpret the binary data but PostGIS provides a number of functions that can output the geometry in human readable format binary data could be picture, shape any things These are functions that can output geometry as human redable text • ST_AsText(), ST_AsEWKT(), ST_AsGeoJSON, etc. • The combination of a geometry and the attribute that describes that geometry is known as features
  • 41. © 2018 EnterpriseDB® Corporation. All rights reserved. 41 Geometry vs Geography • Two different ways to store a features spatial information − Geometry (data type). Based on plain surface − Geography. (data type). Based on circular earth , math behind calculation is complicated • Geometry − Based on planner surface − Can be in a variety of coordinates reference systems defined by OGC − Are mathematically simple − Rich set of functions available − OGC standard , GEOS libraries, etc. − Accuracy declines as spatial extent increases.
  • 42. © 2018 EnterpriseDB® Corporation. All rights reserved. 42 Geometry vs Geography cont .. • Geography − Based on round earth − Can only be in geographic coordinates system (latitude/longitude) − Are mathematically complex − Only support a fraction of the functions that are available for geometries − Accurate measurements − Which should you use ?? − Scale of your data and if larger distance use geography − Availability of functions that you need − performance
  • 43. © 2018 EnterpriseDB® Corporation. All rights reserved. 43 Working with Geometries • What can we do with Geometries in PostGIS − Get information about it − GeometryType(geom) what type point, line or polygon − ST_CoordDIM(geom). How many coordinate associate with each points − ST_Dimension(geom). Like if line then it is one dimenstional, polygon is area which is two dimensional − ST_SRID(geom). :- special reference id for geometry − ST_IsCollection(geom) :- returns true if geometry is single point or multipoint polygon − ST_NumGeometries(geom),ST_NuminteriorRings(geom),ST_NumPoints(geom) − ST_IsSimple(geom),ST_IsEmpty(geom),ST_IsClosed(geom),ST_isRing(geom) − ST_IsValid(geom), ST_IsValidReason(geom) • Change it’s spatial reference • ST_SetSRID(geom,SRID) changes special reference id associated with that geometry • ST_Transform(geom,SRID) converts one coordinate reference system to another
  • 44. © 2018 EnterpriseDB® Corporation. All rights reserved. 44 Spatial Queries :- Measurements • What we can do with geometry ? − Measure it − ST_Length(line) − Geometry- Cartesian length in SRID units − Geography-length in meters over the spheroid − ST_3DLength(line) - Geometry-3D cartesian length using SRID - Geography - Not supported − ST_LengthSpheroid(line, spheroid) − ST_Area(polygon) − Geometry- cartesian area in SRID units − Geography-area in square meters over the spheroid − ST_Perimeter(polygon), ST_3DPerimeter(polygon)
  • 45. © 2018 EnterpriseDB® Corporation. All rights reserved. 45 Spatial Queries :- Accessing the Geometries • What we can do with geometry ? − Calculate distance from other geometries − ST_Distance(geom1,geom2) Geometry-cartesian distance in SRID units Geography – length in meters over the spheroid − ST_3DDistance(geom1,geom2) - Geometry- cartesian distance using SRID in units - Geography - Not supported ST_DistanceSphere(geom1,geom2) Geometry-cartesian area in SRID units squre degrees Geography:- area in squre meters over the spheroid ST_Perimeter(polygon), ST3DPerimeter(polygon)
  • 46. © 2018 EnterpriseDB® Corporation. All rights reserved. 46 Spatial Queries :- Accessing the Geometries • What we can do with geometry ? − Calculate distance from other geometries − See it’s coordinate in text form − ST_AsText(geom), ST_AsWKT(geom) − ST_AsGeoJSON(geom) − ST_AsGML(geom), ST_AsKML(geom) − ST_AsMVT(table) − Access it’s Coordinates - ST_X(point), ST_Y(point), ST_Z(point), ST_M(point) - ST_StartPoint(geom0, ST_EndPoint(geom) − ST_PointN(geom,n), ST_LineinterpolatePoint(geom,proportion) − ST_GeometryN(geom,n) − ST_ExteriorRing(geom), ST_interiorRingN(geom,n)
  • 47. © 2018 EnterpriseDB® Corporation. All rights reserved. 47 • Docs - http://www.postgis.org/docs/ • PostGIS in Action, 2nd Edition − http://www.amazon.com/gp/search?index=books&linkCode=qs&keywords=9781617291395 Resources:
  • 48. © 2018 EnterpriseDB® Corporation. All rights reserved. 48 48 Postgres Vision Goes Virtual in 2020. APJ Track on 24th June Time: 8.30am – 11.45am IST/ 11.00am – 2.45pm Singapore/1.00pm to 4.45pm AU EST Attend from the comfort of your home. Learn: • how organizations are using PostgreSQL to reduce cost & increase innovation • the tools and technology that PostgreSQL experts are using • how developers are using PostgreSQL databases • about the of future of PostgreSQL and much more REGISTER NOW
  • 49. © 2018 EnterpriseDB® Corporation. All rights reserved. 49 THANK YOU [email protected] www.enterprisedb.com CONFIDENTIAL © Copyright EnterpriseDB