private static bool CreateLateralFromMainPoint(ref IApplication app, ref  IEditor editor, IFeature pointFeature,
                                                     IFeatureLayer mainLineFLayer, IFeatureLayer targetLineFLayer, IEditTemplate targetLineEditTemplate,
                                                     List<pointAlongSettings> pointAlongLayers, bool startAtMain, FromToField[] fromToPairs, LateralLine_AngleDetails latDet, bool SearchOnLayer, bool CheckSelection)
        {
            List<IFeature> pointsAlong = new List<IFeature>();

            //IGeometry pGeometry;
            IPolyline polyline;

            //IPoint pToPoint;
            //IPoint pFromPoint;
            //IConstructPoint pConstructPoint;

            UID pId = new UID();

            IFeature pFeat;
            // double pi;
            double dblDegrees;
            double dblAngleRad;
            double dblLateralLength;

            //Find LineAngle field in the layer
            //iLayerLineAngleFieldPos = pFC.FindField(c_sLineAngleFieldName)
            //If iLayerLineAngleFieldPos < 0 Then
            //  MsgBox c_sLineAngleFieldName & " was not found in the highlighted layer.", vbCritical, c_sTitle
            //  Exit Sub
            //End If

            if (targetLineFLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
            { //MsgBox "Edit target must be a polyline layer (i.e. laterals).", vbCritical, c_sTitle
                return false;
            }

            dblDegrees = 90;
            if (!Globals.IsNumeric(latDet.AngleField))
            {
                int fldIdx = Globals.GetFieldIndex(pointFeature.Class.Fields, latDet.AngleField);

                if (fldIdx > -1)
                {

                    string temp = pointFeature.get_Value(fldIdx).ToString();
                    if (Globals.IsNumeric(temp))
                    {
                        Double.TryParse(temp, out dblDegrees);
                    }
                }

            }
            else
            {
                Double.TryParse(latDet.AngleField, out dblDegrees);
            }

            dblLateralLength = 10;
            if (!Globals.IsNumeric(latDet.LengthField))
            {
                int fldIdx = Globals.GetFieldIndex(pointFeature.Class.Fields, latDet.LengthField);

                if (fldIdx > -1)
                {

                    string temp = pointFeature.get_Value(fldIdx).ToString();
                    if (Globals.IsNumeric(temp))
                    {
                        Double.TryParse(temp, out dblLateralLength);
                    }
                }

            }
            else
            {
                Double.TryParse(latDet.LengthField, out dblLateralLength);
            }

            if (latDet.AngleType.ToUpper() == "CLOCK")
            {
                dblAngleRad = Globals.ConvertDegToRads(Globals.ConvertClockPositionToDegrees(dblDegrees));
            }
            else if (latDet.AngleType.ToUpper() == "RADIANS")
                dblAngleRad = Globals.ConvertDegToRads(dblDegrees);
            else
                dblAngleRad = dblDegrees;

            string dirVal = latDet.DirectionField;
            if (dirVal != "")
            {
                int fldIdx = Globals.GetFieldIndex(pointFeature.Class.Fields, dirVal);

                if (fldIdx > -1)
                {

                    dirVal = pointFeature.get_Value(fldIdx).ToString();

                }

            }
            else
            {
                dirVal = "";
            }

            if (dirVal.ToUpper() == latDet.LookingUpstreamValue.ToUpper())
            {
                dblAngleRad = Globals.ConvertDegToRads(Globals.ConvertRadsToDegrees(dblAngleRad) + 180);
            }
            else if (dirVal == latDet.LookingDownstreamValue)
            {

            }
            else
            {

            }

            if (latDet.OnlyPerp.ToUpper() == "TRUE")
            {
                double val = Globals.ConvertRadsToDegrees(dblAngleRad);
                if (val >= 0.0 && val <= 180.0)
                {
                    dblAngleRad = Globals.ConvertDegToRads(90);
                }
                else
                {
                    dblAngleRad = Globals.ConvertDegToRads(270);

                }
            }
            polyline = Globals.CreateAngledLineFromLocationOnLine((IPoint)pointFeature.Shape, mainLineFLayer, SearchOnLayer, dblAngleRad, dblLateralLength, latDet.AddAngleToLineAngle, startAtMain, CheckSelection);
            //Add that line to Laterals lateral
            if (targetLineEditTemplate != null)
            {
                pFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
            }
            else
            {
                pFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
            }
            pFeat.Store();
            if (pointAlongLayers != null)
            {
                foreach (pointAlongSettings pPointAlongLayer in pointAlongLayers)
                {
                    if (pPointAlongLayer.PolygonIntersectLayer != null)
                        pointsAlong.Add(Globals.AddPointAlongLineWithIntersect(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate, pPointAlongLayer.PolygonIntersectLayer, pPointAlongLayer.PolygonIntersectSide));

                    else
                        pointsAlong.Add(Globals.AddPointAlongLine(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate));

                    //   idx++;
                }
            }

            if (pFeat is INetworkFeature)
            {
                INetworkFeature pNF = (INetworkFeature)pFeat;
                pNF.CreateNetworkElements();
                //pNF.Connect();

            }

            return true;
        }
        private static void StorePipeInfoPointFeature(IFeature lineFeature, IFeature pointFeature, FromToField[] fromToPairs, bool store)
        {
            try
            {

                if (fromToPairs == null)
                {

                    return;

                }

                if (fromToPairs.Length == 0)
                {

                    return;

                }
                if (pointFeature == null)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_8"));
                    return;

                }
                foreach (FromToField frmTo in fromToPairs)
                {
                    int pointFieldToCalc = pointFeature.Fields.FindField(frmTo.TargetField);
                    int matchFieldForCalc = lineFeature.Fields.FindField(frmTo.SourceField);
                    if (pointFieldToCalc > -1 && matchFieldForCalc > -1)
                    {
                        if (pointFeature.Fields.get_Field(pointFieldToCalc).Type == esriFieldType.esriFieldTypeString)
                            pointFeature.set_Value(pointFieldToCalc, frmTo.Prefix + lineFeature.get_Value(matchFieldForCalc).ToString());
                        else
                            pointFeature.set_Value(pointFieldToCalc, lineFeature.get_Value(matchFieldForCalc));

                    }

                }
                if (store)
                {
                    pointFeature.Store();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_9") + ex.Message);

            }
        }
        private static bool CreateDual(ref IApplication app, ref  IEditor editor, IFeature pointFeature, IFeature pointFeature2, ILine distanceLine,
                                                          IFeatureLayer matchLineFLayer,
                                                          IFeatureLayer targetLineFLayer, IEditTemplate targetLineEditTemplate,
                                                          List<pointAlongSettings> pointAlongLayers,
                                                          bool deleteExistingLines, bool startAtMain, bool squareDualLines,
                                                         FromToField[] fromToPairs, double doglegDistance, bool DistAsPercent, double tolerenceForDelete, bool store, bool SearchOnLayer, int searchDistance, double angle, bool checkSelection)
        {
            IPoint point = null;
            IPoint point2 = null;
            IPoint turnPoint = null;
            IPoint toPoint = null;
            IPoint joinPoint = null;
            IPoint sqPoint1 = null;
            IPoint sqPoint2 = null;
            IPoint midPoint = null;
            IFeature lineFeature = null;
            IPolyline polyline = null;
            IFeature pLineFeat = null;
            ICurve mainCurve = null;
            try
            {
                point = (IPoint)pointFeature.Shape;
                point2 = (IPoint)pointFeature2.Shape;

                //Determine mid point
                midPoint = new PointClass();
                distanceLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, midPoint);

                // Get closest main to midpoint (if a single main was not selected)

                lineFeature = Globals.GetClosestFeature(midPoint, matchLineFLayer, Convert.ToDouble(searchDistance), SearchOnLayer, checkSelection);

                if (lineFeature != null)
                {
                    //Delete any existing lateral lines at these locations
                    if (deleteExistingLines)
                    {
                        DeleteExistingFeatures(pointFeature, targetLineFLayer, pointAlongLayers, tolerenceForDelete);
                        DeleteExistingFeatures(pointFeature2, targetLineFLayer, pointAlongLayers, tolerenceForDelete);
                    }

                    //Determine To and Turn Points (and possible square points)
                    mainCurve = lineFeature.ShapeCopy as ICurve;
                    CreateToAndTurnPointsDual(mainCurve, midPoint, distanceLine, out toPoint, out turnPoint,
                                                            out joinPoint, out  sqPoint1, out  sqPoint2, doglegDistance, DistAsPercent,
                                                            squareDualLines, tolerenceForDelete);

                    //Create the new base line (possibly hooked)

                    polyline = Globals.CreatePolylineFromPointsNewTurn(joinPoint, turnPoint, toPoint, ref matchLineFLayer, ref lineFeature, SearchOnLayer, angle,editor.Map.SpatialReference);

                    //If requested, store pipe id in the point
                    StorePipeInfoPointFeature(lineFeature, pointFeature, fromToPairs, store);
                    StorePipeInfoPointFeature(lineFeature, pointFeature2, fromToPairs, store);

                    if (polyline.Length != 0.0)
                    {
                        if (startAtMain)
                            polyline.ReverseOrientation();

                        if (targetLineEditTemplate != null)
                        {
                            pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                        }
                        else
                        {
                            pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                        }

                        pLineFeat.Store();

                        // Globals.SetFlowDirection(pLineFeat, targetLineFLayer, ((IMxDocument)app.Document).FocusMap);
                        if (pointAlongLayers != null)
                        {
                            foreach (pointAlongSettings pPointAlongLayer in pointAlongLayers)
                            {
                                if (pPointAlongLayer.PolygonIntersectLayer != null)
                                    Globals.AddPointAlongLineWithIntersect(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate, pPointAlongLayer.PolygonIntersectLayer, pPointAlongLayer.PolygonIntersectSide);

                                else
                                    Globals.AddPointAlongLine(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate);

                            }
                        }

                        if (squareDualLines)
                        {
                            //Create Arm 1
                            polyline = Globals.CreatePolylineFromPoints(point, sqPoint1, joinPoint);
                            if (startAtMain)
                                polyline.ReverseOrientation();

                            if (targetLineEditTemplate != null)
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                            }
                            else
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                            }
                            // Globals.SetFlowDirection(pLineFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                            //Create Arm 2
                            polyline = Globals.CreatePolylineFromPoints(point2, sqPoint2, joinPoint);
                            if (startAtMain)
                                polyline.ReverseOrientation();
                            pLineFeat.Store();

                            if (targetLineEditTemplate != null)
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                            }
                            else
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                            }

                            // Globals.SetFlowDirection(pLineFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                            pLineFeat.Store();

                            return true;
                        }
                        else
                        {

                            //Create Arm 1
                            polyline = Globals.CreatePolylineFromPoints(point, joinPoint);
                            if (startAtMain)
                                polyline.ReverseOrientation();

                            if (targetLineEditTemplate != null)
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                            }
                            else
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                            }
                            // Globals.SetFlowDirection(pLineFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                            //Create Arm 2
                            polyline = Globals.CreatePolylineFromPoints(point2, joinPoint);
                            if (startAtMain)
                                polyline.ReverseOrientation();
                            pLineFeat.Store();

                            if (targetLineEditTemplate != null)
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                            }
                            else
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                            }
                            //idx = 0;
                            //  Globals.SetFlowDirection(pLineFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                            pLineFeat.Store();

                            return true;

                        }
                    }
                    else
                    {
                        //Create branch 1
                        polyline = Globals.CreatePolylineFromPoints(point, joinPoint);
                        if (polyline.Length != 0.0)
                        {
                            if (startAtMain)
                                polyline.ReverseOrientation();

                            if (targetLineEditTemplate != null)
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                            }
                            else
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                            }

                            //  Globals.SetFlowDirection(pLineFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                            pLineFeat.Store();

                            if (pointAlongLayers != null)
                            {
                                foreach (pointAlongSettings pPointAlongLayer in pointAlongLayers)
                                {
                                    Globals.AddPointAlongLine(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate);
                                    //   idx++;
                                }
                            }

                            //Create branch 2
                            polyline = Globals.CreatePolylineFromPoints(point2, joinPoint);
                            if (startAtMain)
                                polyline.ReverseOrientation();

                            if (targetLineEditTemplate != null)
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                            }
                            else
                            {
                                pLineFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                            }

                            //  Globals.SetFlowDirection(pLineFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                            pLineFeat.Store();

                            if (pointAlongLayers != null)
                            {
                                foreach (pointAlongSettings pPointAlongLayer in pointAlongLayers)
                                {
                                    Globals.AddPointAlongLine(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate);
                                    //   idx++;
                                }
                            }

                            return true;
                        }
                        else
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_6"));
                            return false;

                        }
                    }
                }
                else
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_7"));
                    return false;

                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("ConstructionToolsLbl_4") + "\n" + ex.Message, ex.Source);
                return false;
            }

            finally
            {
                point = null;
                point2 = null;
                turnPoint = null;
                toPoint = null;
                joinPoint = null;
                sqPoint1 = null;
                sqPoint2 = null;
                midPoint = null;
                lineFeature = null;
                polyline = null;
                pLineFeat = null;
                mainCurve = null;
            }
        }
        private static bool CreateSingle(ref IApplication app, ref  IEditor editor, IFeature pointFeature, IFeatureLayer matchLineFLayer,
                                                  IFeatureLayer targetLineFLayer, IEditTemplate targetLineEditTemplate,
                                                  List<pointAlongSettings> pointAlongLayers,
                                                  bool startAtMain, bool deleteExistingLines, FromToField[] fromToPairs, double doglegDistance,
                                                  bool DistAsPercent, double tolerenceForDelete, bool store, bool SearchOnLayer, int searchDistance, double angle, bool checkSelection)
        {
            IFeature lineFeature = null;
            IPoint thisPoint = null;
            IPoint turnPoint = null;
            IPoint toPoint = null;
            ICurve mainCurve = null;
            IPolyline polyline = null;
            IFeature pFeat = null;
            try
            {
                // Get closest main to point1

                thisPoint = (IPoint)pointFeature.ShapeCopy;

                lineFeature = Globals.GetClosestFeature(thisPoint, matchLineFLayer, Convert.ToDouble(searchDistance), SearchOnLayer, checkSelection);
                //    (_app.Document as IMxDocument).FocusMap.ClearSelection();

                if (lineFeature != null)
                {
                    //Delete any existing lateral lines at this location
                    if (deleteExistingLines)
                    {
                        DeleteExistingFeatures(pointFeature, targetLineFLayer, pointAlongLayers, tolerenceForDelete);
                    }

                    //Determine To and Turn Points
                    mainCurve = lineFeature.ShapeCopy as ICurve;
                    CreateToAndTurnPoints(mainCurve, thisPoint, out toPoint, out turnPoint, doglegDistance, DistAsPercent);

                    //Create the new line
                    polyline = Globals.CreatePolylineFromPointsNewTurn(thisPoint, turnPoint, toPoint, ref matchLineFLayer, ref lineFeature, SearchOnLayer, angle, editor.Map.SpatialReference);
                    //If requested, store pipe id in the point
                    StorePipeInfoPointFeature(lineFeature, pointFeature, fromToPairs, store);

                    if (polyline.Length > 0)
                    {
                        if (startAtMain)
                            polyline.ReverseOrientation();

                        if (targetLineEditTemplate != null)
                        {
                            pFeat = Globals.CreateFeature(polyline as IGeometry, targetLineEditTemplate, editor, app, false, false, true);
                        }
                        else
                        {
                            pFeat = Globals.CreateFeature(polyline as IGeometry, targetLineFLayer, editor, app, false, false, true);
                        }
                        if (pFeat == null)
                        {
                            editor.AbortOperation();
                            return false;

                        }
                        //Globals.SetFlowDirection(pFeat, targetLineFLayer);
                        try
                        {
                            if (pFeat != null)
                            {
                                Globals.ValidateFeature(pFeat);
                                pFeat.Store();
                            }
                            //if (pFeat is INetworkFeature)
                            //{
                            //    INetworkFeature pNF = (INetworkFeature)pFeat;

                            //    pNF.Connect();
                            //}
                        }
                        catch (Exception ex)
                        {
                            // MessageBox.Show("The Feature could not be stored, this is typically because the layer has Z and the geometric network was not created to honors, you need to drop the network and recreate it with Z's enabled\n" + ex.Message);
                        }

                        //Old Way
                        //IFeature pFeat = CreateLineFeature(targetLineFLayer, newPolyLine, targetLineValue, targetLineFieldName, targetLineSubtype);

                        //Optionally, create new point along line
                        // int idx = 0;
                        if (pointAlongLayers != null)
                        {
                            foreach (pointAlongSettings pPointAlongLayer in pointAlongLayers)
                            {
                                if (pPointAlongLayer.PolygonIntersectLayer != null)
                                    Globals.AddPointAlongLineWithIntersect(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate, pPointAlongLayer.PolygonIntersectLayer, pPointAlongLayer.PolygonIntersectSide);

                                else
                                    Globals.AddPointAlongLine(ref app, ref editor, polyline as ICurve, pPointAlongLayer.PointAlongLayer, pPointAlongLayer.PointAlongDistance, pPointAlongLayer.DistanceIsPercent, pPointAlongLayer.PointAlongEditTemplate);
                                //   idx++;
                            }
                        }

                        //Globals.SetFlowDirection(pFeat, targetLineFLayer,((IMxDocument)app.Document).FocusMap);
                        //try
                        //{
                        //    if (pFeat != null)
                        //    {
                        //      //  Globals.ValidateFeature(pFeat);
                        //        pFeat.Store();
                        //    }
                        //    //if (pFeat is INetworkFeature)
                        //    //{
                        //    //    INetworkFeature pNF = (INetworkFeature)pFeat;

                        //    //    pNF.Connect();
                        //    //}
                        //}
                        //catch (Exception ex)
                        //{
                        //    // MessageBox.Show("The Feature could not be stored, this is typically because the layer has Z and the geometric network was not created to honors, you need to drop the network and recreate it with Z's enabled\n" + ex.Message);
                        //}
                        return true;
                        //AddPointAlongLine(newPolyLine as ICurve, targetPointFLayer, targetPointDistance, targetPointDistanceIsPercent, targetPointSubtype, targetPointValue, targetPointFieldName);
                    }
                    else
                    {
                        MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_6"));
                        return false;

                    }
                }
                else
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_5a") + matchLineFLayer.Name + A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_5b") + searchDistance + A4LGSharedFunctions.Localizer.GetString("ConstructionToolsError_5c"));

                    return false;

                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("ConstructionToolsLbl_3") + "\n" + ex.Message, ex.Source);
                return false;
            }

            finally
            {
                lineFeature = null;
                thisPoint = null;
                turnPoint = null;
                toPoint = null;
                mainCurve = null;
                polyline = null;
                pFeat = null;
            }
        }
        private static void StorePipeInfoPointFeature(IFeature lineFeature, IFeature pointFeature, FromToField[] fromToPairs, bool store)
        {
            try
            {

                if (fromToPairs == null)
                {

                    return;

                }

                if (fromToPairs.Length == 0)
                {

                    return;

                }
                if (pointFeature == null)
                {
                    MessageBox.Show("The Point Along feature class was not found");
                    return;

                }
                foreach (FromToField frmTo in fromToPairs)
                {
                    int pointFieldToCalc = pointFeature.Fields.FindField(frmTo.TargetField);
                    int matchFieldForCalc = lineFeature.Fields.FindField(frmTo.SourceField);
                    if (pointFieldToCalc > -1 && matchFieldForCalc > -1)
                    {
                        if (pointFeature.Fields.get_Field(pointFieldToCalc).Type == esriFieldType.esriFieldTypeString)
                            pointFeature.set_Value(pointFieldToCalc, frmTo.Prefix + lineFeature.get_Value(matchFieldForCalc).ToString());
                        else
                            pointFeature.set_Value(pointFieldToCalc, lineFeature.get_Value(matchFieldForCalc));

                    }

                }
                if (store)
                {
                    pointFeature.Store();

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error trying to store the ID of the pipe on the feature\r\n" + ex.Message);

            }
        }