Spatial Query error

597
2
Jump to solution
11-15-2012 09:06 PM
InsuHong1
New Contributor
Hi guys

I've got a problem with spatial query.

I generate IGeometry igPairLine and compare it a map boundary (IGeometrybag gbBaseMap) using IRelationalOperator.

The purpose is checking whether a line is within the map boundary or not.

I repeat this process for thousands of thousands lines (literally). But 60 of them were wrong. My code determined they are within the map boundary, but actually not.

I don't know why exact same code make such error for certain cases.

Does anybody know why?


Thank you



                  ISpatialReference sRef;                             ifMerged = fcMerged.GetFeature(1);                             IPoint pt = new PointClass();                             pt = (IPoint)ifMerged.ShapeCopy;                             sRef = pt.SpatialReference;                              IPoint fromPoint = new PointClass();                             IPoint toPoint = new PointClass();                             fromPoint = pcTempPair.get_Point(0);                             toPoint = pcTempPair.get_Point(1);                              IPolyline5 ipPairLine = new PolylineClass();                             ipPairLine.ToPoint = toPoint;                             ipPairLine.FromPoint = fromPoint;                             ipPairLine.Project(sRef);                             IGeometry igPairLine = (IGeometry)ipPairLine;                             IRelationalOperator relOperatore = (IRelationalOperator)gbBaseMap;                             Boolean contain = relOperatore.Contains(igPairLine);
Reply
0 Kudos
1 Solution

Accepted Solutions
DubravkoAntonic
New Contributor III
Seems to me that you have invalid geometry.

Found these features and check if the are Simple
ITopologicalOperator.IsSimple
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/d/002m000003vt000000.htm


ITopologicalOperator.Simplify
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//002m000003w0000000

After Simplify you can set it using ITopologicalOperator2.IsKnownSimple_2
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IsKnownSimple_Property/0...

It should be something like this.
IGeometry igPairLine = (IGeometry)ipPairLine; ITopologicalOperator pTopOp = igPairLine as ITopologicalOperator; pTopOp.Simplify();  IRelationalOperator relOperatore = (IRelationalOperator)gbBaseMap;


If this doesn't help you should set IsKnownSimple to false prior Simplifying.
IGeometry igPairLine = (IGeometry)ipPairLine; ITopologicalOperator2 pTopOp = igPairLine as ITopologicalOperator2; pTopOp.IsKnownSimple_2 = false; pTopOp.Simplify();  IRelationalOperator relOperatore = (IRelationalOperator)gbBaseMap;


Regards, Dubravko

View solution in original post

Reply
0 Kudos
2 Replies
DubravkoAntonic
New Contributor III
Seems to me that you have invalid geometry.

Found these features and check if the are Simple
ITopologicalOperator.IsSimple
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/d/002m000003vt000000.htm


ITopologicalOperator.Simplify
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//002m000003w0000000

After Simplify you can set it using ITopologicalOperator2.IsKnownSimple_2
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IsKnownSimple_Property/0...

It should be something like this.
IGeometry igPairLine = (IGeometry)ipPairLine; ITopologicalOperator pTopOp = igPairLine as ITopologicalOperator; pTopOp.Simplify();  IRelationalOperator relOperatore = (IRelationalOperator)gbBaseMap;


If this doesn't help you should set IsKnownSimple to false prior Simplifying.
IGeometry igPairLine = (IGeometry)ipPairLine; ITopologicalOperator2 pTopOp = igPairLine as ITopologicalOperator2; pTopOp.IsKnownSimple_2 = false; pTopOp.Simplify();  IRelationalOperator relOperatore = (IRelationalOperator)gbBaseMap;


Regards, Dubravko

View solution in original post

Reply
0 Kudos
FridjofSchmidt
Occasional Contributor


                            ISpatialReference sRef;
                            ifMerged = fcMerged.GetFeature(1);
                            IPoint pt = new PointClass();
                            pt = (IPoint)ifMerged.ShapeCopy;
                            sRef = pt.SpatialReference;

                            IPoint fromPoint = new PointClass();
                            IPoint toPoint = new PointClass();
                            fromPoint = pcTempPair.get_Point(0);
                            toPoint = pcTempPair.get_Point(1);

                            IPolyline5 ipPairLine = new PolylineClass();
                            ipPairLine.ToPoint = toPoint;
                            ipPairLine.FromPoint = fromPoint;
                            ipPairLine.Project(sRef);
                            IGeometry igPairLine = (IGeometry)ipPairLine;
                            IRelationalOperator relOperatore = (IRelationalOperator)gbBaseMap;
                            Boolean contain = relOperatore.Contains(igPairLine);


Insu,

It seems that you are projecting the polyline without assigning its spatial reference first. Try to assign sRef to ipPairLine.SpatialReference first and then project it to gbBaseMap.SpatialReference (if required). See if that helps. You might also want to check for ipPairLine.IsEmpty after applying ipPairLine.SnapToSpatialReference() and a Simplify as suggested by Dubravko.

Regards,
Fridjof
Reply
0 Kudos