
<p>Spatial Databases by Open Standards and Software 5.</p><p>Basics of PostGIS</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Gábor Nagy</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Spatial Databases by Open Standards and Software 5.: Basics of PostGIS</p><p>Gábor Nagy</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Lector: Zoltán Siki</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. This module was created within TÁMOP - 4.1.2-08/1/A-2009-0027 "Tananyagfejlesztéssel a GEO-ért" ("Educational material development for GEO") project. The project was funded by the European Union and the Hungarian Government to the amount of HUF 44,706,488.</p><p> v 1.0</p><p>Publication date 2010</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Copyright </p><p>©</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2010 University of West Hungary Faculty of Geoinformatics</p><p>Abstract</p><p>PostGIS is a geospatial addition for the PostgreSQL, which is based in OGC 06-103r4 and OGC 04-104r4.</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The right to this intellectual property is protected by the 1999/LXXVI copyright law. Any unauthorized use of this material is prohibited. No part of this product may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system without express written permission from the author/publisher.</p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Created by </p><p>XMLmind XSL-FO Converter</p><p>. Table of Contents</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5. Basics of PostGIS</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 1. 5.1 Introduction</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>2. 5.2 Installing PostGIS</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.1. 5.2.1 Installing from compiled binaries</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.2. 5.2.2 Installing from source</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.3. 5.2.3 Installing to a database</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>3. 5.3 Creating spatial tables</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4. 5.4 Input and output functions</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.1. 5.4.1 GeomFromText</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.2. 5.4.2 GeomFromEWKT</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>4.3. 5.4.3 AsText</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.4. 5.4.4 Binary input and output</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.5. 5.4.5 GML and KML input and output</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>5. 5.5 Calculating numerical attributes of geometry</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5.1. 5.5.1 Area</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5.2. 5.5.2 Perimeter</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5.3. 5.5.3 Length</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>6. 5.6 Calculating geometry values</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.1. 5.6.1 Buffer</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.2. 5.6.2 ConvexHull</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>6.3. 5.6.3 Centroid</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.4. 5.6.4 Simplify</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.5. 5.6.5 Segmentize</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7. 5.7 Relation of two geometries</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>7.1. 5.7.1 Distance</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.2. 5.7.2 Azimuth</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.3. 5.7.3 Equals</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>7.4. 5.7.4 Contains</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>7.5. 5.7.5 Overlaps</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.6. 5.7.6 Intersects</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.7. 5.7.7 Touches</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>7.8. 5.7.8 Relate</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 8. 5.8 Calculate derived geometry</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 8.1. 5.8.1 Transform</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>8.2. 5.8.2 Affine</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 8.3. 5.8.3 SnapToGrid</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9. 5.9 Set functions</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.1. 5.9.1 ST_Union</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>9.2. 5.9.2 Intersection</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.3. 5.9.3 Difference</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.4. 5.9.4 SymDifference</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>10. 5.10 Aggregate functions</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>10.1. 5.10.1 ST_Union</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 10.2. 5.10.2 Collect</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 10.3. 5.10.3 Poligonize</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0</p><p>11. 5.11 Operators</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>...... </p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. List of Tables</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 1. Operators of PostGIS</p><p>...... </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Chapter 5. Basics of PostGIS</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 1. 5.1 Introduction</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The PostGIS is an additional package to PostgreSQL, which provides geographic objects and functions based on OGC 06-103r4 and OGC 06-104r4. The PostGIS (like PostgreSQL) is an open source software, developed by the Refractions Research.</p><p>PostGIS uses some other open source softwares. PROJ.4 for the reprojection, and the GEOS (Geometry Engine, Open Source) for many geospatial functions.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. PostGIS provides geometry and geography type and functions for these types. Most of these functions are based on OGC 06-103r4 and OGC 06-104r4 standards, but PostGIS has some other functions.</p><p>PostGIS 1.5.2 contains 10 types, 785 functions and 17 aggregate functions. The functions and aggregate</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. functions are started with “ST_” prefix, but most of them may be used without this prefix. The descriptions of the functions use the name with prefix, where we can not use the function without “ST_” (for example </p><p>ST_UNION</p><p>).</p><p>Geography type is similar to geometry type. The objects of geography type are determined on a sphere or</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. spheroid. It is different from a geometry type with spherical reference system, because it uses spherical topology instead of plane.</p><p>2. 5.2 Installing PostGIS</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.1. 5.2.1 Installing from compiled binaries</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Under Linux operating system, the simplest solution is to use the package manager to install the PostGIS package of the distribution. For example use the </p><p> apt-get install postgis</p><p> command in a Debian based system. (The name of the required package may be different.)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. When we would like to install PostgreSQL to a Windows operating system, we can use more different installer programs. Some installers contain the PostGIS package, and it is selectable during the installation process.</p><p>The PostgreSQL and PostGIS could be installed from a ZIP file too. Both of the downloaded files must be unpacked to a directory. The PostgreSQL programs are available from this directory.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.2. 5.2.2 Installing from source</p><p>The PostgreSQL and the PostGIS are open source programs. The source code of these programs can be downloaded from the following home pages (http://www.postgresql.org and http://www.postgis.org).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Both of these programs have regular build system, and could be installed by </p><p>./configure</p><p>, </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. make</p><p> and </p><p> make install</p><p> commands. This work needs some other software. We can install this software by the package manager (need the development packages, with -dev ended name) or build from source also.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.3. 5.2.3 Installing to a database</p><p>The installation of PostGIS to the database server is not sufficient, because PostGIS contains stored procedures. These stored procedures (and types) must be available in each database, where we should use the geospatial function of PostGIS.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. All of the necessary SQL commands, which create the required database objects, are in the </p><p> postgis.sql</p><p> file. This file is in the </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. share/contrib/postgis-version</p><p> directory, where version is the version of PostGIS.</p><p>This file can be run from the psql console. For example:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. \i /usr/local/share/contrib/postgis-1.5/postgis.sql</p><p>We can use the -f option of the psql command from the shell:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. psql -f /usr/local/share/contrib/postgis-1.5/postgis.sql gisdatabase gisuser</p><p>After the execution of these commands, PostGIS is available in the database.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The </p><p> spatial_ref_sys</p><p> table was created by the </p><p> postgis.sql</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. , but the table is empty. We can fill the descriptions of the spatial reference systems to this table by the </p><p> spatial_ref_sys.sql</p><p> file, which locates in the directory of the </p><p> postgis.sql</p><p>.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 3. 5.3 Creating spatial tables</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. PostGIS provides geometry and geography types. Geometry and geography columns can be created by the </p><p>CREATE TABLE</p><p>SQL command, together with the other columns of the table:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# CREATE TABLE gistable </p><p>(id serial PRIMARY KEY,</p><p> name char(20),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. geom geometry);</p><p>CREATE TABLE</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. This is not a perfect solution, because many applications need one record in the geometry</p><p>_columns</p><p> table for each geometry type columns of the tables of the database. Use the </p><p>AddGeomemertyColumns</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function instead to create the geometry type columns of a table, after the table has been created. This function can be called by a </p><p>SELECT</p><p> command. For example:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# CREATE TABLE gistable </p><p>(id serial PRIMARY KEY,</p><p> name char(20));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. CREATE TABLE</p><p> gisdb=# SELECT AddGeometryColumn('gistable', 'geom', 23700, 'POLYGON', 2);</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. addgeometrycolumn</p><p>------</p><p> public.gistable.geom SRID:23700 TYPE:POLYGON DIMS:2</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>The first parameter of the function is the name of the table, the second parameter is the name of the new geometry column. The third parameter is the SRID (the identification number of the reference system), the fourth prameter is the type of the geometry, fifth parameter is the dimension of the geometry.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. AddGeomemertyColumn</p><p> function inserts the necessary record into the geometry_columns table, and set constrains to check the geometry type, dimension and SRID (identification number of the spatial reference system).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The spatial index is very important for effective spatial queries. GIST type indexes can be built for the geometry type columns:</p><p> gisdb=# CREATE INDEX gistable_geom ON gistable USING GIST (geom);</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. CREATE INDEX</p><p>The GIST (Generalized Search Tree) index provides an R-tree like data structure for fast queries on the basis of the bounding rectangles. The creation of this index is recommended for each geometry column, because it is very useful in many geospatial operations.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The </p><p>DropGeometryColumn</p><p> function can be used to remove a geometry column from a table. For example:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. SELECT DropGeometryColumn('gistable','geom');</p><p>4. 5.4 Input and output functions</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. These functions provide the creation of geometry objects from text and binary data, and dump the geometry to various text and binary formats.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.1. 5.4.1 GeomFromText</p><p>The </p><p>GeomFromText</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. or </p><p>GeometryFromText</p><p> function returns a geometry value.</p><p>GeomFromText('POLYGON((4 4,4 7,7 7,7 4,4 4))', 23700)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The first parameter is the WKT representation of the geometry, the second parameter is the identification number of the spatial reference system (SRID).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The </p><p>ST_GeogFromText</p><p> is similar to the </p><p>GeomFromText</p><p>, but creates geography values. This function needs only one parameter, the WKT representation of the geography; the SRID will be 4326 (WGS84).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.2. 5.4.2 GeomFromEWKT</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The </p><p>GeomFromEWKT</p><p> is similar to the </p><p>GeomFromText</p><p> function, but uses EWKT (Extended WKT) representation.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. GeomFromEWKT('SRID=23700;POLYGON((4 4,4 7,7 7,7 4,4 4))')</p><p>This function has only one parameter: The EWKT representation text of the geometry, which contains the SRID too.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.3. 5.4.3 AsText</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. AsTex</p><p> t function returns the WKT representation of the geometry. The </p><p>AsEWKT</p><p> is very similar, but the result contains the SRID of the geometry too. Both of these functions have one parameter: one geometry value.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.4. 5.4.4 Binary input and output</p><p>PostGIS has functions for the binary input and output. These functions are very similar to the text functions, but</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. use WKB or EWKB format for the input (</p><p>GeomFromWKB</p><p>, </p><p>GeomFromEWBK</p><p>) or the output (</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. AsBinary</p><p>, </p><p>AsEWKB</p><p>).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4.5. 5.4.5 GML and KML input and output</p><p>PostGIS can handle GML and KML data. The </p><p>AsGML</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. and the </p><p>AsKML</p><p> functions return the representation of the geometry in these XML based formats. The result is a text value. This text value contains the XML description of the geometry in the required format:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsGML(GeomFromText('POLYGON((4 4,4 7,7 7,7 4,4 4))', 4326));</p><p> asgml</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs></p><p><gml:LinearRing></p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. <gml:coordinates>4,4 4,7 7,7 7,4 4,4</gml:coordinates></p><p></gml:LinearRing></p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </gml:outerBoundaryIs></gml:Polygon></p><p>(1 row)</p><p> gisdb=# SELECT AsKML(GeomFromText('POLYGON((4 4,4 7,7 7,7 4,4 4))', 4326));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. askml</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. <Polygon><outerBoundaryIs><LinearRing></p><p><coordinates>4,4 4,7 7,7 7,4 4,4</coordinates></p><p></LinearRing></outerBoundaryIs></Polygon></p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>The </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. GeomFromGML</p><p> and </p><p>GeomFromKML</p><p> functions provide the data input from these formats.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5. 5.5 Calculating numerical attributes of geometry</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5.1. 5.5.1 Area</p><p>Area</p><p> function returns the area of a Polygon or MultiPolygon geometry or the total area of the polygon elements of a GeometryCollection. If the parameter of the function has a different geometry type the result will be zero.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT ST_Area('POLYGON((1 1,1 4,4 4,4 1,1 1))');</p><p> st_area</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>9</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT ST_Area('POLYGON((1 1,1 4,4 4,4 1,1 1),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (2 2,2 3,3 3,3 2,2 2))');</p><p> st_area</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 8</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT ST_Area('LINESTRING(4 5,7 9,11 2)');</p><p> st_area</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT ST_Area('GEOMETRYCOLLECTION(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((1 1,1 4,4 4,4 1,1 1)),POINT(7 8))');</p><p> st_area</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The parameter of the </p><p>ST_Area</p><p> function (as in the examples above) may be a text value with the WKT representation of the geometry too. This solution will be applied in some of the following examples of other functions.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5.2. 5.5.2 Perimeter</p><p>Perimeter</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function returns the perimeter (length of the boundary) of a Polygon or MultiPolygon geometry or the the total perimeter of the polygon elements of a GeometryCollection. If the parameter of the function has a different geometry type the result will be zero.</p><p> gisdb=# SELECT Perimeter('POLYGON((1 1,1 4,4 4,4 1,1 1))');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. perimeter</p><p>------</p><p>12</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Perimeter('POLYGON((1 1,1 4,4 4,4 1,1 1),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (2 2,2 3,3 3,3 2,2 2))');</p><p> perimeter</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>16</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Perimeter('LINESTRING(4 5,7 9,11 2)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. perimeter</p><p>------</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Perimeter('GEOMETRYCOLLECTION(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((1 1,1 4,4 4,4 1,1 1)),POINT(7 8))');</p><p> perimeter</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>12</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The </p><p>Perimeter3D</p><p> function works similarly to the Perimeter function, but calculates the 3D perimeter, if the geometry has Z coordinates. The </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Perimeter2D</p><p> function always returns the 2D perimeter.</p><p> gisdb=# SELECT Perimeter2D('POLYGON((1 1 0,1 4 0,4 4 4,</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 4 1 0,1 1 0))');</p><p> perimeter2d</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>12</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Perimeter3D('POLYGON((1 1 0,1 4 0,4 4 4,</p><p>4 1 0,1 1 0))');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. perimeter3d</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 16</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5.3. 5.5.3 Length</p><p>Length</p><p> function returns the length of a LineString or MultiLineString geometry or the the total length of the linestring</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. elements of a GeometryCollection. If the parameter of the function has a different geometry type the result will be zero.</p><p> gisdb=# SELECT ST_Length('LINESTRING(1 2,5 2,9 5)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. st_length</p><p>------</p><p>9</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT ST_Length('MULTILINESTRING((1 2,5 2,9 5),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 4,3 4))');</p><p> st_length</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>11</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT ST_Length('POLYGON((1 1,1 4,4 4,4 1,1 1))');</p><p> st_length</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT ST_Length('GEOMETRYCOLLECTION(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(1 4,1 10),POINT(7 8))');</p><p> st_length</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>6</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The “length” is also the name of the function, which returns the length of a text. PostgreSQL makes a distinction between the two length functions by the type of the parameter. We have to use </p><p>GeomFromText</p><p> function in the </p><p>Length</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function, or use </p><p>ST_Length</p><p> function.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Length3D</p><p> function works similarly to the Length function, but calculates the 3D perimeter, if the geometry has Z coordinates.</p><p> gisdb=# SELECT ST_Length('LINESTRING(1 3 2,5 15 5)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. st_length</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 12.6491106406735</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT ST_Length2D('LINESTRING(1 3 2,5 15 5)');</p><p> st_length2d</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 12.6491106406735</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT ST_Length3D('LINESTRING(1 3 2,5 15 5)');</p><p> st_length3d</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>13</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>Length_Spheroid</p><p>(and </p><p>Lebgth3D_Spheroid</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ) function can calculate the length of the geometry on a spheroid (sphere or ellipsoid).</p><p> gisdb=# SELECT ST_Length_Spheroid('LINESTRING(18.41281 47.18458,</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 18.41883 47.18878,18.42706 47.19097)',</p><p>'SPHEROID["WGS84",6378137,298.257223563]');</p><p> st_length_spheroid</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>1322.39548875418</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>6. 5.6 Calculating geometry values</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. These functions return a new geometry, which are built from the original geometries and sometimes other parameters.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.1. 5.6.1 Buffer</p><p>Buffer</p><p> function returns a Polygon or MultiPolygon geometry that represents the set of the points whose distance from a geometry specified by the first parameter are less than or equal to the distance specified by the second parameter.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Buffer('POINT(3 4)',1));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>POLYGON((4 4,3.981 3.805,3.924 3.617,3.831 3.444,3.707 3.293,</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 3.556 3.169,3.383 3.076,3.195 3.019,3 3,</p><p>2.805 3.019,2.617 3.076,2.444 3.169,2.293 3.293,</p><p>2.169 3.444,2.076 3.617,2.019 3.805,2 4,</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2.019 4.195,2.076 4.383,2.169 4.556,2.293 4.707,</p><p>2.444 4.831,2.617 4.924,2.805 4.981,3 5,</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 3.195 4.981,3.383 4.924,3.556 4.831,3.707 4.707,</p><p>3.831 4.556,3.924 4.383,3.981 4.195,4 4))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. By definition, the boundary of the shape of the buffer contains arc sections, but the Polygon and MultiPolygon geometries are limited to have linear rings. The arc sections will be replaced by more linear sections. By default, a quarter of a circle will be replaced by 8 line segments. The optionally third parameter of the function specifies the number of line segments or other parameters of the buffer generation.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ST_Buffer('POINT(3 4)',1,'quad_segs=2'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>POLYGON((4 4,3.707 3.293,3 3,2.293 3.293,2 4,</p><p>2.293 4.707,3 5,3.707 4.707,4 4))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>6.2. 5.6.2 ConvexHull</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ConvexHull</p><p> function returns a geometry that represents the least convex point set, which contains all the points of a geometry, which were specified by the parameter of the function.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ConvexHull('POINT(3 5)'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>POINT(3 5)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ConvexHull('LINESTRING(2 3,5 8)'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>LINESTRING(2 3,5 8)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(ConvexHull('MULTIPOINT(2 2,4 5)'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>LINESTRING(2 2,4 5)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ConvexHull('MULTIPOINT(2 2,4 5,3 4)'));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((2 2,3 4,4 5,2 2))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ConvexHull('POLYGON((1 1,1 4,4 4,4 1,1 1),</p><p>(2 2,2 3,3 3,3 2,2 2))'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>POLYGON((1 1,1 4,4 4,4 1,1 1))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(ConvexHull('POLYGON((1 5,6 9,4 6,8 2,1 5))'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((8 2,1 5,6 9,8 2))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.3. 5.6.3 Centroid</p><p>Centroid</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function returns the geometric centre of the geometry as a Point geometry.</p><p> gisdb=# SELECT AsText(Centroid('POLYGON((1 1,1 4,4 4,4 1,1 1))'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>POINT(2.5 2.5)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(Centroid('POLYGON((1 1,1 4,4 4,4 1,1 1),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (2 2,2 3,3 3,3 2,2 2))'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>POINT(2.5 2.5)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.4. 5.6.4 Simplify</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Simplify</p><p> function returns a simplified variant of the geometry, which is the first parameter of the function. This function uses the Douglas-Peuker algorithm, with a tolerance, which is the second parameter.</p><p> gisdb=# SELECT AsText(Simplify('LINESTRING(2 4,4 7,7 9)', 1));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(2 4,7 9)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Simplify('LINESTRING(2 4,4 7,7 9)', 0.5));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(2 4,4 7,7 9)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ST_SiplifyPreserveTopology</p><p> function is the same as the </p><p>Simplify</p><p>, but preserves the topology relations of parts of the object (linear rings, linestring segments).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. SELECT AsText(Simplify(ST_GeomFromText(</p><p>'MULTILINESTRING((1 5,5 7,9 5),(1 1,5 6,9 1))'),2));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>MULTILINESTRING((1 5,9 5),(1 1,5 6,9 1))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>SELECT AsText(ST_SimplifyPreserveTopology(ST_GeomFromText(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'MULTILINESTRING((1 5,5 7,9 5),(1 1,5 6,9 1))'),2));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. MULTILINESTRING((1 5,5 7,9 5),(1 1,5 6,9 1))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 6.5. 5.6.5 Segmentize</p><p>Segmentize</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function returns a modified variant of the geometry (the first parameter), which has no longer segments than a given distance (the second parameter).</p><p> gisdb=# SELECT AsText(Segmentize('LINESTRING(1 3,1 6)',3));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>LINESTRING(1 3,1 6)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Segmentize('LINESTRING(1 3,1 9)',3));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(1 3,1 6,1 9)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Segmentize('LINESTRING(1 3,1 9)',2));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>LINESTRING(1 3,1 5,1 7,1 9)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Segmentize(</p><p>'POLYGON((3 2,3 8,5 8,5 2,3 2))',3));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((3 2,3 5,3 8,5 8,5 5,5 2,3 2))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7. 5.7 Relation of two geometries</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.1. 5.7.1 Distance</p><p>Distance</p><p> function returns the shortest distance between two geometries, which are the parameters of the function. The result is zero, if the geometries have a common point.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Distance('POINT(1 2)','POINT(4 6)');</p><p> distance</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>5</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Distance('LINESTRING(2 2,8 2)','POINT(4 6)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. distance</p><p>------</p><p>4</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Distance('POLYGON((2 2,2 3,8 3,8 2,2 2))',</p><p>'POINT(4 6)');</p><p> distance</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>3</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>Distance</p><p> function can be used between geography objects too.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT ST_Distance(</p><p>ST_GeogFromText('SRID=4326;POINT(18.41883 47.18878)'),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ST_GeogFromText('SRID=4326;POINT(18.41281 47.18458)'));</p><p> st_distance</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 652.839475007109</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ST_ShortestLine</p><p> function returns the shortest line segment between two geometries as a LineString geometry. The length of this LineString equals to the result of the </p><p>Distance</p><p> function.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ST_ShortestLine('POINT(1 2)','POINT(4 6)'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>LINESTRING(1 2,4 6)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(ST_ShortestLine('LINESTRING(2 2,8 2)',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POINT(4 6)'));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(4 2,4 6)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ST_ShortestLine(</p><p>'POLYGON((2 2,2 3,8 3,8 2,2 2))','POINT(4 6)'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(4 3,4 6)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.2. 5.7.2 Azimuth</p><p>Azimuth</p><p> function returns the azimuth in radians from the point specified in the first parameter to the point specified in the second parameter. If any parameter has no Point geometry, the function returns NULL.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Azimuth('POINT(1 1)','POINT(1 2)');</p><p> azimuth</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>0</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Azimuth('POINT(1 1)','POINT(2 2)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. azimuth</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 0.785398163397448</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.3. 5.7.3 Equals</p><p>Equals</p><p> function returns true value, if the point set of the geometries (specified by the parameters of the function) are spatially equal.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Equals('POINT(2 4)','POINT(3 5)');</p><p> equals</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> f</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Equals('POINT(2 4)','POINT(2 4)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. equals</p><p>------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Equals('MULTIPOINT(2 4,5 8)','MULTIPOINT(5 8,2 4)');</p><p> equals</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Equals('LINESTRING(2 4,5 8)','LINESTRING(5 8,2 4)');</p><p> equals</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Equals('POLYGON((1 1,1 5,5 1,1 1))',</p><p>'POLYGON((1 5,1 1,5 1,1 5))');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. equals</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Equals('POLYGON((2 2,2 4,4 4,4 2,2 2))',</p><p>'POLYGON((2 2,2 3,2 4,4 4,4 2,2 2))');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. equals</p><p>------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>7.4. 5.7.4 Contains</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Contains</p><p> function returns true value, if the geometry specified by the first parameter contains all the points of the geometry specified by the second parameter.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Contains('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POINT(3 3)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. contains</p><p>------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Contains('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POINT(8 4)');</p><p> contains</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> f</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Contains('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'LINESTRING(2 2,3 4)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. contains</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Contains('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'LINESTRING(2 4,6 4)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. contains</p><p>------</p><p> f</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Contains('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((2 2,2 3,3 3,3 2,2 2))');</p><p> contains</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Contains('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((4 4,4 7,7 7,7 4,4 4))');</p><p> contains</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. f</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Contains('LINESTRING(2 3,4 3)',</p><p>'POINT(3 3)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. contains</p><p>------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Contains('LINESTRING(2 3,7 3)',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'LINESTRING(3 3,4 3)');</p><p> contains</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>7.5. 5.7.5 Overlaps</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Overlaps</p><p> function returns true value, if the common set of the points of the two geometries has the same dimension as the objects. This function returns true value, if the two geometries have common points, but both of the geometries have points, which are not contained by the other object. This function does not work with GeometryCollection objects.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Overlaps('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((2 2,2 3,3 3,3 2,2 2))');</p><p> overlaps</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> f</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Overlaps('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((4 4,4 7,7 7,7 4,4 4))');</p><p> overlaps</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Overlaps('LINESTRING(2 3,7 3)',</p><p>'LINESTRING(3 3,4 3)');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. overlaps</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. f</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Overlaps('LINESTRING(2 3,7 3)',</p><p>'LINESTRING(1 3,4 3)');</p><p> overlaps</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>7.6. 5.7.6 Intersects</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Intersects</p><p> function returns true value, if the two geometries have at least one common point.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Intersects('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((4 4,4 7,7 7,7 4,4 4))');</p><p> intersects</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Intersects('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'LINESTRING(2 4,6 4)'); intersects</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. t</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Intersects('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'LINESTRING(6 4,7 4)');</p><p> intersects</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> f</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>7.7. 5.7.7 Touches</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Touches</p><p> function returns true value, if the two geometries have common points, but these points are located only on the boundaries of the objects.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Touches('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((5 2,5 4,7 4,7 2,5 2))');</p><p> touches</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT Touches('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((5 2,4 4,7 4,7 2,5 2))');</p><p> touches</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p> f</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7.8. 5.7.8 Relate</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Relate</p><p> function returns a text, which contains the element of the DE-9IM.</p><p> gisdb=# SELECT Relate('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((5 2,5 4,7 4,7 2,5 2))');</p><p> relate</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. FF2F11212</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. If the </p><p>Relate</p><p> function has three parameters, the third parameter is a DE-9IM pattern. The function returns true, if the pattern matches the relation of the two geometries, given in the first and second parameters.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT Relate('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((5 2,5 4,7 4,7 2,5 2))','****1****');</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. relate</p><p>------</p><p> t</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>8. 5.8 Calculate derived geometry</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. These functions return a modified geometry preserving the topology of the original object.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 8.1. 5.8.1 Transform</p><p>PostGIS can transform geometries between spatial reference systems. The geometries contain the identification number of spatial reference system, further on SRID. The spatial_ref_sys table contains the descriptions of spatial reference systems identified by the SRID.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Transform</p><p> function returns a transformed geometry from the original reference system (specified as the first parameter, SRID is involved in the geometry) to a new reference system, which SRID is specified by the second parameter.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Transform(</p><p>'SRID=4326;POINT(18.4183 47.1888)',23700));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>POINT(602233.50006042 205129.440451882)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>4326 is the SRID of WGS84, 23700 is the SRID of Hungarian Projection System (EOV).</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. The SRID of an object can be modified without transformation by the </p><p>SetSRID</p><p> function.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ST_SetSRID</p><p>('SRID=4326;POINT(18.4183 47.1888)',23700));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>POINT(18.4183 47.1888)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>8.2. 5.8.2 Affine</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Affine</p><p> function returns an affine transformed geometry from the input geometry specified as the first parameter. The other 6 or 12 parameters of the function contain the parameters of a 2D or 3D transformation.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 8.3. 5.8.3 SnapToGrid</p><p>SnapToGrid</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function returns modified geometry snapping points to a grid. The resolution of the grid is specified by the second parameter. The coordinates of a geometry can be rounded up by this function.</p><p> gisdb=# SELECT AsText(SnapToGrid(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POINT(602233.50006042 205129.440451882)',0.01));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POINT(602233.5 205129.44)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9. 5.9 Set functions</p><p>These functions return a geometry which represents a point set which is the result of a set operation between two geometries.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.1. 5.9.1 ST_Union</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ST_</p><p>Union</p><p> function returns a geometry that represents the union of the two geometries, which are specified as the parameters of the function.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(ST_Union('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((3 3,3 7,7 7,7 3,3 3))'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>POLYGON((1 1,1 5,3 5,3 7,7 7,7 3,5 3,5 1,1 1))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Figure 1. Union of two POLYGON geometries</p><p> gisdb=# SELECT AsText(ST_Union('LINESTRING(2 3,5 3)',</p><p>'LINESTRING(4 3,7 3)')); astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>MULTILINESTRING((2 3,4 3),(4 3,5 3),(5 3,7 3))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(ST_Union('POINT(2 4)','POINT(7 3)'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. MULTIPOINT(2 4,7 3)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.2. 5.9.2 Intersection</p><p>Intersection</p><p> function returns a geometry that represents the common parts of the two geometries, which are specified as the parameters of the function.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Intersection('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((3 3,3 7,7 7,73,3 3))'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((3 5,5 5,5 3,3 3,3 5))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Figure 2. Intersection of two POLYGON geometries</p><p> gisdb=# SELECT AsText(Intersection('LINESTRING(2 3,5 3)',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'LINESTRING(4 3,7 3)')); astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. LINESTRING(4 3,5 3)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Intersection('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'LINESTRING(3 4,8 9)'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>LINESTRING(3 4,4 5)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(Intersection('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'MULTIPOINT(2 4,6 2)'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>POINT(2 4)</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.3. 5.9.3 Difference</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Difference</p><p> function returns a geometry that represents that part of the first geometry, which is not in the second geometry.</p><p> gisdb=# SELECT AsText(Difference('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((3 3,3 7,7 7,7 3,3 3))'));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((1 1,1 5,3 5,3 3,5 3,5 1,1 1))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Figure 3. Difference of two POLYGON geometries</p><p> gisdb=# SELECT AsText(Difference('LINESTRING(2 3,5 3)',</p><p>'LINESTRING(4 3,7 3)')); astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>LINESTRING(2 3,4 3)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p> gisdb=# SELECT AsText(Difference('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'LINESTRING(3 4,8 9)')); astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((1 1,1 5,4 5,5 5,5 1,1 1))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Difference('POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'MULTIPOINT(2 4,6 2)')); astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((1 1,1 5,5 5,5 1,1 1))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 9.4. 5.9.4 SymDifference</p><p>SymDifference</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. function returns a geometry that represents that part of the two input geometry, which belongs to only one of them.</p><p> gisdb=# SELECT AsText(SymDifference(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((1 1,1 5,5 5,5 1,1 1))',</p><p>'POLYGON((3 3,3 7,7 7,7 3,3 3))'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>MULTIPOLYGON(((1 1,1 5,3 5,3 3,5 3,5 1,1 1)),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ((5 3,5 5,3 5,3 7,7 7,7 3,5 3)))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. </p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Figure 4. Symmetric difference of two POLYGON geometries</p><p> gisdb=# SELECT AsText(SymDifference('LINESTRING(2 3,5 3)',</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'LINESTRING(4 3,7 3)'));</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>MULTILINESTRING((2 3,4 3),(5 3,7 3))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(SymDifference(</p><p>'POLYGON((1 1,1 5,5 5,5 1,1 1))','LINESTRING(3 4,8 9)'));</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. GEOMETRYCOLLECTION(LINESTRING(4 5,8 9),</p><p>POLYGON((1 1,1 5,4 5,5 5,5 1,1 1)))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(SymDifference(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 'POLYGON((1 1,1 5,5 5,5 1,1 1))','MULTIPOINT(2 4,6 2)'));</p><p> astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. GEOMETRYCOLLECTION(POINT(6 2),</p><p>POLYGON((1 1,1 5,5 5,5 1,1 1)))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>10. 5.10 Aggregate functions</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. PostGIS’ aggregate functions create geometry from more geometries. These are used, where the usual SQL aggregate functions, for example in queries containing GROUP BY statement.</p><p>10.1. 5.10.1 ST_Union</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ST_Union</p><p> aggregate returns a geometry that represents the union of all input geometries.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT id, AsText(geom) FROM polygons; id | astext</p><p>----+------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 1 | POLYGON((1 1,1 5,5 5,5 1,1 1))</p><p>2 | POLYGON((3 3,3 7,7 7,7 3,3 3))</p><p>3 | POLYGON((8 8,8 9,9 9,9 8,8 8))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (3 rows)</p><p> gisdb=# SELECT AsText(ST_Union(geom)) FROM polygons;</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. MULTIPOLYGON(((8 8,8 9,9 9,9 8,8 8)),</p><p>((1 1,1 5,3 5,3 7,7 7,7 3,5 3,5 1,1 1)))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>10.2. 5.10.2 Collect</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Collect</p><p> aggregate returns a Multi* geometry or a GeometryCollection, which contains the elements of the original geometries. In contrast to the </p><p>ST_Union</p><p>, this aggregate does not do any spatial operation between the geometries.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT AsText(Collect(geom)) FROM polygons;</p><p> astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ------</p><p>MULTIPOLYGON(((1 1,1 5,5 5,5 1,1 1)),((3 3,3 7,7 7,7 3,3 3)),</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ((8 8,8 9,9 9,9 8,8 8)))</p><p>(1 row)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 10.3. 5.10.3 Poligonize</p><p>Poligonize</p><p> aggregate returns a GeometryCollection that contains the possible Polygons, which can be created from the input LineString and MultiLineString objects.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. gisdb=# SELECT id, AsText(geom) from linework;</p><p> id | astext</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. ----+------</p><p>1 | LINESTRING(1 1,1 2)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 2 | LINESTRING(1 2,2 2)</p><p>3 | LINESTRING(2 2,2 1)</p><p>4 | LINESTRING(2 1,1 1)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 5 | LINESTRING(2 2,3 2)</p><p>6 | LINESTRING(3 2,3 3)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 7 | LINESTRING(3 3,2 3)</p><p>8 | LINESTRING(2 3,2 2)</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (8 rows)</p><p> gisdb=# SELECT AsText(Polygonize(geom)) from linework;</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. astext</p><p>------</p><p>GEOMETRYCOLLECTION(</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. POLYGON((1 1,1 2,2 2,2 1,1 1)),</p><p>POLYGON((3 2,2 2,2 3,3 3,3 2)))</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. (1 row)</p><p>11. 5.11 Operators</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. PostGIS has some operators that return true or false values depending on the spatial relationship of the bounding boxes of the operands. These operators use spatial indexes of any operands.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Table 1. Operators of PostGIS</p><p> returns TRUE if A's bounding box overlaps B's A && B</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. A &< B returns TRUE if A's bounding box overlaps or is to the left of B's</p><p>A &<| returns TRUE if A's bounding box overlaps or is below B's B</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. A &> B returns TRUE if A' bounding box overlaps or is to the right of B's</p><p>A << B returns TRUE if A's bounding box is strictly to the left of B's</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. A <<| returns TRUE if A's bounding box is strictly below B's B</p><p>A = B returns TRUE if A's bounding box is the same as B's</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. A >> B returns TRUE if A's bounding box is strictly to the right of B's</p><p>A @ B returns TRUE if A's bounding box is contained by B's</p><p>A |&> </p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. B returns TRUE if A's bounding box overlaps or is above B's</p><p>A |>> returns TRUE if A's bounding box is strictly above B's B</p><p>A ~ B returns TRUE if A's bounding box contains B's</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. A ~= B returns TRUE if A's bounding box is the same as B's</p><p>These operators are very useful for fast pre-screening in spatial queries.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Bibliography</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. PostgreSQL Global Development Group:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. 1996-2010.</p><p>Refractions Research Inc.:</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. PostGIS 1.5.2 manual,</p><p>2010.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Open Geospatial Consortium:</p><p>OpenGIS Implementation Standard for Geographic information - Simple feature access - Part 1: Common architecture, OGC 06-103r4,</p><p>2010.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. Open Geospatial Consortium:</p><p>OpenGIS Implementation Standard for Geographic information - Simple feature access - Part 2: SQL</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>. option, OGC 06-104r4,</p><p>2010.</p><p></p><p>Created by </p><p>XMLmind XSL-FO Converter</p><p>.</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages469 Page
-
File Size-