[FWTools] sql string functions for shapefiles in ogrinfo

Bryan Keith bryan at geomega.com
Tue Jan 16 17:22:57 EST 2007

Mateusz Loskot wrote:
> Bryan Keith wrote:
>> Mateusz Loskot wrote:
>>> Bryan Keith wrote:
>>>> Hello,
>>>> I can use this command and get the output I expect from a shapefile:
>>>> ogrinfo "myfile.shp" -al -sql "select * from 'myfile' where ID =
>>>> 'SB-18'"
>>>> However, what if I want all records where ID starts with 'SB'?  If I
>>>> tried left, substr and others e.g.:
>>>> where left(ID,2) = 'SB'
>>>> I assume if you're using a db like PostGIS then the sql is parsed by the
>>>> db, and you can read the db documentation for the sql syntax.  Which sql
>>>> syntax reference should I be using for shapefiles?
>>> SQL query compiler in OGR supports SQL standard operators: LIKE, ILIKE,
>>> IS, IN, etc.
>>> So, you can write your query as follows:
>>> "select * from myfile where ID LIKE 'SB%'"
>>> Cheers
>> Mateusz,
>> That works for me.  Thank you.
> Bryan,
> I'm glad.
> By the way, there is a document describing OGR SQL dialect in details:
> http://www.gdal.org/ogr/ogr_sql.html

Ah, the page that would have answered my question in the first place. 
I've got it bookmarked now.  Thanks, Mateusz


> Cheers

More information about the FWTools mailing list