[FWTools] sql string functions for shapefiles in ogrinfo

Bryan Keith bryan at geomega.com
Tue Jan 16 12:02:18 EST 2007


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


More information about the FWTools mailing list