SlideShare uma empresa Scribd logo
1 de 15
Integrating Map Data with PostGIS




     UK PostgreSQL Conference 2008

            Mark Cave-Ayland
            Sirius Corporation
What is PostGIS?


●   What is PostGIS?
    –   A collection of SQL types, operators and
        functions to “spatially enable” PostgreSQL
    –   Also includes a spatial R-Tree indexing
        scheme
         ●   Implemented using GiST
    –   This allows us to extend PostgreSQL to ask
        questions like:
         ●   How many features lie within 100m?
         ●   What is the total length of a given road?
         ●   What is the total area of water in my city?
How can we use PostGIS?


●   PostGIS can primarily be used in two
    different ways
    –   GIS object data store
         ●   ESRI Shapefiles
         ●   OS MasterMap
    –   Spatial object processing
         ●   Calculate binary predicates such as Crosses(),
             Touches(), and Intersects()
         ●   Calculate the geometric results of Intersection()
             and Union()
PostGIS dependencies


●   PostGIS makes use of two popular
    existing libraries
    –   PROJ.4
         ●   Provides co-ordinate system and on-the-fly
             reprojection support
    –   GEOS
         ●   Provides spatial predicates and geometric
             processing functions
●   But all functions can be accessed using
    SQL
Installation


●   Installation
    –   Very easy with RHEL 5
         ●   http://yum.pgsqlrpms.org/
    –   This installs the libraries required
         ●   All that remains is to load the new functions into
             the database
    –   PostGIS provides 2 files:
         ●   lwpostgis.sql
              –   Main operators and types (ST prefixed)
         ●   spatial_ref_sys.sql
              –   A list of international spatial reference systems
Creating a spatial database


●   Creating a spatial database
    –   PostGIS requires PL/PGSQL
    postgres@cleopatra:~$ createdb postgis
    CREATE DATABASE
    postgres@cleopatra:~$ createlang plpgsql postgis
    postgres@cleopatra:~$ psql ­d postgis /usr/share/postgresql/lwpostgis.sql
    postgres@cleopatra:~$ psql ­d postgis /usr/share/postgresql/spatial_ref_sys.sql




●   Check that everything is working
    postgis=# SELECT postgis_full_version();
                                    postgis_full_version
    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
     POSTGIS="1.3.2" GEOS="3.0.0­CAPI­1.4.1" PROJ="Rel. 4.6.0, 21 Dec 2007" USE_STATS
    (1 row)




●   Now we can start adding geometries
PostGIS Geometries


●   PostGIS supports OGC-compliant
    geometries
    –   From the Open Geospatial Consortium
         ●   http://www.opengeospatial.org/
         ●   Geometries are defined as part of the “OpenGIS
             Simple Features Implementation Specification for
             SQL”
         ●   The specification can be downloaded for free
    –   PostGIS has been officially certified as OGC
        SFS 1.1 compliant
Basic Geometry Types


●   Basic OGC geometry types
    –   POINT
    –   POLYGON
    –   LINESTRING
●   Geometry array types
    –   MULTIPOINT
    –   MULTIPOLYGON
    –   MULTILINESTRING
    –   GEOMETRYCOLLECTION
Basic Geometry Examples


●   Basic geometry examples
    postgis=# SELECT ST_AsText(ST_GeomFromText('POINT(4 51)'));
      st_astext
    ­­­­­­­­­­­­­
     POINT(4 51)
    (1 row)

    postgis=# SELECT ST_AsText(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3)'));
              st_astext
    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
     LINESTRING(0 0,1 1,2 2,3 3)
    (1 row)

    postgis=# SELECT ST_AsText(ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'));
               st_astext
    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
     POLYGON((0 0,0 1,1 1,1 0,0 0))
    (1 row)

    postgis=# SELECT ST_AsText(ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 ­1))'));
    ERROR:  geometry contains non­closed rings
    CONTEXT:  SQL function "st_geomfromtext" statement 1

    postgis=# SELECT ST_AsText(ST_GeomFromText('LINESTRING(0,0 1,1 2,2 3,3)'));
    ERROR:  parse error ­ invalid geometry
    CONTEXT:  SQL function "st_geomfromtext" statement 1
More complex queries


●   These examples use the free datasets
    from http://mappinghacks.com
●   Imported into PostGIS from ESRI
    Shapefiles
    –   World Borders
         ●   Country outlines stored as 2D POLYGONs
    –   Cities
         ●   POINTs representing major cities throughout the
             world
More complex queries

