Monday 28 October 2019

arcgis 10.0 - How to determine a point lays within a polyline in arc engine?


I recently asked a similiar question on this, however I needed to know if there is a way to solve this if I only have a IPolyline Feature, and not the whole layer.


I want to know if I can determine if a point lays within my Polyline feature.


I tried using both intersect and difference from ITopologicalOperator, but still no use.


Please Help:


  private bool PointLaysWithinLine(IPolyline currentPath, IPoint iPoint)
{
IPolyline newLine = new PolylineClass();

((IPointCollection)newLine).AddPoint(iPoint);
newLine.Project(currentPath.SpatialReference);

//This doesn't work
IPolyline intersection = ((ITopologicalOperator)currentPath).Intersect(newLine, esriGeometryDimension.esriGeometryNoDimension) as IPolyline;

//This also doesn't work
IPolyline difference = ((ITopologicalOperator)currentPath).Difference(newLine) as IPolyline;

return currentPath.Length != difference.Length;

}

*************************UPDATE*************************


So after playing around for 2 days with user's comments and ideas. I came up with this code (thanks jakub)


point.SpatialReference = IMap.SpatialReference;
ISpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.Geometry = point;
spatialFilter.GeometryField = ((IFeatureLayer)layer).FeatureClass.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor flowPathCursor = ((IFeatureLayer)layer).FeatureClass.Search(spatialFilter, true);


if (flowPathCursor.NextFeature() != null)
result = true;

The above code works for MOST time, however, some rare case it still CANNOT find the feature. Note that I USED snapping (vertices/edges) so it should be dead on.


Also I tried using the slope y=mx+b method, and IIdentify2.Identify. They all work MOST time but some rare case (i notice it happening most often on straight EDGES).


Any one have any idea? This is driving me insane.



Answer



You could use Spatial Filter to query for intersecting features. (Your basic spatial query) Use the ISpatialFilter interface SpatialRel Property. The property takes in a esriSpatialRelEnum constant parameter. To get a cursor of intersecting features you use the esriSpatialRelIntersects constant.


If the returned FeatureCursor contains no features then no intersecting features were found. If the cursor contains more then one feature you can iterate through the features in the cursor and compare the iFeature.OID to find your polyline. You can find detailed information and lot's of C# and VB .Net examples here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_All_Features_from_Point_Search_in_GeoFeatureLayer_Snippet/004900000078000000/



The above should work fine but iHitTest may be a more efficient way to do this. I have suggested this in your last post. Have you tried it?


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...