Cvičná databáze PostGIS: Porovnání verzí
m →osm |
|||
Řádek 120: | Řádek 120: | ||
=== osm_routing === | === osm_routing === | ||
Data {{freegis|OpenStreetMap}} pro území ČR ([http://spatialreference.org | Data {{freegis|OpenStreetMap}} pro území ČR ([http://spatialreference.org/ Google Mercator]) speciálně upravena pro {{freegis|pgRouting}}. | ||
<source lang=sql> | |||
SELECT * FROM geometry_columns WHERE f_table_schema = 'osm_routing'; | |||
</source> | |||
<pre> | |||
f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid | type | |||
-----------------+----------------+--------------+-------------------+-----------------+------+------------ | |||
pgis_student | osm_routing | ways | the_geom | 2 | 4326 | LINESTRING | |||
</source> | |||
=== fgcz === | === fgcz === |
Verze z 6. 5. 2013, 16:56
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 odstraněna (obnova databáze je nastavena na každý den ráno).
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 | MULTIPOLYGON 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)
gis2
Obsahuje data ze cvičení předmětu GIS2 (EPSG:2065).
- Vektorová data:
SELECT * FROM geometry_columns WHERE f_table_schema = 'gis2';
f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid | type -----------------+----------------+--------------+-------------------+-----------------+------+----------------- pgis_student | gis2 | silnice | geom | 2 | 2065 | MULTILINESTRING pgis_student | gis2 | teploty | geom | 2 | 2065 | POINT (2 rows)
- Rastrová data:
SELECT r_table_catalog,r_table_schema,r_table_name,r_raster_column,srid,scale_x,scale_y,blocksize_x,blocksize_y,num_bands,pixel_types,nodata_values
FROM raster_columns WHERE r_table_schema = 'gis2';
r_table_catalog | r_table_schema | r_table_name | r_raster_column | srid | scale_x | scale_y | blocksize_x | blocksize_y | num_bands | pixel_types | nodata_values -----------------+----------------+--------------+-----------------+------+---------+---------+-------------+-------------+-----------+-------------+--------------- pgis_student | gis2 | dmt | rast | 2065 | 10 | -10 | 1063 | 1185 | 1 | {32BF} | pgis_student | gis2 | viewshed | rast | 2065 | 10 | -10 | 1063 | 1185 | 1 | {8BUI} | {127} pgis_student | gis2 | spline | rast | 2065 | 10 | -10 | 894 | 961 | 1 | {32BF} | {NULL} pgis_student | gis2 | nn | rast | 2065 | 10 | -10 | 894 | 961 | 1 | {32BF} | pgis_student | gis2 | idw | rast | 2065 | 10 | -10 | 894 | 961 | 1 | {32BF} | {NULL} pgis_student | gis2 | kriging | rast | 2065 | 10 | -10 | 894 | 961 | 1 | {32BF} | {NULL} (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 pro území ČR (Google Mercator). Viz návod na import.
SELECT * FROM geometry_columns WHERE f_table_schema = 'osm';
f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid | type -----------------+----------------+---------------+-------------------+-----------------+--------+------------ pgis_student | osm | czech_line | geom | 2 | 900913 | LINESTRING pgis_student | osm | czech_polygon | geom | 2 | 900913 | POLYGON pgis_student | osm | czech_roads | geom | 2 | 900913 | LINESTRING pgis_student | osm | czech_point | geom | 2 | 900913 | POINT (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;
osm_routing
Data OpenStreetMap pro území ČR (Google Mercator) speciálně upravena pro pgRouting.
SELECT * FROM geometry_columns WHERE f_table_schema = 'osm_routing';
f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid | type -----------------+----------------+--------------+-------------------+-----------------+------+------------ pgis_student | osm_routing | ways | the_geom | 2 | 4326 | LINESTRING </source> === fgcz === Data z datasetu [http://grass.fsv.cvut.cz/gwiki/FreeGeodataCZ FreeGeodataCZ] ([http://spatialreference.org/ref/epsg/2065/ EPSG:2065]). <source lang=sql> SELECT * FROM geometry_columns WHERE f_table_schema = 'fgcz'; </source> <pre> f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid | type -----------------+----------------+-----------------+-------------------+-----------------+------+------------ pgis_student | fgcz | kraje_pseudo | geom | 2 | 2065 | POLYGON pgis_student | fgcz | silnice_useky | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | mes_casti | geom | 2 | 2065 | POINT pgis_student | fgcz | mesta_b | geom | 2 | 2065 | POINT pgis_student | fgcz | mesta_p | geom | 2 | 2065 | POLYGON pgis_student | fgcz | silnice_uzly | geom | 2 | 2065 | POINT pgis_student | fgcz | obce | geom | 2 | 2065 | POINT pgis_student | fgcz | voda | geom | 2 | 2065 | POLYGON pgis_student | fgcz | zeleznice | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | okresy_pseudo | geom | 2 | 2065 | POLYGON pgis_student | fgcz | silnice_pasport | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | reky | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | klad_zm10 | geom | 2 | 2065 | POINT pgis_student | fgcz | silnice | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | cr | geom | 2 | 2065 | POLYGON pgis_student | fgcz | cesty | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | czfree_nodes | geom | 2 | 2065 | POINT pgis_student | fgcz | casti_obce | geom | 2 | 2065 | POINT pgis_student | fgcz | dsnimky | geom | 2 | 2065 | LINESTRING pgis_student | fgcz | cfm_points | geom | 2 | 2065 | POINT pgis_student | fgcz | cfm_areas | geom | 2 | 2065 | POLYGON (21 rows)
nc
Vektorová data z edukačního datasetu OSGeo North Carolina (EPSG:3358).
SELECT * FROM geometry_columns WHERE f_table_schema = 'nc';
f_table_catalog | f_table_schema | f_table_name | f_geometry_column | coord_dimension | srid | type -----------------+----------------+-----------------------+-------------------+-----------------+------+------------ pgis_student | nc | busroute_a | geom | 2 | 3358 | LINESTRING pgis_student | nc | p079214 | geom | 2 | 3358 | GEOMETRY pgis_student | nc | elev_lidrural_mrptsft | geom | 2 | 3358 | POINT pgis_student | nc | nc_state | geom | 2 | 3358 | POLYGON pgis_student | nc | busroutesall | geom | 2 | 3358 | LINESTRING pgis_student | nc | p079215 | geom | 2 | 3358 | GEOMETRY pgis_student | nc | elev_ned10m_cont10m | geom | 2 | 3358 | LINESTRING pgis_student | nc | streams | geom | 2 | 3358 | LINESTRING pgis_student | nc | overpasses | geom | 2 | 3358 | POINT pgis_student | nc | p079218 | geom | 2 | 3358 | GEOMETRY pgis_student | nc | poi_names_wake | geom | 2 | 3358 | POINT pgis_student | nc | firestations | geom | 2 | 3358 | POINT pgis_student | nc | busstopsall | geom | 2 | 3358 | POINT pgis_student | nc | precip_30ynormals | geom | 2 | 3358 | POINT pgis_student | nc | geodetic_pts | geom | 2 | 3358 | POINT pgis_student | nc | census_wake2000 | geom | 2 | 3358 | POLYGON pgis_student | nc | p079219 | geom | 2 | 3358 | GEOMETRY pgis_student | nc | streets_wake | geom | 2 | 3358 | LINESTRING pgis_student | nc | censusblk_swwake | geom | 2 | 3358 | POLYGON pgis_student | nc | boundary_county | geom | 2 | 3358 | POLYGON pgis_student | nc | swwake_10m | geom | 2 | 3358 | POLYGON pgis_student | nc | geodetic_swwake_pts | geom | 2 | 3358 | POINT pgis_student | nc | precip_30ynormals_3d | geom | 2 | 3358 | POINT pgis_student | nc | urbanarea | geom | 2 | 3358 | POLYGON pgis_student | nc | railroads | geom | 2 | 3358 | LINESTRING pgis_student | nc | geology | geom | 2 | 3358 | POLYGON pgis_student | nc | comm_colleges | geom | 2 | 3358 | POINT pgis_student | nc | boundary_municp | geom | 2 | 3358 | POLYGON pgis_student | nc | elev_lid792_bepts | geom | 2 | 3358 | POINT pgis_student | nc | roadsmajor | geom | 2 | 3358 | LINESTRING pgis_student | nc | bridges | geom | 2 | 3358 | POINT pgis_student | nc | geonames_nc | geom | 2 | 3358 | POINT pgis_student | nc | geonames_wake | geom | 2 | 3358 | POINT pgis_student | nc | elev_lid792_cont1m | geom | 2 | 3358 | LINESTRING pgis_student | nc | busroute1 | geom | 2 | 3358 | LINESTRING pgis_student | nc | schools_wake | geom | 2 | 3358 | POINT pgis_student | nc | elev_lid792_randpts | geom | 2 | 3358 | POINT pgis_student | nc | usgsgages | geom | 2 | 3358 | POINT pgis_student | nc | soils_general | geom | 2 | 3358 | POLYGON pgis_student | nc | hospitals | geom | 2 | 3358 | POINT pgis_student | nc | busroute11 | geom | 2 | 3358 | LINESTRING pgis_student | nc | soils_wake | geom | 2 | 3358 | POLYGON pgis_student | nc | lakes | geom | 2 | 3358 | POLYGON pgis_student | nc | zipcodes_wake | geom | 2 | 3358 | POLYGON pgis_student | nc | elev_lidrural_mrpts | geom | 2 | 3358 | POINT pgis_student | nc | busroute6 | geom | 2 | 3358 | LINESTRING (46 rows)
Přístup k databázi
Příkazová řádka - psql
psql pgis_student -U postgis -h geo102.fsv.cvut.cz -W

GUI - pgAdmin
pgAdmin je grafické uživatelské rozhraní pro přístup k PostgreSQL databázi. Nástroj je multiplatformní a je ke stažení na adrese http://www.pgadmin.org/download/. Viz instalace PostgreSQL na MS Windows.
Připojení k databázi pgis_student můžete přidat z menu
File -> Add server
![]() |
![]() |
Vizualizace dat
QGIS
QGIS je multiplatformní desktopová GIS aplikace.
K datům uložených v geodatabázi PostGIS lze přistupovat z menu či nástrojové lišty :

Layer -> Add PostGIS Layer
Nové připojení k PostGIS databázi - New

Po stisknutí tlačítka Connect se QGIS připojí k databázovému serveru a zobrazí seznam dostupných datových vrstev.


MapServer
Příklady prostorových dotazů
-- nejprve vytvoříme vlastní schéma a nastavíme vyhledávací cestu
-- nově vytvářené tabulky, tak budou vytvořeny ve vlastním schématu
CREATE SCHEMA landamar;
SET search_path TO landamar, osm, public;
-- příklad vytvoření bodové vrstvy knihoven
CREATE TABLE knihovny AS SELECT * FROM czech_point WHERE amenity = 'library';
-- zjištění celkového počtu knihoven
SELECT COUNT(*) FROM knihovny;
- Příklady z přednášek předmětu Úvod do zpracování prostorových dat
- 2. cvičení GIS 1
- 3. cvičení GIS 1
- 4. cvičení GIS 1
Stažení databáze pro vlastní potřebu
Geodatabáze pgis_student obsahuje pouze volně šířitelná data. Data si tedy můžete stáhnout a používat pro vlastní účely.
Ke stažení je dostupný dump soubor pgis_student.dump (>970 MB !).
Poznámka: Dávka byla vytvořena příkazem
pg_dump -Fc -b -v -f pgis_student.dump pgis_student
Příklad importu dat (včetně vytvoření databáze pgis_student):
- Vytvoření nové PostGIS geodatabáze pgis_student
- 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