●   Example 1
      ●    Given a table of countries, find the names of all of
           the countries that border Chad
          postgis=# SELECT t1.cntry_name FROM world_borders t1, world_borders t2 WHERE 
          ST_Touches(t1.the_geom, t2.the_geom) AND t2.cntry_name = 'Chad';
                  cntry_name        
          ­­­­­­­­­­­­­­­­­­­­­­­­­­
           Libya
           Niger
           Sudan
           Cameroon
           Central African Republic
           Nigeria
          (6 rows)
More complex queries

●   Example 2
      ●    Given a table of cities and a table of countries,
           find the total number of cities within each country
           and return the list in alphabetical order
          postgis=# SELECT world_borders.cntry_name, COUNT(world_borders.cntry_name) 
           FROM cities, world_borders WHERE ST_Within(cities.the_geom, world_borders.the_geom)
           GROUP BY world_borders.cntry_name
           ORDER BY world_borders.cntry_name;

           cntry_name  | count
          ­­­­­­­­­­­­­+­­­­­­­
           Afghanistan |     3
           Albania     |     1
           Algeria     |     5
           Angola      |     3
           Argentina   |     9
           Armenia     |     1
           Australia   |    14
           Austria     |     5
           Azerbaijan  |     1
           Bangladesh  |     3

          ... etc ...
Tools that can use PostGIS


●   There are many GIS tools that can access
    data within PostGIS
    –   Open source
         ●   JUMP
         ●   QGIS
         ●   GeoServer
         ●   MapServer
    –   Some proprietary support also exists
         ●   CadCorp SIS
         ●   Safe Software FME
         ●   ESRI
Tools that can use PostGIS


●   Similarly any applications that can
    connect to PostgreSQL can access spatial
    data
    –   Java, PHP, Perl etc.
●   This allows data to loaded into online
    mapping applications such as Google
    Maps
●   Wrapper classes are available for most
    languages
Demonstration & Questions


●   Demonstration & Questions




●   For more information:
    –   http://postgis.refractions.net
●   Or specific enquiries:
    –   http://www.siriusit.co.uk

Mais conteúdo relacionado

Destaque

Enabling model based decision support[1]
Enabling model based decision support[1]Enabling model based decision support[1]
Enabling model based decision support[1]
Karl Glorstad
 
演示文稿1
演示文稿1演示文稿1
演示文稿1
bryan630
 
Skincare transcript mr qual excerpt
Skincare transcript mr qual excerptSkincare transcript mr qual excerpt
Skincare transcript mr qual excerpt
MrQual
 
HIPPA Compliance
HIPPA ComplianceHIPPA Compliance
HIPPA Compliance
dixibee
 
8 permendiknasno-41tahun2007standarproses
8 permendiknasno-41tahun2007standarproses8 permendiknasno-41tahun2007standarproses
8 permendiknasno-41tahun2007standarproses
catalova
 

Destaque (13)

Salas de informatica
Salas de informaticaSalas de informatica
Salas de informatica
 
Skincare Online Qual Case Study
Skincare Online Qual Case StudySkincare Online Qual Case Study
Skincare Online Qual Case Study
 
Bank mini
Bank miniBank mini
Bank mini
 
Enabling model based decision support[1]
Enabling model based decision support[1]Enabling model based decision support[1]
Enabling model based decision support[1]
 
Dear all
Dear allDear all
Dear all
 
演示文稿1
演示文稿1演示文稿1
演示文稿1
 
An Introduction to Online Qualitative Research Methods
An Introduction to Online Qualitative Research MethodsAn Introduction to Online Qualitative Research Methods
An Introduction to Online Qualitative Research Methods
 
Skincare transcript mr qual excerpt
Skincare transcript mr qual excerptSkincare transcript mr qual excerpt
Skincare transcript mr qual excerpt
 
Be a local insider
Be a local insider Be a local insider
Be a local insider
 
Change Lessons Learned - Implementing a Kanban System for Enterprise Agility
Change Lessons Learned - Implementing a Kanban System for Enterprise AgilityChange Lessons Learned - Implementing a Kanban System for Enterprise Agility
Change Lessons Learned - Implementing a Kanban System for Enterprise Agility
 
HIPPA Compliance
HIPPA ComplianceHIPPA Compliance
HIPPA Compliance
 
Business Agility and Organisational Learning
Business Agility and Organisational LearningBusiness Agility and Organisational Learning
Business Agility and Organisational Learning
 
8 permendiknasno-41tahun2007standarproses
8 permendiknasno-41tahun2007standarproses8 permendiknasno-41tahun2007standarproses
8 permendiknasno-41tahun2007standarproses
 

Semelhante a Post gispguk

