Ticket #2949 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

Add OGR_GEOM_AREA special field

Reported by: dmorissette Owned by: dmorissette
Priority: normal Milestone: 1.7.0
Component: OGR_SF Version: unspecified
Severity: normal Keywords:
Cc: warmerdam, rouault

Description (last modified by dmorissette) (diff)

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

ticket2949.patch Download (2.9 KB) - added by dmorissette 4 years ago.
Patch against SVN trunk that implements support for OGR_GEOM_AREA
ticket2949_v2.patch Download (4.6 KB) - added by rouault 4 years ago.
ticket2949-3.patch Download (3.5 KB) - added by dmorissette 4 years ago.

Change History

Changed 4 years ago by dmorissette

  • description modified (diff)

Changed 4 years ago by dmorissette

Patch against SVN trunk that implements support for OGR_GEOM_AREA

Changed 4 years ago by 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 4 years ago by rouault

Changed 4 years ago by dmorissette

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

Changed 4 years ago by warmerdam

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

Changed 4 years ago by dmorissette

  • status changed from new to assigned

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

Changed 4 years ago by dmorissette

Changed 4 years ago by dmorissette

  • status changed from assigned to closed
  • resolution set to fixed

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

Changed 4 years ago by rouault

Test added in r16793

Changed 4 years ago by 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.