Geoscience Reference
In-Depth Information
ogrinfo
natural.shp -sql 'select DISTINCT type from natural'
INFO: Open of 'natural.shp'
using driver 'ESRI Shapefile' successful.
Layer name: natural
Geometry: Polygon
Feature Count: 4
Layer SRS WKT:
(unknown)
type: String (16.0)
OGRFeature(natural):0
type (String) = riverbank
OGRFeature(natural):1
type (String) = park
OGRFeature(natural):2
type (String) = water
OGRFeature(natural):3
type (String) = forest
The results indicate that there are four classifications of natural areas within
the dataset that include: riverbanks, parks, water and forests. In the next example,
the SQL statement is adapted to count the number of forests polygons within the
natural.shp dataset using the COUNT SQL operator (7566).
#return a list of unique natural classes from the 'type' field
ogrinfo
natural.shp -sql 'select COUNT(type) from natural WHERE
type = "forest"'
INFO: Open of 'natural.shp'
using driver 'ESRI Shapefile' successful.
Layer name: natural
Geometry: Polygon
Feature Count: 1
Layer SRS WKT:
(unknown)
COUNT_type: Integer (0.0)
OGRFeature(natural):0
COUNT_type (Integer) = 7566
In some instances, you may want to extract all features from a dataset that match
a particular query. For instance, all polygons above a certain area threshold or all
features of a particular classification. At this stage, it is important to hightlight two
different filters that can be used with ogr2ogr , which is -select and -where .
The main distinction between the two is that -where selects a subset of the fea-
tures including all attributes and outputs them to the destination data source, whereas
-select outputs all features, but with a subset of the attributes. In other words,
unless the wildcard ( * ) is used, each field name that should be written to the desti-
 
 
Search WWH ::




Custom Search