Pg intro part1-theory_slides
Pg intro part1-theory_slidesPg intro part1-theory_slides
Pg intro part1-theory_slides
lasmasi
 
오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS
JungHwan Yun
 

Semelhante a Post gispguk (20)

Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
 
공간정보연구원 PostGIS 강의교재
공간정보연구원 PostGIS 강의교재공간정보연구원 PostGIS 강의교재
공간정보연구원 PostGIS 강의교재
 
An Introduction to Postgresql
An Introduction to PostgresqlAn Introduction to Postgresql
An Introduction to Postgresql
 
Pg intro part1-theory_slides
Pg intro part1-theory_slidesPg intro part1-theory_slides
Pg intro part1-theory_slides
 
Building Location Aware Apps - Get Started with PostGIS, PART I
Building Location Aware Apps - Get Started with PostGIS, PART IBuilding Location Aware Apps - Get Started with PostGIS, PART I
Building Location Aware Apps - Get Started with PostGIS, PART I
 
FOSS4G 2010 PostGIS Raster: an Open Source alternative to Oracle GeoRaster
FOSS4G 2010 PostGIS Raster: an Open Source alternative to Oracle GeoRasterFOSS4G 2010 PostGIS Raster: an Open Source alternative to Oracle GeoRaster
FOSS4G 2010 PostGIS Raster: an Open Source alternative to Oracle GeoRaster
 
LocationTech Projects
LocationTech ProjectsLocationTech Projects
LocationTech Projects
 
Postgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial ExtensionsPostgres Vision 2018: PostGIS and Spatial Extensions
Postgres Vision 2018: PostGIS and Spatial Extensions
 
Building Location Aware Apps - Get Started with PostGIS, PART II
Building Location Aware Apps - Get Started with PostGIS, PART IIBuilding Location Aware Apps - Get Started with PostGIS, PART II
Building Location Aware Apps - Get Started with PostGIS, PART II
 
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World2017 RM-URISA Track:  Spatial SQL - The Best Kept Secret in the Geospatial World
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
 
Introduction To PostGIS
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGIS
 
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
 
오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS오픈소스 GIS 교육 - PostGIS
오픈소스 GIS 교육 - PostGIS
 
Using python to analyze spatial data
Using python to analyze spatial dataUsing python to analyze spatial data
Using python to analyze spatial data
 
