0

I have a Polyline and a Point FeatureClass. I create a point feature on the Point layer for both the FromPoint and the ToPoint of the IPolyline5 similar to below:

IFeature pointFeature1 = pointFeatureClass.CreateFeature ();
pointFeature1.Shape = polyline.FromPoint;
IFeature pointFeature2 = pointFeatureClass.CreateFeature ();
pointFeature2.Shape = polyline.ToPoint;

Later, I then run both the from point and to point geometries through a method like the below to find all the intersecting polyline features from the polyline feature class.

ISpatialFilter filter = new SpatialFilter ();
filter.Geometry = pointGeometry;
filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor cursor = lineFeatureClass.FeatureClass.Search (filter, false);

At the very least, the intersect filter should find the polyline off which I got the 2 points. The strange thing is, it works for the FromPoint, but not with the ToPoint.

Both feature classes are using the same Geographic Coordinate System and Projected Coordinate System.

I hope I am doing something stupid, but just can't figure out what.

Jacques Bosch
  • 2,165
  • 3
  • 25
  • 36

3 Answers3

0

instead of

pointFeature1.Shape = polyline.FromPoint;

use

PointFeature1.Shape = ((polyline.FromPoint as IPoint) as IFeature).ShapeCopy;

and for

pointFeature2.Shape = polyline.ToPoint;

use

PointFeature1.Shape = ((polyline.ToPoint as IPoint) as IFeature).ShapeCopy;
Raidri
  • 17,258
  • 9
  • 62
  • 65
0

I got it to work consistently with esriSpatialRelIntersects by just buffering the point by 0.001.

Jacques Bosch
  • 2,165
  • 3
  • 25
  • 36
0

When creating new features from existing features, you should not use the direct reference, but the ShapeCopy. Try to change yout first block to:

pointFeature1.Shape = polyline.FromPoint.ShapeCopy;
pointFeature2.Shape = polyline.ToPoint.ShapeCopy;
dr pain
  • 570
  • 1
  • 5
  • 13
  • The thing is that polyline.FromPoint is not an IFeature, it is an IPoint. And the ShapeCopy is defined on IFeature. I get my polyline from IFeature.Shape, and then the FromPoint and ToPoint off the polyLine. Hence, the only place were I can get a ShapeCopy is the polyLine off the original IFeature. So, my question is, do I still have to use ShapeCopy if I am not creating a new feature off my line feature directly, but off the points on my line feature? – Jacques Bosch Feb 08 '12 at 13:14
  • Oops, you are right. Did you try to use PutCoords to set X and Y of the new Points? `pointFeature1.PutCoords(polyline.FromPoint.X, polyline.FromPoint.Y);` – dr pain Feb 10 '12 at 08:29
  • You mean casting pointFeature1.Shape to a IPoint and calling PutCoords on that? Well, I didn't, but I have now. Makes no difference. I don't see how it could make a difference though, as pointFeature1.Shape is already the same instance as polyline.FromPoint. It is in fact the exact same point, not? – Jacques Bosch Feb 10 '12 at 13:10
  • Sorry I forgot to mention that you should not set the reference for the new point to the old point of the polyline. Instead, create a new Point object and call PutCoords on it: `IFeature pointFeature1 = pointFeatureClass.CreateFeature (); var point1 = new PointClass(); point1.PutCoords(polyline.FromPoint.X, polyline.FromPoint.Y); pointFeature1.Shape = (IGeometry)point1` – dr pain Feb 16 '12 at 08:14
  • Ok. Thank you. I just tried that now, but behavior is identical as when I set the point from the polyline directly into the pointFeature.Shape. So, mystery still not solved. :) But I am happy to lay it to rest now. The 0.0001 meter buffer work-around is sufficient for now. Thanx again. – Jacques Bosch Feb 16 '12 at 12:53