Geography Reference
In-Depth Information
spatial index can be a time-consuming affair for large tables. You might
want to defer building the index, especially if you are loading a lot of
data with a script.
So, what do we really need to specify? Not much when it comes down
to it, but here's one word of caution: before you start going wild loading
data, think about the SRID you should use and then specify it for every
layer. 11 If you don't do it up front, you'll regret it later. Let's load a
shapefile as an example:
$ shp2pgsql -s 4326 -I cities.shp cities_pg | psql -d gis_data
Shapefile type: Point
Postgis type: POINT[2]
BEGIN
NOTICE: CREATE TABLE will create implicit sequence "cities_pg_gid_seq"
for serial column "cities_pg.gid"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
"cities_pg_pkey" for table "cities_pg"
CREATE TABLE
addgeometrycolumn
-------------------------------------------------------
public.cities_pg.the_geom SRID:4326 TYPE:POINT DIMS:2
(1 row)
CREATE INDEX
INSERT 0 1
INSERT 0 1
INSERT 0 1
...
COMMIT
OK, let's analyze what we did here. We knew beforehand that the EPSG
code for cities.shp was 4326, so we specified that as the SRID. The only
other option we used was -I to build the spatial index. Other than that,
we give the shapefile name and the name of the table we want to create,
in this case cities_pg . If we had ended the command there and hit Enter ,
we would have seen a slew of SQL statements scroll by. That's because
shp2pgsql sends its output to stdout (in other words, your terminal or
command window). We could pipe that to a file using > and then use the
file in an application that was capable of running SQL commands from
a file to send it to the appropriate database. We can take a shortcut,
though, and just pipe the output from shp2pgsql directly to psql , the
PostgreSQL interactive terminal. Passing the name of the database to
11. The shapefiles have to be in the same projection as the SRID you plan to use—loading
them into PostGIS won't transform them.
 
Search WWH ::




Custom Search