PostGIS Topology: Porovnání verzí

Z GeoWikiCZ
m (Obsah stránky nahrazen textem „{{freegiswiki|PostGIS Topology}}“)
 
Řádek 1: Řádek 1:
[http://trac.osgeo.org/postgis/wiki/UsersWikiPostgisTopology PostGIS Topology] je rozšíření pro [[PostGIS]] umožňující ''topologickou'' správu vektorových dat v prostředí PostGIS/[[PostgreSQL]].
{{freegiswiki|PostGIS Topology}}
 
Více přednášky [[153UZPD#Přednášky|Úvod do zpracování prostorových dat]].
 
== Příklad (kltm50) ==
 
Data z [[Cvičná databáze PostGIS|cvičné databáze]] <tt>pgis_student</tt>.
 
<source lang=sql>
CREATE SCHEMA my_schema;
SET search_path TO my_schema,public,topology,gis1;
</source>
 
=== Feature table 'tm50_cr' ===
 
<source lang=sql>
CREATE TABLE tm50_cr AS SELECT DISTINCT k.ogc_fid,k.tm50,k.geom FROM kltm50 AS k JOIN obce AS o ON ST_Overlaps(k.geom, o.geom);
SELECT COUNT(*) FROM tm50_cr;
</source>
 
<pre>
count
-------
  289
(1 row)
</pre>
 
[[Image:tm50-qgis-sf.png|640px|thumb|center|Klad mapových listu TM50 (území ČR)]]
 
=== Vytvoření topologického schématu 'topo_tm50_cr' ===
 
* [http://postgis.org/documentation/manual-svn/CreateTopology.html CreateTopology()]
 
<source lang=sql>
SELECT topology.createtopology('topo_tm50_cr', find_srid('gis1', 'kltm50', 'geom'), 1);
</source>
 
''Argumenty:''
* <tt>find_srid('gis1', 'kltm50', 'geom')</tt> &rarr; 2065 (EPSG)
* 1 (přesnost v mapových jednotkách, tj. v tomto případě v metrech)
 
<source lang=sql>
SELECT * from topology.topology;
</source>
 
<pre>
id |    name    | srid | precision | hasz
----+--------------+------+-----------+------
  1 | topo_tm50_cr | 2065 |        1 | f
(1 row)
</pre>
 
\dt topo_tm50_cr.
 
<pre>
            List of relations
    Schema    |  Name    | Type  |  Owner 
--------------+-----------+-------+---------
topo_tm50_cr | edge_data | table | postgis
topo_tm50_cr | face      | table | postgis
topo_tm50_cr | node      | table | postgis
topo_tm50_cr | relation  | table | postgis
(4 rows)
</pre>
 
=== Přidání atributu topologie do feature table ===
 
* [http://postgis.org/documentation/manual-svn/AddTopoGeometryColumn.html AddTopoGeometryColumn()]
 
<source lang=sql>
SELECT topology.AddTopoGeometryColumn('topo_tm50_cr', 'my_schema', 'tm50_cr', 'topo', 'POLYGON');
</source>
 
<source lang=sql>
SELECT * FROM topology.layer;
</source>
 
<pre>
topology_id | layer_id | schema_name | table_name | feature_column | feature_type | level | child_id
-------------+----------+-------------+------------+----------------+--------------+-------+----------
          1 |        1 | my_schema  | tm50_cr    | topo          |            3 |    0 |       
</pre>
 
''Poznámka:'' <tt>feature_type</tt> '3' odpovídá 'face' (1 - node, 2 - edge).
 
=== Sestavení topologie (Geometry &rarr; TopoGeometry) ===
 
* [http://postgis.org/documentation/manual-svn/toTopoGeom.html toTopoGeom()]
 
<source lang=sql>
UPDATE tm50_cr set topo = topology.toTopoGeom(geom, 'topo_tm50_cr', 1);
SELECT tm50,topo from tm50_cr limit 3;
</source>
 
<pre>
  tm50    |    topo   
-----------+------------
M-33-29-D | (1,1,1,3)
M-33-30-C | (1,1,2,3)
M-33-30-D | (1,1,3,3)
(3 rows)
</pre>
 
''Poznámka:''
(1,1,1,3) odpovídá (topology_id,layer_id,id,type)
 
Počet uzlů:
 
<source lang=sql>
SELECT count(*) FROM topo_tm50_cr.node;
</source>
<pre>
count
-------
  313
(1 row)
</pre>
 
Počet hran:
 
<source lang=sql>
SELECT count(*) FROM topo_tm50_cr.edge;
</source>
<pre>
count
-------
  601
(1 row)
</pre>
 
Počet stěn:
 
<source lang=sql>
SELECT count(*) FROM topo_tm50_cr.face;
</source>
<pre>
count
-------
  290
(1 row)
</pre>
 
Hrany, které vedou z anebo do uzlu číslo '164'
 
<source lang=sql>
SELECT edge_id,left_face,right_face FROM topo_tm50_cr.edge WHERE start_node = 164 OR end_node = 164;
</source>
<pre>
edge_id | left_face | right_face
---------+-----------+------------
    289 |      146 |        134
    310 |      160 |        146
    308 |      172 |        134
    360 |      172 |        160
(4 rows)
</pre>
 
[[Image:tm50-qgis-topo.png|640px|thumb|center|Klad mapových listu TM50 (území ČR) - topologická primitiva - uzly a hrany]]
 
== Externí odkazy ==
 
* [http://2010.foss4g.org/presentations/3555.pdf State of the art of FOSS4G for topology and network analysis]
* [http://www.postgis.org/documentation/manual-svn/Topology.html PostGIS 2.0 Topology section of manual]
* [http://cs.wikipedia.org/wiki/Topologie Topogie] {{bullet}} [http://cs.wikipedia.org/wiki/Sedm_most%C5%AF_m%C4%9Bsta_Kr%C3%A1lovce Sedm mostů města Královce] {{bullet}} [http://en.wikipedia.org/wiki/Geographic_information_system#Topological_modeling Topological modeling]
* [http://cs.wikipedia.org/wiki/Geografick%C3%BD_informa%C4%8Dn%C3%AD_syst%C3%A9m#Vektorov.C3.A9_modely Vektorové modely]
* [http://strk.keybit.net/projects/postgis/ strk's page about PostGIS]
* [http://strk.keybit.net/blog/2011/10/14/postgis-topology-iso-sqlmm-complete/ PostGIS topology ISO SQL/MM complete]
* [http://strk.keybit.net/blog/2012/04/13/simplifying-a-map-layer-using-postgis-topology/ Simplifying a map layer using PostGIS topology]
* Topo-Geo-and-Topo-Net - [http://www.wiscorp.com/H2-2004-168r2-Topo-Geo-and-Topo-Net-1-The-Concepts.pdf The Concepts] <!-- {{bullet}} [http://www.wiscorp.com/H2-2005-107r2-Topo-Concepts-The-Sequel.pdf Concepts, The Sequel] --> {{bullet}} [http://www.wiscorp.com/H2-2005-108r2-Topo-Routine-Details.pdf Routine Details]
* [http://jtc1sc32.org/doc/N2001-2050/32N2047T%204FDIS-03-spatial-2010-07.doc ISO 13249-3] Information Technology - Database languages - SQL Multimedia and application packages (Text for FDIS)
{{Databáze}}
{{GIS}}
{{GFOSS}}

Aktuální verze z 9. 1. 2013, 10:50

Stránky přesunuty na Free GIS Portál: http://geo.fsv.cvut.cz/freegis/PostGIS_Topology