Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've got a polyline feature class and I've identified the first feature that is a multipart feature. I now want to find out which of the paths of this multipart feature intersects with a point. Up till now I managed to fill a geometry collection with the parts (paths) of the polyline. My method to check for the intersection requires a polyline input. And this is where I'm stuck. How can I convert/cast/? one of the two paths in the geometry collection to a polyline?

Here is some code, but pPolylineCSPart is null:

//right polyline into geometry collection
IGeometryCollection pGeometryCollection = new PolylineClass();
pGeometryCollection = pRightPolyline as IGeometryCollection;
//loop through geometry collection
for (int intPartCount = 0; intPartCount < pGeometryCollection.GeometryCount; intPartCount++)
{
    IPolyline pPolylineCSPart = new PolylineClass();
    //cast polyline part to polyline
    pPolylineCSPart = pGeometryCollection.get_Geometry(intPartCount) as IPolyline;
    //check if part intersects river
    bMultipartIntersectRiver = PolylineIntersectioCheck.Are2PolylinesIntersecting(pPoint, pPolylineCSPart);
    if (bMultipartIntersectRiver)
    {
        pSplitFeat.Shape = pPolylineCSPart;
        SplitCSFClass.CopyAttributes(pTransectSplit, pSplitFeat);
        pSplitFeat.Store();
    }
}

Many Thanks!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You need to wrap individual paths into the higher-level geometries, which is a Polyline. Then you can check for intersection with another geometry.

The most reliable way to wrap a path in a polyline is to:

  1. Create a new instance of Polyline
  2. Cast the original Path as ISegmentCollection
  3. Cast the new Polyline as ISegmentCollection
  4. Add the path's segments to the polyline using ISegmentCollection.AddSegmentCollection

Depending on you scenario you may need to clone the geometries first (see IClone) to create a proper copy.

UPDATE: Not sure why I didn't realize it while writing the above, but as described in the comment, just adding the path (or its clone) to the newly created polyline of course does the trick as well, and is a lot more straightforward.

share|improve this answer
    
Thanks Petr! I had some success in the meanwhile: 1) creating a new instance of a polyline; 2) casting the path in the geometry collection to IPath; 3) casting the new instance of a polyline to a new geometry collection; 4) add the path as geometry to the geometry collection; I would post it as code here but I can't figure out how it works in comments. Anyway, thanks for your solution, I consider it as answered. –  Hubert May 14 '13 at 13:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.