You are on page 1of 64

PostGIS, 1.3.

PostGIS
1.3.4, 16.08.2008

GIS-Lab.info

PostGIS, 1.3.4

PostGIS - - PostgreSQL
. PostGIS R-Tree/GiST
.
1.3.4 ( ). : 1.4SVN


(http://xbb.uz). ,
: (sim@gis-lab.info). .
(http://gislab.info/docs/postgis/manual/terms.html).

GIS-Lab.info

ii

PostGIS, 1.3.4

1. ...........................................................................................................................................................1
1.1. ..................................................................................................................................................1
1.2. .........................................................................................................................1
2. ...............................................................................................................................................................2
2.1. .......................................................................................................................................................2
2.2. PostGIS..............................................................................................................................................................2
2.2.1. , PostGIS,
.............................................................................................................................................................................3
2.2.2. ...............................................................................................................................................3
2.2.3. .................................................................................................................................4
2.3. JDBC .................................................................................................................................................................5
2.4. /.............................................................................................................................................5
3. ..................................................................................................................................6
4. PostGIS ........................................................................................................................................8
4.1. ...................................................................................................................................................8
4.1.1. OpenGIS WKB WKT .............................................................................................................................8
4.1.2. PostGIS EWKB, EWKT ...................................................................................8
4.1.3. SQL-MM ...................................................................................................................................................9
4.2. OpenGIS............................................................................................................10
4.2.1. SPATIAL_REF_SYS ...............................................................................................................10
4.2.2. GEOMETRY_COLUMNS.......................................................................................................11
4.2.3. ..................................................................................................11
4.2.4. OpenGIS ...........................................................................12
4.3. ....................................................................................................................................13
4.3.1. SQL ...............................................................................................................................13
4.3.2. ....................................................................................................................14
4.4. ................................................................................................................................15
4.4.1. SQL ...............................................................................................................................15
4.4.2. .........................................................................................................................16
4.5. ....................................................................................................................................17
4.5.1. GiST.........................................................................................................................................17
4.5.2. .......................................................................................................................17
4.6. ..........................................................................................................................................18
4.6.1. ........................................................................................................................18
4.6.2. SQL .......................................................................................................19
4.7. Mapserver .............................................................................................................................21
4.7.1. ..........................................................................................................................21
4.7.2. ....................................................................................................................23
4.7.3. .................................................................................................................24
4.7.4. .................................................................................................................................................24
4.8. Java (JDBC).....................................................................................................................................26
4.9. C (libpq)...........................................................................................................................................28
4.9.1. ..............................................................................................................................28
4.9.2. ...............................................................................................................................28
5. ........................................................................................................................29
5.1. ....................................................................................................29
5.1.1. ...............................................................................................................................29
5.1.2. .............................................................................................................................29
5.2. CLUSTER- ..............................................................................................29
5.3. ..............................................................................................................30
6. PostGIS ...........................................................................................................................................31
6.1. OpenGIS..........................................................................................................................................31
6.1.1. .............................................................................................................................31
6.1.2. ............................................................................................................31
6.1.3. .............................................................................................................33
6.1.4. ........................................................................................................34
6.1.5. .............................................................................................................36
6.2.1. .............................................................................................................................37
6.2.2. ..............................................................................................................................................39
6.2.3. ...............................................................................................................................39
GIS-Lab.info

iii

PostGIS, 1.3.4
6.2.4. ..........................................................................................................................40
6.2.5. .............................................................................................................41
6.2.6. ...................................................................................................................42
6.2.7. ...................................................................................................................................44
6.2.8. ......................................................................................................................................................45
6.2.9. .............................................................................................................46
6.3. SQL-MM.........................................................................................................................................46
6.4. ArcSDE ...........................................................................................................................................50
7. ........................................................................................................................................51
7.1. ...............................................................................51
7.2. .....................................................................................................51
A.1. ...................................................................................................................................52

GIS-Lab.info

iv

PostGIS, 1.3.4

1.
PostGIS Refractions Research Inc
. Refractions Research Inc
, , .
PostGIS
, OpenGIS,
(, , ),
.

1.1.
Sandro Santilli <strk@refractions.net>
, GEOS,
.
Mark Leslie <mleslie@refractions.net>
.
Chris Hodgson <chodgson@refractions.net>
7.2.
Paul Ramsey <pramsey@refractions.net>
.
Jeff Lounsbury <jeffloun@refractions.net>
/ shape-.
Dave Blasby <dblasby@gmail.com>
PostGIS. Dave ,
.

: Alex Bodnaru, Alex Mayrhofer, Bruce Rindahl, Bernhard Reiter, Bruno Wolff III, Carl
Anderson, Charlie Savage, David Skea, David Techer, IIDA Tetsushi, Geographic Data BC, Gerald Fenoy, Gino
Lucrezi, Klaus Foerster, Kris Jurka, Mark Cave-Ayland, Mark Sondheim, Markus Schaber, Michael Fuhr, Nikita
Shulga, Norman Vine, Olivier Courtin, Ralph Mason, Steffen Macke.

GEOS (http://geos.refractions.net/)
Martin Davis Vivid Solutions.
Proj4 (http://trac.osgeo.org/proj/)
Gerald Evenden Frank Warmerdam.

1.2.
, PostGIS http://postgis.refractions.net.
GEOS
http://geos.refractions.net.
Proj4 http://trac.osgeo.org/proj.
PostgreSQL PostgreSQL
http://www.postgresql.org.
GiST PostgreSQL GiST
http://www.sai.msu.su/~megera/postgres/gist.
- Mapserver
http://mapserver.gis.umn.edu.
"Simple Features for Specification for SQL" OpenGIS: http://www.opengis.org.

GIS-Lab.info

PostGIS, 1.3.4

2.
2.1.
PostGIS :
PostgreSQL ( ). PostgreSQL
http://www.postgresql.org. 7.2 .
GNU C (gcc). ANSI C
PostGIS, , gcc.
GNU Make (gmake make). GNU make make .
make -v. make Makefile
PostGIS.
() Proj4. Proj4 PostGIS
. Proj4
http://www.remotesensing.org/proj.
() GEOS. GEOS PostGIS
(ST_Touches(), ST_Contains(), ST_Intersects()) (ST_Buffer(),
ST_Union(), ST_Difference()). GEOS http://geos.refractions.net.

2.2. PostGIS
PostGIS PostgreSQL. PostGIS 1.3.3
PostgreSQL. PostgreSQL
http://www.postgresql.org.
PostGIS 1.3.3 PostgreSQL 7.2.0 .
PostgreSQL .
PostGIS PostgreSQL.
: GEOS,
PostgreSQL C++:
LDFLAGS=-lstdc++ ./configure [ ]
C++ .
( - ), .
, PostgreSQL.
PostGIS: http://postgis.refractions.net/postgis-1.3.3SVN.tar.gz. :
# gzip -d -c postgis-1.3.3SVN.tar.gz | tar xvf
postgis-1.3.3SVN :
# ./configure
,
Proj4. ./configure , --with-proj=PATH ,
Proj4.
GEOS, GEOS. ./configure
, --with-geos=PATH ,
geos-config.
.
# make # make install
, pg_config.
[pkglibdir]/lib/contrib.
, lwpostgis.sql, [prefix]/share/contrib.
[bindir]/.
PostGIS PL/pgSQL. lwpostgis.sql
PL/pgSQL. createlang. -
, PostgreSQL.
# createlang plpgsql [yourdatabase]

GIS-Lab.info

PostGIS, 1.3.4
PostGIS
lwpostgis.sql.
# psql -d [yourdatabase] -f lwpostgis.sql
PostGIS .
EPSG
spatial_ref_sys.sql SPATIAL_REF_SYS.
# psql -d [yourdatabase] -f spatial_ref_sys.sql

2.2.1. , PostGIS,

PostGIS ( Win32 PostGIS >= 1.1.5)
PostGIS template_postgis.
PostgreSQL template_postgis, /
- . ,
.
shell:
# createdb -T template_postgis my_spatial_db
SQL:
postgres=# CREATE DATABASE my_spatial_db TEMPLATE=template_postgis

2.2.2.
,
PostGIS.
, ,
dump/reload.
PostGIS SOFT UPGRADE ,
HARD UPGRADE .
PostGIS .
pg_dump -Fc, HARD UPGRADE.

2.2.2.1. SOFT-
SOFT- lwpostgis_upgrade.sql
:
$ psql -f lwpostgis_upgrade.sql -d your_spatial_database
SOFT-, ,
HARD-.
: lwpostgis_upgrade.sql, ,
1.1 . :
$ utils/postgis_proc_upgrade.pl lwpostgis.sql > lwpostgis_upgrade.sql

2.2.2.2. HARD-
HARD- dump/reload PostGIS. HARD , PostGIS SOFT. , dump/reload (HARD) .
PostGIS , pg_dump -Fc.
.
:
, , "olddb". "custom-format" .
$ pg_dump -Fc olddb > olddb.dump

GIS-Lab.info

PostGIS, 1.3.4
PostGIS .
. postgis_restore createdb ,
, ,
. "newdb" UNICODE:
$ sh utils/postgis_restore.pl lwpostgis.sql newdb olddb.dump -E=UNICODE >
restore.log
,
lwpostgis.sql.
$ grep ^KEEPING restore.log | less
PostgreSQL < 8.0 >= 8.0, attrelid, varattnum
stats geometry_columns, . .
, , !
$ psql newdb -c "ALTER TABLE geometry_columns DROP attrelid"
$ psql newdb -c "ALTER TABLE geometry_columns DROP varattnum"
$ psql newdb -c "ALTER TABLE geometry_columns DROP stats"
spatial_ref_sys
, , , .
, . ,
, .
:
$ psql newdb
newdb=> drop spatial_ref_sys;
DROP
newdb=> \i spatial_ref_sys.sql

2.2.3.
, .
PostGIS contrib PostgreSQL.
, , PGSQL_SRC,
PostgreSQL. PostGIS, make install
, PostGIS
.
, PostgreSQL 7.2 ,
PostgreSQL, . ,
(Linux) PostgreSQL, , ,
PostgreSQL. PostGIS PostgreSQL 7.2 .
, .
PostgreSQL, psql :
SELECT version();
RPM-, rpm
: rpm -qa | grep postgresql
, Makefile.config.
:
, Proj4,
Makefile.config USE_PROJ 1, PROJ_DIR
.
GEOS, GEOS , Makefile.config
USE_GEOS 1, USE_GEOS .

GIS-Lab.info

PostGIS, 1.3.4

2.3. JDBC
JDBC Java PostGIS.
Java-, PostGIS,
.
java/jdbc PostGIS.
ant. postgis.jar , java.
JDBC PostgreSQL JDBC
CLASSPATH . PostgreSQL JDBC ,
JAR , -D:
# ant -Dclasspath=/path/to/postgresql-jdbc.jar
PostgreSQL JDBC http://jdbc.postgresql.org.

2.4. /
PostGIS.
:
# cd postgis-1.3.3SVN/loader
# make
# make install
shp2pgsql ESRI Shape- SQL
PostGIS/PostgreSQL. pgsql2shp ( ) ESRI Shape. - .

GIS-Lab.info

PostGIS, 1.3.4

3.
?
point, line, polygon, multipoint, multiline, multipolygon, and geometrycollections (,
, , , , ).
Well Known Text Open GIS ( XYZ, XYM, XYZM).
?
"geometry", . psql SQL:
CREATE TABLE gtest ( ID int4, NAME varchar(20) );
SELECT AddGeometryColumn('', 'gtest','geom',-1,'LINESTRING',2);
, , , PostGIS
. .
, SQL- insert.
"well-known text" OpenGIS:
INSERT INTO gtest (ID, NAME, GEOM)
VALUES (
1,
' ',
GeomFromText('LINESTRING(2 3,4 5,6 5,7 8)', -1)
);
.
- :
SELECT id, name, AsText(geom) AS geom FROM gtest;
:

id | name
| geom
---+------------------+----------------------------1 | | LINESTRING(2 3,4 5,6 5,7 8)
(1 row)
?
, , SQL- ,
, .
, :
,
.
" " (&&),
. && , ,
. .
, , Distance(), ST_Intersects(),
ST_Contains() and ST_Within() .
. ,
, .
.
SELECT id, the_geom FROM thetable
WHERE
the_geom && 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'
AND
_ST_Contains(the_geom,'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))');
?
, ,
. .

GIS-Lab.info

PostGIS, 1.3.4
geometry, "CREATE
INDEX", :
CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometrycolumn] );
"USING GIST" , GiST (Generalized Search Tree ).
: GiST . (
- ) .
PostgreSQL
, . , " "
.
PostgreSQL 8.0.x , VACUUM ANALYZE.
PostgreSQL 7.4.x , SELECT UPDATE_GEOMETRY_STATS()
R-Tree PostgreSQL?
PostGIS R-Tree PostgreSQL.
0.6, R-Tree--GiST.
, R-Tree GiST .
R-Tree PostgreSQL ,
(, R-Tree PostgreSQL,
R-Tree):
R-Tree PostgreSQL , 8K. GiST
, "" , .
R-Tree PostgreSQL "null-", .. ,
null .
AddGeometryColumn()
OpenGIS?
OpenGIS, .
, CREATE.
SRID, -1, - OpenGIS
. , PostGIS, ,
AddGeometryColumn() .
, - geometry_columns, Mapserver.
Mapserver SRID
.
?
, ,
: ,
,
.
ST_DWithin(geometry, geometry,
distance). , ,
.
.
, 100 POINT(1000 1000), :
SELECT * FROM geotable
WHERE ST_DWithin(geocolumn, 'POINT(1000 1000)', 100.0);
?
,
SPATIAL_REF_SYS, SRID. ,
SRID.
SELECT ST_Transform(the_geom,4269) FROM geotable;

GIS-Lab.info

PostGIS, 1.3.4

4. PostGIS
4.1.
, PostGIS, "Simple Features",
OpenGIS (OGC). 0.9, PostGIS ,
OGC "Simple Features SQL".
PostGIS 3DZ, 3DM 4D.

4.1.1. OpenGIS WKB WKT


OpenGIS :
Well-Known Text (WKT) Well-Known Binary (WKB). WKT WKB
, .
(WKT) :
POINT(0 0)
LINESTRING(0 0,1 1,1 2)
POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))
MULTIPOINT(0 0,1 2)
MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))
MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))
GEOMETRYCOLLECTION(POINT(2 3),LINESTRING((2 3,3 4)))
, OpenGIS ,
(spatial referencing system identifier - SRID). SRID
.
/ :
bytea WKB = asBinary(geometry);
text WKT = asText(geometry);
geometry = GeomFromWKB(bytea WKB, SRID);
geometry = GeometryFromText(text WKT, SRID);
, insert OGC
:
INSERT INTO geotable ( the_geom, the_name )
VALUES (GeomFromText('POINT(-126.4 45.32)', 312), 'A Place');