PINOGIO : A simple way to create a web infographic map (피노지오 : 웹 인포그래픽 맵을 만드는...
PINOGIO : A simple way to create a web infographic map (피노지오 : 웹 인포그래픽 맵을 만드는...PINOGIO : A simple way to create a web infographic map (피노지오 : 웹 인포그래픽 맵을 만드는...
PINOGIO : A simple way to create a web infographic map (피노지오 : 웹 인포그래픽 맵을 만드는...
 
Pycon2011
Pycon2011Pycon2011
Pycon2011
 
Spatial
SpatialSpatial
Spatial
 
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINAGetting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
Getting Started with PostGIS geographic database - Lasma Sietinsone, EDINA
 
Getting started with PostGIS geographic database
Getting started with PostGIS geographic databaseGetting started with PostGIS geographic database
Getting started with PostGIS geographic database
 
LX 공간정보아카데미 PostGIS 강의자료
LX 공간정보아카데미 PostGIS 강의자료LX 공간정보아카데미 PostGIS 강의자료
LX 공간정보아카데미 PostGIS 강의자료
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

Post gispguk

  • 1. Integrating Map Data with PostGIS UK PostgreSQL Conference 2008 Mark Cave-Ayland Sirius Corporation
  • 2. What is PostGIS? ● What is PostGIS? – A collection of SQL types, operators and functions to “spatially enable” PostgreSQL – Also includes a spatial R-Tree indexing scheme ● Implemented using GiST – This allows us to extend PostgreSQL to ask questions like: ● How many features lie within 100m? ● What is the total length of a given road? ● What is the total area of water in my city?
  • 3. How can we use PostGIS? ● PostGIS can primarily be used in two different ways – GIS object data store ● ESRI Shapefiles ● OS MasterMap – Spatial object processing ● Calculate binary predicates such as Crosses(), Touches(), and Intersects() ● Calculate the geometric results of Intersection() and Union()
  • 4. PostGIS dependencies ● PostGIS makes use of two popular existing libraries – PROJ.4 ● Provides co-ordinate system and on-the-fly reprojection support – GEOS ● Provides spatial predicates and geometric processing functions ● But all functions can be accessed using SQL
  • 5. Installation ● Installation – Very easy with RHEL 5 ● http://yum.pgsqlrpms.org/ – This installs the libraries required ● All that remains is to load the new functions into the database – PostGIS provides 2 files: ● lwpostgis.sql – Main operators and types (ST prefixed) ● spatial_ref_sys.sql – A list of international spatial reference systems
  • 6. Creating a spatial database ● Creating a spatial database – PostGIS requires PL/PGSQL postgres@cleopatra:~$ createdb postgis CREATE DATABASE postgres@cleopatra:~$ createlang plpgsql postgis postgres@cleopatra:~$ psql ­d postgis /usr/share/postgresql/lwpostgis.sql postgres@cleopatra:~$ psql ­d postgis /usr/share/postgresql/spatial_ref_sys.sql ● Check that everything is working postgis=# SELECT postgis_full_version();                                 postgis_full_version ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­  POSTGIS="1.3.2" GEOS="3.0.0­CAPI­1.4.1" PROJ="Rel. 4.6.0, 21 Dec 2007" USE_STATS (1 row) ● Now we can start adding geometries
  • 7. PostGIS Geometries ● PostGIS supports OGC-compliant geometries – From the Open Geospatial Consortium ● http://www.opengeospatial.org/ ● Geometries are defined as part of the “OpenGIS Simple Features Implementation Specification for SQL” ● The specification can be downloaded for free – PostGIS has been officially certified as OGC SFS 1.1 compliant
  • 8. Basic Geometry Types ● Basic OGC geometry types – POINT – POLYGON – LINESTRING ● Geometry array types – MULTIPOINT – MULTIPOLYGON – MULTILINESTRING – GEOMETRYCOLLECTION
  • 9. Basic Geometry Examples ● Basic geometry examples postgis=# SELECT ST_AsText(ST_GeomFromText('POINT(4 51)'));   st_astext ­­­­­­­­­­­­­  POINT(4 51) (1 row) postgis=# SELECT ST_AsText(ST_GeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3)'));           st_astext ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­  LINESTRING(0 0,1 1,2 2,3 3) (1 row) postgis=# SELECT ST_AsText(ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'));            st_astext ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­  POLYGON((0 0,0 1,1 1,1 0,0 0)) (1 row) postgis=# SELECT ST_AsText(ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 ­1))')); ERROR:  geometry contains non­closed rings CONTEXT:  SQL function "st_geomfromtext" statement 1 postgis=# SELECT ST_AsText(ST_GeomFromText('LINESTRING(0,0 1,1 2,2 3,3)')); ERROR:  parse error ­ invalid geometry CONTEXT:  SQL function "st_geomfromtext" statement 1
  • 10. More complex queries ● These examples use the free datasets from http://mappinghacks.com ● Imported into PostGIS from ESRI Shapefiles – World Borders ● Country outlines stored as 2D POLYGONs – Cities ● POINTs representing major cities throughout the world
  • 11. More complex queries ● Example 1 ● Given a table of countries, find the names of all of the countries that border Chad postgis=# SELECT t1.cntry_name FROM world_borders t1, world_borders t2 WHERE  ST_Touches(t1.the_geom, t2.the_geom) AND t2.cntry_name = 'Chad';         cntry_name         ­­­­­­­­­­­­­­­­­­­­­­­­­­  Libya  Niger  Sudan  Cameroon  Central African Republic  Nigeria (6 rows)
  • 12. More complex queries ● Example 2 ● Given a table of cities and a table of countries, find the total number of cities within each country and return the list in alphabetical order postgis=# SELECT world_borders.cntry_name, COUNT(world_borders.cntry_name)   FROM cities, world_borders WHERE ST_Within(cities.the_geom, world_borders.the_geom)  GROUP BY world_borders.cntry_name  ORDER BY world_borders.cntry_name;  cntry_name  | count ­­­­­­­­­­­­­+­­­­­­­  Afghanistan |     3  Albania     |     1  Algeria     |     5  Angola      |     3  Argentina   |     9  Armenia     |     1  Australia   |    14  Austria     |     5  Azerbaijan  |     1  Bangladesh  |     3 ... etc ...
  • 13. Tools that can use PostGIS ● There are many GIS tools that can access data within PostGIS – Open source ● JUMP ● QGIS ● GeoServer ● MapServer – Some proprietary support also exists ● CadCorp SIS ● Safe Software FME ● ESRI
  • 14. Tools that can use PostGIS ● Similarly any applications that can connect to PostgreSQL can access spatial data – Java, PHP, Perl etc. ● This allows data to loaded into online mapping applications such as Google Maps ● Wrapper classes are available for most languages
  • 15. Demonstration & Questions ● Demonstration & Questions ● For more information: – http://postgis.refractions.net ● Or specific enquiries: – http://www.siriusit.co.uk