[GIS] How to create perpendicular line from point on one line to an intersection with the nearest polygon layer

arcgis-10.0linear-referencingpolyline-creation

I am trying to create laterals from a layer of sewer mainlines and have yet to Google a thoroughly helpful answer. Hoping to find some help here.

I have a layer of mainlines that have a direction associated with them pointing from upstream to downstream. I have tabular data that represents the intersection of a lateral line with the mainline. It has the ID of the mainline, the distance from the upstream manhole where it intersects and the side of the mainline that it is on (numbers 0-12, directly downstream being 0/12 or directly upstream being 6, 7-11 being to the left of the downstream direction of the line). I need to create perpendicular lines from these intersection points to the nearest polygon in my parcel layer and extend that lateral line 2 feet into the parcel. I also need to add that parcel number to the lateral in my attribute table and label the laterals ID_1, ID_2, ID_3, etc. on each mainline.

So far in ArcMap 10.0 sp4 ArcInfo license, I have created a set of points representing those intersections on the mainline. With Linear Referencing, I created routes out of the mainlines and then made an event layer of lateral lines using the distance from the "zero" measure of the mainline. Now I'm stuck. How do I make perpendicular lines on the correct side of the mainline for these 45k laterals to cross 2 feet into the nearest parcel polygon?

Best Answer

Here's some pseudo code with notes for the arcobjects interfaces you could use. I've made this community wiki since I don't have time to go into details.

Foreach lateral
    // use IFeatureClass.Search with queryfilter
    mainline = findmainlinebyid(lateral.mainid)
    // use IMSegmentation2.GetPointsatM
    point1 = mseg.Getpoint(lateral.measure)
    // use ICurve.QueryNormal
    polyline1 = constructperpendicular(point1,mainline,length)
    // use IFeatureclass.Search with spatialfilter
    listofparcels = getintersectedparcels(polyline1)
    // loop through each parcel calling IProximityOperator.ReturnDistance
    closestparcel = getclosestparcel(point1,listofparcels)
    // use ITopologicalOperator.Intersect
    multipoint = getcrossingpoint(closestparcel,polyline1)
    // use IproximityOperator.Return distance to get closest point
    point2 = getclosestpoint(multipoint,point1)
    // use ipointcollection to create a polyline
    polyline2 = makepolyline(point1,point2)
    // use ICurve.QueryPoint with distance of 2
    polyline3 = ExtendPolyline(polyline2, 2)
    // use IFeatureClass.CreateFeature(), store
    WriteFeature(polyline3,lateral.mainid)
next lateral