Problem with create new ILine or IPolyLine

2156
3
Jump to solution
06-22-2012 12:13 PM
InsuHong1
New Contributor
Hello,

I'm trying to create polyline object and then want to do some geoprocessing with that polyline with other featureclass.

this is process

1. Create point object from other IFeatureClass object by select by attribute
                        IGeometry geo = new MultipointClass();                         IPointCollection5 mtpCollection = geo as IPointCollection5;                          ISpatialFilter sFilter1 = new SpatialFilterClass();                         sFilter1.GeometryField = fcMerged.ShapeFieldName;                         sFilter1.WhereClause = "id_f = '" + tempPair.getOri + "' OR id_f = '" + tempPair.getDes + "'";                         IFeatureCursor curMerged3 = fcMerged.Search(sFilter1, false);                         IFeature ifMerged = null;                         while ((ifMerged = curMerged3.NextFeature()) != null)                         {                             IPoint ptIn = new PointClass();                             ptIn = (IPoint)ifMerged.ShapeCopy;                             mtpCollection.AddPoint(ptIn);                         } 



2. Create ILine or IPolyline from Point (1) : ilPairLine

                        IPoint fromPoint = new PointClass();                         IPoint toPoint = new PointClass();                         fromPoint = mtpCollection.get_Point(0);                         toPoint = mtpCollection.get_Point(1);                         ILine ilPairLine = new LineClass();                         ilPairLine.FromPoint = fromPoint;                         ilPairLine.ToPoint = toPoint;



3. Do some operation like this: (fcBoundary is Ifeatureclass Polygon)

                        IFeature ifBaseMap = fcBoundary.GetFeature(1);                          IGeometry igPairLine = (IGeometry)ilPairLine;                         IGeometry igBaseMap = ifBaseMap.Shape;                          IRelationalOperator relOperatore = (IRelationalOperator)igBaseMap;                         Boolean contain = relOperatore.Contains(igPairLine);                                                  if (contain)                         {                             vgDict[tempPair] = Convert.ToDouble(ilPairLine.Length.ToString());                             Console.WriteLine("contained: {0}",vgDict[tempPair]);                         } 




with above codes, operation was failed.

What's the problem?

I need to make polyline from give two points, and then with that line need to do several geoprocessing.

Currently, I create IFeatureClass line using geoprocessing tool 'Create line from points', but calling geoprocessing object is to slow.

So I want to use ILine or IPolyline for newly generated line for my process. I can make line object, but that line can be applied to other operation like spatialFilter or TopologicalOperator.


Thnks.
0 Kudos
1 Solution

Accepted Solutions
WeifengHe
Esri Contributor
IRelationalOperator does not support ILine as input geometry, but it takes IPolyline.  So in your code, try create a polyline using ISegmentCollection or IPointCollection.

View solution in original post

0 Kudos
3 Replies
BenGilles1
New Contributor
Could try something like this:

var wksPoint = new WKSPointZ[2];
wksPoint[0].X = fromPoint.X;
wksPoint[0].Y = fromPoint.Y;
wksPoint[0].Z = 0;
wksPoint[1].X = toPoint.X;
wksPoint[1].Y = toPoint.Y;
wksPoint[1].Z = 0;
            

var pointCollection = new PolylineClass();
IGeometryBridge2 geometryBridge = new GeometryEnvironmentClass();
geometryBridge.AddWKSPointZs(pointCollection, ref wksPoint);
var polyline = (IPolyline6)pointCollection;
0 Kudos
WeifengHe
Esri Contributor
IRelationalOperator does not support ILine as input geometry, but it takes IPolyline.  So in your code, try create a polyline using ISegmentCollection or IPointCollection.
0 Kudos
InsuHong1
New Contributor
Thank you guys!
0 Kudos