Your SlideShare is downloading. ×
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Getting started with PostGIS geographic database
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Getting started with PostGIS geographic database

2,195

Published on

Presentation delivered by Lasma Sietinsone at the DevCSI / GECO Open Mapping Workshop, Glasgow UK, August 2011.

Presentation delivered by Lasma Sietinsone at the DevCSI / GECO Open Mapping Workshop, Glasgow UK, August 2011.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,195
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
90
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Lasma Sietinsone [email_address] Getting started with PostGIS geographic database
  • 2. Survey
    • Experience of audience:
      • SQL?
      • RDBMS?
      • OS?
    • This demo requires:
      • SQL – basic knowledge (SELECT, UPDATE, DELETE)
      • RDBMS – none
      • OS - Windows
  • 3. Contents
    • Theoretical background (~15 mins)
    • Demonstrator (~40 minutes):
      • Install and configure PostgreSQL with PostGIS
      • Build example database to support location based queries
  • 4. What is PostGIS?
    • PostGIS is a spatial extension to the PostgreSQL object-relational database that supports work with geographic data
  • 5. Advantages of a DBMS
    • Data Independence from application programs
    • Efficient Data Access
    • Data Integrity and Security
    • Centralized Data Administration
    • Concurrent Access and Crash Recovery
    • Reduced Application Development Time – common data access functions
  • 6. PostGIS extension provides
    • Geometry/geography data types for points, linestrings, polygons, curves, geometry collections, 3D geometries
    • Spatial operators such as contains @, overlaps, intersects &&, same as =, is to the left/right/below/above
    • Spatial functions
  • 7. Spatial functions
    • Constructors
      • e.g. ST_GeomFromText(), ST_MakePoint(), ST_MakePolygon
    • Output
      • e.g. ST_AsGML(), ST_AsGeoJSON(), ST_AsBinary()
    • Accessors : getters and setters
      • e.g. ST_Transform(), ST_GeometryType(), ST_IsValid(), ST_npoints(), ST_SetDRID()
    • Measurement
      • e.g. ST_Distance_Sphere(), ST_Length_2D(), ST_Perimeter(), ST_Azimuth()
  • 8. Spatial functions (continued)
    • Decomposition
      • e.g. ST_Centroid(), ST_Box2D(), ST_Boundary(), ST_GeometryN(), ST_DumpRings()
    • Composition
      • e.g. ST_MakePoint(), ST_MakePolygon(), ST_BuildArea(), ST_Polygonize()
    • Simplification
      • e.g. ST_Simplify(), ST_SimplifyPreserveTopology(), ST_SnapToGrid()
  • 9. Common workflow
    • Load/populate table
    • Add geometry column with certain dimensions and spatial reference system (SRS/SRID)
    • Register geometry column in geometry_columns table
    • Optimise performance by:
      • Creating spatial index
      • Clustering data based on spatial index
  • 10. Common workflow (continued)
    • View/Edit/Query data with:
      • desktop GIS, e.g. QGIS, OpenJUMP, GRASS etc.
      • Web map servers, e.g. GeoServer, MapServer, Deegree etc.
      • Custom applications communicating via database connectors such as JDBC
  • 11. Data Loading
    • Standard formats: CSV, TEXT
      • $ psql --help
      • $ psql –h [host] –p [port] –U [user] –c “COPY [tablename] FROM [filename] WITH CSV DELIMITER ‘,’” [database]
    • Utilities:
      • shp2pgsql, shp2pgsql-gui: load SHP, DBF files
      • $ shp2pgsql --help
      • $ shp2pgsql [options] [shapefile schema.table | psql –h [host] –p [port] –U [user] [database]
      • osm2pgsql : load OSM data
      • $ osm2pgsql --help
      • $ osm2pgsql [options] planet.osm
      • $ osm2pgsql [options] planet.osm.{gz,bz2}
      • $ osm2pgsql [options] file1.osm file2.osm file3.osm
  • 12. Demonstrator OSM based nearest POI queries for location enabled mobile device e.g. pub? (-> food?) -> cash? -> food?
  • 13. Install & configure PostgreSQL
    • Download Postgres Plus Standard Server 9.0:
      • http://www.enterprisedb.com/downloads/postgres-postgresql-downloads
    • Install package (database server + pgAdmin III + PostGIS)
    • Add the new directory path to your system variable path
    • Create PostGIS database template
    • Install PostGIS:
    • C:Program FilesPostgresPlus9.0SSsharecontribpostgis.sql
    • C:Program FilesPostgresPlus9.0SSsharecontribspatial_ref_sys.sql
  • 14. Install & configure PostgreSQL
    • Install any other contribution modules such as “hstore”:
    • C:Program FilesPostgresPlus9.0SSsharecontribhstore.sql
    • Grant permissions to use PostGIS tables to “public”
    • Create your own username
    • Create a new database, e.g. pg_intro from template_postgis
  • 15. Install osm2pgsql
    • Download: http://tile.openstreetmap.org/osm2pgsql.zip
    • Extract the zip to a new directory on your local disk
    • Add the new directory path to your system variable path
    • log out and back in so the new variable is active
    • Open up command prompt ie... run
    • Change directories so that you are located in the extracted osm2pgsql directory
    • now run the > osm2pgsql -h this will show you the help
    • on windows it would be important to use parameter -S or --style to locate the stylefile. Default is a unix like path
    • Example prompt> osm2pgsql -c -d gis -U postgres -W -H localhost -P 5432 N:Geo_dataOpenStreetMapOSM_xmlyourOSM_filename.bz2
    • Wiki: http://wiki.openstreetmap.org/wiki/Osm2pgsql
  • 16. Data loading
    • Download OSM data (Edinburgh):
    • http://api1.osm.absolight.net/api/0.6/map?bbox=-3.2612228,55.9126578,-3.1441498,55.9720691
    • $ curl --location --globoff "http://api1.osm.absolight.net/api/0.6/map?bbox=-3.2612228,55.9126578,-3.1441498,55.9720691" -o edinburgh.osm
    • Load file: $ osm2pgsql --create --database pg_intro --username lasma --password --host localhost --port 5432 --style "C:Program FilesPostgresPlusosm2pgsqldefault.style" --merc --hstore --slim edinburgh.osm
  • 17. Create user tables
    • Look at data, make a plan
    • Create user tables for OSM POIs
    • > create_amenities_tables.sql
    • Parse data
    • > get_amenities.sql
    • Create stored procedure for location queries
  • 18. Desktop GIS Tools – Fun!
    • View database contents
    • Create on-the-fly maps – example choropleth map with pub stats
    • QGIS – Quantum GIS http://www.qgis.org/
    • OPENJump http://www.openjump.org/
  • 19. Thank you!
    • Read online:
    • PostgreSQL docs ***** http://www.postgresql.org/docs/9.0/interactive/index.html
    • PostGIS docs ***** http://www.postgis.org/docs/

×