Download presentation
Presentation is loading. Please wait.
Published byLiliana Day Modified over 9 years ago
1
Guofeng Cao CyberInfrastructure and Geospatial Information Laboratory Department of Geography National Center for Supercomputing Applications (NCSA) University of Illinois at Urbana-Champaign Geog 480: Principles of GIS
2
Spaital Database (PostGIS) Handson
3
PostGIS PostGIS “spatially enables” the PostgreSQL open source relational database. The database can then be used to store and query spatial data (points, lines and polygons). PostGIS o High performance, robust spatial database built on PostgreSQLPostgreSQL o Provides spatial representations of geometry types (points, lines, polygons)geometry types o Support for common and advanced spatial operations such as geometry creation and conversion, reprojection, buffer, convex hull, generalization, union, and morecommon and advanced spatial operations o Geodetic support for measurements across the globe/dateline Geodetic support o Widely supported as a spatial database back-end to client and server software
4
Several Pre-installed Tables
5
Connecting to Geog480 server
6
Connecting to Database psql -U username -d database_name o username = geog480 o database_name = tutorial o Enter passwd when prompted (same as username) Postgres Commands o \l List all accessible databases o \dt List all the tables in current DB o \? Help o \q Quite
7
Create a sample spatial table CREATE TABLE geometries_your_netid (name varchar, geom geometry); Insert a point: INSERT INTO geometries_your_netid VALUES ('Point', 'POINT(0 0)'); Insert a line: INSERT INTO geometries_your_netid VALUES (‘LineString', 'LINESTRING(0 0, 1 1, 2 1, 2 2)'); Insert a polygon: INSERT INTO geometries_your_netid VALUES ('Polygon', 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'); Populate geometry_columns table: Select Populate_Geometry_Columns();
8
Other geometry types you could try Insert a polygon with hole: INSERT INTO geometries_your_netid VALUES('PolygonWithHole', 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))'); Insert a geometry collection: : INSERT INTO geometries_your_netid VALUES('Collection', 'GEOMETRYCOLLECTION(POINT(2 0),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))');
9
Query the spatial data table SELECT name, ST_AsText(geom) FROM geometries_your_netid; Query length of linestring: SELECT ST_Length(geom) FROM geometries WHERE name = 'Linestring'; Query area of polygons: SELECT name, ST_Area(geom) FROM geometries WHERE name LIKE 'Polygon%';
10
Import Shape Files into Databases Step 1: shp2pgsql -c -i -s 4326 /srv/cigi/example/states/states.shp public.postgis_states_your_netid > $HOME/states.sql Step 2: psql -U geog480 -d tutorial -f $HOME/states.sql Query: select state_name, state_fips, ST_AsText(the_geom) from postgis_states_your_netid where state_name ilike 'illinois';
11
End of this topic
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.