[Gdal-dev] How to Create a Geometry Filter
Frank Warmerdam
warmerdam at pobox.com
Wed Oct 10 17:56:53 EDT 2007
Kent Eschenberg wrote:
> Greetings,
>
> This is a combination complaint/question. I'm trying to use the layer
> classes' geometry filter to select only features in an area bounded by
> 4 points.
>
> I can't do that directly but must use SetSpatialFilter and first create
> an instance of OGRPolygon. I do so and look for a way to set the
> polygon's points.
>
> I can't do that directly but must use addRing and first create an
> instance of OGRLinearRing. I do that and look for a way to set the
> ring's points.
>
> I can't do that directly but must use importFromWkb and first create a
> buffer of "the well known binary data".
Kent,
The convenience function SetSpatialFilterRect() shows the simpliest
approach (in C++) to create a filter polygon with four points.
void OGRLayer::SetSpatialFilterRect( double dfMinX, double dfMinY,
double dfMaxX, double dfMaxY )
{
OGRLinearRing oRing;
OGRPolygon oPoly;
oRing.addPoint( dfMinX, dfMinY );
oRing.addPoint( dfMinX, dfMaxY );
oRing.addPoint( dfMaxX, dfMaxY );
oRing.addPoint( dfMaxX, dfMinY );
oRing.addPoint( dfMinX, dfMinY );
oPoly.addRing( &oRing );
SetSpatialFilter( &oPoly );
}
In short, it is not normal practice to create WKB in programs, since
that is ... not very convenient. It is a useful interchange format
with other systems (ie. postgis).
The OGRLinearRing isn't a "proper" OGC simple features geometry and
so has no corresponding it WKB format. OGRLinearRings are only
allowed to exist in the context of a polygon.
I hope this helps.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
More information about the Gdal-dev
mailing list