Geoscience Reference
In-Depth Information
Geometry: Polygon
Feature Count: 7566
Extent: (1.393187, 48.113148) - (3.576257, 49.237916)
Layer SRS WKT:
GEOGCS["GCS_WGS_1984",
DATUM["WGS_1984",
SPHEROID["WGS_84",6378137,298.257223563]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]]
osm_id: Real (11.0)
name: String (48.0)
The option
-sql
provides
ogr2ogr
with a lot of flexibilty in terms of the queries
that can be run on the input dateset. The following examples will demonstrate how to
carry out a range of data processing steps with SQL. Supposing you want to rename
the field
name
from the above example to something that is more explantorary, such
as
osm_name
, it suffices to append the following SQL statement to
ogr2ogr
.
ogr2ogr natural_select_rename.shp natural_select.shp -sql
→
"SELECT name AS osm_name FROM natural_select"
The words in capitals in the SQL statement are core words from SQL and the
words:
name,osm_name and natural_select
represent variables names, the
latter indicating the name of the dataset. The use of capitals for SQL terms is not
mandatory, but is more of a convention. Similarly, the
SQL
statement can be adapted
to calculate the area of the polygon using the
OGR_GEOM_AREA
special field.
As of GDAL 1.10, both
ogrinfo
and
ogr2ogr
support the SQLite dialect
to query Shapefiles and other OGR supported vector formats. The advantage over
SQL is that it provides more functionality as well as the spatial functions. In the
following example we use the SQLite dialect to return the coordinates of the centroid
and area of the polygon
natural_select_rename.shp
using the functions
ST_Centroid
and
ST_Area
. It is important to note that as input each of the
functions take the
geometry
as input.
ogrinfo natural_select_rename.shp -dialect SQLite -sql "select
→
ST_Centroid(geometry), SUM(ST_Area(geometry)) from
→
natural_select_rename"
Layer name: SELECT
Geometry: Unknown (any)
Feature Count: 1
Extent: (3.116159, 48.947486) - (3.116159, 48.947486)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
Search WWH ::
Custom Search