/// <summary>
 /// 计算延长线上的距离
 /// </summary>
 /// <params name="startP"></params>
 /// <params name="endP"></params>
 /// <params name="jjcd"></params>
 /// <returns></returns>
 public IPoint CalculateExtendPointNew(IPolyline plin, IPoint pntTo, double jjcd, out bool bres)
 {
     bres = false;
     IPoint pntOut = new PointClass();
     double distfrom = 0.0, distto = 0.0;
     double outdistfrom = 0.0, outdistto = 0.0;
     bool boolfrom = false;
     plin.QueryPointAndDistance(esriSegmentExtension.esriExtendAtFrom, pntTo, false, pntOut, ref distfrom, ref outdistfrom, ref boolfrom);
     plin.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pntTo, false, pntOut, ref distto, ref outdistto, ref boolfrom);
     if (distfrom < distto)//反向的
     {
         bres = true;
         plin.ReverseOrientation();
         plin.QueryPoint(esriSegmentExtension.esriExtendAtTo, jjcd + plin.Length, false, pntOut);
     }
     else//正向
     {
         bres = false;
         plin.QueryPoint(esriSegmentExtension.esriExtendAtTo, jjcd + plin.Length, false, pntOut);
     }
     return pntOut;
 }
        private IPolygon FlatBuffer(IPolyline pLline1, double pBufferDis)
        {
            object o = System.Type.Missing;
            //分别对输入的线平移两次(正方向和负方向)
            IConstructCurve pCurve1 = new PolylineClass();

            pCurve1.ConstructOffset(pLline1, pBufferDis, ref o, ref o);
            IPointCollection pCol    = pCurve1 as IPointCollection;
            IConstructCurve  pCurve2 = new PolylineClass();

            pCurve2.ConstructOffset(pLline1, -1 * pBufferDis, ref o, ref o);
            //把第二次平移的线的所有节点翻转
            IPolyline pline2 = pCurve2 as IPolyline;

            pline2.ReverseOrientation();
            //把第二条的所有节点放到第一条线的IPointCollection里面
            IPointCollection pCol2 = pline2 as IPointCollection;

            pCol.AddPointCollection(pCol2);
            //用面去初始化一个IPointCollection
            IPointCollection pPointCol = new PolygonClass();

            pPointCol.AddPointCollection(pCol);
            //把IPointCollection转换为面
            IPolygon pPolygon = pPointCol as IPolygon;

            //简化节点次序
            pPolygon.SimplifyPreserveFromTo();
            return(pPolygon);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建区间线段
        /// </summary>
        /// <param name="pLine">输入的线图形</param>
        /// <param name="p1">插入的其中一个点</param>
        /// <param name="p2">插入的一种一个点</param>
        /// <returns>这两点间的线段</returns>
        /// 创建人 : zw
        private IPolyline BuildLine(IPolyline pLine, IPoint p1, IPoint p2, Boolean Reverse)
        {
            if (Reverse)
            {
                pLine.ReverseOrientation();
            }
            bool isSplit;
            int  splitIndex, segIndex;

            //插入第一点,segIndex记录插入点的相对线的节点位置
            pLine.SplitAtPoint(p1, true, false, out isSplit, out splitIndex, out segIndex);
            int fIndex = segIndex;

            //插入第二点
            pLine.SplitAtPoint(p2, true, false, out isSplit, out splitIndex, out segIndex);
            int sIndex = segIndex;

            //比较一下插入第一点和第二点的节点次序
            if (fIndex > sIndex)
            {
                int temp = fIndex;
                fIndex = sIndex;
                sIndex = temp;
            }
            IPointCollection pPointCol = new PolylineClass();
            object           o         = Type.Missing;
            //利用两点区间,获取线上区间所在的点,并将其转换为线
            IPointCollection LineCol = pLine as IPointCollection;

            for (int i = fIndex; i <= sIndex; i++)
            {
                pPointCol.AddPoint(LineCol.get_Point(i), ref o, ref o);
            }
            return(pPointCol as IPolyline);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 判断pline的frompoint 在pnt1和 pnt2组成的线的哪一侧
        /// </summary>
        /// <params name="pnt1"></params>
        /// <params name="pnt2"></params>
        /// <params name="pline"></params>
        /// <returns>返回与回采方向相同的巷道线 </returns>
        private IPolyline GetPointPos(IPoint pnt1, IPoint pnt2, IPolyline pline, int iDirect)
        {
            IPoint pntstart = pline.FromPoint;

            if (pntstart == pnt1) //pline 起点与pnt1相同
            {
                return(pline);
            }
            else if (pline.ToPoint == pnt1) //pline 终点与pnt1相同
            {
                pline.ReverseOrientation();
                //return pline;
            }
            else //非切眼状态
            {
                //(p2-p0)*(p1-p0)>0 则p0p1在p1点拐向右侧得到p1p2,(p2-p0)*(p1-p0)<0 则p0p1在p1点拐向左侧得到p1p2, p1为共同点
                IPoint p1p0 = new PointClass();
                //p1-p0
                p1p0.X = pnt1.X - pnt2.X;
                p1p0.Y = pnt1.Y - pnt2.Y;
                IPoint p2p0 = new PointClass();
                //p2-p0
                p2p0.X = pntstart.X - pnt2.X;
                p2p0.Y = pntstart.Y - pnt2.Y;
                //(p2-p0)*(p1-p0)
                double newrel = p2p0.X * p1p0.Y - p1p0.X * p2p0.Y;
                if (newrel > 0)  //frompoint 在切眼右侧
                {
                    if (iDirect == -1)
                    {
                        pline.ReverseOrientation();
                    }
                }
                else if (newrel < 0) //frompoint 在切眼左侧
                {
                    if (iDirect == 1)
                    {
                        pline.ReverseOrientation();
                    }
                    //return pline;
                }
            }
            return(pline);
        }
Ejemplo n.º 5
0
        private static bool ValidateFlowDirection(
            [NotNull] IFeature feature,
            [NotNull] ILinearNetworkFeatureFinder featureFinder,
            [NotNull] NotificationCollection notifications)
        {
            if (((IFeatureClass)feature.Class).ShapeType != esriGeometryType.esriGeometryPolyline)
            {
                return(true);
            }

            IGeometry newGeometry = feature.Shape;

            IPolyline polyline = (IPolyline)newGeometry;

            bool hasCorrectOrientation = false;
            bool hasWrongOrientation   = false;
            int  fromEdgeCount         = ValidateConnections(feature, LineEnd.From, featureFinder,
                                                             ref hasCorrectOrientation,
                                                             ref hasWrongOrientation);

            int toEdgeCount = ValidateConnections(feature, LineEnd.To, featureFinder,
                                                  ref hasCorrectOrientation,
                                                  ref hasWrongOrientation);

            if (!hasWrongOrientation)
            {
                return(true);
            }

            if (!hasCorrectOrientation)
            {
                // all other connections are different -> flip
                polyline.ReverseOrientation();
                feature.Shape = polyline;
                feature.Store();

                _msg.InfoFormat("Feature {0} was flipped to enforce flow direction",
                                GdbObjectUtils.ToString(feature));
                return(true);
            }

            // Mixed situation:
            if (fromEdgeCount <= 1 && toEdgeCount <= 1)
            {
                // No bifurcation or confluence but still incorrect at one end -> error?
                NotificationUtils.Add(notifications,
                                      "Feature {0} does not have a consistent flow direction with respect to its connected edges",
                                      GdbObjectUtils.ToString(feature));
                return(false);
            }

            // Confluence or bifurcation -> probably ok
            return(true);
        }
        private static void EnsureOrientation([NotNull] IPolyline original,
                                              [NotNull] IPolyline prolonged)
        {
            if (GeometryUtils.AreEqualInXY(original.FromPoint, prolonged.FromPoint) ||
                GeometryUtils.AreEqualInXY(original.ToPoint, prolonged.ToPoint))
            {
                return;
            }

            // otherwise we need flipping
            prolonged.ReverseOrientation();
            ((ISegmentCollection)prolonged).SegmentsChanged();

            Assert.True(GeometryUtils.AreEqualInXY(original.FromPoint, prolonged.FromPoint) ||
                        GeometryUtils.AreEqualInXY(original.ToPoint, prolonged.ToPoint),
                        "Unexpected geometry after reshape. One end must stay stable.");
        }
Ejemplo n.º 7
0
        //���ݶ���ߺͷ������鴴���߳�����
        public static void ProfileCreateGraph(AxMapControl ppAxMapControl, IPolyline pPolyline, IArray pSewerElevArray)
        {
            IZ pPolylineZ = pPolyline as IZ;
            IRasterLayer pRasterLyr = FindRasterLayer("Elevation", ppAxMapControl);
            //��ñ�����в�ֵ
            ISurface pSurface = GetSurface(pRasterLyr);
            //����Polyline z-ware;
            IZAware pZAwareLineZ = pPolyline as IZAware;
            pZAwareLineZ.ZAware = true;
            //'* work around for InterpolateFromSurface sometimes flipping polyline
            IPoint pPtOrigFrom = pPolyline.FromPoint;
            IPoint pPtOrigTo = pPolyline.ToPoint;
            //���Zֵ���������
            pPolylineZ.InterpolateFromSurface(pSurface);
            if (pPolyline.FromPoint.X != pPtOrigFrom.X || pPolyline.FromPoint.Y != pPtOrigFrom.Y)
                pPolyline.ReverseOrientation();
            //���Mֵ������
            IMSegmentation pMSegmentation = pPolyline as IMSegmentation;
            IMAware pMAware = pPolyline as IMAware;
            pMAware.MAware = true;
            pMSegmentation.SetMsAsDistance(false);
            //�������
            ITable pTable = ProfileCreateTable();
            int i = 0;
            if (pTable != null)
            {
                //��ͼ���б�ؼ���Ҫȷ���ñ�񻹲����ڣ����������ɾ����
                IStandaloneTableCollection pStandAloneTabColl = ppAxMapControl.ActiveView.FocusMap as IStandaloneTableCollection;
                for (i = 0; i <= pStandAloneTabColl.StandaloneTableCount - 1; i++)
                {
                    if (pStandAloneTabColl.get_StandaloneTable(i).Name == "xxprofiletable")
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.get_StandaloneTable(i));
                }
                //����һ���µĶ��������������ӵ���ͼ������
                IStandaloneTable pStandAloneTab = new StandaloneTableClass();
                pStandAloneTab.Table = pTable;
                pStandAloneTabColl = ppAxMapControl.ActiveView.FocusMap as IStandaloneTableCollection;
                pStandAloneTabColl.AddStandaloneTable(pStandAloneTab);
                pTable = pStandAloneTab as ITable;
                //Ϊ�����ֶ����ñ���
                ITableFields pTableFields = pStandAloneTab as ITableFields;
                IFieldInfo pFieldInfo = pTableFields.get_FieldInfo(pTableFields.FindField("Z"));
                pFieldInfo.Alias = "Ground Elevation";
                pFieldInfo = pTableFields.get_FieldInfo(pTableFields.FindField("SewerElev"));
                pFieldInfo.Alias = "Sewer Line Elevation";
                //Ϊ�����һ��������
                ICursor pCursor = pTable.Insert(true);
                IRowBuffer pRowBuff;
                //
                IPointCollection pPtCollection = pPolyline as IPointCollection;
                IEnumVertex pEnumVertex = pPtCollection.EnumVertices;
                pEnumVertex.Reset();
                IPoint pPT;
                int iPartIndex;
                int iVertexIndex;
                i = 0;
                //��ӽڵ�XYZ���±����
                pEnumVertex.Next(out pPT, out iPartIndex, out iVertexIndex);
                while (pPT != null)
                {
                    pRowBuff = pTable.CreateRowBuffer();
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("X"), pPT.X);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("Y"), pPT.Y);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("Z"), pPT.Z);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("M"), pPT.M);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("SewerElev"), Convert.ToDouble(pSewerElevArray.get_Element(i)));
                    pCursor.InsertRow(pRowBuff);
                    pEnumVertex.Next(out pPT, out iPartIndex, out iVertexIndex);
                    i = i + 1;
                }
                pCursor.Flush();
                pCursor = null;
                pCursor = pTable.Search(null, false);
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "SewerElev <> -99";
                ICursor pCursorSewerElev = pTable.Search(pQueryFilter, false);

                pCursor = null;
                pCursor = pTable.Update(null, false);
                pRowBuff = pCursor.NextRow();
                double m = 0;
                double Mmin = 0;
                double Mmax = 0;
                double deltaM = 0;
                double deltaSewerElev = 0;
                double sewerelev = 0;
                double newZ = 0;
                int j = 0;
                double minSewerElev = 0;
                double maxSewerElev = 0;
                IRow pRowSewerElev;
                while (pRowBuff != null)
                {
                    if (Convert.ToDouble(pRowBuff.get_Value(pRowBuff.Fields.FindField("SewerElev"))) == -99)
                    {
                        m = Convert.ToDouble(pRowBuff.get_Value(pRowBuff.Fields.FindField("M")));
                        newZ = (((m - Mmin) / deltaM) * deltaSewerElev) + sewerelev;
                        pRowBuff.set_Value(pRowBuff.Fields.FindField("SewerElev"), newZ);
                        pCursor.UpdateRow(pRowBuff as IRow);
                    }
                    else
                    {
                        if (j == 0)
                        {
                            pRowSewerElev = pCursorSewerElev.NextRow();
                            minSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev")));
                            Mmin = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                            pRowSewerElev = pCursorSewerElev.NextRow();
                            maxSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev")));
                            Mmax = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                        }
                        else
                        {
                            pRowSewerElev = pCursorSewerElev.NextRow();
                            if (pRowSewerElev != null)
                            {
                                minSewerElev = maxSewerElev;
                                Mmin = Mmax;
                                maxSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev")));
                                Mmax = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                            }
                        }
                        deltaSewerElev = maxSewerElev - minSewerElev;
                        deltaM = Mmax - Mmin;
                        sewerelev = minSewerElev;
                        j = j + 1;
                    }
                    pRowBuff = pCursor.NextRow() as IRowBuffer;
                }
                pCursor.Flush();
                //�ӱ���д���ͼ��
                m_SewerElevStructArray = new ArrayClass();

                pCursor = null;
                pCursor = pTable.Search(null, false);
                pRowSewerElev = null;
                pRowSewerElev = pCursor.NextRow();
                //ma
                //while (pRowSewerElev != null)
                //{
                //    clsProfileStruct pProfileDataStruct = new clsProfileStruct();
                //    pProfileDataStruct.M = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                //    pProfileDataStruct.Z = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("Z")));
                //    pProfileDataStruct.dSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("Sewerelev")));
                //    m_SewerElevStructArray.Add(pProfileDataStruct);
                //    pRowSewerElev = pCursor.NextRow();
                //}

                //frmDrawProfile frmDrawProfile1 = new frmDrawProfile(m_SewerElevStructArray);
                //frmDrawProfile1.Show();
            }
        }
