Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#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 Daniel Morissette)

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)

ticket2949.patch (2.9 KB) - added by Daniel Morissette 12 years ago.
Patch against SVN trunk that implements support for OGR_GEOM_AREA
ticket2949_v2.patch (4.6 KB) - added by Even Rouault 12 years ago.
ticket2949-3.patch (3.5 KB) - added by Daniel Morissette 12 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 12 years ago by Daniel Morissette

Description: modified (diff)

Changed 12 years ago by Daniel Morissette

Attachment: ticket2949.patch added

Patch against SVN trunk that implements support for OGR_GEOM_AREA

comment:2 Changed 12 years ago by Even Rouault

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...

Changed 12 years ago by Even Rouault

Attachment: ticket2949_v2.patch added

comment:3 Changed 12 years ago by Daniel Morissette

Cc: Even Rouault 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:4 Changed 12 years ago by warmerdam

Calling C functions from C++ like this is fine.

comment:5 Changed 12 years ago by Daniel Morissette

Status: newassigned

I'll attach a new patch that uses OGR_G_GetArea() everywhere then.

Changed 12 years ago by Daniel Morissette

Attachment: ticket2949-3.patch added

comment:6 Changed 12 years ago by Daniel Morissette

Resolution: fixed
Status: assignedclosed

Fixed. Committed in SVN trunk r16787, and updated docs in r16788.

comment:7 Changed 12 years ago by Even Rouault

Test added in r16793

comment:8 Changed 12 years ago by Even Rouault

In r16928 : additionnal missing cases for SWQ_FLOAT type, so that SQL requests containing 'ORDER BY OGR_GEOM_AREA' run correctly instead of crashing...

Note: See TracTickets for help on using tickets.