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

Z GeoWikiCZ
Řádek 185: Řádek 185:


[[Image:pgadmin3-postgis.png|center|thumb|300px|Dialog pgAdmin3 pro přihlášení ke studentské PostGIS databázi]]
[[Image:pgadmin3-postgis.png|center|thumb|300px|Dialog pgAdmin3 pro přihlášení ke studentské PostGIS databázi]]
=== QGIS ===


== Vizualizace dat ==
== Vizualizace dat ==

Verze z 21. 3. 2011, 13:46

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í určena pro skladování dat, data vytvořená uživateli jsou každodenně odstraněna (během noci).

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

Data - schémata

gis1

Obsahuje data ze cvičení předmětu GIS1.

pgis_student=> \dt gis1.
             List of relations
 Schema |       Name        | Type  | Owner 
--------+-------------------+-------+-------
 gis1   | kltm50            | table | landa
 gis1   | lesy              | table | landa
 gis1   | obce              | table | landa
 gis1   | obce_b            | table | landa
 gis1   | zeleznice         | table | landa
 gis1   | zeleznice_stanice | table | landa
(6 rows)

intro

Data z tutoriálu Introduction to PostGIS (Paul Ramsey).

pgis_student=> \dt intro.
            List of relations
 Schema |      Name       | Type  | Owner 
--------+-----------------+-------+-------
 intro  | bc_border       | table | landa
 intro  | bc_hospitals    | table | landa
 intro  | bc_municipality | table | landa
 intro  | bc_pubs         | table | landa
 intro  | bc_roads        | table | landa
 intro  | bc_voting_areas | table | landa
 intro  | cities          | table | landa
 intro  | countries       | table | landa
 intro  | newyork_census  | table | landa
 intro  | timezone        | table | landa
 intro  | usa_counties    | table | landa
(11 rows)

osm

Data OpenStreetMap ČR ze dne 9.3.2011

pgis_student=> \dt osm.
           List of relations
 Schema |     Name      | Type  | Owner 
--------+---------------+-------+-------
 osm    | czech_line    | table | landa
 osm    | czech_nodes   | table | landa
 osm    | czech_point   | table | landa
 osm    | czech_polygon | table | landa
 osm    | czech_rels    | table | landa
 osm    | czech_roads   | table | landa
 osm    | czech_ways    | table | landa
(7 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     | planimetry_rural      | table | landa
 nc     | planimetry_rural3d    | 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
(44 rows)

Přístup k databázi

psql

psql pgis_student -U postgis -W -h geo102

pgAdmin

File -> Add server
Dialog pgAdmin3 pro přihlášení ke studentské PostGIS databázi

Vizualizace dat

QGIS

PostGIS

Layer -> Add PostGIS Layer
New
Dialog QGIS pro přihlášení ke studentské PostGIS databázi
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ů

Stažení dat - dávkové soubory

Vytvoření dávky celé databáze

Příklad vytvoření SQL dávkového souboru

pg_dump -C -O -x pgis_student > pgis_student.sql

včetně komprese výstupního souboru pomocí gzip

pg_dump -C -O -x pgis_student | gzip > pgis_student.sql.gz

Obnovení databáze se skládá ze dvou kroků - vytvoření prázdné databáze

createdb pgis_student

a nahrání dávky (včetně dekomprese)

gunzip -c pgis_student.sql.gz | psql pgis_student

Vytvoření dávky pro schéma gis1

Vytvoření dávky (schéma 'public' a 'gis1')

pg_dump -C -O -x -n public pgis_student | pg_dump -C -O -x -n gis1 pgis_student | \
gzip > pgis_student_gis1.sql.gz

Obnovení databáze

createdb pgis_student
gunzip -c pgis_student_gis1.sql.gz | psql pgis_student

Data ke stažení

Ke stažení jsou dostupné dávkové soubory:

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

wget http://geo.fsv.cvut.cz/~landa/vyuka/postgis/pgis_student_gis1.sql.gz
gzip -d pgis_student_gis1.sql.gz

createdb pgis_student
createlang plpgsql pgis_student
psql pgis_student < pgis_student_gis1.sql

Poznámka: dávkové soubory jsou vygenerovány pro verzi PostGIS 1.5. Při importu do jiné verze PostGIS je nutné dávkový soubor modifikovat, např. pro verzi 2.0 nahradit 'postgis-1.5' za 'postgis-2.0'.

sed 's/postgis-1.5/postgis-2.0/g' pgis_student_gis1.sql | psql pgis_student