[fdo-users] How to Create Spatial Filter

surrounded Rob.Sosnowski at itd.idaho.gov
Thu Oct 2 13:41:10 EDT 2008


Gavin,

With your example you confirmed that the logic is in order, so I guess it's
time to move away from the circle and try other geometries.  The unit tests
have bailed me out a time or two already.    Thanks....




Gavin Cramer wrote:
> 
> The unit tests are a good source of working example code.  It is mostly
> unmanaged C++, but the concepts and most classes/methods have virtually
> the same names.  Here is a snippet:
> 
> SpatialFilterTests::runSpatialQuery( FdoString* class_name,
> FdoSpatialOperations spOp, FdoIPolygon* poly)
> {
>     int count = 0;
> 
>     try
>     {
>         FdoPtr<FdoISelect> select =
> (FdoISelect*)mConnection->CreateCommand(FdoCommandType_Select);
> 
>         select->SetFeatureClassName( class_name );
> 
>         FdoPtr<FdoFgfGeometryFactory> gf =
> FdoFgfGeometryFactory::GetInstance();
> 
>         FdoPtr<FdoByteArray> polyfgf = gf->GetFgf(poly);
>         FdoPtr<FdoGeometryValue> gv = FdoGeometryValue::Create(polyfgf);
> 
>         FdoPtr<FdoSpatialCondition> filter =
> FdoSpatialCondition::Create(L"Geometry", spOp, gv);
> 
>         select->SetFilter(filter);
> 
>         FdoPtr<FdoIFeatureReader> reader = select->Execute();
> 
>         while (reader->ReadNext())
>         {
> ...
> 
> 
> Have you tried a simple rectangle or other polygon instead of a circle? 
> SHP as a datastore does not support circular arcs.  I am not sure whether
> the spatial filtering does, but using regular Polygon instead of a
> CurvePolygon would be a good way to rule that out as a factor.
> 
> Gavin
> 
> 
> -----Original Message-----
> From: fdo-users-bounces at lists.osgeo.org
> [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of surrounded
> Sent: Thursday, October 02, 2008 1:21 PM
> To: fdo-users at lists.osgeo.org
> Subject: [fdo-users] How to Create Spatial Filter
> 
> 
> I am trying to create a filter that will allow me to intersect a circle
> geometry with a shapefile layer, returning only the features from the
> shapefile that meet the intersection criteria.  The following code does
> not
> produce errors, BUT the reader object has no values in it.  PLEASE LET ME
> KNOW WHERE MY LOGIC IS WRONG OR IF YOU HAVE AN EXAMPLE SPATIAL QUERY THAT
> I
> COULD TWEAK TO WORK FOR MY NEEDS.    THANKS .....
> 
> 
> //CREATE CIRCLE GEOMETRY
> FgfGeometryFactory gFac = new FgfGeometryFactory();
> IDirectPosition startPos = gFac.CreatePositionXY(longitude - 1.0,
> latitude);
> IDirectPosition midPos = gFac.CreatePositionXY(longitude, latitude + 1.0);
> IDirectPosition endPos = gFac.CreatePositionXY(longitude - 1.0, latitude);
> ICircularArcSegment pCircleSegs = gFac.CreateCircularArcSegment(startPos,
> midPos, endPos);
> CurveSegmentCollection pCSC = new CurveSegmentCollection();
> pCSC.Add(pCircleSegs);
> IRing pRing = gFac.CreateRing(pCSC);
> RingCollection pRC = new RingCollection();
> pRC.Add(pRing);
> ICurvePolygon pCPoly = gFac.CreateCurvePolygon(pRing, pRC);
> //IEnvelope pEnv = pCPoly.Envelope;
> IGeometry pGeom = gFac.CreateGeometry(pCPoly);
> 
> //CONVERT GEOMETRY INTO BYTE ARRAY TO CREATE FILTER
> byte[] pByte = gFac.GetFgf(pGeom);
> OSGeo.FDO.Expression.GeometryValue pGVal = new GeometryValue(pByte);
> 
> //BUILD THE SPATIAL FILTER
> OSGeo.FDO.Expression.Identifier pPropName = new Identifier("Geometry");
> IdentifierCollection pIDColl = sel.PropertyNames;
> pIDColl.Add(pPropName);
> OSGeo.FDO.Filter.Filter pPtLineFilter = new
> OSGeo.FDO.Filter.SpatialCondition(pPropName,
> OSGeo.FDO.Filter.SpatialOperations.SpatialOperations_Inside, pGVal);
> 
> OSGeo.FDO.Commands.Feature.IFeatureReader reader = sel.Execute();
> while (reader.ReadNext())
> {
>     ....CODE....
> }
> --
> View this message in context:
> http://n2.nabble.com/How-to-Create-Spatial-Filter-tp1134432p1134432.html
> Sent from the FDO Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> 
> 

-- 
View this message in context: http://n2.nabble.com/How-to-Create-Spatial-Filter-tp1134432p1134481.html
Sent from the FDO Users mailing list archive at Nabble.com.



More information about the fdo-users mailing list