I have a shapefile with several polygons. I would like to clip a series of rasters but only use a single feature from the shapefile feature class. I am using gdal_warp. There is an option to query the feature class using sql by using the -csql option in the tool.

Can any one provide an example of how this looks in the command line?

Perhaps this is only used when connecting to a spatially enabled database as a datasource?


Here's my answer:

Although I don't completely understand how layers work in gdal I have found they are almost always the file name without path or extension. For example: "C:/Folder/AllRiverMileSegments.shp" would be loaded as the layer "AllRiverMileSegments".

Writing a SQL statement for gdalwarp uses this layer as the table name and calls columns in the attribute table as columns of that table. In my above shapefile I want to query river mile segments. In my attribute table I have have a column called "RiverMile" that I will use to query river mile segments from the feature class. The section of gdalwarp that calls for this statement will look like this:

-csql "SELECT * FROM AllRiverSegments WHERE RiverMile = $RIVERMILE"

Where $RIVERMILE is the river mile number I want to query.

Thanks to MerseyViking for getting me started here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.