4.1.2. PostGIS EWKB, EWKT


OGC 2d , SRID
/ .
PostGIS OGC ( WKB/WKT
EWKB/EWKT), , OGC ,
. , !
EWKB/EWKT PostGIS 3dm, 3dz, 4d SRID.
(EWKT) ,
:
POINT(0 0 0) -- XYZ
SRID=32632;POINT(0 0) -- XY SRID
POINTM(0 0 0) -- XM
POINT(0 0 0 0) -- XYZM
SRID=4326;MULTIPOINTM(0 0 0,1 2 1) -- XYM SRID
MULTILINESTRING((0 0 0,1 1 0,1 2 1),(2 3 1,3 2 1,5 4 1))
POLYGON((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2 0,1 2 0,1 1 0))
MULTIPOLYGON(((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2 0,1 2 0,1 1 0)),((-1 -1 0,-1 -2 0,-2 -2 0,-2 -1 0,-1 -1
0)))

GIS-Lab.info

PostGIS, 1.3.4
GEOMETRYCOLLECTIONM(POINTM(2 3 9), LINESTRINGM(2 3 4, 3 4 5))
/ :
bytea EWKB = asEWKB(geometry);
text EWKT = asEWKT(geometry);
geometry = GeomFromEWKB(bytea EWKB);
geometry = GeomFromEWKT(text EWKT);
insert PostGIS:
INSERT INTO geotable ( the_geom, the_name )
VALUES ( GeomFromEWKT('SRID=312;POINTM(-126.4 45.32 15)'), 'A Place' )
" " PostgreSQL
( ) insert, update
. PostGIS- "geometry":

-
- binary: EWKB
ascii: HEXEWKB (EWKB 16- )
-
- binary: EWKB
ascii: HEXEWKB|EWKT
, EWKT HEXEWKB /
ascii:
=# SELECT 'SRID=4;POINT(0 0)'::geometry;
geometry
---------------------------------------------------01010000200400000000000000000000000000000000000000
(1 row)

4.1.3. SQL-MM
SQL
SQL, , .
SQL-MM 3dm, 3dz 4d,
SRID.
WKT .
:
CIRCULARSTRING(0 0, 1 1, 1 0)
COMPOUNDCURVE(CIRCULARSTRING(0 0, 1 1, 1 0),(1 0, 0 1))
CURVEPOLYGON(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0),(1 1, 3 3, 3 1, 1 1))
MULTICURVE((0 0, 5 5),CIRCULARSTRING(4 0, 4 4, 8 4))
MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0),(1 1, 3 3, 3 1, 1 1)),((10 10, 14 12,
11 10, 10 10),(11 11, 11.5 11, 11 11.5, 11 11)))
: PostGIS
.
: SQL-MM
, - 1E-8.

GIS-Lab.info

PostGIS, 1.3.4

4.2. OpenGIS
"Simple Features Specification for SQL" OpenGIS ,
, . ,

, OpenGIS.
OpenGIS: SPATIAL_REF_SYS GEOMETRY_COLUMNS.
SPATIAL_REF_SYS ID ,
.

4.2.1. SPATIAL_REF_SYS
SPATIAL_REF_SYS :
CREATE TABLE spatial_ref_sys (
srid INTEGER NOT NULL PRIMARY KEY,
auth_name VARCHAR(256),
auth_srid INTEGER,
srtext VARCHAR(2048),
proj4text VARCHAR(2048)
)

SPATIAL_REF_SYS :
SRID
- (Spatial Referencing System, SRS)
.
AUTH_NAME
,
. , AUTH_NAME "EPSG".
AUTH_SRID
, AUTH_NAME.
EPSG, EPSG.
SRTEXT
WKT . WKT SRS :
PROJCS["NAD83 / UTM Zone 10N",
GEOGCS["NAD83",
DATUM["North_American_Datum_1983",
SPHEROID["GRS 1980",6378137,298.257222101]
],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433]
],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",-123],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["metre",1]
]
EPSG WKT
http://www.opengis.org/techno/interop/EPSG2WKT.TXT. WKT
Open
GIS
"Coordinate
Transformation
Services
Implementation
Specification":
http://www.opengis.org/techno/specs.htm. European Petroleum Survey Group (EPSG)
http://epsg.org.

GIS-Lab.info

10

PostGIS, 1.3.4
PROJ4TEXT
PostGIS Proj4 . PROJ4TEXT
Proj4 SRID. :
+proj=utm +zone=10 +ellps=clrk66 +datum=NAD27 +units=m
Proj4: http://www.remotesensing.org/proj. spatial_ref_sys.sql
SRTEXT PROJ4TEXT EPSG.

4.2.2. GEOMETRY_COLUMNS
GEOMETRY_COLUMNS :
CREATE TABLE geometry_columns (
f_table_catalog

VARRCHAR(256) NOT NULL,

f_table_schema

VARCHAR(256) NOT NULL,

f_table_nam

VARCHAR(256) NOT NULL,

f_geometry_column

VARCHAR(256) NOT NULL,

coord_dimension

INTEGER NOT NULL,

srid

INTEGER NOT NULL,

type

VARCHAR(30) NOT NULL

)
:
F_TABLE_CATALOG, F_TABLE_SCHEMA, F_TABLE_NAME
, . , "catalog"
"scheme" Oracle. PostgreSQL "catalog",
. "scheme" PostgreSQL ( public).
F_GEOMETRY_COLUMN
.
COORD_DIMENSION
(2, 3 4 ).
SRID
, .
SPATIAL_REF_SYS.
TYPE
. : POINT, LINESTRING, POLYGON,
MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION XYM POINTM, LINESTRINGM, POLYGONM, MULTIPOINTM, MULTILINESTRINGM, MULTIPOLYGONM,
GEOMETRYCOLLECTIONM.
"GEOMETRY" .
: , , OpenGIS,
.

4.2.3.
:
.
: CREATE TABLE ROADS_GEOM ( ID int4, NAME varchar(25) )
OpenGIS "AddGeometryColumn".
:
AddGeometryColumn(
<schema_name>,
<table_name>,
<column_name>,
<srid>,
<type>,

GIS-Lab.info

11

PostGIS, 1.3.4
<dimension>
)
:
AddGeometryColumn(
<table_name>,
<column_name>,
<srid>,
<type>,
<dimension>
)
1: SELECT AddGeometryColumn('public', 'roads_geom', 'geom', 423, 'LINESTRING', 2)
2: SELECT AddGeometryColumn( 'roads_geom', 'geom', 423, 'LINESTRING', 2)
SQL (
, SRID 128 ):
CREATE TABLE parks (
park_id

INTEGER,

park_name

VARCHAR,

park_date

DATE,

park_type

VARCHAR

);
SELECT AddGeometryColumn('parks', 'park_geom', 128, 'MULTIPOLYGON', 2 );
, "geometry" SRID -1:
CREATE TABLE roads (
road_id INTEGER,
road_name VARCHAR
);
SELECT AddGeometryColumn( 'roads', 'roads_geom', -1, 'GEOMETRY', 3 );

4.2.4. OpenGIS
, GEOS, ,
Simple Feature Specification OpenGIS.
IsValid():
gisdb=# select isvalid('LINESTRING(0 0, 1 1)'),
isvalid('LINESTRING(0 0,0 0)');
isvalid | isvalid
---------+--------t |

PostGIS ,
, .
, ,
"CHECK":
ALTER TABLE mytable
ADD CONSTRAINT geometry_valid_check
CHECK (isvalid(the_geom));
, "GEOS Intersection() threw an error!" "JTS
Intersection() threw an error!", PostGIS , ,
, PostGIS ,
PostGIS. , PostGIS
.