Ejemplo n.º 8
0
        public static ISegment MakeOneHatch(IPolyline pSubPL, double dist, double m, double numhatch, double dTxtInterval, double dHatchLen, double dHatchOffset)
        {
            ILine pL = new LineClass();
            int result;
            ISegmentM pSegM;
            Math.DivRem((int)numhatch, (int)dTxtInterval, out result);
            if (!(result == 0))
            {
                if (dHatchOffset == 0)
                    pSubPL.QueryNormal(esriSegmentExtension.esriNoExtension, dist, false, (dHatchLen * 0.5), pL);
                else if (dHatchOffset > 0)
                    pSubPL.QueryNormal(esriSegmentExtension.esriNoExtension, dist, false, (dHatchLen * 0.5) + dHatchOffset, pL);
                else if (dHatchOffset < 0)
                {
                    pSubPL.ReverseOrientation();
                    pSubPL.QueryNormal(esriSegmentExtension.esriNoExtension, pSubPL.Length - dist, false, dHatchLen + Math.Abs(dHatchOffset), pL);
                    pSubPL.ReverseOrientation();
                }
            }
            ICurve pCurve;

            if (dHatchOffset != 0)
            {
                pL.GetSubcurve(Math.Abs(dHatchOffset), pL.Length, false, out pCurve);
                pSegM = pCurve as ISegmentM;
            }
            else
                pSegM = pL as ISegmentM;
            pSegM.SetMs(m, m);
            return pSegM as ISegment;
        }
        /// <summary>
        /// object polyline. Distance negative -> upstream
        /// </summary>
        /// <param name="geometricNetwork">object geometricNetwork</param>
        /// <param name="resultEdges">objects resultEdges</param>
        /// <param name="distance">value of distance</param>
        /// <param name="point">object point</param>
        /// <param name="offset">offset of polyline</param>
        /// <param name="messageInfo">info on result</param>
        /// <returns>object IGeometry (polyline or point)</returns>
        internal static IGeometry GetPolylinePosAlong(ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork, IEnumNetEID resultEdges, double distance, IPoint point, double?offset, ref string messageInfo)
        {
            IGeometry geometryBag = new GeometryBagClass();

            geometryBag.SpatialReference = point.SpatialReference;
            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;

            IEIDHelper eidHelper = new EIDHelperClass();

            eidHelper.GeometricNetwork = geometricNetwork;
            eidHelper.ReturnGeometries = true;
            eidHelper.ReturnFeatures   = false;

            IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(resultEdges);

            enumEIDinfo.Reset();
            IEIDInfo eidInfo = enumEIDinfo.Next();

            while (eidInfo != null)
            {
                IGeometry geometry = eidInfo.Geometry;
                geometryCollection.AddGeometry(geometry);
                eidInfo = enumEIDinfo.Next();
            }

            ITopologicalOperator unionedPolyline = new PolylineClass();

            unionedPolyline.ConstructUnion(geometryBag as IEnumGeometry);

            IPolyline pl = unionedPolyline as IPolyline;

            if (distance < 0)
            {
                pl.ReverseOrientation();
                distance = Math.Abs(distance);
            }

            IMAware mAware = pl as IMAware;

            mAware.MAware = true;
            IMSegmentation3 mSegmentation = unionedPolyline as IMSegmentation3;

            mSegmentation.SetMsAsDistance(false);

            IPoint ptTmp             = new PointClass();
            double distanceAlong     = 0;
            double distanceFromCurve = 0;
            bool   rightSide         = false;

            pl.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, ptTmp, ref distanceAlong, ref distanceFromCurve, ref rightSide);
            object mStartArray = mSegmentation.GetMsAtDistance(distanceAlong, false);

            double[]  mStart             = mStartArray as double[];
            double    distanceDownStream = distanceAlong + distance;
            IPolyline resultPolyline     = mSegmentation.GetSubcurveBetweenMs(mStart[0], distanceDownStream) as IPolyline;

            if (resultPolyline.IsEmpty)
            {
                return(point);
            }

            if (mSegmentation.MMax < distanceDownStream)
            {
                messageInfo = "The set distance exceeds the length of network";
            }

            return(Helper.ConstructOffset(resultPolyline, offset));
        }
        private static void ProfileCreateGraph(IApplication app, List<ProfileGraphDetails> ProfileGraph, IPolyline pPolyline, List<mainDetails> SewerColMains,
                                        List<manholeDetails> SewerColManholes, List<tapDetails> SewerColTap, int CurrentDetail)
        {
            // profile the sewer line and the surface elevation data
            // pPolyLine is a line composed from the edge results of the network trace
            IWorkspace pWS = null;
            ICursor pCursor = null;
            IMxDocument pMxDoc = null;
            IMap pMap = null;
            IZ pPolyLineZ = null;

            IZAware pZAwareLineZ = null;
            ISurface pSurface = null;
            IRasterLayer pRasterLayer = null;

            //get the elevation layer
            ILayer pRasLay = null;
            IPoint pPtOrigFrom = null;
            IPoint pPtOrigTo = null;
            IStandaloneTableCollection pStandAloneTabColl = null;
            IStandaloneTable pStandAloneTabMainLabel = null;
            ITable pTapTable = null;
            ITable pMainTable = null;
            ITable pManholeTable = null;

            ITable pSurfaceTable = null;

            ITable pMainLabelTable = null;
            ITableFields pTableFieldsMainLabel = null;
            IStandaloneTable pStandAloneTabMain = null;
            ITableFields pTableFieldsMain = null;
            IStandaloneTable pStandAloneTabManhole = null;
            ITableFields pTableFieldsManhole = null;
            IStandaloneTable pStandAloneTabSurface = null;
            ITableFields pTableFieldsSurface = null;
            IStandaloneTable pStandAloneTabTap = null;
            ITableFields pTableFieldsTap = null;
            IRowBuffer pRowBuff = null;
            ICursor pLabelCursor = null;

            ICursor pTapCursor = null;
            ISegment pSegment = null;
            ILine pLine = null;
            IPoint pFromPnt = null;
            IPoint pToPnt = null;
            IPoint pMidPnt = null;
            IDataGraphBase pDataGraphBase = null;
            IDataGraphT pDataGraphT = null;

            IPointCollection pPtCollection = null;
            IEnumVertex pEnumVertex = null;
            IPoint pPt = null;
            ISeriesProperties pAreaSeriesProps = null;
            IColor pColor = null;

            String strXDataFldName = null;
            String strYDataFldName = null;
            IDataSortSeriesProperties pSortFlds = null;
            IPointSeriesProperties pScatterSeriesProps2 = null;
            ISeriesProperties pScatterSeriesProps = null;
            IBarSeriesProperties pManHoleSeries = null;
            ILineSeriesProperties pLineSeriesProps2 = null;

            ISeriesProperties pLineSeriesProps = null;
            ITrackCancel pCancelTracker = null;
            IDataGraphWindow2 pDataGraphWin = null;
            IDataGraphCollection pDataGraphs = null;
            try
            {

                pMxDoc = (IMxDocument)app.Document;
                pMap = pMxDoc.FocusMap;

                // Open the Workspace
                pWS = Globals.CreateInMemoryWorkspace();

                //get the elevation layer
                bool FCorLayerRas = true;
                pRasLay = Globals.FindLayer(pMap, ProfileGraph[CurrentDetail].Elevation_LayerName, ref FCorLayerRas);

                if (pRasLay != null)
                {
                    pRasterLayer = pRasLay as IRasterLayer;
                    // get the surface to interpolate from
                    pSurface = Globals.GetSurface(pRasterLayer);

                    // make the polyline z-aware
                    pZAwareLineZ = (IZAware)pPolyline;
                    pZAwareLineZ.ZAware = true;

                    // work around for InterpolateFromSurface sometimes flipping polyline

                    pPtOrigFrom = pPolyline.FromPoint;
                    pPtOrigTo = pPolyline.ToPoint;
                    pPolyline.Project((pRasterLayer as IGeoDataset).SpatialReference);
                    // add z values to the polyline
                    pPolyLineZ = (IZ)pPolyline;

                    pPolyLineZ.InterpolateFromSurface(pSurface);
                    pPolyline.ReverseOrientation();

                }
                int i;

                pStandAloneTabColl = (IStandaloneTableCollection)pMap;
                for (i = pStandAloneTabColl.StandaloneTableCount - 1; i > 0; i--)
                {
                    if (pStandAloneTabColl.StandaloneTable[i].Name == "Point Table")
                    {
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.StandaloneTable[i]);
                        continue;
                    }
                    else if (pStandAloneTabColl.StandaloneTable[i].Name == "Surface Table")
                    {
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.StandaloneTable[i]);
                        continue;
                    }
                    else if (pStandAloneTabColl.StandaloneTable[i].Name == "Line Table")
                    {
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.StandaloneTable[i]);
                        continue;
                    }
                    else if (pStandAloneTabColl.StandaloneTable[i].Name == "Line Label Table")
                    {
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.StandaloneTable[i]);
                        continue;
                    }
                    else if (pStandAloneTabColl.StandaloneTable[i].Name == "Points Along Table")
                    {
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.StandaloneTable[i]);
                        continue;
                    }
                }

                pMainTable = Globals.createTableInMemory("Line Table", createLineFields(), pWS);
                if (pMainTable == null)
                    return;
                pManholeTable = Globals.createTableInMemory("Point Table", createPointFields(), pWS);
                if (pManholeTable == null)
                    return;

                if (pRasterLayer != null)
                {
                    pSurfaceTable = Globals.createTableInMemory("Surface Table", createSurfaceFields(), pWS);
                    if (pSurfaceTable == null)
                        return;
                }

                pMainLabelTable = Globals.createTableInMemory("Line Label Table", createLineLabelFields(), pWS);
                if (pMainLabelTable == null)
                    return;

                pTapTable = Globals.createTableInMemory("Points Along Table", createLineLabelFields(), pWS);
                if (pTapTable == null)
                    return;

                // add the table to the map so it can be edited
                // Create a new standalone table and add it to the collection of the focus map

                pStandAloneTabMainLabel = new StandaloneTableClass();
                pStandAloneTabMainLabel.Table = pMainLabelTable;
                pStandAloneTabColl.AddStandaloneTable(pStandAloneTabMainLabel);
                pMainLabelTable = (ITable)pStandAloneTabMainLabel;// QI, used in data graph
                pTableFieldsMainLabel = (ITableFields)pStandAloneTabMainLabel;

                pStandAloneTabMain = new StandaloneTableClass();
                pStandAloneTabMain.Table = pMainTable;
                pStandAloneTabColl.AddStandaloneTable(pStandAloneTabMain);
                pMainTable = (ITable)pStandAloneTabMain;// QI, used in data graph
                pTableFieldsMain = (ITableFields)pStandAloneTabMain;

                pStandAloneTabManhole = new StandaloneTableClass();
                pStandAloneTabManhole.Table = pManholeTable;
                pStandAloneTabColl.AddStandaloneTable(pStandAloneTabManhole);
                pManholeTable = (ITable)pStandAloneTabManhole;// QI, used in data graph
                pTableFieldsManhole = (ITableFields)pStandAloneTabManhole;

                if (pSurfaceTable != null)
                {
                    pStandAloneTabSurface = new StandaloneTableClass();
                    pStandAloneTabSurface.Table = pSurfaceTable;
                    pStandAloneTabColl.AddStandaloneTable(pStandAloneTabSurface);
                    pSurfaceTable = (ITable)pStandAloneTabSurface;// QI, used in data graph

                    pTableFieldsSurface = (ITableFields)pStandAloneTabSurface;
                }
                if (pTapTable != null)
                {

                    pStandAloneTabTap = new StandaloneTableClass();
                    pStandAloneTabTap.Table = pTapTable;
                    pStandAloneTabColl.AddStandaloneTable(pStandAloneTabTap);
                    pTapTable = (ITable)pStandAloneTabTap;// QI, used in data graph

                    pTableFieldsTap = (ITableFields)pStandAloneTabTap;
                }

                // Refresh the TOC
                pMxDoc.UpdateContents();

                // get an insert cursor for the table

                pCursor = pManholeTable.Insert(true);

                double minChartVal = 0.0;
                double maxChartVal = 0.0;
                int id = 0;
                foreach (manholeDetails manholeDetail in SewerColManholes)
                {
                    //SewerElevCollManholesDetails.Add(new object[] { pPt.M, manRim, manInvElev, manInv, manID });

                    pRowBuff = pManholeTable.CreateRowBuffer();
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("X"), manholeDetail.M);//0
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("TOPELEV"), manholeDetail.Top);//1
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("BOTELEV"), manholeDetail.Bottom);//2
                    //pRowBuff.set_Value(pRowBuff.Fields.FindField("INVERT"), manholeDetail.Invert);//3
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("ID"), manholeDetail.ManholeID);//4

                    if (id == 0)
                    {
                        minChartVal = (double)manholeDetail.Bottom;
                        maxChartVal = (double)manholeDetail.Top;
                        id++;
                    }
                    else
                    {
                        if (minChartVal > (double)manholeDetail.Bottom)
                            minChartVal = (double)manholeDetail.Bottom;
                        if (maxChartVal < (double)manholeDetail.Top)
                            maxChartVal = (double)manholeDetail.Top;
                    }
                    pCursor.InsertRow(pRowBuff);

                }
                // flush any writes
                pCursor.Flush();
                Marshal.ReleaseComObject(pCursor);

                pCursor = pMainTable.Insert(true);
                pLabelCursor = pMainLabelTable.Insert(true);
                pTapCursor = pTapTable.Insert(true);

                foreach (mainDetails mainDetail in SewerColMains)
                {
                    //SewerElevCollManholesDetails.Add(new object[] { pPt.M, manRim, manInvElev, manInv, manID });

                    //pRowBuff.set_Value(pRowBuff.Fields.FindField("FROMM"), mainDetail.UpM);//0
                    //pRowBuff.set_Value(pRowBuff.Fields.FindField("TOM"), mainDetail.DownM);//1
                    //pRowBuff.set_Value(pRowBuff.Fields.FindField("FROMELEV"), mainDetail.UpElev);//2
                    //pRowBuff.set_Value(pRowBuff.Fields.FindField("TOELEV"), mainDetail.DownElev);//3
                    pRowBuff = pMainTable.CreateRowBuffer();
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("ELEVATION"), mainDetail.UpElev);//2
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("MEASURE"), mainDetail.UpM);//3
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("FACILITYID"), mainDetail.MainID);//4
                    pCursor.InsertRow(pRowBuff);

                    pRowBuff = pMainTable.CreateRowBuffer();
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("ELEVATION"), mainDetail.DownElev);//2
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("MEASURE"), mainDetail.DownM);//3
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("FACILITYID"), mainDetail.MainID);//4
                    pCursor.InsertRow(pRowBuff);

                    pLine = new LineClass();
                    pFromPnt = new PointClass();
                    pToPnt = new PointClass();
                    pMidPnt = new PointClass();

                    pFromPnt.Y = mainDetail.UpElev;
                    pFromPnt.X = mainDetail.UpM;

                    pToPnt.Y = mainDetail.DownElev;
                    pToPnt.X = mainDetail.DownM;
                    pLine.PutCoords(pFromPnt, pToPnt);
                    pSegment = pLine as ISegment;

                    pSegment.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, pMidPnt);

                    //   pSegM = (ISegmentM)pSegment;
                    // pSegM.SetMs(

                    pRowBuff = pMainLabelTable.CreateRowBuffer();
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("ELEVATION"), pMidPnt.Y);//2
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("MEASURE"), pMidPnt.X);//3
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("FACILITYID"), mainDetail.MainID);//4
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("LABEL"), mainDetail.Label);//4
                    pLabelCursor.InsertRow(pRowBuff);
                    double slope = (pToPnt.Y - pFromPnt.Y) / (pToPnt.X - pFromPnt.X);

                    foreach (tapDetails tpDet in SewerColTap)
                    {
                        double distDown;
                        if (tpDet.Added == true)
                            continue;
                        if (pFromPnt.X < pToPnt.X)
                        {
                            if (tpDet.M > pFromPnt.X && tpDet.M < pToPnt.X)
                            {
                                distDown = tpDet.M - pFromPnt.X;

                            }
                            else
                                continue;
                        }
                        else
                        {
                            if (tpDet.M > pToPnt.X && tpDet.M < pFromPnt.X)
                            {
                                distDown = tpDet.M - pToPnt.X;

                            }
                            else
                                continue;
                        }
                        {

                            pSegment.QueryPoint(esriSegmentExtension.esriNoExtension, distDown, false, pMidPnt);
                            //if (pMidPnt.X == tpDet.M)
                            //{
                            pRowBuff = pTapTable.CreateRowBuffer();
                            pRowBuff.set_Value(pRowBuff.Fields.FindField("ELEVATION"), pMidPnt.Y);//2
                            pRowBuff.set_Value(pRowBuff.Fields.FindField("MEASURE"), tpDet.M);//3
                            pRowBuff.set_Value(pRowBuff.Fields.FindField("FACILITYID"), tpDet.tapID);//4
                            pRowBuff.set_Value(pRowBuff.Fields.FindField("LABEL"), tpDet.tapLabel);//4
                            //pRowBuff.set_Value(pRowBuff.Fields.FindField("LABEL"), mainDetail.Label);//4
                            pTapCursor.InsertRow(pRowBuff);
                            tpDet.Added = true;
                            //SewerColTap.Remove(tpDet);

                            // }
                        }
                    }

                    //if (minChartVal > (double)manholeDetail.InvertElev)
                    //    minChartVal = (double)manholeDetail.InvertElev;
                    //if (maxChartVal < (double)manholeDetail.Rim)
                    //    maxChartVal = (double)manholeDetail.Rim;

                }
                // flush any writes
                pCursor.Flush();
                Marshal.ReleaseComObject(pCursor);

                pLabelCursor.Flush();
                Marshal.ReleaseComObject(pLabelCursor);

                pTapCursor.Flush();
                Marshal.ReleaseComObject(pTapCursor);

                if (pSurfaceTable != null)
                {
                    pPtCollection = (IPointCollection)pPolyLineZ;

                    pEnumVertex = pPtCollection.EnumVertices;
                    pEnumVertex.Reset();

                    int lPartIndex;
                    int lVertexIndex;
                    pEnumVertex.Next(out pPt, out lPartIndex, out lVertexIndex);
                    pCursor = pSurfaceTable.Insert(true);
                    while (pPt != null)
                    {
                        pRowBuff = pSurfaceTable.CreateRowBuffer();
                        pRowBuff.set_Value(pRowBuff.Fields.FindField("X"), pPt.M);//2
                        pRowBuff.set_Value(pRowBuff.Fields.FindField("Y"), pPt.Z);//3

                        pCursor.InsertRow(pRowBuff);
                        pEnumVertex.Next(out pPt, out lPartIndex, out lVertexIndex);

                    }
                }

                //=============================================================================
                // create the graph from the table

                // create graph
                pDataGraphBase = new DataGraphTClass();
                pDataGraphT = (IDataGraphT)pDataGraphBase;

                // graph, axis and legend titles. Substitute them for different input layer
                pDataGraphT.GeneralProperties.Title = ProfileGraph[CurrentDetail].GraphTitle_Name; // "Sewer Main Profile";
                pDataGraphT.LegendProperties.Title = ProfileGraph[CurrentDetail].Legend_Name; //"Profile Legend";

                //   IDataGraphTAxisProperties pHort = pDataGraphT.AxisProperties[0];

                pDataGraphT.AxisProperties[0].Title = ProfileGraph[CurrentDetail].LeftAxis_Name;
                pDataGraphT.AxisProperties[0].AutomaticMaximum = true;
                pDataGraphT.AxisProperties[0].AutomaticMinimum = true;
                pDataGraphT.AxisProperties[0].Minimum = minChartVal - 5;
                pDataGraphT.AxisProperties[0].Maximum = maxChartVal + 5;
                pDataGraphT.AxisProperties[0].InitDefaults();

                //pDataGraphT.AxisProperties[1].AutomaticMaximum = true;
                //pDataGraphT.AxisProperties[1].AutomaticMinimum = false;
                //pDataGraphT.AxisProperties[1].Minimum = minChartVal - 5;
                ////pDataGraphT.AxisProperties[1].Title = "Manholes";
                //pDataGraphT.AxisProperties[1].Visible = true;

                pDataGraphT.AxisProperties[3].Visible = true;
                pDataGraphT.AxisProperties[3].Title = ProfileGraph[CurrentDetail].TopAxis_Name;
                pDataGraphT.AxisProperties[2].Title = ProfileGraph[CurrentDetail].BottomAxis_Name; // "Date";
                pDataGraphT.AxisProperties[2].ValueFormat = "0";
                pDataGraphT.AxisProperties[2].Minimum = 0;
                pDataGraphT.AxisProperties[2].AutomaticMinimum = false;
                pDataGraphT.AxisProperties[2].ValueFormat = "#,##0.###";
                pDataGraphBase.Name = ProfileGraph[CurrentDetail].Graph_Name; ;

                // & strTableName  layerName;
                //IDataGraphTGeneralProperties pGenProp = pDataGraphT.GeneralProperties;
                //pGenProp.Show3D = true;

                // put the legend below the graph
                //pDataGraphT.LegendProperties.Alignment = esriDataGraphTLegendBottom

                // use only for series-specific properties
                //IPointSeriesProperties pPtSeries;
                //IAreaSeriesProperties pAreaSeries;
                //ILineSeriesProperties pLineSeries;

                //-------------------------------------------------------------------------------
                // area series - ground elevation

                int idx = 0;
                if (pSurfaceTable != null)
                {
                    // create the area graph for the ground elevation
                    pAreaSeriesProps = pDataGraphT.AddSeries("area:vertical"); //("scatter_plot")  '("line:vertical")
                    pAreaSeriesProps.SourceData = pSurfaceTable;// pLayer
                    pAreaSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                    pColor = Globals.GetColor(137, 112, 68);

                    pAreaSeriesProps.CustomColor = pColor.RGB; // pSymbol.Color.RGB

                    // get the fields to graph - ground elevation
                    strXDataFldName = "X"; //pTable.Fields.Field(i).Name ' "Dist_to_Rds"
                    strYDataFldName = "Y"; // pTable.Fields.Field(i).Name ' "Dist_to_Rds"

                    //  pSeriesProps.whereClause = whereClause
                    pAreaSeriesProps.InLegend = true; //show legend   ' false = don't show legend
                    pAreaSeriesProps.Name = ProfileGraph[CurrentDetail].Elevation_LayerName;//A4LGSharedFunctions.Localizer.GetString("GeoNetToolsAlias_1");
                    //pSeriesProps.LabelField = "OBJECTID";
                    pAreaSeriesProps.ValueFormat = "0 ";
                    pAreaSeriesProps.SetField(0, strXDataFldName); // timefldName
                    pAreaSeriesProps.SetField(1, strYDataFldName);

                    // sort on the X value
                    pSortFlds = (IDataSortSeriesProperties)pAreaSeriesProps;

                    pSortFlds.AddSortingField(strXDataFldName, true, ref idx);
                }
                //-------------------------------------------------------------------------------

                //------Manhole Locations

                // create the area graph for the ground elevation
                pAreaSeriesProps = pDataGraphT.AddSeries("bar:minmax"); //("scatter_plot")  '("line:vertical")

                pManHoleSeries = (IBarSeriesProperties)pAreaSeriesProps;
                pManHoleSeries.BarStyle = esriBarStyle.esriCylinderBar;
                pManHoleSeries.BarSize = 5;
                pAreaSeriesProps.SourceData = pManholeTable;// pLayer
                pAreaSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                pColor = Globals.GetColor(255, 255, 68);

                pAreaSeriesProps.CustomColor = pColor.RGB; // pSymbol.Color.RGB
                pAreaSeriesProps.InLegend = true; //show legend   ' false = don't show legend

                pAreaSeriesProps.Name = ProfileGraph[CurrentDetail].Point_LayerName;//"Point Locations";

                pAreaSeriesProps.HorizontalAxis = 3;
                pAreaSeriesProps.LabelField = "ID";

                pAreaSeriesProps.SetField(0, "X");
                pAreaSeriesProps.SetField(1, "BOTELEV");
                pAreaSeriesProps.SetField(2, "TOPELEV");

                // sort on the X value

                //pSortFlds = (IDataSortSeriesProperties)pAreaSeriesProps;
                //idx = 0;
                //pSortFlds.AddSortingField("X", true, ref idx);

                //----

                // line series - sewer line

                pColor = Globals.GetColor(76, 230, 0);// green

                pLineSeriesProps = pDataGraphT.AddSeries("line:vertical"); //("area:vertical") '("scatter_plot")  '("line:vertical")

                pLineSeriesProps.SourceData = pMainTable; // pLayer
                pLineSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                pLineSeriesProps.PenProperties.Width = 3;
                pLineSeriesProps.CustomColor = pColor.RGB;  // pSymbol.Color.RGB

                // don't have any symbols on the line, just solid
                pLineSeriesProps2 = (ILineSeriesProperties)pLineSeriesProps;// 'QI
                pLineSeriesProps2.SymbolProperties.Style = esriDataGraphTSymbolType.esriDataGraphTSymbolNothing;

                // get the fields to graph
                strXDataFldName = "MEASURE";
                strYDataFldName = "ELEVATION";

                pLineSeriesProps.InLegend = true; // show legend   ' false = don't show legend
                pLineSeriesProps.Name = ProfileGraph[CurrentDetail].Line_LayerName;//"Line Profile";// pMainTable.Fields.get_Field(pMainTable.Fields.FindField("ELEVATION")).AliasName;
                //pSeriesProps.LabelField = "OBJECTID"
                pLineSeriesProps.ValueFormat = "0 ";
                pLineSeriesProps.SetField(0, strXDataFldName);// timefldName
                pLineSeriesProps.SetField(1, strYDataFldName);

                // sort on the X value
                pSortFlds = (IDataSortSeriesProperties)pLineSeriesProps;
                pSortFlds.AddSortingField(strXDataFldName, true, ref idx);

                //----------  end line series

                pScatterSeriesProps = pDataGraphT.AddSeries("scatter_plot"); //("area:vertical") '("scatter_plot")  '("line:vertical")

                pScatterSeriesProps.SourceData = pMainLabelTable; // pLayer
                pScatterSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                pScatterSeriesProps.PenProperties.Width = 3;
                pScatterSeriesProps.CustomColor = pColor.RGB;  // pSymbol.Color.RGB

                // don't have any symbols on the line, just solid

                pScatterSeriesProps2 = (IPointSeriesProperties)pScatterSeriesProps;// 'QI

                pScatterSeriesProps2.SymbolProperties.Style = esriDataGraphTSymbolType.esriDataGraphTSymbolCircle;
                pScatterSeriesProps2.SymbolProperties.Visible = false;

                pScatterSeriesProps2.SymbolProperties.Color = pColor.RGB;
                pScatterSeriesProps2.SymbolProperties.BorderProperties.Color = pColor.RGB;
                pScatterSeriesProps2.SymbolProperties.BorderProperties.Style = esriDataGraphTPenType.esriDataGraphTPenClear;

                // get the fields to graph
                strXDataFldName = "MEASURE";
                strYDataFldName = "ELEVATION";

                pScatterSeriesProps.InLegend = false; // show legend   ' false = don't show legend
                pScatterSeriesProps.Name = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsAlias_14");
                //pSeriesProps.LabelField = "OBJECTID"
                pScatterSeriesProps.ValueFormat = " ";
                pScatterSeriesProps.HorizontalAxis = 3;
                pScatterSeriesProps.LabelField = "LABEL";
                pScatterSeriesProps.Marks = true;

                pScatterSeriesProps.SetField(0, strXDataFldName);// timefldName
                pScatterSeriesProps.SetField(1, strYDataFldName);
                //pScatterSeriesProps.SetField(2, "LABEL");
                // sort on the X value
                //  pSortFlds = (IDataSortSeriesProperties)pScatterSeriesProps;
                // pSortFlds.AddSortingField(strXDataFldName, true, ref idx);

                //ISeriesProperties pScatterSeriesProps;

                pScatterSeriesProps = pDataGraphT.AddSeries("scatter_plot"); //("area:vertical") '("scatter_plot")  '("line:vertical")

                pScatterSeriesProps.SourceData = pTapTable; // pLayer

                // get the fields to graph
                strXDataFldName = "MEASURE";
                strYDataFldName = "ELEVATION";

                pScatterSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                pScatterSeriesProps.PenProperties.Width = 3;
                pScatterSeriesProps.HorizontalAxis = 5;
                pScatterSeriesProps.LabelField = "LABEL";

                if (ProfileGraph[CurrentDetail].PointAlong_ShowLabels.ToUpper() == "TRUE" && ProfileGraph[CurrentDetail].PointAlong_Labels.Length > 0)
                {

                    pScatterSeriesProps.Marks = true;
                }

                pScatterSeriesProps.InLegend = true; // show legend   ' false = don't show legend
                pScatterSeriesProps.Name = ProfileGraph[CurrentDetail].PointAlong_LayerName;//"Points Along";
                //pSeriesProps.LabelField = "OBJECTID"
                pScatterSeriesProps.ValueFormat = " ";

                pScatterSeriesProps.SetField(0, strXDataFldName);// timefldName
                pScatterSeriesProps.SetField(1, strYDataFldName);

                pColor = Globals.GetColor(255, 0, 0);// green

                pScatterSeriesProps.CustomColor = pColor.RGB;  // pSymbol.Color.RGB

                // don't have any symbols on the line, just solid
                //IPointSeriesProperties pScatterSeriesProps2;
                pScatterSeriesProps2 = (IPointSeriesProperties)pScatterSeriesProps;// 'QI

                pScatterSeriesProps2.SymbolProperties.Style = esriDataGraphTSymbolType.esriDataGraphTSymbolStar;
                pScatterSeriesProps2.SymbolProperties.Visible = true;

                pScatterSeriesProps2.SymbolProperties.Color = pColor.RGB;
                pScatterSeriesProps2.SymbolProperties.BorderProperties.Color = pColor.RGB;
                pScatterSeriesProps2.SymbolProperties.BorderProperties.Style = esriDataGraphTPenType.esriDataGraphTPenSolid;

                pDataGraphBase.UseSelectedSet = false;

                pCancelTracker = new CancelTrackerClass();
                pDataGraphT.Update(pCancelTracker);

                // create data graph window

                pDataGraphWin = new DataGraphWindowClass();
                pDataGraphWin.DataGraphBase = pDataGraphBase;
                pDataGraphWin.Application = app;
                // size and position the window
                pDataGraphWin.PutPosition(0, 0, 900, 250);

                // add the graph to the project

                pDataGraphs = (IDataGraphCollection)pMxDoc; //QI
                pDataGraphs.AddDataGraph(pDataGraphBase);
                //IDataGraphT ptmp = (IDataGraphT)pDataGraphs.DataGraph[1];

                //string fld = ptmp.SeriesProperties[5].GetField(0);
                //fld = ptmp.SeriesProperties[5].GetField(1);
                //fld = ptmp.SeriesProperties[5].GetField(2);
                //fld = ptmp.SeriesProperties[5].LabelField;
                //fld = ptmp.SeriesProperties[5].Marks.ToString();
                //   fld = ptmp.SeriesProperties[5].HorizontalAxis;

                pDataGraphT.AxisProperties[0].AutomaticMaximum = true;
                pDataGraphT.AxisProperties[0].AutomaticMinimum = true;
                // pDataGraphT.AxisProperties[0].Minimum = minChartVal - 5;
                //pDataGraphT.AxisProperties[0].Maximum = maxChartVal + 5;
                pDataGraphT.AxisProperties[0].InitDefaults();

                // show the graph
                pDataGraphWin.Show(true);

                //// get an insert cursor for the table
                //pCursor = null;
                //pRowBuff = null;
                //pCursor = pProfTable.Insert(true);

                //// populate the table
                //IPoint pPt;
                //int lPartIndex;
                //int lVertexIndex;
                //IEnumVertex pEnumVertex;

                //pPtCollection = (IPointCollection)pPolyline;
                //pEnumVertex = pPtCollection.EnumVertices;
                //pEnumVertex.Reset();

                //// add the vertex xyz to the new table
                //i = 0;
                //pEnumVertex.Next(out pPt, out lPartIndex, out lVertexIndex);

                //while (pPt != null)
                //{

                //    pRowBuff = pProfTable.CreateRowBuffer();
                //    pRowBuff.set_Value(pRowBuff.Fields.FindField("X"), pPt.X);
                //    pRowBuff.set_Value(pRowBuff.Fields.FindField("Y"), pPt.Y);
                //    pRowBuff.set_Value(pRowBuff.Fields.FindField("Z"), pPt.Z);
                //    pRowBuff.set_Value(pRowBuff.Fields.FindField("M"), pPt.M);

                //    // keep -99999 as a flag, data will be calculated later,
                //    // right now a graph can't ignore null values
                //    if (SewerElevCollFroms[i] == null || SewerElevCollFroms[i].ToString() == "")
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("UPELEV"), -99999);
                //        if (MessageBox.Show("There is a null value in the Upstream Elevations, Continue?", "Missing Data", MessageBoxButtons.YesNo) == DialogResult.No)
                //        {
                //            return;

                //        }
                //    }
                //    else
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("UPELEV"), SewerElevCollFroms[i]);
                //    }

                //    if (SewerElevCollTos[i] == null || SewerElevCollTos[i].ToString() == "")
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("DOWNELEV"), -99999);
                //        if (MessageBox.Show("There is a null value in the Downstream Elevations, Continue?", "Missing Data", MessageBoxButtons.YesNo) == DialogResult.No)
                //        {
                //            return;

                //        }
                //    }
                //    else
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("DOWNELEV"), SewerElevCollTos[i]);
                //    }

                //    if (SewerElevCollRim[i] == null || SewerElevCollRim[i].ToString() == "")
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("RIMELEV"), -99999);
                //        if (MessageBox.Show("There is a null value in the Rim Elevation, Continue?", "Missing Data", MessageBoxButtons.YesNo) == DialogResult.No)
                //        {
                //            return;

                //        }
                //    }

                //    else
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("RIMELEV"), SewerElevCollRim[i]);
                //    }

                //    if (SewerElevCollInvertElev[i] == null || SewerElevCollInvertElev[i].ToString() == "")
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("INVERTELEV"), -99999);
                //        if (MessageBox.Show("There is a null value in the Invert Elevation, Continue?", "Missing Data", MessageBoxButtons.YesNo) == DialogResult.No)
                //        {
                //            return;

                //        }

                //    }
                //    else
                //    {
                //        pRowBuff.set_Value(pRowBuff.Fields.FindField("INVERTELEV"), SewerElevCollInvertElev[i]);
                //    }
                //    // pRowBuff.set_Value(pRowBuff.Fields.FindField("UPELEV"), SewerElevCollFroms[i]);
                //    //pRowBuff.set_Value(pRowBuff.Fields.FindField("DOWNELEV"), SewerElevCollTos[i]);
                //    // pRowBuff.set_Value(pRowBuff.Fields.FindField("RIMELEV"), SewerElevCollRim[i]);
                //    // pRowBuff.set_Value(pRowBuff.Fields.FindField("INVERTELEV"), SewerElevCollInvertElev[i]);

                //    /** use this code if graph can ignore null data
                //    '    ' skip records with -99999 as sewer elev
                //    '  If SewerElevColl(i) <> -99999 Then
                //    '    pRowBuff.Value(pRowBuff.Fields.FindField("SewerElev")) = SewerElevColl(i)
                //    '  Else
                //    '    pRowBuff.Value(pRowBuff.Fields.FindField("SewerElev")) = Null
                //    '  End If*/
                //    pCursor.InsertRow(pRowBuff);
                //    pEnumVertex.Next(out pPt, out lPartIndex, out lVertexIndex);
                //    i++;
                //}
                //// flush any writes
                //pCursor.Flush();
                //Marshal.ReleaseComObject(pCursor);

                ///*
                //  ' Calculate a value for an intermediate point between 2 manholes
                //  ' needed because graph requires a value for every record or it gives it a zero.
                //  ' Sewer lines have values at each manhole but a sewerline is composed of many
                //  ' lines - where the laterals break it.
                //  ' ** this may change if they modify the software to ignore null values in a graph
                //  */

                //// make a cursor of just the records that have a valid sewer elev
                //// needed to get the deltaSewerElev of the sewer elev data

                ////*********
                //string currentField = "UPELEV";
                //for (int k = 0; k < 4; k++)
                //{
                //    switch (k)
                //    {
                //        case 0:
                //            currentField = "UPELEV";
                //            break;
                //        case 1:
                //            currentField = "DOWNELEV";
                //            break;
                //        case 2:
                //            currentField = "RIMELEV";
                //            break;
                //        case 3:
                //            currentField = "INVERTELEV";
                //            break;
                //    }
                //    double Mmin = 0.0;
                //    double Mmax = 0.0;
                //    double minSewerElev = 0.0;
                //    double maxSewerElev = 0.0;
                //    double deltaSewerElev = 0.0;
                //    double deltaM = 0.0;
                //    double newZ = 0.0;
                //    double m = 0.0;
                //    double sewerelev = 0.0;
                //    int j;
                //    IRow pRowSewerElev;

                //    ICursor pCursorSewerElev;
                //    IQueryFilter pQueryFilter;
                //    pQueryFilter = new QueryFilterClass();
                //    pQueryFilter.WhereClause = currentField + " <> -99999";
                //    pCursorSewerElev = pProfTable.Search(pQueryFilter, false);

                //    // recreate the cursor as an update cursor
                //    pCursor = null;
                //    pCursor = pProfTable.Update(null, false);
                //    pRowBuff = pCursor.NextRow();

                //    j = 0;
                //    deltaM = 0;
                //    while (pRowBuff != null)
                //    {
                //        // for the intermediate records, SewerElev will have a value of -99999,
                //        // update them with a calculated value
                //        if ((double)(pRowBuff.get_Value(pRowBuff.Fields.FindField(currentField))) == -99999)
                //        {
                //            m = (double)pRowBuff.get_Value(pRowBuff.Fields.FindField("M"));
                //            newZ = (((m - Mmin) / deltaM) * deltaSewerElev) + sewerelev;
                //            pRowBuff.set_Value(pRowBuff.Fields.FindField(currentField), newZ);
                //            pCursor.UpdateRow(pRowBuff as IRow);
                //        }
                //        else
                //        {
                //            //valid sewer elev record
                //            // calculate the delta sewer elev
                //            if (j == 0)
                //            {
                //                // get the min and max sewer elev values
                //                // get the man and max M value, this is used in the ratio calculation,
                //                //  I can't use the whole line length as the M because the slope of the
                //                //  sewer pipe can change at each manhole so the calculation has to be
                //                //  from manhole to manhole, not the whole line
                //                try
                //                {
                //                    pRowSewerElev = pCursorSewerElev.NextRow();
                //                    minSewerElev = (double)pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField(currentField));
                //                    //string tmp = pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")).ToString();
                //                    //if (tmp == "")
                //                    //    Mmin = 0.0;
                //                    //else
                //                    //    Mmin = Convert.ToDouble(tmp);
                //                    Mmin = (double)pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"));
                //                    pRowSewerElev = pCursorSewerElev.NextRow();
                //                    maxSewerElev = (double)pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField(currentField));
                //                    Mmax = (double)pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"));
                //                }
                //                catch (Exception Ex)
                //                {
                //                    MessageBox.Show(Ex.Message);

                //                }

                //            }
                //            else
                //            {
                //                pRowSewerElev = pCursorSewerElev.NextRow();
                //                if (pRowSewerElev == null)
                //                {
                //                    break;
                //                }
                //                minSewerElev = maxSewerElev;
                //                Mmin = Mmax;
                //                maxSewerElev = (double)pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField(currentField));
                //                Mmax = (double)pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"));
                //            }
                //            deltaSewerElev = maxSewerElev - minSewerElev;
                //            deltaM = Mmax - Mmin;

                //            // this value is the base value that the calc'd values need as a base
                //            sewerelev = minSewerElev;//pRowBuff.Value(pRowBuff.Fields.FindField("SewerElev"))
                //            j++;
                //        }
                //        pRowBuff = (IRowBuffer)pCursor.NextRow();
                //    }
                //    pCursor.Flush();
                //    Marshal.ReleaseComObject(pCursor);
                //    Marshal.ReleaseComObject(pCursorSewerElev);

                //}

                ////=============================================================================
                //// create the graph from the table

                //IDataGraphBase pDataGraphBase;
                //IDataGraphT pDataGraphT;

                //// create graph
                //pDataGraphBase = new DataGraphTClass();
                //pDataGraphT = (IDataGraphT)pDataGraphBase;

                //// graph, axis and legend titles. Substitute them for different input layer
                //pDataGraphT.GeneralProperties.Title = "Sewer Main Profile";
                //pDataGraphT.LegendProperties.Title = "Profile Legend";

                ////   IDataGraphTAxisProperties pHort = pDataGraphT.AxisProperties[0];

                //pDataGraphT.AxisProperties[0].Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsAlias_13");
                //pDataGraphT.AxisProperties[0].AutomaticMaximum = true;
                //pDataGraphT.AxisProperties[0].AutomaticMinimum = true;
                ////pDataGraphT.AxisProperties[0].Minimum = minChartVal - 5;
                ////pDataGraphT.AxisProperties[0].Maximum= maxChartVal + 5;

                ////pDataGraphT.AxisProperties[1].AutomaticMaximum = true;
                ////pDataGraphT.AxisProperties[1].AutomaticMinimum = false;
                ////pDataGraphT.AxisProperties[1].Minimum = minChartVal - 5;
                //////pDataGraphT.AxisProperties[1].Title = "Manholes";
                ////pDataGraphT.AxisProperties[1].Visible = true;

                //pDataGraphT.AxisProperties[3].Visible = true;

                //pDataGraphT.AxisProperties[3].Title = "Manholes";

                //pDataGraphT.AxisProperties[2].Title = "Length (feet)"; // "Date";

                //pDataGraphT.AxisProperties[2].ValueFormat = "0";
                //pDataGraphT.AxisProperties[2].Minimum = 0;
                //pDataGraphT.AxisProperties[2].AutomaticMinimum = false;
                //pDataGraphT.AxisProperties[2].ValueFormat = "#,##0.###";
                //pDataGraphBase.Name = "Sewer Main Profile Graph"; // & strTableName  layerName;
                ////IDataGraphTGeneralProperties pGenProp = pDataGraphT.GeneralProperties;
                ////pGenProp.Show3D = true;

                //// put the legend below the graph
                ////pDataGraphT.LegendProperties.Alignment = esriDataGraphTLegendBottom

                //// use only for series-specific properties
                ////IPointSeriesProperties pPtSeries;
                ////IAreaSeriesProperties pAreaSeries;
                ////ILineSeriesProperties pLineSeries;

                ////-------------------------------------------------------------------------------
                //// area series - ground elevation
                //ISeriesProperties pAreaSeriesProps;
                //IColor pColor;

                //// create the area graph for the ground elevation
                //pAreaSeriesProps = pDataGraphT.AddSeries("area:vertical"); //("scatter_plot")  '("line:vertical")
                //pAreaSeriesProps.SourceData = pProfTable;// pLayer
                //pAreaSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                //pColor = Globals.GetColor(137, 112, 68);

                //pAreaSeriesProps.CustomColor = pColor.RGB; // pSymbol.Color.RGB

                //String strXDataFldName;
                //String strYDataFldName;

                //// get the fields to graph - ground elevation
                //strXDataFldName = "M"; //pTable.Fields.Field(i).Name ' "Dist_to_Rds"
                //strYDataFldName = "Z"; // pTable.Fields.Field(i).Name ' "Dist_to_Rds"
                ////timefldName = "TSDateTime"   ' substitute data/time field name for different dataset
                ////gageIDFldName = "Name"         ' substitute gage ID field name for different dataset

                ////  pSeriesProps.whereClause = whereClause
                //pAreaSeriesProps.InLegend = true; //show legend   ' false = don't show legend
                //pAreaSeriesProps.Name = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsAlias_1");
                ////pSeriesProps.LabelField = "OBJECTID";
                //pAreaSeriesProps.ValueFormat = "0 ";
                //pAreaSeriesProps.SetField(0, strXDataFldName); // timefldName
                //pAreaSeriesProps.SetField(1, strYDataFldName);

                //// sort on the X value
                //IDataSortSeriesProperties pSortFlds;
                //pSortFlds = (IDataSortSeriesProperties)pAreaSeriesProps;
                //int idx = 0;
                //pSortFlds.AddSortingField(strXDataFldName, true, ref idx);

                ////-------------------------------------------------------------------------------

                ////------Manhole Locations

                //IBarSeriesProperties pManHoleSeries;

                //// create the area graph for the ground elevation
                //pAreaSeriesProps = pDataGraphT.AddSeries("bar:minmax"); //("scatter_plot")  '("line:vertical")

                //pManHoleSeries = (IBarSeriesProperties)pAreaSeriesProps;
                //pManHoleSeries.BarStyle = esriBarStyle.esriCylinderBar;
                //pManHoleSeries.BarSize = 5;
                //pAreaSeriesProps.SourceData = pManTable;// pLayer
                //pAreaSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                //pColor = Globals.GetColor(255, 255, 68);

                //pAreaSeriesProps.CustomColor = pColor.RGB; // pSymbol.Color.RGB
                //pAreaSeriesProps.InLegend = true; //show legend   ' false = don't show legend

                //pAreaSeriesProps.Name = "Manhole Locations";

                //pAreaSeriesProps.HorizontalAxis = 3;
                //pAreaSeriesProps.LabelField = "ID";

                //pAreaSeriesProps.SetField(0, "X");
                //pAreaSeriesProps.SetField(1, "INVERTELEV");
                //pAreaSeriesProps.SetField(2, "RIMELEV");

                //// sort on the X value

                ////pSortFlds = (IDataSortSeriesProperties)pAreaSeriesProps;
                ////idx = 0;
                ////pSortFlds.AddSortingField("X", true, ref idx);

                ////----

                //// line series - sewer line
                //currentField = "UPELEV";
                //int currentFieldWidth = 1;
                //for (int k = 3; k >= 0; k--)
                //{

                //    switch (k)
                //    {
                //        case 0:
                //            currentField = "UPELEV";
                //            pColor = Globals.GetColor(76, 230, 0);// green
                //            currentFieldWidth = 3;
                //            break;
                //        case 1:
                //            currentField = "DOWNELEV";
                //            pColor = Globals.GetColor(76, 0, 255);
                //            currentFieldWidth = 3;

                //            break;
                //        case 2:
                //            currentField = "RIMELEV";
                //            pColor = Globals.GetColor(76, 230, 255);
                //            currentFieldWidth = 3;
                //            continue;
                //        //break;
                //        case 3:
                //            currentField = "INVERTELEV";
                //            pColor = Globals.GetColor(255, 230, 0);
                //            currentFieldWidth = 3;
                //            break;
                //    }

                //    ISeriesProperties pLineSeriesProps;

                //    pLineSeriesProps = pDataGraphT.AddSeries("line:vertical"); //("area:vertical") '("scatter_plot")  '("line:vertical")

                //    pLineSeriesProps.SourceData = pProfTable; // pLayer
                //    pLineSeriesProps.ColorType = esriGraphColorType.esriGraphColorCustomAll;
                //    pLineSeriesProps.PenProperties.Width = currentFieldWidth;
                //    pLineSeriesProps.CustomColor = pColor.RGB;  // pSymbol.Color.RGB

                //    // don't have any symbols on the line, just solid
                //    ILineSeriesProperties pLineSeriesProps2;
                //    pLineSeriesProps2 = (ILineSeriesProperties)pLineSeriesProps;// 'QI
                //    pLineSeriesProps2.SymbolProperties.Style = esriDataGraphTSymbolType.esriDataGraphTSymbolNothing;

                //    // get the fields to graph
                //    strXDataFldName = "M";
                //    strYDataFldName = currentField;

                //    pLineSeriesProps.InLegend = true; // show legend   ' false = don't show legend
                //    pLineSeriesProps.Name = pProfTable.Fields.get_Field(pProfTable.Fields.FindField(currentField)).AliasName;
                //    //pSeriesProps.LabelField = "OBJECTID"
                //    pLineSeriesProps.ValueFormat = "0 ";
                //    pLineSeriesProps.SetField(0, strXDataFldName);// timefldName
                //    pLineSeriesProps.SetField(1, strYDataFldName);

                //    // sort on the X value
                //    pSortFlds = (IDataSortSeriesProperties)pLineSeriesProps;
                //    pSortFlds.AddSortingField(strXDataFldName, true, ref idx);

                //    //----------  end line series

                //}

                //pDataGraphBase.UseSelectedSet = false;

                //ITrackCancel pCancelTracker;
                //pCancelTracker = new CancelTrackerClass();
                //pDataGraphT.Update(pCancelTracker);
                ////pDataGraphT.get_AxisProperties(0).AutomaticMaximum = true;
                ////pDataGraphT.get_AxisProperties(0).AutomaticMinimum= true;
                ////pDataGraphT.get_AxisProperties(1).AutomaticMaximum = true;
                ////pDataGraphT.get_AxisProperties(1).AutomaticMinimum = true;
                ////pDataGraphT.get_AxisProperties(2).AutomaticMaximum = true;
                ////pDataGraphT.get_AxisProperties(2).AutomaticMinimum = true;
                ////pDataGraphT.get_AxisProperties(3).AutomaticMaximum = true;
                ////pDataGraphT.get_AxisProperties(3).AutomaticMinimum = true;

                //// create data graph window
                //IDataGraphWindow2 pDataGraphWin;
                //pDataGraphWin = new DataGraphWindowClass();
                //pDataGraphWin.DataGraphBase = pDataGraphBase;
                //pDataGraphWin.Application = app;
                //// size and position the window
                //pDataGraphWin.PutPosition(0, 0, 900, 250);

                //// add the graph to the project
                //IDataGraphCollection pDataGraphs;
                //pDataGraphs = (IDataGraphCollection)pMxDoc; //QI
                //pDataGraphs.AddDataGraph(pDataGraphBase);
                ////IDataGraphT ptmp = (IDataGraphT)pDataGraphs.DataGraph[1];

                ////string fld = ptmp.SeriesProperties[5].GetField(0);
                ////fld = ptmp.SeriesProperties[5].GetField(1);
                ////fld = ptmp.SeriesProperties[5].GetField(2);
                ////fld = ptmp.SeriesProperties[5].LabelField;
                ////fld = ptmp.SeriesProperties[5].Marks.ToString();
                ////   fld = ptmp.SeriesProperties[5].HorizontalAxis;

                //// show the graph
                //pDataGraphWin.Show(true);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "ProfileCreateGraph " + Ex.Message);
            }
            finally
            {

                pWS = null;
                pCursor = null;
                pMxDoc = null;
                pMap = null;
                pPolyLineZ = null;

                pZAwareLineZ = null;
                pSurface = null;
                pRasterLayer = null;

                pRasLay = null;
                pPtOrigFrom = null;
                pPtOrigTo = null;
                pStandAloneTabColl = null;
                pStandAloneTabMainLabel = null;
                pTapTable = null;
                pMainTable = null;
                pManholeTable = null;

                pSurfaceTable = null;

                pMainLabelTable = null;
                pTableFieldsMainLabel = null;
                pStandAloneTabMain = null;
                pTableFieldsMain = null;
                pStandAloneTabManhole = null;
                pTableFieldsManhole = null;
                pStandAloneTabSurface = null;
                pTableFieldsSurface = null;
                pStandAloneTabTap = null;
                pTableFieldsTap = null;
                pRowBuff = null;
                pLabelCursor = null;

                pTapCursor = null;
                pSegment = null;
                pLine = null;
                pFromPnt = null;
                pToPnt = null;
                pMidPnt = null;
                pDataGraphBase = null;
                pDataGraphT = null;

                pPtCollection = null;
                pEnumVertex = null;
                pPt = null;
                pAreaSeriesProps = null;
                pColor = null;

                pSortFlds = null;
                pScatterSeriesProps2 = null;
                pScatterSeriesProps = null;
                pManHoleSeries = null;
                pLineSeriesProps2 = null;

                pLineSeriesProps = null;
                pCancelTracker = null;
                pDataGraphWin = null;
                pDataGraphs = null;
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 判断pline的frompoint 在pnt1和 pnt2组成的线的哪一侧
 /// </summary>
 /// <params name="pnt1"></params>
 /// <params name="pnt2"></params>
 /// <params name="pline"></params>
 /// <returns>返回与回采方向相同的巷道线 </returns>
 private IPolyline GetPointPos(IPoint pnt1, IPoint pnt2, IPolyline pline, int iDirect)
 {
     IPoint pntstart = pline.FromPoint;
     if (pntstart == pnt1) //pline 起点与pnt1相同
     {
         return pline;
     }
     else if (pline.ToPoint == pnt1) //pline 终点与pnt1相同
     {
         pline.ReverseOrientation();
         //return pline;
     }
     else //非切眼状态
     {
         //(p2-p0)*(p1-p0)>0 则p0p1在p1点拐向右侧得到p1p2,(p2-p0)*(p1-p0)<0 则p0p1在p1点拐向左侧得到p1p2, p1为共同点
         IPoint p1p0 = new PointClass();
         //p1-p0
         p1p0.X = pnt1.X - pnt2.X;
         p1p0.Y = pnt1.Y - pnt2.Y;
         IPoint p2p0 = new PointClass();
         //p2-p0
         p2p0.X = pntstart.X - pnt2.X;
         p2p0.Y = pntstart.Y - pnt2.Y;
         //(p2-p0)*(p1-p0)
         double newrel = p2p0.X * p1p0.Y - p1p0.X * p2p0.Y;
         if (newrel > 0)  //frompoint 在切眼右侧
         {
             if (iDirect == -1)
                 pline.ReverseOrientation();
         }
         else if (newrel < 0) //frompoint 在切眼左侧
         {
             if (iDirect == 1)
                 pline.ReverseOrientation();
             //return pline;
         }
     }
     return pline;
 }
Ejemplo n.º 12
0
        //根据多段线和阀门数组创建高程剖面 
        public static void ProfileCreateGraph(MainFrm pMainFrm, IPolyline pPolyline, IArray pSewerElevArray)
        {
            AxMapControl axMap = pMainFrm.getMapControl();
            IZ pPolylineZ = pPolyline as IZ;
            IRasterLayer pRasterLyr = FindRasterLayer("Elevation", pMainFrm);
            //获得表面进行插值
            ISurface pSurface = GetSurface(pRasterLyr);
            //创建Polyline z-ware;
            IZAware pZAwareLineZ = pPolyline as IZAware;
            pZAwareLineZ.ZAware = true;
            //'* work around for InterpolateFromSurface sometimes flipping polyline
            IPoint pPtOrigFrom = pPolyline.FromPoint;
            IPoint pPtOrigTo = pPolyline.ToPoint;
            //添加Z值到多边形上
            pPolylineZ.InterpolateFromSurface(pSurface);
            if (pPolyline.FromPoint.X != pPtOrigFrom.X || pPolyline.FromPoint.Y != pPtOrigFrom.Y)
                pPolyline.ReverseOrientation();
            //添加M值到线上
            IMSegmentation pMSegmentation = pPolyline as IMSegmentation;
            IMAware pMAware = pPolyline as IMAware;
            pMAware.MAware = true;
            pMSegmentation.SetMsAsDistance(false);
            //创建表格
            ITable pTable = ProfileCreateTable();
            int i=0;
            if (pTable != null)
            {
                //在图层列表控件中要确保该表格还不存在,如果存在则删除它
                IStandaloneTableCollection pStandAloneTabColl = axMap.ActiveView.FocusMap as IStandaloneTableCollection;
                for ( i = 0; i<=pStandAloneTabColl.StandaloneTableCount - 1; i++)
                {
                    if (pStandAloneTabColl.get_StandaloneTable(i).Name == "xxprofiletable")
                        pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.get_StandaloneTable(i));
                }
                //创建一个新的独立表,并把它添加到地图集合中
                IStandaloneTable pStandAloneTab = new StandaloneTableClass();
                pStandAloneTab.Table = pTable;
                pStandAloneTabColl = axMap.ActiveView.FocusMap as IStandaloneTableCollection;
                pStandAloneTabColl.AddStandaloneTable(pStandAloneTab);
                pTable = pStandAloneTab as ITable;
                                //为两个字段设置别名 
                ITableFields pTableFields = pStandAloneTab as ITableFields;
                IFieldInfo pFieldInfo = pTableFields.get_FieldInfo(pTableFields.FindField("Z"));
                pFieldInfo.Alias = "Ground Elevation";
                pFieldInfo = pTableFields.get_FieldInfo(pTableFields.FindField("SewerElev"));
                pFieldInfo.Alias = "Sewer Line Elevation";
                //为表格获得一个插入光标 
                ICursor pCursor=pTable.Insert(true);
                IRowBuffer pRowBuff;
                //
                IPointCollection pPtCollection = pPolyline as IPointCollection;
                IEnumVertex pEnumVertex = pPtCollection.EnumVertices;
                pEnumVertex.Reset();
                IPoint pPT;
                 int iPartIndex;
                int iVertexIndex;
                  i = 0;
                //添加节点XYZ到新表格中
                pEnumVertex.Next(out pPT, out iPartIndex, out iVertexIndex);
                while (pPT != null)
                {
                    pRowBuff = pTable.CreateRowBuffer();
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("X"),pPT.X);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("Y"),pPT.Y);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("Z"),pPT.Z);
                    pRowBuff.set_Value( pRowBuff.Fields.FindField("M"),pPT.M);
                    pRowBuff.set_Value(pRowBuff.Fields.FindField("SewerElev"), Convert.ToDouble(pSewerElevArray.get_Element(i)));
                    pCursor.InsertRow(pRowBuff);
                    pEnumVertex.Next(out pPT, out iPartIndex, out iVertexIndex);
                    i = i + 1;
                }
                pCursor.Flush();
                pCursor = null;
                pCursor = pTable.Search(null, false);
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "SewerElev <> -99";
                ICursor pCursorSewerElev = pTable.Search(pQueryFilter, false);

                pCursor = null;
                pCursor = pTable.Update(null, false);
                pRowBuff = pCursor.NextRow();
                double m = 0;
                double Mmin=0;
                double Mmax=0;
                double deltaM=0;
                double deltaSewerElev=0;
                double sewerelev=0;
                double newZ=0;
                int j = 0;
                double minSewerElev=0;
                double maxSewerElev=0;
                IRow pRowSewerElev;
                while (pRowBuff != null)
                {
                    if (Convert.ToDouble(pRowBuff.get_Value(pRowBuff.Fields.FindField("SewerElev"))) == -99)
                    {
                        m = Convert.ToDouble(pRowBuff.get_Value(pRowBuff.Fields.FindField("M")));
                        newZ = (((m - Mmin) / deltaM) * deltaSewerElev) + sewerelev;
                        pRowBuff.set_Value(pRowBuff.Fields.FindField("SewerElev"), newZ);
                        pCursor.UpdateRow(pRowBuff as IRow);
                    }
                    else
                    {
                        if (j == 0)
                        {
                            pRowSewerElev = pCursorSewerElev.NextRow();
                            minSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev")));
                            Mmin = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                            pRowSewerElev = pCursorSewerElev.NextRow();
                            maxSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev")));
                            Mmax = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                        }
                        else
                        {
                            pRowSewerElev = pCursorSewerElev.NextRow();
                            if (pRowSewerElev != null)
                            {
                                minSewerElev = maxSewerElev;
                                Mmin = Mmax;
                                maxSewerElev =Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev")));
                                Mmax = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                            }
                        }
                        deltaSewerElev = maxSewerElev - minSewerElev;
                        deltaM = Mmax - Mmin;
                        sewerelev = minSewerElev;
                        j = j + 1;
                    }
                    pRowBuff = pCursor.NextRow() as IRowBuffer;
                }
                pCursor.Flush();    
                //从表格中创建图形
                m_SewerElevStructArray = new ArrayClass();
               
                pCursor = null;
                pCursor = pTable.Search(null, false);
                pRowSewerElev = null;
                pRowSewerElev = pCursor.NextRow();
                while (pRowSewerElev != null)
                {
                    clsProfileStruct pProfileDataStruct = new clsProfileStruct();
                    pProfileDataStruct.M = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M")));
                    pProfileDataStruct.Z = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("Z")));
                    pProfileDataStruct.dSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("Sewerelev")));
                    m_SewerElevStructArray.Add(pProfileDataStruct);
                    pRowSewerElev = pCursor.NextRow();
                }

                frmDrawProfile frmDrawProfile1 = new frmDrawProfile(m_SewerElevStructArray);
                frmDrawProfile1.Show();
            }
        }