#2949 closed defect (fixed)
Add OGR_GEOM_AREA special field
Reported by: | Daniel Morissette | Owned by: | Daniel Morissette |
---|---|---|---|
Priority: | normal | Milestone: | 1.7.0 |
Component: | OGR_SF | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: | warmerdam, Even Rouault |
Description (last modified by )
I'd like to use a OGR SQL statement to filter features from a shapefile based on their area. e.g. keep only the large lakes in a water layer for instance.
A simple way to allow this would be to add a new OGR_GEOM_AREA special field on OGRFeatures that calls the OGRSurface::getArea() method and would be handled similar to the OGR_GEOM_WKT and other special fields in OGRFeature::GetFieldAsString().
Another option could be to add operators on geometries in the SQL parser but that could be a bit more involved (e.g. "select ST_Area(geom) from ...").
Attachments (3)
Change History (11)
comment:1 by , 15 years ago
Description: | modified (diff) |
---|
by , 15 years ago
Attachment: | ticket2949.patch added |
---|
comment:2 by , 15 years ago
Daniel, here's a V2 of your patch that seems to work well in the "ogrinfo -sql 'select OGR_GEOM_AREA, * from province WHERE OGR_GEOM_AREA > 10' /tmp/province.shp" case.
There were 2 places where FLOAT type in special fields wasn't taken into account + special case for OGR_GEOM_AREA in GetFieldAsDouble() and GetFieldAsInteger(). I'm not sure that the special case for GetFieldAsInteger() and GetFieldAsString() are necessary, but they exist for the FID, so there may be a case where it is necessary...
by , 15 years ago
Attachment: | ticket2949_v2.patch added |
---|
comment:3 by , 15 years ago
Cc: | added |
---|
Thanks a lot Even. I tested your new patch and it indeed solves the problems I was having.
I see that you called the C API's OGR_G_GetArea() from the C++ code. I agree that this makes the code much simpler and easier to maintain in the long run. I thought of doing that too but wasn't sure if that was allowed... if doing this is an accepted practice then we should adapt the patch to use that in the GetFieldAsString() case as well.
comment:5 by , 15 years ago
Status: | new → assigned |
---|
I'll attach a new patch that uses OGR_G_GetArea() everywhere then.
by , 15 years ago
Attachment: | ticket2949-3.patch added |
---|
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:8 by , 15 years ago
In r16928 : additionnal missing cases for SWQ_FLOAT type, so that SQL requests containing 'ORDER BY OGR_GEOM_AREA' run correctly instead of crashing...
Patch against SVN trunk that implements support for OGR_GEOM_AREA