
438
|
Chapter 8, Building the Geospatial Web
#87 Build a Spatially Indexed Data Store
HACK
This step loads the PostGIS schema and functions into your new database:
#> psql -d tiger -f postgis.sql
You may need to provide the full path to wherever postgis.sql was installed
on your system. One final step is needed to add data to the
spatial_ref_sys
table, which contains metadata about the different spatial projections that
the geometry can be in:
#> psql -d tiger -f spatial_ref_sys.sql
If everything’s working, you should see the last line COMMIT (see also http://
postgis.refractions.net/docs/x83.htm).
Getting Data into PostGIS
A spatial database is no fun without spatially meaningful data. There are
several techniques for getting your information into PostGIS.
Import a shapefile into PostGIS with shp2pgsql. You can use shp2pgsql to import
geospatial data in shapefile format into PostGIS. For example, you might
have a shapefile that contains a set of political boundaries for which you
want to ask, “Which voting area contains this address? Where is the nearest
polling station? What was the voter turnout rate in the last election?”
The shp2pgsql script comes with PostGIS and will convert a shapefile into a
set of insert statements suitable for loading into a PostGIS database. To
import a shapefile, try the following command:
shp2pgsql -c shapefile [database_name.]table_name
The database name is optional. To