Cvičná databáze PostGIS: Porovnání verzí

Z GeoWikiCZ
Řádek 30: Řádek 30:
=== intro ===
=== intro ===


Data z tutoriálu [http://www.foss4g2007.org/workshops/W-04/ Introduction to PostGIS] (Paul Ramsey).
Data z tutoriálu [http://www.foss4g2007.org/workshops/W-04/ Introduction to PostGIS] ([http://spatialreference.org/ref/epsg/4326/ EPSG:4326]).


<source lang=sql>
SELECT * FROM geometry_columns WHERE f_table_schema = 'intro';
</source>
<pre>
<pre>
pgis_student=> \dt intro.
  f_table_catalog | f_table_schema f_table_name  | f_geometry_column | coord_dimension | srid |      type     
            List of relations
-----------------+----------------+-----------------+-------------------+-----------------+------+-----------------
  Schema |     Name      | Type | Owner
  pgis_student    | intro         | countries       | geom              |              2 | 4326 | MULTIPOLYGON
--------+-----------------+-------+-------
  pgis_student    | intro         | bc_municipality | geom              |               2 | 4326 | MULTIPOLYGON
  intro | bc_border       | table | landa
  pgis_student    | intro         | bc_voting_areas | geom              |               2 | 4326 | MULTIPOLYGON
  intro | bc_hospitals    | table | landa
  pgis_student    | intro         | cities          | geom              |               2 | 4326 | POINT
  intro | bc_municipality | table | landa
  pgis_student    | intro         | newyork_census | geom              |              2 | 4326 | MULTIPOLYGON
  intro | bc_pubs        | table | landa
  pgis_student    | intro         | bc_border      | geom              |               2 | 4326 | MULTILINESTRING
  intro  | bc_roads        | table | landa
  pgis_student    | intro          | bc_hospitals    | geom              |               2 | 4326 | POINT
  intro | bc_voting_areas | table | landa
  pgis_student    | intro         | bc_roads        | geom              |               2 | 4326 | MULTILINESTRING
  intro | cities         | table | landa
  pgis_student    | intro         | timezone        | geom              |              2 | 4326 | MULTIPOLYGON
intro  | countries      | table | landa
  pgis_student    | intro         | usa_counties    | geom              |              2 | 4326 | MULTIPOLYGON
  intro | newyork_census  | table | landa
pgis_student    | intro          | bc_pubs        | geom              |              2 | 4326 | POINT
  intro | timezone        | table | landa
  intro | usa_counties    | table | landa
(11 rows)
(11 rows)
</pre>
</pre>

Verze z 7. 3. 2012, 18:26

Na serveru geo102 je umístěna cvičná databáze PostGIS pgis_student. Databáze je přístupná všem uživatelům serveru geo102 bez omezení a je určena pro experimenty. Databáze je pracovní - každý den je vrácena do původního stavu! Není tedy určena pro skladování dat, data vytvořená uživateli jsou každodenně odstraněna (během noci).

V případě problémů či dotazů se obraťte na správce databáze.

Data - schémata

gis1

Obsahuje data ze cvičení předmětu GIS1 (EPSG:2065).

SELECT * FROM geometry_columns WHERE f_table_schema = 'gis1';
 f_table_catalog | f_table_schema |   f_table_name    | f_geometry_column | coord_dimension | srid |    type    
-----------------+----------------+-------------------+-------------------+-----------------+------+------------
 pgis_student    | gis1           | lesy              | geom              |               2 | 2065 | POLYGON
 pgis_student    | gis1           | zeleznice         | geom              |               2 | 2065 | LINESTRING
 pgis_student    | gis1           | obce              | geom              |               2 | 2065 | POLYGON
 pgis_student    | gis1           | zeleznice_stanice | geom              |               2 | 2065 | POINT
 pgis_student    | gis1           | kltm50            | geom              |               2 | 2065 | POLYGON
 pgis_student    | gis1           | obce_b            | geom              |               2 | 2065 | POINT
(6 rows)

intro

Data z tutoriálu Introduction to PostGIS (EPSG:4326).

SELECT * FROM geometry_columns WHERE f_table_schema = 'intro';
 f_table_catalog | f_table_schema |  f_table_name   | f_geometry_column | coord_dimension | srid |      type       
-----------------+----------------+-----------------+-------------------+-----------------+------+-----------------
 pgis_student    | intro          | countries       | geom              |               2 | 4326 | MULTIPOLYGON
 pgis_student    | intro          | bc_municipality | geom              |               2 | 4326 | MULTIPOLYGON
 pgis_student    | intro          | bc_voting_areas | geom              |               2 | 4326 | MULTIPOLYGON
 pgis_student    | intro          | cities          | geom              |               2 | 4326 | POINT
 pgis_student    | intro          | newyork_census  | geom              |               2 | 4326 | MULTIPOLYGON
 pgis_student    | intro          | bc_border       | geom              |               2 | 4326 | MULTILINESTRING
 pgis_student    | intro          | bc_hospitals    | geom              |               2 | 4326 | POINT
 pgis_student    | intro          | bc_roads        | geom              |               2 | 4326 | MULTILINESTRING
 pgis_student    | intro          | timezone        | geom              |               2 | 4326 | MULTIPOLYGON
 pgis_student    | intro          | usa_counties    | geom              |               2 | 4326 | MULTIPOLYGON
 pgis_student    | intro          | bc_pubs         | geom              |               2 | 4326 | POINT
(11 rows)

osm

Data OpenStreetMap ČR ze dne 21.2.2012

pgis_student=> \dt osm.
           List of relations
 Schema |     Name      | Type  | Owner 
--------+---------------+-------+-------
 osm    | czech_line    | table | landa
 osm    | czech_point   | table | landa
 osm    | czech_polygon | table | landa
 osm    | czech_roads   | table | landa
(4 rows)

Popisek tabulek - viz osm2pgsql schéma.

Příklad odvození tématické vrstvy silnic - viz popis zájmových objektů mapování OSM.

CREATE TABLE silnice AS
 SELECT * from osm.czech_line where highway IN ('motorway', 'motorway_link',
  'trunk', 'trunk_link', 'primary', 'primary_link',
  'secondary', 'secondary_link', 'tertiary', 'tertiary_link');

SELECT Populate_Geometry_Columns('public.silnice'::regclass);
-- nutne pro vizualizaci v QGISu
ALTER TABLE silnice ADD PRIMARY KEY (osm_id); 
GRANT SELECT ON silnice TO postgis;

fgcz

Data z datasetu FreeGeodataCZ.

pgis_student=> \dt fgcz.
            List of relations
 Schema |      Name       | Type  | Owner 
--------+-----------------+-------+-------
 fgcz   | casti_obce      | table | landa
 fgcz   | cesty           | table | landa
 fgcz   | cfm_areas       | table | landa
 fgcz   | cfm_points      | table | landa
 fgcz   | cr              | table | landa
 fgcz   | czfree_nodes    | table | landa
 fgcz   | dsnimky         | table | landa
 fgcz   | klad_zm10       | table | landa
 fgcz   | kraje_pseudo    | table | landa
 fgcz   | mes_casti       | table | landa
 fgcz   | mesta_b         | table | landa
 fgcz   | mesta_p         | table | landa
 fgcz   | obce            | table | landa
 fgcz   | okresy_pseudo   | table | landa
 fgcz   | reky            | table | landa
 fgcz   | silnice         | table | landa
 fgcz   | silnice_pasport | table | landa
 fgcz   | silnice_useky   | table | landa
 fgcz   | silnice_uzly    | table | landa
 fgcz   | vodni_plochy    | table | landa
 fgcz   | zeleznice       | table | landa
(21 rows)

nc

Vektorová data z edukačního datasetu OSGeo North Carolina.

pgis_student=> \dt nc.
              List of relations
 Schema |         Name          | Type  | Owner 
--------+-----------------------+-------+-------
 nc     | boundary_county       | table | landa
 nc     | boundary_municp       | table | landa
 nc     | bridges               | table | landa
 nc     | busroute1             | table | landa
 nc     | busroute11            | table | landa
 nc     | busroute6             | table | landa
 nc     | busroute_a            | table | landa
 nc     | busroutesall          | table | landa
 nc     | busstopsall           | table | landa
 nc     | census_wake2000       | table | landa
 nc     | censusblk_swwake      | table | landa
 nc     | comm_colleges         | table | landa
 nc     | elev_lid792_bepts     | table | landa
 nc     | elev_lid792_cont1m    | table | landa
 nc     | elev_lid792_randpts   | table | landa
 nc     | elev_lidrural_mrpts   | table | landa
 nc     | elev_lidrural_mrptsft | table | landa
 nc     | elev_ned10m_cont10m   | table | landa
 nc     | firestations          | table | landa
 nc     | geodetic_pts          | table | landa
 nc     | geodetic_swwake_pts   | table | landa
 nc     | geology               | table | landa
 nc     | geonames_nc           | table | landa
 nc     | geonames_wake         | table | landa
 nc     | hospitals             | table | landa
 nc     | lakes                 | table | landa
 nc     | nc_state              | table | landa
 nc     | overpasses            | table | landa
 nc     | p079214               | table | landa
 nc     | p079215               | table | landa
 nc     | p079218               | table | landa
 nc     | p079219               | table | landa
 nc     | poi_names_wake        | table | landa
 nc     | precip_30ynormals     | table | landa
 nc     | precip_30ynormals_3d  | table | landa
 nc     | railroads             | table | landa
 nc     | roadsmajor            | table | landa
 nc     | schools_wake          | table | landa
 nc     | soils_general         | table | landa
 nc     | soils_wake            | table | landa
 nc     | streams               | table | landa
 nc     | streets_wake          | table | landa
 nc     | swwake_10m            | table | landa
 nc     | urbanarea             | table | landa
 nc     | usgsgages             | table | landa
 nc     | zipcodes_wake         | table | landa
(46 rows)

Přístup k databázi

psql

psql pgis_student -U postgis -h geo102.fsv.cvut.cz -W

pgAdmin

pgAdmin je ke stažení na adrese http://www.pgadmin.org/download/

File -> Add server
Dialog pgAdmin3 pro přihlášení ke studentské PostGIS databázi
pgAdmin3: příklad prostorového SQL dotazu

Vizualizace dat

QGIS

QGIS je ke stažení na adrese http://hub.qgis.org/projects/quantum-gis/wiki/Download

PostGIS

Layer -> Add PostGIS Layer
New
Dialog QGIS pro přihlášení ke studentské PostGIS databázi
Connect
Připojení k databázi pgis_student v QGISu
Vizualizace PostGIS dat v QGISu

WMS

Nastavení připojení k WMS serveru v QGISu
Připojení k WMS serveru na josefovi v QGISu
Výběr vrstvy WMS serveru v QGISu

MapServer

příklad vizualizace dat

Webové služby

Příklady dotazů

CREATE SCHEMA landamar;
SET search_path TO landamar, public;
CREATE TABLE knihovny AS SELECT * FROM osm.czech_point WHERE amenity = 'library';
SELECT populate_geometry_columns('knihovny'::regclass);


Stažení dat

Ke stažení je dostupný dump soubor pgis_student.dump (427 MB).

Poznámka: Dávka byla vytvořena příkazem

pg_dump -Fc -b -v -f gpis_student.dump pgis_student

Příklad importu dat (včetně vytvoření databáze pgis_student):

  1. Vytvoření nové PostGIS geodatabáze pgis_student
  2. Stažení a nahrání dávky do této databáze
wget http://geo.fsv.cvut.cz/~landa/vyuka/postgis/pgis_student.dump
postgis_restore.pl pgis_student.dump | psql pgis_student