• Save
Introduction To PostGIS
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Introduction To PostGIS

on

  • 16,434 views

High level (and incomplete) overview of PostGIS.

High level (and incomplete) overview of PostGIS.

Statistics

Views

Total Views
16,434
Views on SlideShare
16,345
Embed Views
89

Actions

Likes
13
Downloads
0
Comments
0

2 Embeds 89

http://www.slideshare.net 68
http://dev.jamesgreenwood.com 21

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction To PostGIS Presentation Transcript

  • 1. Introduction to PostGIS Spatial Extensions for PostgreSQL Mark Leslie Geospatial Architect LISAsoft
  • 2.  
    • What is PostGIS?
    • 3. Why is PostGIS?
    • 4. What can PostGIS do?
    • 5. Who is using PostGIS?
    • 6. Why use PostGIS?
  • 7. What is PostGIS?
    • Spatial Extensions for PostgreSQL
    • 8. Geometry represented by linear shapes
    • 9. Spatial Functions (Constructors, Accessors, Editors, Processors, Relational Operators, Processing Functions)
    • 10. Advanced geometric indexing
  • 11. Why is PostGIS
    • Shapefile are limited in their transactional capacity
    • 12. Data management of files problematic
    • 13. Existing GIS data services (as of 2001) were terribly expensive
    • 14. No existing integrated spatial databases
    • 15. Refractions had some time to kill
  • 16. Installation - Requirements
    • Proj4 - Cartographic Projections Library
    • 17. GEOS - Geometry Engine - Open Source
    • 18.              Provides spatial predicate functions, spatial operators and topological functions.
    • 19. PostgreSQL - helpful little application
  • 20. Installation - Debian
    • sudo apt-get install postgresql-8.3-postgis
  • 21. Installation - Debian sudo apt-get install postgresql-8.3-postgis or from source svn co http://svn.refractions.net/postgis/trunk/ postgis/ cd postgis ./autogen.sh ./configure make sudo make install
  • 22. Installation - Windows
    • Included in the PostgreSQL installer
  • 23. Installation - Windows
    • Included in the PostgreSQL installer
    • 24. or need a more recent version?
    • 25. Use the Stack Builder application for version PostgreSQL 8.3
    • 26. Download the installer for PostgreSQL 8.3 from
    • 27. http://postgis.refractions.net/download/windows/
  • 28. Installation - Windows
    • Included in the PostgreSQL installer
    • 29. or need a more recent version?
    • 30. Use the Stack Builder application for version PostgreSQL 8.3
    • 31. Download the installer for PostgreSQL 8.3 from
    • 32. http://postgis.refractions.net/download/windows/
    • 33. or from source?
    • 34. Good luck.
  • 35. Loading Data - shp2pgsql
    • shp2pgsql -s 4326 -D -I -S roads.shp roads | psql demo
    • 36. -s 4326 – Use WGA83 coordinate reference system
    • 37. -D – Use PostgreSQL dump format (faster than inserts)
    • 38. -I – Create spatial (GIST) index after loading
    • 39. -S – Generate simple geometries (eg. Line instead of Multiline)
  • 40. Loading Data - shp2pgsql
    •   shp2pgsql -s 4326 -D -I -S roads.shp roads | psql demo
    • 41. On Windows use:
    • 42. shp2pgsql -s 4326 -D -I -S roads.shp roads > roads.sql
    • 43. psql -f roads.sql demo
    • 44. or setup a .pgpass file
  • 45. Loading Data - ogr2ogr
    • ogr2ogr -f "PostgreSQL" PG:dbname=demo cities/
    • 46. Format options include:
    • ESRI Shapefile MapInfo File TIGER
    • 47. S57 DGN Memory BNA CSV MySQL
    • 48. GML GPX KML GeoJSON Interlis 1
    • 49. Interlis 2 GMT SQLite ODBC PostgreSQL
  • 50. Loading Data - osm2pgsql
    • osm2pgsql --host seymour.ms.a2end.com --database osm --verbose planet-latest.osm.bz2
    • 51.  
    • 52. Then get some coffee, in Perth.
    • 53. Node stats: total(231808103), max(256523410) Way stats: total(18781596), max(23689770) Relation stats: total(6967), max(9763) real    806m40.109s user    394m41.460s sys    5m8.507s
  • 54. Loading Data – Spatial Data Integrator
  • 55. Basic Schema Objects
    • geometry_columns
    • 56.     Allows standard discovery of geographic objects and their parameters: point dimension, type, projection.
    • 57. spatial_reference_sys
    • 58.     Provides definitions of available projections.
  • 59. Inserting Data
    • INSERT INTO fishing_hole (name, the_geom)
    • 60. VALUES ("Greenwich Ferry Wharf",
    • 61. ST_SetSRID(ST_GeometryAsText(
    • 62. "POINT(151.18323 -33.84162)"), 4283);
  • 63. Inserting Data
    • INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
    • 64. ..."LINESTRING(151.18456 -33.84225,151.18424 -33.84196,151.18342 -33.84122)"...
  • 65. Inserting Data
    • INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
    • 66. ..."LINESTRING(151.18456 -33.84225,151.18424 -33.84196,151.18342 -33.84122)"...
    • 67. ..."POLYGON((151.2111 -33.8754,151.2109 -33.8753,151.211 -33.8749,151.2111 -33.8749,151.2111 -33.8753)(151.211 -33.8750,151.2111 -33.8751,151.211 -33.8751,151.211 -33.875,151.211 -33.8750))"...
  • 68. Inserting Data
    • INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
    • 69. ..."LINESTRING(151.18456 -33.84225,151.18424 -33.84196,151.18342 -33.84122)"...
    • 70. ..."POLYGON((151.2111 -33.8754,151.2109 -33.8753,151.211 -33.8749,151.2111 -33.8749,151.2111 -33.8753)(151.211 -33.8750,151.2111 -33.8751,151.211 -33.8751,151.211 -33.875,151.211 -33.8750))"...
    • 71. Plus MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, COLLECTION
  • 72. Inserting Data
    • INSERT INTO fishing_hole (name, the_geom) VALUES ("Greenwich Ferry Wharf", ST_SetSRID(ST_GeometryAsText("POINT(151.18323 -33.84162)"), 4283);
    • 73. ..."LINESTRING(151.18456 -33.84225,151.18424 -33.84196,151.18342 -33.84122)"...
    • 74. ..."POLYGON((151.2111 -33.8754,151.2109 -33.8753,151.211 -33.8749,151.2111 -33.8749,151.2111 -33.8753)(151.211 -33.8750,151.2111 -33.8751,151.211 -33.8751,151.211 -33.875,151.211 -33.8750))"...
    • 75. Plus MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, COLLECTION
    • 76. And even CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON, MULTICURVE and MULTISURFACE
  • 77. Accessing Data
    • select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B4000000080F9595FBF
  • 78. Accessing Data
    • select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B4000000080F9595FBF
    • 79. select ST_asText(the_geom) from road where gid = 1; LINESTRING(111.846282958984 0,111.844451904297 -0.00191354146227241)
  • 80. Accessing Data
    • select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B4000000080F9595FBF
    • 81. select ST_asText(the_geom) from road where gid = 1; LINESTRING(111.846282958984 0,111.844451904297 -0.00191354146227241)
    • 82. select ST_asGML(the_geom) from road where gid = 1; <gml:LineString srsName=&quot;EPSG:4326&quot;><gml:coordinates>111.846282958984,0 111.844451904297,-0.00191354146227241</gml:coordinates></gml:LineString>
  • 83. Accessing Data
    • select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B4000000080F9595FBF
    • 84. select ST_asText(the_geom) from road where gid = 1; LINESTRING(111.846282958984 0,111.844451904297 -0.00191354146227241)
    • 85. select ST_asGML(the_geom) from road where gid = 1; <gml:LineString srsName=&quot;EPSG:4326&quot;><gml:coordinates>111.846282958984,0 111.844451904297,-0.00191354146227241</gml:coordinates></gml:LineString>
    • 86. select ST_asSVG(the_geom) from road where gid = 1; M 111.84628295898437 0 111.84445190429687 0.001913541462272
  • 87. Accessing Data
    • select the_geom from road where gid = 1; 0102000020E6100000020000000000008029F65B400000000000000000000000800BF65B4000000080F9595FBF
    • 88. select ST_asText(the_geom) from road where gid = 1; LINESTRING(111.846282958984 0,111.844451904297 -0.00191354146227241)
    • 89. select ST_asGML(the_geom) from road where gid = 1; <gml:LineString srsName=&quot;EPSG:4326&quot;><gml:coordinates>111.846282958984,0 111.844451904297,-0.00191354146227241</gml:coordinates></gml:LineString>
    • 90. select ST_asSVG(the_geom) from road where gid = 1; M 111.84628295898437 0 111.84445190429687 0.001913541462272
    • 91. select ST_asGeoJSON(the_geom) from road where gid = 1; {&quot;type&quot;:&quot;LineString&quot;,&quot;coordinates&quot;:[[111.846282958984375,0.000000000000000],[111.844451904296875,-0.001913541462272]]}
  • 92. Basic Operations - Constructors
    • ST_Polygonize(linestring set), ST_BuildArea(linestring)
    • 93. ST_MakePoint(x, y, [z], [m]), ST_MakePointM(x, y, m)
    • 94. ST_MakeLine(point, point), ST_MakeLine(point set)
    • 95. ST_LineFromMultiPoint(multipoint)
    • 96. ST_MakePolygon(linestring, linestring[])
    • 97. ST_Collect(geometry, geometry), ST_Collect(geometry set)
    • 98. ST_Dump(geometry)
  • 99. Basic Operations - Transformation
    • ST_Transform(geometry, integer)
    • ST_Affine(geometry, float8, float8, float8, float8, float8, float8, [float8, float8, float8, float8, float8, float8])
    • ST_Translate(geometry, x, y, z) 
    • 100. ST_Scale(geometry, xScale, yScale, zScale)
    • 101. ST_RotateX(geometry, radians) 
    • 102. ST_RotateY(geometry, radians)
    • 103. ST_RotateZ(geometry, radians)
  • 104. Basic Operations - Validation
    • ST_isValid(geometry)
    • 105. ST_Reverse(geometry)
    • 106. ST_ForceRHR(geometry)
    • 107. ST_SnapToGrid(geometry, originX, originY, sizeX, sizeY)
    • 108. ST_SnapToGrid(geometry, sizeX, sizeY)
    • 109. ST_SnapToGrid(geometry, size)
    • 110. ST_SnapToGrid(geometry, geometry, sizeX, sizeY, sizeZ, sizeM)
  • 111. Basic Operations - Accessing and Editing
    • ST_GeometryN(multigeom)
    • 112. ST_ExteriorRing(polygon), ST_InteriorRingN(polygon)
    • 113. ST_PointN(linestring), ST_StartPoint(linestring), ST_EndPoint(linestring)
    • 114. ST_X(point), ST_Y(point), ST_Z(point), ST_M(point)
    • 115. ST_AddPoint(linestring), ST_RemovePoint(linestring), ST_SetPoint(linestring)
  • 116. Relational Operators
    • Numerical relational operators work on 1d values with no width.
    • 117. <, <=, ==, >=, >, !=
  • 118. Relational Operators
    • Numerical relational operators work on 1d values with no width.
    • 119. <, <=, ==, >=, >, !=
    • 120. Geometric relational operators work on 2d-4d values with or without width, height or depth
  • 121. ST_Within, ST_Contains
    • Geometry A is completely within Geometry B
    • 122. ST_Within(A, B) = ST_Contains(B, A)
  • 123. ST_Overlaps
    • Geometries share space, are of the same dimension, but are not completely contained by each other.
    • 124.  
    • 125.  
  • 126. ST_Disjoint
    • Geometries do not share any space together.
  • 127. ST_Touches
    • Geometries have at least one point in common, but their interiors do not intersect.
  • 128. ST_Crosses
    • Geometries have some, but not all, interior points in common.
  • 129. ST_Intersects
    • Geometries share any portion of space.
  • 130. ST_Covers, ST_CoveredBy
    • No point in Geometry B is outside Geometry A
    • 131. ST_Covers(A, B) = ST_CoveredBy(B, A)
  • 132. Basic Operations - Relational Operators
    • ST_DWithin( GeomA, GeomB, N ) – GeomB is within N of GeomA
    • 133. ST_Distance – Minimum distance beteen geometries
    • 134. ST_Distance_Spheroid – Minimum distance between geometries over a specific spheroid
    • 135. ST_DistanceSphere – Minimum distance between geometries over a perfect sphere
  • 136. Real Estate Evaluation
    • cities:
    • 137. wkb_geometry – Geometry column (Point)
    • 138. name – City name
    • 139. boundaries:
    • 140. the_geom – Geometry column (Polygon)
    • 141. state – State containing boundary
    • 142. earthquake_risk:
    • 143. the_geom – Geometry column (Polygon)
    • 144. riskval – Indicator of earthquake risk
  • 145. Real Estate Evaluation
    • SELECT c.name
    • 146. FROM cities c, earthquake_risk er, boundaries b
    • 147. WHERE er.riskval = '> 0.10'
    • 148. AND ST_Within(c.wkb_geometry, er.the_geom)
    • 149. AND c.name IS NOT NULL
    • 150. AND ST_Within(c.wkb_geometry, b.the_geom)
    • 151. AND b.state = 'NEW SOUTH WALES';
  • 152. Real Estate Evaluation
    • name
    • 153. ---------------
    • 154. Stratford
    • 155. Craven
    • 156. Bunyah
    • 157. Chichester
    • 158. Salisbury
    • 159. Coolongolook
    • 160. Wootton
    • 161. ...
    • 162. (36 rows)
  • 163. Environmental Change
    • Data describes the type and coverage of vegetation in Australia in 1788 and 1988.
    • 164. nveg_1788, pveg_1988
    • 165. the_geom – Geometry (Polygon)
    • 166. tn_d – Percentage of ground shaded by vegetation
  • 167. Environmental Change
    • SELECT n.ts_d as n_ts_d, p.ts_d as p_ts_d,
    • 168. CASE WHEN n.ts_d > p.ts_d THEN 'Loss'
    • 169. WHEN n.ts_d < p.ts_d THEN 'Gain'
    • 170. ELSE 'No Change' END as change,
    • 171. ST_Intersection(n.the_geom, p.the_geom) as the_geom
    • 172. FROM nveg_1788 as n, pveg_1988 as p
    • 173. WHERE ST_Intersects(n.the_geom, p.the_geom);
  • 174. Verify Assumptions
  • 175. Better Verification
    • SELECT ST_Area(ST_SymDifference(a.the_geom, b.the_geom)) FROM
    • 176. (SELECT ST_Union(the_geom) AS the_geom FROM nveg_1788) a,
    • 177. (SELECT ST_Union(the_Geom) AS the_geom FROM pveg_1988) b;
    • 178. st_area
    • 179. 4.58800965870143e-05
  • 180. Environmental Change
    • SELECT count(*), change
    • 181. FROM change GROUP BY change;
    • 182. count | change
    • 183. -------+-----------
    • 184. 4785 | No Change
    • 185. 2013 | Gain
    • 186. 2465 | Loss
  • 187. Environmental Change
    • SELECT count(*), change,
    • 188. sum(ST_Area(ST_Intersection)) AS area
    • 189. FROM change GROUP BY change;
    • 190. count | change | sum
    • 191. -------+-----------+------------------
    • 192. 4785 | No Change | 521.507080938973
    • 193. 2013 | Gain | 54.5533372716394
    • 194. 2465 | Loss | 119.174361913388
  • 195. Environmental Change
  • 196. ST_Relate
    • <http://docs.codehaus.org/display/GEOTDOC/Point+Set+Theory+and+the+DE-9IM+Matrix#PointSetTheoryandtheDE-9IMMatrix-9IntersectionMatrix>
  • 197. Advanced Operations
    • Nearest Neighbor <http://postgis.refractions.net/support/wiki/index.php?Nearest%20Neighbor%20Search>
    • 198. Relational Constraints <http://www.nabble.com/Any-Projected-Straights-Function--td19439097.html#a19448155>
    • 199. Tiger Geocoder <http://postgis.refractions.net/support/wiki/index.php?Tiger%20Geocoder>
    • 200. Topology <http://postgis.refractions.net/support/wiki/index.php?PostgisTopology>
  • 201. Who is Using PostGIS
    • Infoterra, United Kingdom
    • 202. Infoterra, a leading European satellite and aerial imagery provider, runs their data provision and sales systems on PostGIS, and stores the complete Ordnance Survey database on PostGIS.
  • 203. Who is Using PostGIS
    • Infoterra, United Kingdom
    • 204. EU Joint Research Centre
    • 205. With billion dollar satellites and PostGIS, the EU Joint Research Centre monitors fishing vessels in the North Atlantic and provides real-time reporting and mapping to decision makers and regulators.
  • 206. Who is Using PostGIS
    • Infoterra, United Kingdom
    • 207. EU Joint Research Centre
    • 208. MADEIRA GPS
    • 209. MADEIRA GPS, a company that started in 2005, with a simple project in mind: Deliver PDA-based navigation, with auto-routing, for Madeira Island's tourism.
  • 210. Why Use PostGIS
    • Huge client/server/library support
    • 211. Advanced indexing
    • 212. Transformation support
    • 213. Variety of output format options ((E)WKB, (E)WKT, GeoJSON, GML, KML, SVG)
    • 214. Wide variety of processing and relational operators
    • Accessors and editors
    • 215. Measurement and Linear Referencing
    • 216. Spatial Aggregates
    • http://www.bostongis.com/PrinterFriendly.aspx?content_name=sqlserver2008_postgis_mysql_compare
  • 217. Limitations
    • No true geodetic support
    • 218. Fewer hosting providers than Oracle/MSSQLServer/mySQL
    • 219. Incomplete curve support
    • 220. Non-production topology support
  • 221. Resources
    • Support WIKI
    • 222. http://postgis.refractions.net/support/wiki/
    • 223. User List
    • 224. http://postgis.refractions.net/mailman/listinfo/postgis-users
    • 225. IRC
    • 226. irc://chat.freenode.net/postgis
    • 227. Me
    • 228. [email_address]
  • 229.
    • Presentations
    • 230. Workshops and tutorials
    • 231. Climate Change Integration Plugfest
    • 232. Installfest
    • 233. Bird of a Feather sessions
    • 234. Code Sprint
    • 235. Good times