Geography Reference
In-Depth Information
Using SQL to Load Data
To load spatial data using SQL, use the GeomFromText function. This
function is part of the OGC specification and as an argument takes the
Well-Known Text (WKT) representation of a feature. WKT is a simple
way to specify a feature type and its coordinates. Some examples of
WKT representations are as follows:
POINT(-151.5 61.5)
LINESTRING(-151.5 61.5, -151.5 62.5, -152.25 63.0)
POLYGON((-155.82 57.31,-155.94 61.18,-152.82
61.18,-152.78
57.31,-155.82
57.31))
To create a polygon in the lakes table created earlier, you would use an
insert statement as follows:
insert into lakes values(1, 'Big Lake', 127.6,
GeomFromText('POLYGON((-155.82 57.31,-155.94 61.18,
-152.82 61.18,-152.78 57.31,-155.82 57.31))', 4326));
This creates a lake (a pretty rectangular one) named Big Lake with an
ID of 1 and a depth of 127.6. The feature type is a polygon, and the
spatial reference ID is 4326.
It makes sense to use this method of loading data when you want to
import data using a script from a text file or in application code where
you are taking input from a user or device. In normal practice, it can
become quite cumbersome to manually enter WKT to build up a SQL
statement. At least now you are aware of the capability, but you don't
need to know this technique to load and use PostGIS data in your desk-
top GIS application.
Using QGIS to Load Data
QGIS comes with a plugin called SPIT, which stands for Shapefile to
PostGIS Import Tool. This plugin allows you to import shapefiles into
PostGIS from within QGIS. To use SPIT, make sure it's loaded from the
Plugins menu. Once loaded, it will appear as a blue elephant icon on
the Plugins toolbar. Before you can use SPIT, you need to have already
created a connection to PostGIS (this isn't strictly true, but it makes
things easier). We haven't talked about creating connections yet, but
you can learn how by jumping ahead to Section 7.4 , Using PostGIS and
Quantum GIS, on page 110 . Assuming you have a working connection,
just click the SPIT icon to open the tool. In Figure 7.2 , on the next
page, you can see the tool with a few shapefiles ready to be loaded into
PostGIS.
 
 
 
Search WWH ::




Custom Search