Geography Reference
In-Depth Information
We can also specify a where clause in ogr2ogr to create a subset of our
data. This works quite well for extracting features from PostGIS where
the database might be quite large and we need only a small set of the
data for our purpose. To extract a subset, use the -where switch and
enclose the clause in double quotes:
$ ogr2ogr -f "ESRI Shapefile" strato_volcanoes.shp \
"PG:dbname=gis_data host=madison" volcanoes -where "type = 'Stratovolcanoes'"
$ ogrinfo -so -al strato_volcanoes.shp
INFO: Open of `strato_volcanoes.shp'
using driver `ESRI Shapefile' successful.
Layer name: strato_volcanoes
Geometry: Point
Feature Count: 7
We just created a shapefile containing only volcanoes of type Strato-
volcanoes from our original layer in PostGIS. The PostGIS layer con-
tains ninety-three volcanoes and our use of the where clause whittled
that down to seven matches. If all you want to do is display a subset
of a PostGIS layer, remember that QGIS supports subsets on the fly;
otherwise, this is another useful technique for moving data around.
A further option when unloading or converting data is to specify a
bounding rectangle using the -spat option. This will allow you to extract
only those features within the rectangle, creating a spatial subset. You
need to specify the bounds of the rectangle in the same coordinate sys-
tem as the layer. To illustrate, let's extract a small subset of the cities
layer we loaded into PostGIS and list the results using ogrinfo .
$ ogr2ogr -f "ESRI Shapefile" cities_subset.shp \
-spat -152 58 -148 62 "PG:dbname=gis_data host=madison" cities
$ ogrinfo -al cities_subset.shp
INFO: Open of `cities_subset.shp'
using driver `ESRI Shapefile' successful.
Layer name: cities_subset
Geometry: Point
Feature Count: 2
Extent: (-149.449997, 60.119999) - (-149.172974, 61.188648)
Layer SRS WKT:
GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_1984",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]]
capital: String (1.0)
country: String (12.0)
name: String (25.0)
 
 
Search WWH ::




Custom Search