VALUES (
1,
'First Geometry',
- GeomFromText('LINESTRING(2 3,4 5,6 5,7 8)', -1)
+ ST_GeomFromText('LINESTRING(2 3,4 5,6 5,7 8)', -1)
);</programlisting>
<para>For more information about other GIS objects, see the <link
much much faster.</para>
<para>You will also make use of spatial functions, such as
- Distance(), ST_Intersects(), ST_Contains() and ST_Within(),
+ ST_Distance(), ST_Intersects(), ST_Contains() and ST_Within(),
among others, to
narrow down the results of your search. Most spatial queries include
both an indexed test and a spatial function test. The index test
<programlisting>SELECT id, the_geom
FROM thetable
WHERE
- the_geom && 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'
+ the_geom && 'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'::geometry
AND
_ST_Contains(the_geom,'POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))');</programlisting>
</answer>
OGC spatial object would be:</para>
<programlisting>INSERT INTO geotable ( the_geom, the_name )
- VALUES ( GeomFromText('POINT(-126.4 45.32)', 312), 'A Place');</programlisting>
+ VALUES ( ST_GeomFromText('POINT(-126.4 45.32)', 312), 'A Place');</programlisting>
</sect2>
<sect2>
<title>Using SQL</title>
<para>The most straightforward means of pulling data out of the
- database is to use a SQL select query and dump the resulting columns
+ database is to use a SQL select query to reduce the number of RECORDS and COLUMNS returned
+ and dump the resulting columns
into a parsable text file:</para>
<programlisting>db=# SELECT road_id, AsText(road_geom) AS geom, road_name FROM roads;
<programlisting>SELECT road_id, road_name
FROM roads
- WHERE roads_geom ~= GeomFromText('LINESTRING(191232 243118,191108 243242)',-1);</programlisting>
+ WHERE roads_geom ~= ST_GeomFromText('LINESTRING(191232 243118,191108 243242)',-1);</programlisting>
<para>The above query would return the single record from the
"ROADS_GEOM" table in which the geometry was equal to that
<programlisting>SELECT road_id, road_name
FROM roads
-WHERE roads_geom && GeomFromText('POLYGON((...))',-1);</programlisting>
+WHERE roads_geom && ST_GeomFromText('POLYGON((...))',-1);</programlisting>
<para>The above query will use the bounding box of the polygon for
comparison purposes.</para>
<programlisting>SELECT the_geom
FROM geom_table
-WHERE ST_Distance(the_geom, GeomFromText('POINT(100000 200000)', -1)) < 100</programlisting>
+WHERE ST_Distance(the_geom, ST_GeomFromText('POINT(100000 200000)', -1)) < 100</programlisting>
<para>This query is selecting all the geometries in geom_table which
are within 100 units of the point (100000, 200000). It will be slow
FROM geom_table
WHERE the_geom && 'BOX3D(90900 190900, 100100 200100)'::box3d
AND
-ST_Distance(the_geom, GeomFromText('POINT(100000 200000)', -1)) < 100</programlisting>
+ST_Distance(the_geom, ST_GeomFromText('POINT(100000 200000)', -1)) < 100</programlisting>
<para>This query selects the same geometries, but it does it in a more
efficient way. Assuming there is a GiST index on the_geom, the query
<para>This function returns a bounding box expanded in all
directions from the bounding box of the input geometry, by an
amount specified in the second argument. Very useful for
- distance() queries, to add an index filter to the query.</para>
+ ST_Distance() queries, to add an index filter to the query.</para>
</listitem>
</varlistentry>
<sect3>
<title>Bug fixes / correctness</title>
- <para>BUGFIX in distance(poly,poly) giving wrong results.</para>
+ <para>BUGFIX in ST_Distance(poly,poly) giving wrong results.</para>
<para>BUGFIX in pgsql2shp successful return code.</para>
<para>More robust selectivity estimator</para>
- <para>Minor speedup in distance()</para>
+ <para>Minor speedup in ST_Distance()</para>
<para>Minor cleanups</para>