protected override IMap CreateMap() { if (_Map != null) { return(_Map); } _Map = new MapClass(); foreach (var o in base.GetTestClasses()) { IFeatureLayer layer = new FeatureLayerClass(); layer.FeatureClass = o; layer.Name = o.AliasName; _Map.AddLayer(layer); } var table = base.GetTestTable(); IStandaloneTable standaloneTable = new StandaloneTableClass(); standaloneTable.Table = table; standaloneTable.Name = ((IDataset)table).Name; IStandaloneTableCollection collection = (IStandaloneTableCollection)_Map; collection.AddStandaloneTable(standaloneTable); return(_Map); }
private IStandaloneTable GetLayerfromSDE(string FClassName) { string strSDEConnString = String.Format("server={0};instance={1};user={2};password={3};version={4}", strServer, strInstance, strUser, strPasswd, strVersion); IWorkspaceFactory2 pWorkFact = new SdeWorkspaceFactoryClass(); IFeatureWorkspace pFWorkspace = pWorkFact.OpenFromString(strSDEConnString, 0) as IFeatureWorkspace; ITable ptable = pFWorkspace.OpenTable(FClassName); IStandaloneTable pStandAloneTable = new StandaloneTableClass(); pStandAloneTable.Table = ptable; return(pStandAloneTable); }
/// <summary> /// Adds the table as a standalone table to the map. /// </summary> /// <param name="source">The source.</param> /// <param name="table">The table.</param> /// <returns>Returns a <see cref="IStandaloneTable" /> representing the table that was added to the map.</returns> public static IStandaloneTable AddTable(this IMap source, ITable table) { var standalone = new StandaloneTableClass { Table = table, Name = ((IDataset)table).Name }; IStandaloneTableCollection collection = (IStandaloneTableCollection)source; collection.AddStandaloneTable(standalone); return(standalone); }
private void AddTable(string strPath,string strFileName) { try { IWorkspaceFactory pFact = new TextFileWorkspaceFactory(); IWorkspace pWorkspace = pFact.OpenFromFile(strPath, 0); IFeatureWorkspace pFeatws = pWorkspace as IFeatureWorkspace; ITable ptable = pFeatws.OpenTable(strFileName); IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IStandaloneTable pStTab = new StandaloneTableClass(); pStTab.Table = ptable; IStandaloneTableCollection pStTabColl = pmap as IStandaloneTableCollection; pStTabColl.AddStandaloneTable(pStTab); pmxdoc.UpdateContents(); ITableWindow2 ptableWindow = new TableWindowClass(); ptableWindow.Application = ArcMap.Application ; ptableWindow.StandaloneTable = pStTab; ptableWindow.Show(true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFact); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspace); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatws); System.Runtime.InteropServices.Marshal.ReleaseComObject(ptable); System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTab); System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTabColl); System.Runtime.InteropServices.Marshal.ReleaseComObject(ptableWindow); GC.Collect(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddTable(string strPath, string strFileName) { try { IWorkspaceFactory pFact = new ShapefileWorkspaceFactory(); IWorkspace pWorkspace = pFact.OpenFromFile(strPath, 0); IFeatureWorkspace pFeatws = pWorkspace as IFeatureWorkspace; ITable ptable = pFeatws.OpenTable(strFileName); IMxDocument pmxdoc = ArcMap.Document as IMxDocument; IMap pmap = pmxdoc.FocusMap; IStandaloneTable pStTab = new StandaloneTableClass(); pStTab.Table = ptable; IStandaloneTableCollection pStTabColl = pmap as IStandaloneTableCollection; pStTabColl.AddStandaloneTable(pStTab); pmxdoc.UpdateContents(); ITableWindow2 ptableWindow = new TableWindowClass(); ptableWindow.Application = ArcMap.Application; ptableWindow.StandaloneTable = pStTab; ptableWindow.Show(true); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFact); System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspace); System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatws); System.Runtime.InteropServices.Marshal.ReleaseComObject(ptable); System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTab); System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTabColl); System.Runtime.InteropServices.Marshal.ReleaseComObject(ptableWindow); GC.Collect(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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; } }
private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool hasTopologyStuff, bool hasStationFunction, bool useRepresentation) { // Get references to the map for adding layers and tables IMxDocument MxDoc = (IMxDocument)ArcMap.Document; IMap thisMap = MxDoc.FocusMap; IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap; // Create a group layer IGroupLayer GeoMapGroupLayer = new GroupLayerClass(); GeoMapGroupLayer.Name = "Geologic Map"; if (hasTopologyStuff == true) { #region "GeologicMapTopology" ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase,"GeologicMapTopology"); ITopologyLayer geoMapTopoTL = new TopologyLayerClass(); geoMapTopoTL.Topology = geoMapTopo; ILayer geoMapTopoL = (ILayer)geoMapTopoTL; geoMapTopoL.Name = "Geologic Map Topology"; geoMapTopoL.Visible = false; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL; ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2); geoMapTopoLegendGroup.Visible = false; GeoMapGroupLayer.Add(geoMapTopoL); #endregion } if (hasStationFunction == true) { // Create a Group layer IGroupLayer stationGroupLayer = new GroupLayerClass(); stationGroupLayer.Name = "Station Data"; #region "StationPoints" // Open a FeatureClass, set it to a FeatureLayer IFeatureClass stationFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "StationPoints"); IFeatureLayer stationFL = new FeatureLayerClass(); stationFL.FeatureClass = stationFC; // Configure the FeatureLayer stationFL.Name = "Stations"; stationFL.DisplayField = "FieldID"; // Collapse the legend for this layer ILegendInfo stationLegendInfo = (ILegendInfo)stationFL; ILegendGroup stationLegendGroup = stationLegendInfo.get_LegendGroup(0); stationLegendGroup.Visible = false; // Finally, add the layer to the group layer stationGroupLayer.Add(stationFL); #endregion // Repeat for all these FeatureClasses #region "SamplePoints" IFeatureClass sampleFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "SamplePoints"); IFeatureLayer sampleFL = new FeatureLayerClass(); sampleFL.FeatureClass = sampleFC; sampleFL.Name = "Samples"; sampleFL.DisplayField = "FieldID"; ILegendInfo sampleLegendInfo = (ILegendInfo)sampleFL; ILegendGroup sampleLegendGroup = sampleLegendInfo.get_LegendGroup(0); sampleLegendGroup.Visible = false; stationGroupLayer.Add(sampleFL); #endregion #region "OrientationDataPoints" IFeatureClass structureFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationDataPoints"); IFeatureLayer structureFL = new FeatureLayerClass(); structureFL.FeatureClass = structureFC; structureFL.Name = "Orientation Data"; structureFL.DisplayField = "Type"; // Symbology, if representations are present if (useRepresentation == true) { // FeatureLayer must be cast as a GeoFeatureLayer in order to access the Renderer IGeoFeatureLayer structureGeoFL = (IGeoFeatureLayer)structureFL; // Create a RepresentationClassRenderer, assign the appropriate RepresentationClass to it IRepresentationRenderer structureRepRend = new RepresentationRendererClass(); structureRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_OrientationDataPoints"); // Assign the RepresentationClassRenderer to the GeoFeatureLayer structureGeoFL.Renderer = (IFeatureRenderer)structureRepRend; // Assign generic FeatureTemplates commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, structureFL as ILayer, "OrientationDataPoints"); } ILegendInfo structureLegendInfo = (ILegendInfo)structureFL; ILegendGroup structureLegendGroup = structureLegendInfo.get_LegendGroup(0); structureLegendGroup.Visible = false; stationGroupLayer.Add(structureFL); #endregion // Add the Group Layer to the main layer stationGroupLayer.Expanded = true; GeoMapGroupLayer.Add(stationGroupLayer); #region "Notes Table" ITable notesTable = commonFunctions.OpenTable(ValidNcgmpDatabase, "Notes"); IStandaloneTable notesStandalone = new StandaloneTableClass(); notesStandalone.Table = notesTable; notesStandalone.Name = "Notes"; notesStandalone.DisplayField = "Type"; thisMapTables.AddStandaloneTable(notesStandalone); #endregion #region "RelatedDocuments Table" ITable relatedDocsTable = commonFunctions.OpenTable(ValidNcgmpDatabase, "RelatedDocuments"); IStandaloneTable relatedDocsStandalone = new StandaloneTableClass(); relatedDocsStandalone.Table = relatedDocsTable; relatedDocsStandalone.Name = "Related Documents"; relatedDocsStandalone.DisplayField = "Type"; thisMapTables.AddStandaloneTable(relatedDocsStandalone); #endregion } if (hasTopologyStuff == true) { #region "OtherLines" IFeatureClass otherLinesFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OtherLines"); IFeatureLayer otherLinesFL = new FeatureLayerClass(); otherLinesFL.FeatureClass = otherLinesFC; otherLinesFL.Name = "Other Lines"; otherLinesFL.DisplayField = "Type"; if (useRepresentation == true) { IGeoFeatureLayer otherLinesGeoFL = (IGeoFeatureLayer)otherLinesFL; IRepresentationRenderer otherLinesRepRend = new RepresentationRendererClass(); otherLinesRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_OtherLines"); otherLinesGeoFL.Renderer = (IFeatureRenderer)otherLinesRepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, otherLinesFL as ILayer, "OtherLines"); } ILegendInfo otherLinesLegendInfo = (ILegendInfo)otherLinesFL; ILegendGroup otherLinesLegendGroup = otherLinesLegendInfo.get_LegendGroup(0); otherLinesLegendGroup.Visible = false; GeoMapGroupLayer.Add(otherLinesFL); #endregion } #region "ContactsAndFaults" IFeatureClass contactsAndFaultsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "ContactsAndFaults"); IFeatureLayer contactsAndFaultsFL = new FeatureLayerClass(); contactsAndFaultsFL.FeatureClass = contactsAndFaultsFC; contactsAndFaultsFL.Name = "Contacts and Faults"; contactsAndFaultsFL.DisplayField = "Type"; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer contactsAndFaultsGeoFL = (IGeoFeatureLayer)contactsAndFaultsFL; IRepresentationRenderer contactsAndFaultsRepRend = new RepresentationRendererClass(); contactsAndFaultsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_ContactsAndFaults"); contactsAndFaultsGeoFL.Renderer = (IFeatureRenderer)contactsAndFaultsRepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, contactsAndFaultsFL as ILayer, "ContactsAndFaults"); } ILegendInfo contactsAndFaultsLegendInfo = (ILegendInfo)contactsAndFaultsFL; ILegendGroup contactsAndFaultsLegendGroup = contactsAndFaultsLegendInfo.get_LegendGroup(0); contactsAndFaultsLegendGroup.Visible = false; GeoMapGroupLayer.Add(contactsAndFaultsFL); #endregion if (hasTopologyStuff == true) { #region "OverlayPolys" IFeatureClass overlayPolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OverlayPolys"); IFeatureLayer overlayPolysFL = new FeatureLayerClass(); overlayPolysFL.FeatureClass = overlayPolysFC; overlayPolysFL.Name = "Overlay Polygons"; overlayPolysFL.DisplayField = "MapUnit"; ILegendInfo overlayPolysLegendInfo = (ILegendInfo)overlayPolysFL; ILegendGroup overlayPolysLegendGroup = overlayPolysLegendInfo.get_LegendGroup(0); overlayPolysLegendGroup.Visible = false; GeoMapGroupLayer.Add(overlayPolysFL); #endregion } #region "MapUnitPolys" IFeatureClass mapUnitPolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "MapUnitPolys"); IFeatureLayer mapUnitPolysFL = new FeatureLayerClass(); mapUnitPolysFL.FeatureClass = mapUnitPolysFC; mapUnitPolysFL.Name = "Distribution of Map Units"; mapUnitPolysFL.DisplayField = "MapUnit"; ILegendInfo mapUnitPolysLegendInfo = (ILegendInfo)mapUnitPolysFL; ILegendGroup mapUnitPolysLegendGroup = mapUnitPolysLegendInfo.get_LegendGroup(0); mapUnitPolysLegendGroup.Visible = false; GeoMapGroupLayer.Add(mapUnitPolysFL); #endregion if (hasTopologyStuff == true) { #region "DataSourcePolys" IFeatureClass dataSourcePolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "DataSourcePolys"); IFeatureLayer dataSourcePolysFL = new FeatureLayerClass(); dataSourcePolysFL.FeatureClass = dataSourcePolysFC; dataSourcePolysFL.Name = "Data Source Polys"; dataSourcePolysFL.DisplayField = "DataSourceID"; ILegendInfo dataSourcePolysLegendInfo = (ILegendInfo)dataSourcePolysFL; ILegendGroup dataSourcePolysLegendGroup = dataSourcePolysLegendInfo.get_LegendGroup(0); dataSourcePolysLegendGroup.Visible = false; GeoMapGroupLayer.Add(dataSourcePolysFL); #endregion } // Add the Geologic Map Group Layer to the map GeoMapGroupLayer.Expanded = true; thisMap.AddLayer(GeoMapGroupLayer); // Adjust the MapUnitPolys Renderer commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase); // Adjust the MapUnitPolys Feature Templates commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase); }
public static bool LoadTableByDatasetName(string dsName, IMap pMap, IWorkspace pWorkspace) { bool retVal = false; try { IFeatureWorkspace pFeatureWS; pFeatureWS = (IFeatureWorkspace)pWorkspace; ITable pTable = pFeatureWS.OpenTable(dsName); if(pMap != null) { IStandaloneTableCollection pStandaloneTCol = (IStandaloneTableCollection)pMap; IStandaloneTable pStandaloneTable = new StandaloneTableClass(); pStandaloneTable.Table = pTable; pStandaloneTable.Name = dsName; pStandaloneTCol.AddStandaloneTable(pStandaloneTable); } retVal = true; } catch { retVal = false; } return retVal; }
private IStandaloneTable GetLayerfromSDE(string FClassName) { string strSDEConnString = String.Format("server={0};instance={1};user={2};password={3};version={4}",strServer,strInstance,strUser,strPasswd,strVersion); IWorkspaceFactory2 pWorkFact = new SdeWorkspaceFactoryClass(); IFeatureWorkspace pFWorkspace = pWorkFact.OpenFromString(strSDEConnString, 0) as IFeatureWorkspace; ITable ptable = pFWorkspace.OpenTable(FClassName); IStandaloneTable pStandAloneTable = new StandaloneTableClass(); pStandAloneTable.Table = ptable; return pStandAloneTable; }
public void addFunctionRasterToMap(IMap map) { try { ofd.Title = "Add Function Model to map"; ofd.Filter = "Function Dataset|*.fds|Batch Datasets|*.bch|NetCdf|*.nc"; ofd.Multiselect = false; ofd.FilterIndex = 2; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FunctionDatasetPath = ofd.FileName; int fIndex = ofd.FilterIndex; string outName = ""; object outobj = null; string outDesc = ""; if (fIndex == 1) { IRaster outRs; createFunctionRaster(out outName, out outRs, out outDesc); outobj = outRs; } else if (fIndex == 2) { createBatchRaster(out outName, out outobj, out outDesc); } else { createNetCdf(out outName, out outobj, out outDesc); } if (outobj is IFunctionRasterDataset) { IRasterLayer rsLyr = new RasterLayerClass(); rsLyr.CreateFromDataset((IRasterDataset)outobj); rsLyr.Name = outName; rsLyr.Visible = false; map.AddLayer((ILayer)rsLyr); } else if (outobj is IRaster) { IRasterLayer rsLyr = new RasterLayerClass(); rsLyr.CreateFromRaster((IRaster)outobj); rsLyr.Name = outName; rsLyr.Visible = false; map.AddLayer((ILayer)rsLyr); } else if (outobj is FeatureClass) { IFeatureLayer ftrLyr = new FeatureLayerClass(); ftrLyr.Name = outName; ftrLyr.Visible = false; ftrLyr.FeatureClass = (IFeatureClass)outobj; map.AddLayer((ILayer)ftrLyr); } else if (outobj is Table) { IStandaloneTableCollection stCol = (IStandaloneTableCollection)map; IStandaloneTable stTbl = new StandaloneTableClass(); stTbl.Table = (ITable)outobj; stTbl.Name = outName; stCol.AddStandaloneTable(stTbl); } else { System.Windows.Forms.MessageBox.Show("There was a problem parsing the model. Please check your model file"); } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Could not add output to the map:" + e.ToString(), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
// bool hasTopologyStuff, bool hasStationFunction, private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation) { // Get references to the map for adding layers and tables IMxDocument MxDoc = (IMxDocument)ArcMap.Document; IMap thisMap = MxDoc.FocusMap; IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap; // Create a group layer IGroupLayer GeoMapGroupLayer = new GroupLayerClass(); GeoMapGroupLayer.Name = "Geologic Map"; // Create a group layer IGroupLayer StationGroupLayer = new GroupLayerClass(); StationGroupLayer.Name = "Observation Data"; //if (hasTopologyStuff == true) { #region "GeologicMapTopology" ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology"); ITopologyLayer geoMapTopoTL = new TopologyLayerClass(); geoMapTopoTL.Topology = geoMapTopo; ILayer geoMapTopoL = (ILayer)geoMapTopoTL; geoMapTopoL.Name = "Geologic Map Topology"; geoMapTopoL.Visible = false; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL; ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2); geoMapTopoLegendGroup.Visible = false; GeoMapGroupLayer.Add(geoMapTopoL); #endregion } { #region "OrientationPoints" IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints"); IFeatureLayer orientationPointsFL = new FeatureLayerClass(); orientationPointsFL.FeatureClass = orientationPointsFC; orientationPointsFL.Name = "Orientation Points"; orientationPointsFL.DisplayField = "Type"; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL; IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass(); orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep"); orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints"); } ILegendInfo orientationPointsLegendInfo = (ILegendInfo)orientationPointsFL; ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0); orientationPointsLegendGroup.Visible = false; StationGroupLayer.Add(orientationPointsFL); #endregion #region "ObservationData" string[] arr = new string[4]; // Initialize arr[0] = "Stations"; // Element 1 arr[1] = "GenericPoints"; // Element 2 arr[2] = "GenericSamples"; // Element 3 arr[3] = "GeochronPoints"; // Element 4 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; FL.Visible = false; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; StationGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } //add station group layer to map document GeoMapGroupLayer.Add(StationGroupLayer); { #region "LinesWithoutRepresentations" string[] arr = new string[2]; // Initialize arr[0] = "CartographicLines"; // Element 1 arr[1] = "IsoValueLines"; // Element 2 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; FL.Visible = false; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "LinesWithRepresentations" string[] arr = new string[2]; // Initialize arr[0] = "GeologicLines"; // Element 1 arr[1] = "ContactsAndFaults"; // Element 2 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL; IRepresentationRenderer RepRend = new RepresentationRendererClass(); RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep"); GeoFL.Renderer = (IFeatureRenderer)RepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s); } ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "Polygons" string[] arr = new string[3]; // Initialize arr[0] = "DataSourcePolys"; // Element 1 arr[1] = "MapUnitPolys"; // Element 2 arr[2] = "OtherPolys"; // Element 3 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "Tables" string[] arr = new string[7]; // Initialize arr[0] = "DataSources"; // Element 1 arr[1] = "DescriptionOfMapUnits"; // Element 2 arr[2] = "ExtendedAttributes"; // Element 3 arr[3] = "GeologicEvents"; // Element 4 arr[4] = "Glossary"; // Element 5 arr[5] = "Notes"; // Element 6 arr[6] = "StandardLithology"; // Element 7 foreach (string s in arr) { try { ITable Table = commonFunctions.OpenTable(ValidNcgmpDatabase, s); IStandaloneTable Standalone = new StandaloneTableClass(); Standalone.Table = Table; Standalone.Name = s; thisMapTables.AddStandaloneTable(Standalone); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } // Add the Geologic Map Group Layer to the map GeoMapGroupLayer.Expanded = true; thisMap.AddLayer(GeoMapGroupLayer); // Adjust the MapUnitPolys Renderer commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase); // Adjust the MapUnitPolys Feature Templates commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase); }
private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation) // bool hasTopologyStuff, bool hasStationFunction, { // Get references to the map for adding layers and tables IMxDocument MxDoc = (IMxDocument)ArcMap.Document; IMap thisMap = MxDoc.FocusMap; IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap; // Create a group layer IGroupLayer GeoMapGroupLayer = new GroupLayerClass(); GeoMapGroupLayer.Name = "Geologic Map"; // Create a group layer IGroupLayer StationGroupLayer = new GroupLayerClass(); StationGroupLayer.Name = "Observation Data"; //if (hasTopologyStuff == true) { #region "GeologicMapTopology" ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology"); ITopologyLayer geoMapTopoTL = new TopologyLayerClass(); geoMapTopoTL.Topology = geoMapTopo; ILayer geoMapTopoL = (ILayer)geoMapTopoTL; geoMapTopoL.Name = "Geologic Map Topology"; geoMapTopoL.Visible = false; // Minimizing the legend info in the Table of Contents is not trivial ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL; ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1); geoMapTopoLegendGroup.Visible = false; geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2); geoMapTopoLegendGroup.Visible = false; GeoMapGroupLayer.Add(geoMapTopoL); #endregion } { #region "OrientationPoints" IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints"); IFeatureLayer orientationPointsFL = new FeatureLayerClass(); orientationPointsFL.FeatureClass = orientationPointsFC; orientationPointsFL.Name = "Orientation Points"; orientationPointsFL.DisplayField = "Type"; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL; IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass(); orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep"); orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints"); } ILegendInfo orientationPointsLegendInfo = (ILegendInfo)orientationPointsFL; ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0); orientationPointsLegendGroup.Visible = false; StationGroupLayer.Add(orientationPointsFL); #endregion #region "ObservationData" string[] arr = new string[4]; // Initialize arr[0] = "Stations"; // Element 1 arr[1] = "GenericPoints"; // Element 2 arr[2] = "GenericSamples"; // Element 3 arr[3] = "GeochronPoints"; // Element 4 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; FL.Visible = false; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; StationGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } //add station group layer to map document GeoMapGroupLayer.Add(StationGroupLayer); { #region "LinesWithoutRepresentations" string[] arr = new string[2]; // Initialize arr[0] = "CartographicLines"; // Element 1 arr[1] = "IsoValueLines"; // Element 2 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; FL.Visible = false; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "LinesWithRepresentations" string[] arr = new string[2]; // Initialize arr[0] = "GeologicLines"; // Element 1 arr[1] = "ContactsAndFaults"; // Element 2 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; if (useRepresentation == true) { // Set the layer renderer to use representations IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL; IRepresentationRenderer RepRend = new RepresentationRendererClass(); RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep"); GeoFL.Renderer = (IFeatureRenderer)RepRend; commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s); } ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "Polygons" string[] arr = new string[3]; // Initialize arr[0] = "DataSourcePolys"; // Element 1 arr[1] = "MapUnitPolys"; // Element 2 arr[2] = "OtherPolys"; // Element 3 foreach (string s in arr) { try { IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s); IFeatureLayer FL = new FeatureLayerClass(); FL.FeatureClass = FC; FL.Name = s; ILegendInfo LegendInfo = (ILegendInfo)FL; ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0); LegendGroup.Visible = false; GeoMapGroupLayer.Add(FL); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } { #region "Tables" string[] arr = new string[7]; // Initialize arr[0] = "DataSources"; // Element 1 arr[1] = "DescriptionOfMapUnits"; // Element 2 arr[2] = "ExtendedAttributes"; // Element 3 arr[3] = "GeologicEvents"; // Element 4 arr[4] = "Glossary"; // Element 5 arr[5] = "Notes"; // Element 6 arr[6] = "StandardLithology"; // Element 7 foreach (string s in arr) { try { ITable Table = commonFunctions.OpenTable(ValidNcgmpDatabase, s); IStandaloneTable Standalone = new StandaloneTableClass(); Standalone.Table = Table; Standalone.Name = s; thisMapTables.AddStandaloneTable(Standalone); } catch (Exception ex) { // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt"); string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n"; System.IO.File.AppendAllText(path, message); } } #endregion } // Add the Geologic Map Group Layer to the map GeoMapGroupLayer.Expanded = true; thisMap.AddLayer(GeoMapGroupLayer); // Adjust the MapUnitPolys Renderer commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase); // Adjust the MapUnitPolys Feature Templates commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase); }
/// <summary> /// this function takes a table and creates a shapefile (XY events) layer /// that is then added to the map /// </summary> /// <param name="pMxDoc">the map doc</param> /// <param name="sWorkspacePath">where to put the shapefile that is generated from the xy events / and where the dbf lives</param> /// <param name="sTableName">the name of the dbf to open</param> /// <param name="pSpatRef">the spatial ref for the prj file for the shapefile</param>\ /// <changelog> /// /// comments created. /// /// </changelog> public void addXYEvents(IMxDocument pMxDoc, string sWorkspacePath, string sTableName, ISpatialReference pSpatRef, string xField, string yField, string zField) { IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWSF.OpenFromFile(sWorkspacePath, 0); ITable pTable = (ITable)pFeatureWorkspace.OpenTable(sTableName); if (pTable == null) { MessageBox.Show("The table was not found"); return; } // Create a new standalone table and add it // to the collection of the focus map IStandaloneTable pStTab = new StandaloneTableClass(); pStTab.Table = (ITable)pTable; //sortTable(ref pTable); // Get the table name object IDataset pDataSet = (IDataset)pStTab; IName pTableName = pDataSet.FullName; // Specify the X and Y fields IXYEvent2FieldsProperties pXYEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass(); pXYEvent2FieldsProperties.XFieldName = xField; pXYEvent2FieldsProperties.YFieldName = yField; pXYEvent2FieldsProperties.ZFieldName = zField; // Create the XY name object and set it's properties IXYEventSourceName pXYEventSourceName = new XYEventSourceNameClass(); pXYEventSourceName.EventProperties = pXYEvent2FieldsProperties; if (pSpatRef != null) { pXYEventSourceName.SpatialReference = pSpatRef; } pXYEventSourceName.EventTableName = pTableName; IName pXYName = (IName)pXYEventSourceName; IXYEventSource pXYEventSource = (IXYEventSource)pXYName.Open(); // Create a new Map Layer IFeatureLayer pFLayer = new FeatureLayerClass(); pFLayer.FeatureClass = (IFeatureClass)pXYEventSource; pFLayer.Name = sTableName; //Add the layer extension (this is done so that when you edit //the layer's Source properties and click the Set Data Source //button, the Add XY Events Dialog appears) XYDataSourcePageExtension pRESPageExt = new XYDataSourcePageExtension(); ILayerExtensions pLayerExt = (ILayerExtensions)pFLayer; pLayerExt.AddExtension(pRESPageExt); //Get the FcName from the featureclass IFeatureClass pFc = pFLayer.FeatureClass; pDataSet = (IDataset)pFc; IFeatureClassName pINFeatureClassName = (IFeatureClassName)pDataSet.FullName; IDatasetName pInDsName = (IDatasetName)pINFeatureClassName; //Get the selection set IFeatureSelection pFSel = (IFeatureSelection)pFLayer; ISelectionSet pSelSet = (ISelectionSet)pFSel.SelectionSet; //Define the output feature class name IFeatureClassName pFeatureClassName = new FeatureClassNameClass(); IDatasetName pOutDatasetName = (IDatasetName)pFeatureClassName; //string sDSName = ensureDataName(pDataSet.Name, sWorkspacePath); string sDSName = pDataSet.Name; // +DateTime.UtcNow.DayOfYear + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second; pOutDatasetName.Name = sDSName; IWorkspaceName pWorkspaceName = new WorkspaceNameClass(); pWorkspaceName.PathName = sWorkspacePath; pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapeFileWorkspaceFactory"; pOutDatasetName.WorkspaceName = pWorkspaceName; pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple; pFeatureClassName.ShapeType = esriGeometryType.esriGeometryPoint; pFeatureClassName.ShapeFieldName = "Shape"; //Export IExportOperation pExportOp = new ExportOperationClass(); pExportOp.ExportFeatureClass(pInDsName, null, null, null, pOutDatasetName as IFeatureClassName, 0); IFeatureClass pClass = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(sDSName); IFeatureLayer pLayer = new FeatureLayerClass(); pLayer.FeatureClass = pClass; pLayer.Name = sDSName;//pClass.AliasName; pMxDoc.AddLayer(pLayer); pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); }
//���ݶ���ߺͷ������鴴���߳����� 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(); } }
private void OpenDataset() { if (null == m_hookHelper || null == m_workspace) { return; } if (string.Empty == (string)lstFeatureClasses.SelectedItem) { return; } bool refreshActiveView = false; foreach (string dataset in lstFeatureClasses.SelectedItems) { //get the selected item from the listbox //string dataset = (string)lstFeatureClasses.SelectedItem; //cast the workspace into a feature workspace IFeatureWorkspace featureWorkspace = m_workspace as IFeatureWorkspace; if (null == featureWorkspace) { return; } //get a featureclass (or standalone table) from the workspace ITable table = featureWorkspace.OpenTable(dataset) as ITable; if (table == null) { System.Windows.Forms.MessageBox.Show("Failed to open " + dataset); return; } // figure out if it is a table or featureclass IFeatureClass featureClass = table as IFeatureClass; if (featureClass == null) { // add as table IStandaloneTableCollection tableCollection = m_hookHelper.FocusMap as IStandaloneTableCollection; IStandaloneTable standaloneTable = new StandaloneTableClass(); standaloneTable.Name = ((IDataset)table).Name; standaloneTable.Table = table; tableCollection.AddStandaloneTable(standaloneTable); refreshActiveView = true; } else { // add as feature class IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = featureClass.AliasName; featureLayer.FeatureClass = featureClass; m_hookHelper.FocusMap.AddLayer((ILayer)featureLayer); } } if (refreshActiveView) { m_hookHelper.ActiveView.ContentsChanged(); } }
private void OpenDataset() { if (null == m_hookHelper || null == m_workspace) return; if (string.Empty == (string)lstFeatureClasses.SelectedItem) return; //get the selected item from the listbox string dataset = (string)lstFeatureClasses.SelectedItem; //cast the workspace into a feature workspace IFeatureWorkspace featureWorkspace = m_workspace as IFeatureWorkspace; if (null == featureWorkspace) return; //get a featureclass (or standalone table) from the workspace ITable table = featureWorkspace.OpenTable(dataset) as ITable; if (table == null) { System.Windows.Forms.MessageBox.Show("Failed to open " + dataset); return; } // figure out if it is a table or featureclass IFeatureClass featureClass = table as IFeatureClass; if (featureClass == null) { // add as table IStandaloneTableCollection tableCollection = m_hookHelper.FocusMap as IStandaloneTableCollection; IStandaloneTable standaloneTable = new StandaloneTableClass(); standaloneTable.Name = ((IDataset)table).Name; standaloneTable.Table = table; tableCollection.AddStandaloneTable(standaloneTable); m_hookHelper.ActiveView.ContentsChanged(); } else { // add as feature class IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = featureClass.AliasName; featureLayer.FeatureClass = featureClass; m_hookHelper.FocusMap.AddLayer((ILayer)featureLayer); } }
//根据多段线和阀门数组创建高程剖面 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(); } }