Spatial Query Error

328
6
03-13-2013 01:46 PM
InsuHong1
New Contributor
Hello,

I have a serious problem with spatial query in ArcObject.

                    IRelationalOperator relOperInsideBarriers = (IRelationalOperator) fcInsideBarriers
                    IGeometryBag gbTotalConvexPathSplit = fcUtils.getGeoBag(fcTotalConvexPathSplit);
                    if (relOperInsideBarriers.Crosses(gbTotalConvexPathSplit) == false)
                    {
                        Console.WriteLine("Break");

                        break;
                    }


Code is simple. I update featureclass "fcTotalConvexPathSplit" before this codeblck using other operations, then check 'crossing' with fcInsideBarriers.

fcTotalConvexPathSplit is line, and fcInsideBarriers is polygon.

"relOperInsideBarriers.Crosses(gbTotalConvexPathSplit)" is supposed to return false there is no line in fcTotalConvexPathSplit crosses fcInsideBarriers, right?

But, it return false when there are many number of crossings.

I tried to simplify it, like below



                    IGeometryBag gbTotalConvexPathSplit = fcUtils.getGeoBag(fcTotalConvexPathSplit);
                    ITopologicalOperator pTopOp = gbTotalConvexPathSplit as ITopologicalOperator;
                    pTopOp.Simplify();
                    IGeometry igTopo = pTopOp as IGeometry;
                    if (relOperInsideBarriers.Crosses(igTopo) == false)
                    {
                        Console.WriteLine("Break");

                        break;
                    }



But result was same. It makes error.


I also tried to use ISpatialFilter, but it made similar error, though it sometimes could produce right result, but otherwise couldn't.



What's going on here. I cannot figure out what the problem is...



Thank you
Reply
0 Kudos
6 Replies
nicogis
MVP Frequent Contributor
do the geometries cross or intersect ?  If the polyline is contained in polygon the cross return false ( see http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm )
Reply
0 Kudos
InsuHong1
New Contributor
Hi,

No polylines are not contained by any polygon. It cannot be contained, because prior processes. Also, fcTotalcovnexPathSplit contains large number of polylines.

All of polylines intersected (with boundaries of polygons) or crossed. I confirm that in ArcGIS manually.
Reply
0 Kudos
WeifengHe
Occasional Contributor II
Or you can use Disjoint method to double check.

Another thing seems confusing is fcInsideBarriers a feature class or geometry?  IRelationalOperator only works with geometries.
Reply
0 Kudos
InsuHong1
New Contributor
Or you can use Disjoint method to double check.

Another thing seems confusing is fcInsideBarriers a feature class or geometry?  IRelationalOperator only works with geometries.


hi,

I think that part is my mistake. fcIinsideBarrier is featureclass.


But strange thing is, I also tried same job with ISpatialCursor


                    IGeometryBag gbTotalConvexPathSplit = fcUtils.getGeoBag(fcTotalConvexPathSplit);
                    ISpatialFilter sFilter101 = new SpatialFilterClass();
                    sFilter101.Geometry = gbTotalConvexPathSplit;
                    sFilter101.GeometryField = fcInsideBarriers.ShapeFieldName;
                    sFilter101.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
                    Console.WriteLine(fcInsideBarriers.FeatureCount(sFilter101));
                   
                    if (fcInsideBarriers.FeatureCount(sFilter101) == 0)
                    {
                        Console.WriteLine("Break");
                        Console.ReadKey();
                        break;
                    }



but it also made error. Mostly, it worked fine. But after repeating iterations, suddenly spatialcursor said there was no crossing, though actually there were many crossings.

I will try corrected IRelationalOperator. Thank you
Reply
0 Kudos
InsuHong1
New Contributor
Or you can use Disjoint method to double check.

Another thing seems confusing is fcInsideBarriers a feature class or geometry?  IRelationalOperator only works with geometries.


I tried IRelationalOperator again.. but it was failed.


Does IRelationalOperator compatible with IGeometryBag?



                    IGeometryBag gbTotalConvexPathSplit = fcUtils.getGeoBag(fcTotalConvexPathSplit);
                    IRelationalOperator relOper1 = (IRelationalOperator)gbTotalConvexPathSplit;
                    Console.WriteLine(relOper1.Crosses(gbInsideBarriers));
                    if (!relOper1.Crosses(gbInsideBarriers))
                    {
                        Console.WriteLine("break");
                        break;
                    }



I tried like above... gbTotalConvexPathSplit and gbTotalConvexPathSplit is IGeometryBag object.

Even though they are crossed each other, relOper1.Crosses(gbInsideBarriers) return fales at the very first iteration.
Reply
0 Kudos
WeifengHe
Occasional Contributor II
GeometryBag class does implement IRelationalOperator.  To make it work as you expected for now, I'd recommend IRelationalOperatorNxM instead of IRelationalOperator since you are testing 2 geometry bags.
Reply
0 Kudos