GIS-Lab.info

12

PostGIS, 1.3.4
: , OGC, Z M. IsValid()
! AddGeometryColumn(),
. .

4.3.
, .
PostGIS/PostgreSQL: SQL
/ -.

4.3.1. SQL
, PostGIS
SQL. Oracle SQL
SQL , SQL- "INSERT".
( roads.sql) :
BEGIN;
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (1,GeomFromText('LINESTRING(191232 243118,191108 243242)',1),'Jeff Rd');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (2,GeomFromText('LINESTRING(189141 244158,189265 244817)',1),'Geordie Rd');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (3,GeomFromText('LINESTRING(192783 228138,192612 229814)',1),'Paul St');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (4,GeomFromText('LINESTRING(189412 252431,189631 259122)',1),'Graeme Ave');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (5,GeomFromText('LINESTRING(190131 224148,190871 228134)',1),'Phil Tce');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (6,GeomFromText('LINESTRING(198231 263418,198213 268322)',1),'Dave Cres');
COMMIT;

PostgreSQL SQL "psql":


psql -d [database] -f roads.sql

GIS-Lab.info

13

PostGIS, 1.3.4

4.3.2.
shp2pgsql - ESRI SQL
PostGIS/PostgreSQL. ,
:
-d
-.
-a
- . ,
,
.
-c
-. .
-p
SQL . ,
.
-D
PostgreSQL "dump" . -a, -c
-d. SQL "insert".
.
-s <SRID>
SRID.
-k
(, ). , -
.
-i
32- , 64-
bigint, DBF .
-I
GiST .
-w
WKT (0.x) PostGIS. ,
M -.
-W <>
( DBF). DBF
UTF8. SQL SET
CLIENT_ENCODING to UTF8. , UTF8
, .
, -a, -c, -d -p .
:
# shp2pgsql shaperoads myschema.roadstable > roads.sql
# psql -d roadsdb -f roads.sql
UNIX :
# shp2pgsql shaperoads myschema.roadstable | psql -d roadsdb

GIS-Lab.info

14

PostGIS, 1.3.4

4.4.
SQL / -.
SQL .

4.4.1. SQL
- SQL- "SELECT"
:
db=# SELECT road_id, AsText(road_geom) AS geom, road_name FROM roads;
road_id | geom

| road_name

--------+-----------------------------------------+----------1 | LINESTRING(191232 243118,191108 243242) | Jeff Rd


2 | LINESTRING(189141 244158,189265 244817) | Geordie Rd
3 | LINESTRING(192783 228138,192612 229814) | Paul St
4 | LINESTRING(189412 252431,189631 259122) | Graeme Ave
5 | LINESTRING(190131 224148,190871 228134) | Phil Tce
6 | LINESTRING(198231 263418,198213 268322) | Dave Cres
7 | LINESTRING(218421 284121,224123 241231) | Chris Way
(6 rows)
. ,
SQL, , .
:
&&
, .
~=
, . , 'POLYGON((0
0,1 1,1 0,0 0))' 'POLYGON((0 0,1 1,1 0,0 0))'.
=
. .
. ,
SQL,
"GeomFromText()". :
SELECT road_id, road_name
FROM roads
WHERE roads_geom ~= GeomFromText('LINESTRING(191232 243118,191108
243242)',-1);
"ROADS_GEOM",
.
"&&", BOX3D GEOMETRY.
, GEOMETRY, .
SELECT road_id, road_name
FROM roads
WHERE roads_geom && GeomFromText('POLYGON((...))',-1);
.
, , "-" ("framebased") , , ,
, "" . "BOX3D",
:

GIS-Lab.info

15

PostGIS, 1.3.4
SELECT AsText(roads_geom) AS geom
FROM roads
WHERE
roads_geom && SetSRID('BOX3D(191232 243117,191232 243119)'::box3d,-1);
, SRID BOX3D. -1
SRID.

4.4.2.
pgsql2shp (,
) -. :
pgsql2shp [<options>] <database> [<schema>.]<table>
pgsql2shp [<options>] <database> <query>
:
-f <_>
.
-h <>
, .
-p <>
, .
-P <>
, .
-u <>
, .
-g < >
, -.
.
-b
. , , - .
-r
raw-. gid, .
-d
: 3- - ( 1.0.0)
PostGIS ( 2- -). PostGIS-1.0.0+,
.

GIS-Lab.info

16

PostGIS, 1.3.4

4.5.
.
, " "
. , ,
. PostgreSQL :
B-Tree, R-Tree GiST.
B-Tree (B-) , ; , ,
, . (
: (0,0) (0,1) (1,0)?), B-Tree .
R-Tree ( R-) , -, --
.. R-Tree ,
PostgreSQL R-Tree , GiST.
GiST (Generalized Search Trees - ) "
" ("things to one side"), " " ("things which overlap"), " "
("things which are inside") , . PostGIS
R-Tree GiST .

4.5.1. GiST
GiST " " ("Generalized Search Tree")
. , GiST
( , ..),
B-Tree.
,
( , .
).
GiST- "geometry":
CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometryfield] );
: 1
Solaris 300MHz 1 .
PostgreSQL , :
VACUUM ANALYZE [table_name] [column_name];
-- PostgreSQL 7.4
SELECT UPDATE_GEOMETRY_STATS([table_name], [column_name]);
PostgreSQL GiST R-Tree. -, GiST "null" ("null safe"). , , null.
-, GiST "" ("lossiness"), ,
8 ( PostgreSQL). PostgreSQL
"" . , . R-Tree
, 8K.

4.5.2.
, : ,
,
. , PostgreSQL
GiST. , , , ,
.
, (,
), , :
-, , ,

. PostgreSQL 7.4 update_geometry_stats([table_name,
column_name]) ( ) VACUUM ANALYZE [table_name] [column_name] (
). PostgreSQL 8.0 VACUUM ANALYZE .
. DBA PostgreSQL
VACUUM, cron .
,
SET ENABLE_SEQSCAN=OFF. ,
: , , B-

GIS-Lab.info

17

PostGIS, 1.3.4
Tree. , ENABLE_SEQSCAN,
.
: 0.6
ENABLE_SEQSCAN.
,
, random_page_cost postgresql.conf
SET random_page_cost=#. 4. 1
2. .

4.6.
,
. PostGIS
, .

4.6.1.
, (bounding-box-based),
&& GiST. , distance()
. ,
:
SELECT the_geom
FROM geom_table
WHERE ST_Distance(the_geom, GeomFromText('POINT(100000 200000)', -1)) <
100
geom_table, 100
(100000, 200000). ,
, .. ST_Distance()
. &&,
:
SELECT the_geom
FROM geom_table
WHERE the_geom && 'BOX3D(90900 190900, 100100 200100)'::box3d
AND
ST_Distance(the_geom, GeomFromText('POINT(100000 200000)', -1)) < 100
- , . , the_geom
GiST, ,
, distance(). , BOX3D,
&&, 200 ,
- " " ("query box"). && ,
, ,
" ". , ,
, ,
.
: PostGIS 1.3.0 (Geometry
Relationship Functions), ST_Disjoint ST_Relate,
.

GIS-Lab.info

18

PostGIS, 1.3.4

4.6.2. SQL
: ()
(). bc_roads :
Column

| Type

| Description

------------+-------------------+------------------gid

| integer

| ID

name

| character varying |

the_geom

| geometry

| (Linestring)

bc_municipality :
Column

| Type

| Description

-----------+-------------------+------------------gid

| integer

| ID

code

| integer

| ID

name

| character varying | /

the_geom

| geometry

| (Polygon)

?
SQL-:
SELECT sum(ST_Length(the_geom))/1000 AS km_roads FROM bc_roads;
km_roads
-----------------70842.1243039643
(1 row)

"Prince George" ?
( )
():
SELECT
ST_Area(the_geom)/10000 AS hectares
FROM bc_municipality
WHERE name = 'PRINCE GEORGE';
hectares
-----------------32657.9103824927
(1 row)

?
.
, :
SELECT
name,
ST_Area(the_geom)/10000 AS hectares
FROM
bc_municipality

GIS-Lab.info

19

PostGIS, 1.3.4
ORDER BY hectares DESC
LIMIT 1;
name

| hectares

---------------+----------------TUMBLER RIDGE

| 155020.02556131

(1 row)
, , .
,
. PostgreSQL
"LIMIT" , max().
, ?
- " " (spatial join) ,
(join), ( ),
(" "):
SELECT
m.name,
sum(ST_Length(r.the_geom))/1000 as roads_km
FROM
bc_roads AS r,
bc_municipality AS m
WHERE
ST_Contains(m.the_geom,r.the_geom)
GROUP BY m.name
ORDER BY roads_km;
name

| roads_km

----------------------------+-----------------SURREY

| 1539.47553551242

VANCOUVER

| 1450.33093486576

LANGLEY DISTRICT

| 833.793392535662

BURNABY

| 773.769091404338

PRINCE GEORGE

| 694.37554369147

...
, (
- 250K ). ( ,
) .
"Prince George".
- "" (overlay) ,
. " ",
. join ,
:
CREATE TABLE pg_roads as
SELECT
ST_Intersection(r.the_geom, m.the_geom) AS intersection_geom,
ST_Length(r.the_geom) AS rd_orig_length,
r.*
FROM
bc_roads AS r,
bc_municipality AS m

GIS-Lab.info

20

PostGIS, 1.3.4
WHERE ST_Intersects(r.the_geom, m.the_geom)
AND m.name = 'PRINCE GEORGE';

"Douglas St" "Victoria"?


SELECT
sum(ST_Length(r.the_geom))/1000 AS kilometers
FROM
bc_roads r,
bc_municipality m
WHERE ST_Contains(m.the_geom, r.the_geom)
AND r.name = 'Douglas St'
AND m.name = 'VICTORIA';
kilometers
-----------------4.89151904172838
(1 row)

, ?
SELECT gid, name, ST_Area(the_geom) AS area
FROM bc_municipality
WHERE ST_NRings(the_geom) > 1
ORDER BY area DESC LIMIT 1;
gid

| name

| area

-----+--------------+-----------------12

| SPALLUMCHEEN | 257374619.430216

(1 row)

4.7. Mapserver
Mapserver - -, OpenGIS Web Mapping
Server.
Mapserver: http://mapserver.gis.umn.edu.
OpenGIS -: http://www.opengis.org/techno/specs/01-047r2.pdf.

4.7.1.
PostGIS Mapserver, , Mapserver,
. PostGIS
.
PostGIS Mapserver :
PostGIS 0.6 .
Mapserver 3.5 .
Mapserver PostGIS/PostgreSQL, PostgreSQL,

libpq. , Mapserver
PostGIS, PostgreSQL libpq.
Mapserver "-with-postgis".
map- Mapserver- PostGIS. :

GIS-Lab.info

21

