[FWTools] sql string functions for shapefiles in ogrinfo
Mateusz Loskot
mateusz at loskot.net
Tue Jan 16 12:04:37 EST 2007
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
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net
More information about the FWTools
mailing list