PostGIS, 1.3.4
LAYER
CONNECTIONTYPE postgis
NAME "widehighways"
#
CONNECTION "user=dbuser dbname=gisdatabase host=bigserver"
# 'geom' 'roads'
DATA "geom from roads"
STATUS ON
TYPE LINE
#
FILTER "type = 'highway' and numlanes >= 4"
CLASS
#
2
EXPRESSION ([numlanes] >= 6)
COLOR 255 22 22
SYMBOL "solid"
SIZE 2
END
CLASS
# - 1
EXPRESSION ([numlanes] < 6)
COLOR 205 92 82
END
END
PostGIS:
CONNECTIONTYPE
PostGIS "postgis".
CONNECTION
" ",
( <>):
user=< > password=<> dbname=< > hostname=< > port=<5432>
, / .
.
DATA
"<> from <_>",
, .
FILTER
SQL, ,
"WHERE" SQL-. , , 6- ( ) ,
"num_lanes >= 6".
(GiST) , -
.
CREATE INDEX [_] ON [_] USING GIST (
[_] );
Mapserver, " oid".
Mapserver
Mapserver PostGIS oid PostgreSQL .
,
oid.
" oid" SQL:

GIS-Lab.info

22

PostGIS, 1.3.4
CREATE INDEX [_] ON [_] ( oid );

4.7.2.
EXPRESSION map-, ,
, .
-, PostGIS, EXPRESSIONS,
.
EXPRESSION ([numlanes] >= 6)
FILTER, -, PostGIS
.
-, PostGIS SQL (
SQL, PostGIS Mapserver).
FILTER "type = 'highway' and numlanes >= 4"
PostGIS , -, ?
, PostGIS 10% , -, -
: ,
Mapserver.
, , ,
.
postgis# CREATE INDEX geotable_gix ON geotable USING GIST ( geocolumn );
postgis# SELECT update_geometry_stats(); -- For PGSQL < 8.0
postgis# VACUUM ANALYZE; -- For PGSQL >= 8.0
PostGIS , . ?

.
USING UNIQUE DATA mapserver-
:
DATA "the_geom FROM geotable USING UNIQUE gid"
, PostgreSQL ""
"oid" . "oid"
, .
, oid .
postgis# CREATE INDEX geotable_oid_idx ON geotable (oid);

GIS-Lab.info

23

PostGIS, 1.3.4

4.7.3.
USING -SQL , MapServer
, . :
SELECT ( "FROM"
DATA), mapserver
SRID . USING MapServer
:
DATA "the_geom FROM (
SELECT
table1.the_geom AS the_geom,
table1.oid AS oid,
table2.data AS data
FROM table1
LEFT JOIN table2
ON table1.id = table2.id
) AS new_table USING UNIQUE oid USING SRID=-1"
USING UNIQUE <_id>
Mapserver ,
. , , oid ,
SELECT oid.
Mapserver,
SELECT, USING UNIQUE. , , oid
, ,
.
, USING
DATA. oid
. USING Mapserver-
,
.
: " " ("Querying a Map") - ,
. " " SQL-
DATA.
USING SRID=<srid>
Mapserver , PostGIS ,
. , PostGIS
"geometry_columns", , , " " SELECT
. USING SRID=, SRID
DATA.
: Mapserver PostGIS
. , SQL USING
, , USING UNIQUE USING SRID.

4.7.4.
.
Mapserver:
LAYER
CONNECTIONTYPE postgis
NAME "roads"
CONNECTION "user=theuser password=thepass dbname=thedb
host=theserver"
DATA "the_geom FROM roads"
STATUS ON
TYPE LINE

GIS-Lab.info

24

PostGIS, 1.3.4
CLASS
COLOR 0 0 0
END
END
.
, 1:100000, .
:
LAYER
CONNECTION "user=theuser password=thepass dbname=thedb
host=theserver"
DATA "the_geom FROM roads"
MINSCALE 100000
STATUS ON
TYPE LINE
FILTER "road_type = 'highway'"
CLASS
COLOR 0 0 0
END
END
LAYER
CONNECTION "user=theuser password=thepass dbname=thedb
host=theserver"
DATA "the_geom FROM roads"
MAXSCALE 100000
STATUS ON
TYPE LINE
CLASSITEM road_type
CLASS
EXPRESSION "highway"
SIZE 2
COLOR 255 0 0
END
CLASS
COLOR 0 0 0
END
END
, , 1:100000,
"", . FILTER
"" ("highway").
, 1:100000, ,
, - .
, , MapServer,
DATA. , -
, , .
LAYER
CONNECTION "user=theuser password=thepass dbname=thedb host=theserver"
DATA "the_geom FROM (SELECT roads.oid AS oid, roads.the_geom AS
the_geom,
road_names.name as name FROM roads LEFT JOIN road_names ON

GIS-Lab.info

25

PostGIS, 1.3.4
roads.road_name_id = road_names.road_name_id)
AS named_roads USING UNIQUE oid USING SRID=-1"
MAXSCALE 20000
STATUS ON
TYPE ANNOTATION
LABELITEM name
CLASS
LABEL
ANGLE auto
SIZE 8
COLOR 0 192 0
TYPE truetype
FONT arial
ENDl
END
END
1:20000 .
SQL DATA.

4.8. Java (JDBC)


Java- "geometry" PostGIS PostgreSQL
: , , JDBC,
PostGIS. , "postgis.jar"
CLASSPATH JDBC "postgresql.jar".
import java.sql.*;
import java.util.*;
import java.lang.*;
import org.postgis.*;
public class JavaGIS {
public static void main(String[] args) {
java.sql.Connection conn;
try {
/*
* JDBC .
*/
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/database";
conn = DriverManager.getConnection(url, "postgres", "");
/*
* .
pgsql

* ,
* addDataType().
*/

GIS-Lab.info

26

PostGIS, 1.3.4
((org.postgresql.Connection)conn).addDataType("geometry","org.post
gis.PGgeometry")
;
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis
.PGbox3d");
/*
* select.
*/
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("select AsText(geom) as geom,id
from geomtable");
while( r.next() ) {
/*
* ,
.
* .
*/
PGgeometry geom = (PGgeometry)r.getObject(1);
int id = r.getInt(2);
System.out.println("Row " + id + ":");
System.out.println(geom.toString());
}
s.close();
conn.close();
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
"PGgeometry" ,
( "Geometry") : Point, LineString, Polygon, MultiPoint,
MultiLineString, MultiPolygon.
PGgeometry geom = (PGgeometry)r.getObject(1);
if( geom.getType() = Geometry.POLYGON ) {
Polygon pl = (Polygon)geom.getGeometry();
for( int r = 0; r < pl.numRings(); r++) {
LinearRing rng = pl.getRing(r);
System.out.println("Ring: " + r);
for( int p = 0; p < rng.numPoints(); p++ ) {
Point pt = rng.getPoint(p);
System.out.println("Point: " + p);
System.out.println(pt.toString());
}
}
}
JavaDoc
.

GIS-Lab.info

27

PostGIS, 1.3.4

4.9. C (libpq)
...

4.9.1.
...

4.9.2.
...

GIS-Lab.info

28

PostGIS, 1.3.4

5.
5.1.
5.1.1.
PostgreSQL ( 8.0) TOAST.
TOAST "" (
), ( ,
,

).

http://www.postgresql.org/docs/8.0/static/storage-toast.html.
, , (,
, , ).
, TOAST. 80
3 , TOAST 8225 .
, && ,
. ,
3 80 . ,
. GIST.
. , &&
, , TOAST.
, , postgresql "EXPLAIN ANALYZE".
postgres:
http://archives.postgresql.org/pgsql-performance/2005-02/msg00030.php

5.1.2.
PostgreSQL , TOAST.
:
- .
"SET enable_seqscan TO off;".
. GIST .
,
. "SET enable_seqscan TO on;"
.
, ,
. , "" bbox,
. :
SELECT
addGeometryColumn('myschema','mytable','bbox','4326','GEOMETRY','2');
UPDATE mytable set bbox = Envelope(Force_2d(the_geom));
, && bbox geom_column:
SELECT geom_column
FROM mytable
WHERE bbox && ST_SetSRID('BOX3D(0 0,1 1)'::box3d,4326);
, mytable, bbox.
- . ,
bbox UPDATE
.

5.2. CLUSTER-
, , , ,
CLUSTER, PostgreSQL.
, , . , . , - ,

GIS-Lab.info

29

PostGIS, 1.3.4
, .
( CLUSTER PostgreSQL.)
, PostgreSQL PostGIS GIST,
GIST NULL. :
lwgeom=# CLUSTER my_geom_index ON my_table;
ERROR: cannot cluster when index access method does not handle null
values
HINT: You may be able to work around this by marking column "the_geom"
NOT NULL.
HINT, ,
"not null":
lwgeom=# ALTER TABLE my_table ALTER COLUMN the_geom SET not null;
ALTER TABLE
, , NULL . ,
.
CHECK, : "ALTER TABLE blubb ADD CHECK (geometry is not null);", - .

5.3.
3D- 4D-, OpenGIS
asText() asBinary(), 2D-.
force_2d(),
. :
UPDATE mytable SET the_geom = force_2d(the_geom);
VACUUM FULL ANALYZE mytable;
, AddGeometryColumn(),
. .
, .
UPDATE , UPDATE
WHERE .
"VACUUM;" UPDATE. .
, , UPDATE "WHERE
dimension(the_geom)>2" , 2D.

GIS-Lab.info

30

PostGIS, 1.3.4

6. PostGIS
, , PostGIS.
PostGIS .
: PostGIS SQL-MM. ,
, ,
(ST - spatial type). ,
.
.

6.1. OpenGIS
6.1.1.
AddGeometryColumn(varchar, varchar, varchar, integer, varchar, integer)
:
AddGeometryColumn(<_>,
<_>,
<_>,
<srid>,
<>,
<>). . _ -
( - PostgreSQL). srid
SPATIAL_REF_SYS.
, , 'POLYGON' 'MULTILINESTRING'.
DropGeometryColumn(varchar, varchar, varchar)
: DropGeometryColumn(<_>, <_>, <_>).
. , _ f_schema_name
geometry_columns.
ST_SetSRID(geometry, integer)
SRID .
.

6.1.2.
ST_Distance(geometry, geometry)
. .
ST_DWithin(geometry, geometry, float)
, .
.
ST_Equals(geometry, geometry)
1 (TRUE), " ".
, '='. ST_Equals('LINESTRING(0 0, 10 10)','LINESTRING(0 0, 5
5, 10 10)') .
GEOS.
OGC SPEC s2.1.1.2
ST_Disjoint(geometry, geometry)
1 (TRUE), " ".
GEOS.
GeometryCollection .
: - "" , boolean, integer.
OGC SPEC s2.1.1.2 //s2.1.13.3 - a.Relate(b, 'FF*FF****')
ST_Intersects(geometry, geometry)
1 (TRUE), " ".
GEOS.
GeometryCollection .
,
. ,
_ST_Intersects.
: - "" , boolean integer.
OGC SPEC s2.1.1.2 //s2.1.13.3 - Intersects(g1, g2 ) --> Not (Disjoint(g1, g2 ))
ST_Touches(geometry, geometry)
1 (TRUE), " ".
GEOS.
GeometryCollection .

GIS-Lab.info

31

PostGIS, 1.3.4
,
. ,
_ST_Touches.
: - "" , boolean integer.
OGC SPEC s2.1.1.2 // s2.1.13.3- a.Touches(b) -> (I(a) intersection I(b) = {empty set} ) and (a intersection b) not
empty
ST_Crosses(geometry, geometry)
1 (TRUE), " ".
GEOS.
GeometryCollection .
,
. ,
_ST_Crosses.
: - "" , boolean integer.
OGC SPEC s2.1.1.2 // s2.1.13.3 - a.Relate(b, 'T*T******')
ST_Within(geometry A, geometry B)
1 (TRUE), A " " B.
GEOS.
GeometryCollection .
,
. , _ST_Within.
: - "" , boolean integer.
OGC SPEC s2.1.1.2 // s2.1.13.3 - a.Relate(b, 'T*F**F***')
ST_Overlaps(geometry, geometry)
1 (TRUE), " ".
GEOS.
GeometryCollection .
,
. ,
_ST_Overlaps.
: - "" , boolean integer.
OGC SPEC s2.1.1.2 // s2.1.13.3
ST_Contains(geometry A, geometry B)
1 (TRUE), A " " B.
GEOS.
GeometryCollection .
,
. ,
_ST_Contains.
: - "" , boolean integer.
OGC SPEC s2.1.1.2 // s2.1.13.3 - within(geometry B, geometry A)
ST_Covers(geometry A, geometry B)
1 (TRUE), B A.
,

:
http://lin-ear-thinking.blogspot.com/2007/06/subtleties-of-ogc-covers-spatial.html
,
. , n
_ST_Covers.
ST_CoveredBy(geometry A, geometry B)
1 (TRUE), A B.
,

:
inking.blogspot.com/2007/06/subtleties-of-ogc-covers-spatial.html

http://lin-ear-th-

ST_Intersects(geometry, geometry)
1 (TRUE), " ".
GEOS.
GeometryCollection .
: - "" , boolean, integer.
OGC SPEC s2.1.1.2 // s2.1.13.3 - NOT disjoint(geometry, geometry)
ST_Relate(geometry, geometry, intersectionPatternMatrix)
1 (TRUE), ,
Interior, Boundary and Exterior ,
intersectionPatternMatrix.
GEOS.
GeometryCollection .
: - "" , , boolean integer.

GIS-Lab.info

32

PostGIS, 1.3.4
OGC SPEC s2.1.1.2 // s2.1.13.3
ST_Relate(geometry, geometry)
DE-9IM - (dimensionally extended nineintersection matrix).
GEOS.
GeometryCollection .
OGC, . s2.1.13.2

6.1.3.
ST_Centroid(geometry)
- .
, GEOS ( ).
ST_Area(geometry)
, .
ST_Length(geometry)
.
length2d()
OGC SPEC 2.1.5.1
ST_PointOnSurface(geometry)
, .
GEOS
OGC SPEC 3.2.14.2 3.2.18.2 ST_Boundary(geometry)
. (combinatorial
boundary) 3.12.3.2 OGC. , , ,
, OGC, 3.12.2.
GEOS
OGC SPEC s2.1.1.1
ST_Buffer(geometry, double, [integer])
, , ,
. .
,
( - 8).
GEOS
GeometryCollection .
OGC SPEC s2.1.1.3
ST_ConvexHull(geometry)
, .
GEOS
OGC SPEC s2.1.1.3
ST_Intersection(geometry, geometry)
, .
GEOS
GeometryCollection .
OGC SPEC s2.1.1.3
ST_Shift_Longitude(geometry)
/ , <0,
360. 0-360 -180..180.
ST_SymDifference(geometry A, geometry B)
, A B,
. : ST_SymDifference(A,B) =
ST_SymDifference(B,A).
GEOS
GeometryCollection .
OGC SPEC s2.1.1.3
ST_Difference(geometry A, geometry B)
, A
B.
GEOS
GeometryCollection .
OGC SPEC s2.1.1.3

GIS-Lab.info

33

PostGIS, 1.3.4
ST_Union(geometry, geometry)
, .
GEOS
GeometryCollection .
: "GeomUnion", "union"
SQL.
OGC SPEC s2.1.1.3
ST_Union(geometry set)
,
.
GEOS
GeometryCollection .
OGC.
ST_MemUnion(geometry set)
, , .

6.1.4.
ST_AsText(geometry)
WKT . : POLYGON(0 0,0 1,1 1,1 0,0 0)
OGC SPEC s2.1.1.1
ST_AsBinary(geometry)
" " ("well-known-binary") OGC,
(endian encoding of the server), .
, .
OGC SPEC s2.1.1.1 - asBinary(<geometry>,'XDR') asBinary(<geometry>,'NDR')
ST_SRID(geometry)
SRID .
OGC SPEC s2.1.1.1
ST_Dimension(geometry)
, . OGC SPEC
s2.1.1.1 0 , 1 - , 2 -
GEOMETRYCOLLECTION.
select dimension('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0)');
dimension
----------1
ST_Envelope(geometry)
(POINT, LINESTRING POLYGON) .
( , )
POLYGON.
OGC SPEC s2.1.1.1 - , .
, ((MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX,
MAXY), (MINX, MINY)).
: PostGIS Zmin/Zmax.
ST_IsEmpty(geometry)
1 (TRUE), . true,
, .. GEOMETRYCOLLECTION(EMPTY).
OGC SPEC s2.1.1.1
ST_IsSimple(geometry)
1 (TRUE), .
, .
GEOS
OGC SPEC s2.1.1.1
ST_IsClosed(geometry)
, .
ST_IsRing(geometry)
1 (TRUE), (StartPoint ( ) = EndPoint ( )) (
).
GEOS
OGC spec 2.1.5.1

GIS-Lab.info

34

PostGIS, 1.3.4
ST_NumGeometries(geometry)
GEOMETRYCOLLECTION ( MULTI*), .
NULL.
ST_GeometryN(geometry,int)
N- , GEOMETRYCOLLECTION, MULTIPOINT,
MULTILINESTRING MULTIPOLYGON. NULL.
: 1, OGC 0.8.0.
, , 0.
ST_NumPoints(geometry)
. NULL,
.
ST_PointN(geometry,integer)
N- . NULL,
.
: 1, OGC 0.8.0.
, , 0.
ST_ExteriorRing(geometry)
(exterior ring) . NULL,
.
ST_NumInteriorRings(geometry)
(interior rings) . NULL,
.
ST_NumInteriorRing(geometry)
NumInteriorRings(geometry). OpenGIS
. .
ST_InteriorRingN(geometry,integer)
N- . NULL,
, N .
: 1, OGC 0.8.0.
, , 0.
ST_EndPoint(geometry)
LineString.
ST_StartPoint(geometry)
LineString.
GeometryType(geometry)
. : 'LINESTRING', 'POLYGON', 'MULTIPOINT' ..
OGC SPEC s2.1.1.1 - ,
. .
: , ,
'POINTM'.
ST_GeometryType(geometry)
: : 'Linestring', 'Polygon' ..
GeometryType(geometry) , , ,
M.
ST_X(geometry)
X . .
ST_Y(geometry)
Y . .
ST_Z(geometry)
Z , NULL, . .
ST_M(geometry)
M , NULL, . .
: ( ) OGC,
.

GIS-Lab.info

35

PostGIS, 1.3.4

6.1.5.
ST_GeomFromText(text,[<srid>])
WKT SRID.
OGC SPEC 3.2.6.2 - SRID .
ST_PointFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT .
ST_LineFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT .
ST_LinestringFromText(text,[<srid>])
WKT SRID. SRID , -1 .
.
, WKT .
ST_PolyFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT .
ST_PolygonFromText(text,[<srid>])
WKT SRID. SRID , -1 .
.
, WKT .
ST_MPointFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT MULTIPOINT.
ST_MLineFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT MULTILINESTRING.
ST_MPolyFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT MULTIPOLYGON-
ST_GeomCollFromText(text,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
, WKT GEOMETRYCOLLECTION-
ST_GeomFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.6.2 - SRID .
ST_GeometryFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
ST_PointFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB POINT.
ST_LineFromWKB(bytea,[<srid>])
WKT SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB LINESTRING.
ST_LinestringFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
.
, WKB LINESTRING-.
ST_PolyFromWKB(bytea,[<srid>])

GIS-Lab.info

36

PostGIS, 1.3.4
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB POLYGON-
ST_PolygonFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
.
, WKB POLYGON.
ST_MPointFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB MULTIPOINT.
ST_MLineFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB MULTILINESTRING.
ST_MPolyFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB MULTIPOLYGON.
ST_GeomCollFromWKB(bytea,[<srid>])
WKB SRID. SRID , -1 .
OGC SPEC 3.2.7.2 - SRID .
, WKB GEOMETRYCOLLECTION.
ST_BdPolyFromText(text WKT, integer SRID)
, ,
MultiLineString.
, WKT MULTILINESTRING. ,
MULTIPOLYGON; , , BdMPolyFromText BuildArea(),
PostGIS.
OGC SFSQL 1.1 - 3.2.6.2
1.1.0. GEOS >= 2.1.0.
ST_BdMPolyFromText(text WKT, integer SRID)
, ,
MultiLineString.
, WKT MULTILINESTRING. MULTIPOLYGON
. POLYGON, BdPolyFromText
BuildArea(), PostGIS.
OGC SFSQL 1.1 - 3.2.6.2
1.1.0. GEOS >= 2.1.0.

6.2.1.
DropGeometryTable([<schema_name>], <table_name>)
.
: pgsql , ,
current_schema().
UpdateGeometrySRID([<schema_name>], <table_name>, <column_name>, <srid>)
SRID , .
: pgsql , ,
current_schema().
update_geometry_stats([<table_name>, <column_name>])
. ,
"VACUUM ANALYZE [table_name] [column_name]"
.
: PostgreSQL 8.0 "VACUUM
ANALYZE".
postgis_version()
PostGIS , .
: 1.1.0 , ,
( ).

GIS-Lab.info

37

PostGIS, 1.3.4
postgis_lib_version()
PostGIS.
0.9.0
postgis_lib_build_date()
PostGIS.
1.0.0RC1
postgis_script_build_date()
PostGIS.
1.0.0RC1.
postgis_scripts_installed()
PostGIS, .
: postgis_scripts_released(), , ,
. .
0.9.0.
postgis_scripts_released()
lwpostgis.sql, PostGIS.
: 1.1.0 , postgis_lib_version().
.
0.9.0.
postgis_geos_version()
GEOS, NULL, GEOS .
0.9.0
postgis_jts_version()
JTS, NULL, JTS .
1.1.0
postgis_proj_version()
PROJ4, NULL, PROJ4 .
0.9.0
postgis_uses_stats()
true, STATS, false .
0.9.0
postgis_full_version()
PostGIS .
0.9.0

GIS-Lab.info

38

PostGIS, 1.3.4

6.2.2.
A &< B
"&<" true, A B.
A &> B
"&>" true, A B.
A << B
"<<" true, A B.
A >> B
">>" true, A B.
A &<| B
"&<|" true, A B.
A |&> B
"|&>" true, A B.
A <<| B
"<<|" true, A B.
A |>> B
"|>>" true, A B.
A ~= B
"~=" - " ". ,
. , A B "--", true.
A@B
"@" true, A B.
A~B
"~" true, A B.
A && B
"&&" " " ("overlaps"). A
B, true.

6.2.3.
ST_Area(geometry)
, .
ST_distance_sphere(point, point)
(/).
6370986 (). , distance_spheroid(),
. .
ST_distance_spheroid(point, point, spheroid)
(/) .
, length_spheroid().
.
ST_length2d(geometry)
2- (2-dimensional length) , -.
ST_length3d(geometry)
3- (3-dimensional length) , -.
ST_length_spheroid(geometry,spheroid)
. ,
/ .
:
SPHEROID[<NAME>,<SEMI-MAJOR AXIS>,<INVERSE FLATTENING>]
:
SPHEROID["GRS_1980",6378137,298.257222101]
:

GIS-Lab.info

39

PostGIS, 1.3.4
SELECT length_spheroid( geometry_column,
'SPHEROID["GRS_1980",6378137,298.257222101]' )
FROM geometry_table;
ST_length3d_spheroid(geometry,spheroid)
. length_spheroid,
( , ),
, .
ST_distance(geometry, geometry)
.
ST_max_distance(linestring,linestring)
.
ST_perimeter(geometry)
2- , -.
ST_perimeter2d(geometry)
2- , -.
ST_perimeter3d(geometry)
3- , -.
ST_azimuth(geometry, geometry)
, , NULL,
. .
1.1.0

6.2.4.
ST_AsBinary(geometry,{'NDR'|'XDR'})
"-" ("well-known-binary") OGC,
little-endian (NDR) big-endian (XDR) .
.
ST_AsEWKT(geometry)
EWKT ( ).
ST_AsEWKB(geometry, {'NDR'|'XDR'})
EWKB, little-endian (NDR) bigendian (XDR) .
ST_AsHEXEWKB(geometry, {'NDR'|'XDR'})
HEXEWKB, little-endian (NDR) big-endian
(XDR) .
ST_AsSVG(geometry, [rel], [precision])
SVG. 1 ,
. , (0)
.
( - 15). cx/cy, 'rel'
0, x/y, 'rel' 1.
ST_AsGML([version], geometry, [precision])
, GML. version, , 2, 3.
version , 2.
( - 15).
ST_AsKML(geometry, [precision])
KML.
( - 15).
ST_AsGeoJson([version], geometry, [precision], [options])
GeoJson. (. GeoJson specifications 1.0). 2D 3D
. GeoJson SFS 1.1 ( ).
version 1.
(
15).
'options' Bbox Crs GeoJSON:
0: ( )
1: GeoJson CRS
2: GeoJson Bbox

GIS-Lab.info

40

PostGIS, 1.3.4
3: Both GeoJson Bbox and CRS
GeoJson CRS: auth_name:auth_srid spatial_ref_sys table ( EPSG:4326).
: 1.3.4

6.2.5.
ST_GeomFromEWKT(text)
EWKT.
ST_GeomFromEWKB(bytea)
EWKB.
ST_MakePoint(<x>, <y>, [<z>], [<m>])
2d-, 3dz- 4d-.
ST_MakePointM(<x>, <y>, <m>)
3dm-.
ST_MakeBox2D(<LL>, <UR>)
BOX2D, .
ST_MakeBox3D(<LLB>, <URT>)
BOX3D, .
ST_MakeLine(geometry set)
.
SELECT .
ST_MakeLine(geometry, geometry)
Linestring .
ST_LineFromMultiPoint(multipoint)
Linestring MultiPoint.
ST_MakePolygon(linestring, [linestring[]])
, .
Accum.
( IsClosed GeometryType).
ST_BuildArea(geometry)
, , .
.
, NULL.
BdPolyFromText BdMPolyFromText -
OGC.
1.1.0. GEOS >= 2.1.0.
ST_Polygonize(geometry set)
. GeometryCollection, ,
.
1.0.0RC1. >= 2.1.0.
ST_Collect(geometry set)
GEOMETRYCOLLECTION MULTI- . collect()
"" PostgreSQL. , ,
, sum() mean(). , "SELECT COLLECT(GEOM) FROM
GEOMTABLE GROUP BY ATTRCOLUMN" GEOMETRYCOLLECTION
ATTRCOLUMN.
ST_Collect ST_Union . ST_Collect
ST_Union . MULTI
MULTI Geometry Collections. ,
. ST_Collect
MULTI , , ST_Dump
:
Thread ref: http://postgis.refractions.net/pipermail/postgis-users/2008June/020331.html
SELECT stusps,
ST_Multi(ST_Collect(f.the_geom)) as singlegeom
FROM (SELECT stusps, (ST_Dump(the_geom)).geom As the_geom

GIS-Lab.info

41

PostGIS, 1.3.4
FROM
somestatetable ) As f
GROUP BY stusps
ST_Collect(geometry, geometry)
, .
MULTI* GEOMETRYCOLLECTION.
ST_Dump(geometry)
(SRF - set-returning function).
geometry_dump, (geom) (path).
(POINT, LINESTRING, POLYGON),
"path" "geom".
MULTI, , "path"
.
. GROUP BY ,
. , MULTIPOLYGONS
POLYGONS.
SELECT sometable.*, (ST_Dump(the_geom)).geom As the_geom
FROM somestatetable
PostGIS 1.0.0RC1. PostgreSQL 7.3 .
ST_DumpRings(geometry)
(SRF - set-returning function).
geometry_dump, (geom) (path). "path"
, : 0 ,
. "geom" , .
PostGIS 1.1.3. PostgreSQL 7.3 .

6.2.6.
ST_AddBBOX(geometry)
. , ,
.
ST_DropBBOX(geometry)
. , ,
.
ST_AddPoint(linestring, point, [<position>])
<pos> ( 0).
-1, .
ST_RemovePoint(linestring, offset)
. Offset 0.
1.1.0.
ST_SetPoint(linestring, N, point)
N . 0.
1.1.0.
ST_Force_collection(geometry)
GEOMETRYCOLLECTION.
WKB.

ST_Force_2d(geometry)
"2- ", X Y.
OGC- ( OGC 2-D ).
ST_Force_3dz(geometry), ST_Force_3d(geometry)
XYZ.
ST_Force_3dm(geometry)
XYM.
ST_Force_4d(geometry)
XYZM.
ST_Multi(geometry)
MULTI*. MULTI*,
.
ST_Transform(geometry,integer)

GIS-Lab.info

42

PostGIS, 1.3.4
, SRID,
. SRID SPATIAL_REF_SYS.
ST_Affine(geometry, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8)
3d . :
Affine(geom, a, b, c, d, e, f, g, h, i, xoff, yoff, zoff)
:

/
|
|
\

a
d
g
0

b
e
h
0

c
f
i
0

xoff
yoff
zoff
1

\
|
|
/

:
x' = a*x + b*y + c*z + xoff
y' = d*x + e*y + f*z + yoff
z' = g*x + h*y + i*z + zoff
1.1.2.
ST_Affine(geometry, float8, float8, float8, float8, float8, float8)
2d . :
Affine(geom, a, b, d, e, xoff, yoff)
:

/
|
|
\

a
d
0
0

b
e
0
0

0
0
1
0

xoff
yoff
0
1

\
| rsp.
|
/

/
|
\

a
d
0

b
e
0

xoff
yoff
1

\
|
/

:
x' = a*x + b*y + xoff
y' = d*x + e*y + yoff
z' = z
3D-, .
1.1.2.
ST_Translate(geometry, float8, float8, float8)
. :
translate(geom, X, Y, Z).
ST_Scale(geometry, float8, float8, float8)
.
: scale(geom, Xfactor, Yfactor, Zfactor).
1.1.0.
ST_RotateZ(geometry, float8), ST_RotateX(geometry, float8), ST_RotateY(geometry, float8)
Z, X Y , . .
1.1.2.
ST_TransScale(geometry, float8, float8, float8, float8)
,
. 2D. transscale(geom, X, Y, XFactor, YFactor)
affine(geom, XFactor, 0, 0, 0, YFactor, 0, 0, 0, 1, X*XFactor,
Y*YFactor, 0).
1.1.0.
ST_Reverse(geometry)
.
ST_ForceRHR(geometry)
" ".
ST_Simplify(geometry, tolerance)
"" - (DouglasPeuker). () (),
.

GIS-Lab.info

43

PostGIS, 1.3.4
(object-by-object), GeometryCollection. ,
( IsSimple).
ST_SnapToGrid(geometry, originX, originY, sizeX, sizeY), ST_SnapToGrid(geometry, sizeX, sizeY),
ST_SnapToGrid(geometry, size)
, .
, , , NULL,
, . .
: ( IsSimple).
: 1.1.0 2d-. 1.1.0
, .
. , ,
.
1.0.0RC1.
ST_SnapToGrid(geometry, geometry, sizeX, sizeY, sizeZ, sizeM)
, ( ,
) . ,
0.
1.1.0.
ST_Segmentize(geometry, maxlength)
, .
Z M ( ), 0.
2d.
ST_LineMerge(geometry)
, () , .
1.1.0. GEOS >= 2.1.0

6.2.7.
ST_line_interpolate_point(linestring, location)
, . LINESTRING.
float8 0 1, 2d-
.
line_locate_point(), , .
: 1.1.1 M Z ( ),
0.0.
0.8.2.
ST_line_substring(linestring, start, end)
, .
float8 0 1.
'start' 'end' , line_interpolate_point().
line_locate_point() , .
: 1.1.1 M Z ( ),
.
1.1.0.
ST_line_locate_point(LineString, Point)
float 0 1,
, 2d-.
(line_interpolate_point)
(line_substring).
1.1.0.
ST_locate_along_measure(geometry, float8)
, .
.
ISO/IEC CD 13249-3:200x(E) - CD
.
1.1.0.
ST_locate_between_measures(geometry, float8, float8)
,
. .
ISO/IEC CD 13249-3:200x(E) - CD .
1.1.0.

GIS-Lab.info

44

PostGIS, 1.3.4

6.2.8.
ST_Summary(geometry)
.
ST_box2d(geometry)
BOX2D, .
ST_box3d(geometry)
BOX3D, .
ST_extent(geometry set)
extent() "" PostgreSQL. ,
, , sum() mean(). , "SELECT
EXTENT(GEOM) FROM GEOMTABLE" BOX3D
. , "SELECT EXTENT(GEOM) FROM GEOMTABLE GROUP BY CATEGORY"
.
ST_zmflag(geometry)
ZM ( - dimension semantic) ,
(small int). : 0=2d, 1=3dm, 2=3dz, 3=4d.
ST_HasBBOX(geometry)
TRUE, . - FALSE.
addBBOX() dropBBOX() .
ST_ndims(geometry)
, (small int). : 2, 3 4.
ST_nrings(geometry)
, .
ST_npoints(geometry)
.
ST_isvalid(geometry)
true, .
ST_expand(geometry, float)
, ,
. distance()
.
ST_estimated_extent([schema], table, geocolumn)
"" .
. .
PostgreSQL>=8.0.0 VACUUM ANALYZE,
95% .
PostgreSQL<8.0.0 update_geometry_stats(),
.
ST_find_srid(varchar,varchar,varchar)
: find_srid(</>, <>, <>).
SRID , GEOMETRY_COLUMNS.
AddGeometryColumns(),
.
ST_mem_size(geometry)
( ), .
ST_point_inside_circle(geometry, float, float, float)
: point_inside_circle(<>, <__x>, <__y>, <>).
true, .
false.
ST_xmin(box3d) ymin(box3d) zmin(box3d)
.
ST_xmax(box3d) ymax(box3d) zmax(box3d)
.
ST_Accum(geometry set)
. .

GIS-Lab.info

45

PostGIS, 1.3.4

6.2.9.
pl/pgsql
, Web Feature Service.
: ,
.
EnableLongTransactions()
. ;
. .
1.1.3.
DisableLongTransactions()
. ,
, , .
1.1.3.
CheckAuth([<schema>], <table>, <rowid_col>)
UPDATE DELETE .
<rowid_col>.
1.1.3.
LockRow([<schema>], <table>, <rowid>, <authid>, [<expires>])
/ . <authid>
, <expires> - , now()+1hour. 1,
, 0 - ( ).
1.1.3.
UnlockRows(<authid>)
, .
.
1.1.3.
AddAuth(<authid>)
.
1.1.3.

6.3. SQL-MM
SQL-MM, PostGIS.
ArcSDE , ,
. .
1.2.0 PostGIS.
, .
: SQL-MM SRID 0. SRID
PostGIS -1.
ST_Area
ST_Surface ST_MultiSurface.
SQL-MM 3: 8.1.2, 9.5.3
ST_AsBinary
WKB ST_Geometry.
SQL-MM 3: 5.1.37
ST_AsText
WKT ST_Geometry.
SQL-MM 3: 5.1.25
ST_Boundary
ST_Geometry.
SQL-MM 3: 5.1.14
ST_Buffer
ST_Geometry.
SQL-MM 3: 5.1.17
ST_Centroid
ST_Surface ST_MultiSurface.
SQL-MM 3: 8.1.4, 9.5.5
ST_Contains

GIS-Lab.info

46

PostGIS, 1.3.4
, ST_Geometry ST_Geometry.
SQL-MM 3: 5.1.31
ST_ConvexHull
,
.
MULTI Geometry Collections. ST_Collect .
ST_ConvexHull(ST_Collect(somepointfield)).
.
SQL-MM 3: 5.1.16
ST_CoordDim
ST_Geometry.
SQL-MM 3: 5.1.3
ST_Crosses
, ST_Geometry
ST_Geometry.
SQL-MM 3: 5.1.29
ST_Difference
ST_Geometry,
ST_Geometry.
SQL-MM 3: 5.1.20
ST_Dimension
ST_Geometry.
SQL-MM 3: 5.1.2
ST_Disjoint
,
ST_Geometry.
SQL-MM 3: 5.1.26

ST_Geometry

ST_Distance
.
SQL-MM 3: 5.1.23
ST_EndPoint
ST_Point, ST_Curve.
SQL-MM 3: 7.1.4
ST_Envelope
ST_Geometry.
SQL-MM 3: 5.1.15
ST_Equals
, ST_Geometry
ST_Geometry.
SQL-MM 3: 5.1.24
ST_ExteriorRing
ST_Surface.
SQL-MM 3: 8.2.3, 8.3.3
ST_GeometryN
ST_Geometry ST_GeomCollection.
SQL-MM 3: 9.1.5
ST_GeometryType
ST_Geometry.
SQL-MM 3: 5.1.4
ST_GeomFromText
ST_Geometry.
SQL-MM 3: 5.1.40
ST_GeomFromWKB
ST_Geometry.
SQL-MM 3: 5.1.41
ST_InteriorRingN
ST_Surface.
SQL-MM 3: 8.2.6, 8.3.5

GIS-Lab.info

47

PostGIS, 1.3.4
ST_Intersection
ST_Geometry,
ST_Geometry.
- , .
SQL-MM 3: 5.1.18
ST_Intersects
, ST_Geometry
ST_Geometry.
SQL-MM 3: 5.1.27
ST_IsClosed
, ST_Curve ST_MultiCurve.
: SQL-MM ST_IsClosed(NULL) 0, PostGIS
NULL.
SQL-MM 3: 7.1.5, 9.3.3
ST_IsEmpty
, ST_Geometry .
: SQL-MM ST_IsEmpty(NULL) 0, PostGIS
NULL.
SQL-MM 3: 5.1.7
ST_IsRing
, ST_Curve .
: SQL-MM ST_IsRing(NULL) 0, PostGIS NULL.
SQL-MM 3: 7.1.6
ST_IsSimple
, ST_Geometry , ,
.
: SQL-MM ST_IsSimple(NULL) 0, PostGIS
NULL.
SQL-MM 3: 5.1.8
ST_IsValid
, ST_Geometry .
: SQL-MM ST_IsValid(NULL) 0, PostGIS NULL.
SQL-MM ST_IsValid(NULL) 1.
SQL-MM 3: 5.1.9
ST_Length
ST_Curve ST_MultiCurve.
SQL-MM 3: 7.1.2, 9.3.4
ST_LineFromText
ST_LineString.
SQL-MM 3: 7.2.8
ST_LineFromWKB
ST_LineString.
SQL-MM 3: 7.2.9
ST_MLineFromText
ST_MultiLineString.
SQL-MM 3: 9.4.4
ST_MLineFromWKB
ST_MultiLineString.
SQL-MM 3: 9.4.5
ST_MPointFromText
ST_MultiPoint.
SQL-MM 3: 9.2.4
ST_MPointFromWKB
ST_MultiPoint.
SQL-MM 3: 9.2.5
ST_MPolyFromText
ST_MultiPolygon.
SQL-MM 3: 9.6.4
ST_MPolyFromWKB
ST_MultiPolygon.
SQL-MM 3: 9.6.5

GIS-Lab.info

48

PostGIS, 1.3.4
ST_NumGeometries
ST_GeomCollection.
SQL-MM 3: 9.1.4
ST_NumInteriorRing
ST_Surface.
SQL-MM 3: 8.2.5
ST_NumPoints
ST_LineString ST_CircularString.
SQL-MM 3: 7.2.4
ST_OrderingEquals
ST_OrderingEquals t (TRUE),
; f (FALSE).
: ArcSDE SQL, SQL-MM.
http://edndoc.esri.com/arcsde/9.1/sql_api/sqlapi3.htm#ST_OrderingEquals
SQL-MM 3: 5.1.43
ST_Overlaps
ST_Geometry ST_Geometry.
SQL-MM 3: 5.1.32
ST_Perimeter
ST_Surface ST_MultiRSurface.
SQL-MM 3: 8.1.3, 9.5.4
ST_Point
ST_Point .
SQL-MM 3: 6.1.2
ST_PointFromText
ST_Point.
SQL-MM 3: 6.1.8
ST_PointFromWKB
ST_Point.
SQL-MM 3: 6.1.9
ST_PointN
ST_Point ST_LineString ST_CircularString.
SQL-MM 3: 7.2.5, 7.3.5
ST_PointOnSurface
ST_Point, ST_Surface
ST_MultiSurface.
SQL-MM 3: 8.1.5, 9.5.6
ST_PolyFromText
ST_Polygon.
SQL-MM 3: 8.3.6
ST_PolyFromWKB
ST_Polygon.
SQL-MM 3: 8.3.7
ST_Polygon
, SRID.
SQL-MM 3: 8.3.2
ST_Relate
, ST_Geometry
ST_Geometry.
SQL-MM 3: 5.1.25
ST_SRID
(SRID) ST_Geometry.
SQL-MM 3: 5.1.5
ST_StartPoint
ST_Point, ST_Curve.
SQL-MM 3: 7.1.3
ST_SymDifference
ST_Geometry,
ST_Geometry.
SQL-MM 3: 5.1.21

GIS-Lab.info

49

PostGIS, 1.3.4
ST_Touches
, ST_Geometry
ST_Geometry.
SQL-MM 3: 5.1.28
ST_Transform
ST_Geometry, .
SQL-MM 3: 5.1.6
ST_Union
ST_Geometry,
ST_Geometry.
SQL-MM 3: 5.1.19
ST_Within
,
ST_Geometry.
SQL-MM 3: 5.1.30

ST_Geometry

ST_WKBToSQL
ST_Geometry WKB .
SQL-MM 3: 5.1.36
ST_WKTToSQL
ST_Geometry WKT .
SQL-MM 3: 5.1.34
ST_X
x ST_Point.
SQL-MM 3: 6.1.3
ST_Y
y ST_Point.
SQL-MM 3: 6.1.4

6.4. ArcSDE
, ArcSDE.
SE_EnvelopesIntersect
t (TRUE), ; f (FALSE).
SE_Is3d
, z.
SE_IsMeasured
, m.
SE_LocateAlong
,
.
SE_LocateBetween
,
, .
SE_M
m ST_Point.
SE_Z
z ST_Point.

GIS-Lab.info

50

PostGIS, 1.3.4

7.
7.1.
PostGIS.
PostGIS .
,
, .
SELECT postgis_full_version() [ postgis] SELECT version() [ postgresql].
, release changelog,
.
PostGIS bug tracker , ,
. , ,
, , , ,
.
Simon Tatham
.

7.2.
. ,
.
PostGIS bug tracker.
, ,
.
, Subversion. Unix
4 (, Subversion ):
PostGIS' Subversion trunk. Unix, :
svn checkout http://svn.refractions.net/postgis/trunk/
This will be stored in the directory ./trunk
. Unix,
:
vi trunk/doc/postgis.xml
, SGML HTML, , ,
.
.
Unix, :
svn diff trunk/doc/postgis.xml > doc.patch
bug tracker.

GIS-Lab.info

51

PostGIS, 1.3.4

A.1.
A.1.1. 1.3.3
: 2008/04/12
shp2pgsql, SVG KML,
ST_SimplifyPreserveTopology, GEOS,
, .
A.1.2. 1.3.2
: 2007/12/01
ST_EndPoint() ST_Envelope, JDBC OS/X,
GML ST_AsGML(), GML3.
A.1.3. 1.3.1
: 2007/08/13
, , - ,
, .
A.1.4. 1.3.0
: 2007/08/09
,
SQL-MM,
(ST).
A.1.4.1.
JDBC: Hibernate. Norman Barker.
ST_Covers ST_CoveredBy.
http://lin-ear-th-inking.blogspot.com/2007/06/subtleties-of-ogc-covers-spatial.html
ST_DWithin
A.1.4.2.
-- - ST_Contains,
ST_Intersects, ST_Within ST_Disjoint.
( ST_Disjoint).
A.1.4.3.
.
SQL-MM
(ST) .
PostgreSQL 8.3.
A.1.5. Release 1.2.1
: 2007/01/11
PostgreSQL 8.2 .
A.1.5.1.
"--" Within().
NULL PostgreSQL 8.2.
RPM.
Transform() - no-op.
JDBC: JTS (
). , JavaDoc . classpath GCJ.
pgjdbc 8.2. jdk 1.3 .
A.1.6. Release 1.2.0
: 2006/12/08
/
, SQL-MM, .
A.1.6.1.
/ .
Contains Within "--"
.
A.1.7. 1.1.6
: 2006/11/02
, .. GEOS 64-
. SRS ( Z
). .
A.1.7.1.
1.0.3 , SOFT-.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .

GIS-Lab.info

52

PostGIS, 1.3.4
1.0.0RC6 HARD-.
A.1.7.2.
CAPI, 64- .
/: .
setSRID() JDBC. Thomas Marti.
A.1.7.3.
Z.
spatial_ref_sys.sql EPSG 6.11.1.
Version.config. .
USAGE / Version.config.
JDBC.
A.1.8. 1.1.5
: 2006/10/13
, win32. .
A.1.8.1.
1.0.3 , SOFT-.
1.0.0RC6 1.0.2 (), ""
1.0.3 .
1.0.0RC6 HARD-.
A.1.8.2.
MingW, Win32
PostgreSQL 8.2.
Geometry.equals() Java.
EJB3Spatial.odt GPL "
".
JDBC Jts.
README shp2pgsql/pgsql2shp.
man.
jdbc, "1.1.3" "1.1.4".
A.1.8.3.
-S shp2pgsql.
A.1.9. 1.1.4
: 2006/09/27
Java.
.
A.1.9.1.
1.0.3 , SOFT-.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 "HARD-".
A.1.9.2.
PostgreSQL 8.2
collect(), SRID .
SRID MakeBox2d MakeBox3d.
GEOS-3.0.0.
pgsql2shp.
A.1.9.3. Java
JTS SRID.
GNU Trove.
EJB2, "Geodetix s.r.l.", - http://www.geodetix.it/
/ EJB3, (Norman Barker), - <nbarker@ittvis.com>
layout little.
A.1.10. 1.1.3
: 2006/06/30
, (
) . .
A.1.10.1.
1.0.3 , SOFT-.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 " ".

GIS-Lab.info

53

PostGIS, 1.3.4
A.1.10.2. /
distance(poly,poly), .
pgsql2shp .
shp2pgsql MultiLine WKT.
affine(), .
WKT: (
GEOMETRYCOLLECTION).
A.1.10.3.
. .
DumpRings().
AsHEXEWKB(geom, XDR|NDR).
A.1.10.4. JDBC
: MultiPoint .
jdbc.

.
A.1.10.5.
/.
--with-proj-libdir --with-geos-libdir.
Tru64.
Jade .
pgsql2shp , .
PostgreSQL 8.2.
A.1.11. 1.1.2
: 2006/03/30
. .
.
A.1.11.1.
1.0.3 , SOFT-.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 .
A.1.11.2.
SnapToGrid().
EnforceRHR().
jdbc2 SRID JTS.
64- .
A.1.11.3.
PostGIS.
affine().
rotate{,X,Y,Z}().
affine().
estimated_extent() pgsql >= 8.0.0.
A.1.11.4.
./configure.
./run_test, .
A.1.12. 1.1.1
: 2006/01/23
, .
postgis_restore.pl, HARD-,
GEOS-2.2+, GeometryCollection.
A.1.12.1.
1.0.3 , SOFT-.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 .
A.1.12.2.
postgis_restore.pl.
geometrycollection GEOS-CAPI.
Solaris 2.7 MingW.
line_locate_point().
PostgreSQL.
line_substring().

GIS-Lab.info

54

PostGIS, 1.3.4
.
A.1.12.3.
Z M line_substring().
Z M line_interpolate_point().
NumInteriorRing(), OpenGIS.
A.1.13. 1.1.0
: 2005/12/21
- , . :
; transform();
GEOS ( CAPI); ; .
PostGIS GEOS 2.2.x.
GEOS PostGIS.
A.1.13.1.
(Mark Cave Ayland) proj4.
(Markus Schaber) JDBC2. (Alex Bodnaru)
, PostgreSQL, Debian.
(Michael Fuhr) Solaris. (David Techer)
(Gerald Fenoy) GEOS C-API. (Hartmut Tschauner)
azimuth(). (Devrim GUNDUZ) RPM.
.
.
A.1.13.2.
1.0.3 , /.
lwpostgis_upgrade.sql .
.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 .
A.1.13.3.
scale() transscale(), translate().
line_substring()
line_locate_point()
M(point)
LineMerge(geometry)
shift_longitude(geometry)
azimuth(geometry)
locate_along_measure(geometry, float8)
locate_between_measures(geometry, float8, float8)
SnapToGrid ( 4d).
BuildArea(any_geometry)
OGC BdPolyFromText(linestring_wkt, srid)
OGC BdMPolyFromText(linestring_wkt, srid)
RemovePoint(linestring, offset)
ReplacePoint(linestring, offset, point)
A.1.13.4.
polygonize()
lwgeom_as_anytype.
USE_GEOS, USE_PROJ USE_STATS postgis_version(),
.
A.1.13.5.
SnapToGrid .
Z(), NULL, .
A.1.13.6.
proj4 transform().
fix_geometry_columns() AddGeometryColumns() update_geometry_stats().
A.1.13.7. JDBC2
Makefile.
JTS.
.
.
(Hex)(E)wkb.
DriverWrapper HexWKB / EWKT.
ValueSetter jdk.
EWKT, SRID=4711;.
java2d.

GIS-Lab.info

55

PostGIS, 1.3.4
A.1.13.8.
autoconf, PostgreSQL.
GEOS C-API (2.2.0 ).
.
Debian RPM.
lwpostgis_upgrade.sql
A.1.13.9.
JTS.
DBF SQL.
.
jdbc.
postgis_proc_upgrade.pl.
.
A.1.14. 1.0.6
: 2005/12/06
.
A.1.14.1.
1.0.3 , /.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 .
A.1.14.2.
palloc(0) ( --enable-cassert).
bbox.
geom_accum(NULL, NULL).
addPoint().
lwcollection_clone().
segmentize().
SnapToGrid bbox.
A.1.14.3.
postgresql 8.2.
GEOS ops SRID.
A.1.15. 1.0.5
: 2005/11/25
,
UTF8 .
: shp2pgsql
unix ( 0 ).
A.1.15.1.
1.0.3 , /.
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 .
A.1.15.2.
.
.
getPoint4d_p().
.
force_3dm(), force_3dz() force_4d().
A.1.15.3.
shp2pgsql.
( -).
DBF.
shp2pgsql ( utf8).
A.1.15.4.
postgis_proc_upgrade.pl pgsql 7.2+.
" ".
A.1.16. 1.0.4
: 2005/09/09
. , -
, GiST .
A.1.16.1.
1.0.3, /.

GIS-Lab.info

56

PostGIS, 1.3.4
1.0.0RC6 1.0.2 (),
"" 1.0.3 .
1.0.0RC6 .
A.1.16.2.
GiST.
transform() proj4.
proj4 spatial_ref_sys ( +proj).
: , NULL,
MULTILINESTRING.
MakeLine.
translate(), .
A.1.16.3.
.
.
distance().
.
GiST.
, box3d.
A.1.17. 1.0.3
: 2005/08/08
, ,
.
A.1.17.1.
- , .
.
HARD- (/) (
). , 1.0.0RC6.
1.0.0RC6 , PERL-
(utils/rebuild_bbox_caches.pl),
( , ).
'make install' ( ).
utils/postgis_proc_upgrade.pl PosGIS (
).
A.1.17.2.
2d lwgeom.
POINT WKT (-w) .
64- .
, .
create_undef.pl.
A.1.17.3.
.
.
.
postgis_restore.pl.
rebuild_bbox_caches.pl.
A.1.18. 1.0.2
: 2005/07/04
.
A.1.18.1.
1.0.0RC6 , /.
/.
.
A.1.18.2.
ops b-.
pg_error.
R-.
( CFLAGS CXXFLAGS).
A.1.18.3.
( -I).
PostgreSQL 8.1dev.
A.1.19. 1.0.1
: 2005/05/24
.

GIS-Lab.info

57

PostGIS, 1.3.4
A.1.19.1.
1.0.0RC6 , /.
/.
.
A.1.19.2.
3d- length_spheroid().
.
A.1.19.3. /
shp2pgsql.
PostGIS .
.
jdbc2: "-target 1.2 -source 1.2" .
-k pgsql2shp
createdb postgis_restore.pl.
pgsql2shp.
.
postgis_restore.pl.
A.1.20. 1.0.0
: 2005/04/19
1.0.0. , (
PostGIS) .
A.1.20.1.
1.0.0RC6, /.
/.
.
A.1.20.2.
transform() .
force_3dm() . , .
(defaults, leaks, tuplecount, sd).
A.1.20.3. /
shp2pgsql , .
/.
(HWGEOM) PostGIS shp2pgsql.
-p (prepare) shp2pgsql.
OGC.
JTS.
( LWGEOM ).
A.1.21. 1.0.0RC6
: 2005/03/30
- 1.0.0. .
A.1.21.1.

.

/.

A.1.21.2.
multi()
[ noop] multi()
A.1.21.3.
{x,y}{min,max}(box2d).
A.1.21.4.
postgis_restore.pl.
64-.
A.1.22. 1.0.0RC5
: 2005/03/25
- 1.0.0. .
A.1.22.1.
1.0.0RC4, /.
/.
.
A.1.22.2.
( ) box3d (, !).
( ) estimated_extent().

GIS-Lab.info

58

PostGIS, 1.3.4
A.1.22.3.
.
.
A.1.23. 1.0.0RC4
: 2005/03/18
- 1.0.0. .
A.1.23.1.
/ .
"".
A.1.23.2.
( ) geom_accum().
64- .
box3d .
. .
force_collection.
SnapToGrid().
Box2d : 15 .
A.1.23.3.
distance_sphere().
get_proj4_from_srid: PL/PGSQL SQL.
A.1.23.4.
.
, , .
jdbc2: , Makefile.
FLEX YACC *after* pgsql Makefile.global *stripped* pgsql .
.
.
, Version.config.
postgis_restore.pl
A.1.24. 1.0.0RC3
: 2005/02/24
- 1.0.0. .
A.1.24.1.
/ .
"".
A.1.24.2.
transform(): SRID.
.
force_collection(), mapserver ()
.
GeometryFromText() bbox.
box2d.
DEBUG PGIS_ pgsql.
GEOS2POSTGIS.
.
A.1.24.3.
72 .
probe_geometry_columns() PG72
.
bool::text cast
STABLE IMMUTABLE.
A.1.24.4. JDBC
jdbc2: , box2d/3d, .
jdbc2: pgjdbc 8.0.
jdbc2: jdk1.4 jdk.
jdbc2: pg72jdbc2.jar
jdbc2: makefile
jdbc2: BETA- jts.
jdbc2: "-" PostGIS.
jdbc2: EWKT.
A.1.24.5.
, .
: pgsql72, lwpostgis.sql.

GIS-Lab.info

59

PostGIS, 1.3.4
autoconf.
BUILDDATE .
spatial_ref_sys.sql. vacuum .
spatial_ref_sys: Paris 0.x.
A.1.25. 1.0.0RC2
: 2005/01/26
- 1.0.0, .
A.1.25.1.
/ .
.
A.1.25.2.
box3d.
distance_spheroid
transform() bbox.
jdbc (jdbc2)
GEOMETRYCOLLECTION(EMPTY) .
.
OGC WKB/WKT.
A.1.25.3.
STABLE, IMMUTABLE, STRICT lwpostgis.sql
OGC WKB/WKT.
A.1.25.4.
( i18n).
.
A.1.26. 1.0.0RC1
: 2005/01/13
PostGIS, PostGIS, ,
.
A.1.26.1.
/ .
.
A.1.26.2.
.
.
IO EWKB PG>73.
4d, shapefile->postgis->shapefile.
: UpdateGeometrySRID(), AsGML(), SnapToGrid(), ForceRHR(), estimated_extent(), accum().
.
JOIN.
/ .
API PostGIS.
UTF8 .

GIS-Lab.info

60