protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { int X = arg.X; int Y = arg.Y; IMxApplication pMxApp = null; IMxDocument pMxDoc = null; pMxApp = (IMxApplication)ArcMap.Application; pMxDoc = (IMxDocument)ArcMap.Application.Document; // calculate tolerance rectangle to identify features inside it int Tolerance = 0; Tolerance = pMxDoc.SearchTolerancePixels; IDisplayTransformation pDispTrans = null; pDispTrans = pMxApp.Display.DisplayTransformation; tagRECT pToleranceRect = new tagRECT(); pToleranceRect.left = X - Tolerance; pToleranceRect.right = X + Tolerance; pToleranceRect.top = Y - Tolerance; pToleranceRect.bottom = Y + Tolerance; IEnvelope pSearchEnvelope = null; pSearchEnvelope = new EnvelopeClass(); pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap)); // identify feature points of measurement IBasicDocument pBasicDoc = null; pBasicDoc = (IBasicDocument)ArcMap.Application.Document; pSearchEnvelope.SpatialReference = pMxDoc.ActiveView.FocusMap.SpatialReference; IIdentify pIdentify = null; pIdentify = (IIdentify)pMxDoc.FocusMap.get_Layer(0); if (pIdentify == null) { MessageBox.Show("No layer"); return; } IArray pIDArray = null; pIDArray = pIdentify.Identify(pSearchEnvelope); // get object from feature point IIdentifyObj pIDObj = null; if (pIDArray != null) pIDObj = (IIdentifyObj)pIDArray.get_Element(0); if (pIDObj == null) { MessageBox.Show("No feature was identified"); return; } // get the name of the layer containing feature points ILayer pLayer = null; pLayer = pMxDoc.FocusMap.get_Layer(0); string layerName = null; layerName = pLayer.Name; // get primary display field for measurement values and set names of a date/time field and gage ID field IFeatureLayer pFeatLayer = null; pFeatLayer = (IFeatureLayer)pLayer; string dataFldName = null; string timefldName = null; string gageIDFldName = null; dataFldName = "TSValue"; timefldName = "TSDateTime"; // substitute data/time field name for different dataset gageIDFldName = "Name"; // substitute gage ID field name for different dataset // get display table from layer ITable pTable = null; IDisplayTable pDisplayTable = null; pDisplayTable = (IDisplayTable)pLayer; if (pDisplayTable != null) { pTable = pDisplayTable.DisplayTable; if (pTable == null) goto THEEND; } // get fields from display table IFields pFields = null; pFields = pTable.Fields; long fldCount = 0; fldCount = pFields.FieldCount; // create WHERE clause from identified objects of measurement points int gageIDFldIdx = 0; gageIDFldIdx = pFields.FindField(gageIDFldName); IRowIdentifyObject pRowIDObj = null; pRowIDObj = (IRowIdentifyObject)pIDObj; string gageID = null; gageID = (string)pRowIDObj.Row.get_Value(gageIDFldIdx); IFeatureLayerDefinition pFeatureLayerDef = null; pFeatureLayerDef = (IFeatureLayerDefinition)pLayer; string definitionExpression = null; definitionExpression = pFeatureLayerDef.DefinitionExpression; string whereClause = null; if (definitionExpression == "") whereClause = "[" + gageIDFldName + "] = '" + gageID + "'"; else whereClause = "[" + gageIDFldName + "] = '" + gageID + "' AND " + definitionExpression; //find color for the identified object from feature layer's renderer IGeoFeatureLayer pGeoFeatureLayer = null; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; ILookupSymbol pLookupSymbol = null; pLookupSymbol = (ILookupSymbol)pGeoFeatureLayer.Renderer; IFeature pFeature = null; pFeature = (IFeature)pRowIDObj.Row; IMarkerSymbol pSymbol = null; pSymbol = (IMarkerSymbol)pLookupSymbol.LookupSymbol(false, pFeature); // Find an opened GraphWindow IDataGraphBase pDataGraphBase = null; IDataGraphT pDataGraphT = null; IDataGraphWindow2 pDGWin = null; IDataGraphCollection pDataGraphs = null; pDataGraphs = (IDataGraphCollection)pMxDoc; int grfCount = 0; grfCount = pDataGraphs.DataGraphCount; for (int i = 0; i < grfCount; i++) { pDataGraphBase = pDataGraphs.get_DataGraph(i); pDGWin = FindGraphWindow(ref pDataGraphBase); if (pDGWin != null) break; } // if there is not an opened graph window - create a new graph for if (pDGWin == null) { // create graph pDataGraphT = new DataGraphTClass(); pDataGraphBase = (IDataGraphBase)pDataGraphT; // load template from <ARCGISHOME>\GraphTemplates\ string strPath = null; strPath = Environment.GetEnvironmentVariable("ARCGISHOME"); try { pDataGraphT.LoadTemplate(strPath + @"GraphTemplates\timeseries.tee"); } catch { } // graph, axis and legend titles. Substitute them for different input layer pDataGraphT.GeneralProperties.Title = "Daily Streamflow for Guadalupe Basin in 1999"; pDataGraphT.LegendProperties.Title = "Monitoring Point"; pDataGraphT.get_AxisProperties(0).Title = "Streamflow (cfs)"; pDataGraphT.get_AxisProperties(0).Logarithmic = true; pDataGraphT.get_AxisProperties(2).Title = "Date"; pDataGraphBase.Name = layerName; } else // get graph from the opened window pDataGraphT = (IDataGraphT)pDataGraphBase; // create vertical line series for all measurements for the identified gage ISeriesProperties pSP = null; pSP = pDataGraphT.AddSeries("line:vertical"); pSP.ColorType = esriGraphColorType.esriGraphColorCustomAll; pSP.CustomColor = pSymbol.Color.RGB; pSP.WhereClause = whereClause; pSP.InLegend = true; pSP.Name = gageID; pSP.SourceData = pLayer; pSP.SetField(0, timefldName); pSP.SetField(1, dataFldName); IDataSortSeriesProperties pSortFlds = null; pSortFlds = (IDataSortSeriesProperties)pSP; int idx = 0; pSortFlds.AddSortingField(timefldName, true, ref idx); pDataGraphBase.UseSelectedSet = true; ITrackCancel pCancelTracker = null; pCancelTracker = new CancelTracker(); pDataGraphT.Update(pCancelTracker); // create data graph window if there is not any opened one if (pDGWin == null) { pDGWin = new DataGraphWindowClass(); pDGWin.DataGraphBase = pDataGraphBase; pDGWin.Application = ArcMap.Application; pDGWin.Show(true); pDataGraphs.AddDataGraph(pDataGraphBase); } THEEND: return; //base.OnMouseDown(arg); }
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; } }
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { int X = arg.X; int Y = arg.Y; IMxApplication pMxApp = null; IMxDocument pMxDoc = null; pMxApp = (IMxApplication)ArcMap.Application; pMxDoc = (IMxDocument)ArcMap.Application.Document; // calculate tolerance rectangle to identify features inside it int Tolerance = 0; Tolerance = pMxDoc.SearchTolerancePixels; IDisplayTransformation pDispTrans = null; pDispTrans = pMxApp.Display.DisplayTransformation; tagRECT pToleranceRect = new tagRECT(); pToleranceRect.left = X - Tolerance; pToleranceRect.right = X + Tolerance; pToleranceRect.top = Y - Tolerance; pToleranceRect.bottom = Y + Tolerance; IEnvelope pSearchEnvelope = null; pSearchEnvelope = new EnvelopeClass(); pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap)); // identify feature points of measurement IBasicDocument pBasicDoc = null; pBasicDoc = (IBasicDocument)ArcMap.Application.Document; pSearchEnvelope.SpatialReference = pMxDoc.ActiveView.FocusMap.SpatialReference; IIdentify pIdentify = null; pIdentify = (IIdentify)pMxDoc.FocusMap.get_Layer(0); if (pIdentify == null) { MessageBox.Show("No layer"); return; } IArray pIDArray = null; pIDArray = pIdentify.Identify(pSearchEnvelope); // get object from feature point IIdentifyObj pIDObj = null; if (pIDArray != null) { pIDObj = (IIdentifyObj)pIDArray.get_Element(0); } if (pIDObj == null) { MessageBox.Show("No feature was identified"); return; } // get the name of the layer containing feature points ILayer pLayer = null; pLayer = pMxDoc.FocusMap.get_Layer(0); string layerName = null; layerName = pLayer.Name; // get primary display field for measurement values and set names of a date/time field and gage ID field IFeatureLayer pFeatLayer = null; pFeatLayer = (IFeatureLayer)pLayer; string dataFldName = null; string timefldName = null; string gageIDFldName = null; dataFldName = "TSValue"; timefldName = "TSDateTime"; // substitute data/time field name for different dataset gageIDFldName = "Name"; // substitute gage ID field name for different dataset // get display table from layer ITable pTable = null; IDisplayTable pDisplayTable = null; pDisplayTable = (IDisplayTable)pLayer; if (pDisplayTable != null) { pTable = pDisplayTable.DisplayTable; if (pTable == null) { goto THEEND; } } // get fields from display table IFields pFields = null; pFields = pTable.Fields; long fldCount = 0; fldCount = pFields.FieldCount; // create WHERE clause from identified objects of measurement points int gageIDFldIdx = 0; gageIDFldIdx = pFields.FindField(gageIDFldName); IRowIdentifyObject pRowIDObj = null; pRowIDObj = (IRowIdentifyObject)pIDObj; string gageID = null; gageID = (string)pRowIDObj.Row.get_Value(gageIDFldIdx); IFeatureLayerDefinition pFeatureLayerDef = null; pFeatureLayerDef = (IFeatureLayerDefinition)pLayer; string definitionExpression = null; definitionExpression = pFeatureLayerDef.DefinitionExpression; string whereClause = null; if (definitionExpression == "") { whereClause = "[" + gageIDFldName + "] = '" + gageID + "'"; } else { whereClause = "[" + gageIDFldName + "] = '" + gageID + "' AND " + definitionExpression; } //find color for the identified object from feature layer's renderer IGeoFeatureLayer pGeoFeatureLayer = null; pGeoFeatureLayer = (IGeoFeatureLayer)pLayer; ILookupSymbol pLookupSymbol = null; pLookupSymbol = (ILookupSymbol)pGeoFeatureLayer.Renderer; IFeature pFeature = null; pFeature = (IFeature)pRowIDObj.Row; IMarkerSymbol pSymbol = null; pSymbol = (IMarkerSymbol)pLookupSymbol.LookupSymbol(false, pFeature); // Find an opened GraphWindow IDataGraphBase pDataGraphBase = null; IDataGraphT pDataGraphT = null; IDataGraphWindow2 pDGWin = null; IDataGraphCollection pDataGraphs = null; pDataGraphs = (IDataGraphCollection)pMxDoc; int grfCount = 0; grfCount = pDataGraphs.DataGraphCount; for (int i = 0; i < grfCount; i++) { pDataGraphBase = pDataGraphs.get_DataGraph(i); pDGWin = FindGraphWindow(ref pDataGraphBase); if (pDGWin != null) { break; } } // if there is not an opened graph window - create a new graph for if (pDGWin == null) { // create graph pDataGraphT = new DataGraphTClass(); pDataGraphBase = (IDataGraphBase)pDataGraphT; // load template from <ARCGISHOME>\GraphTemplates\ string strPath = null; strPath = Environment.GetEnvironmentVariable("ARCGISHOME"); try { pDataGraphT.LoadTemplate(strPath + @"GraphTemplates\timeseries.tee"); } catch { } // graph, axis and legend titles. Substitute them for different input layer pDataGraphT.GeneralProperties.Title = "Daily Streamflow for Guadalupe Basin in 1999"; pDataGraphT.LegendProperties.Title = "Monitoring Point"; pDataGraphT.get_AxisProperties(0).Title = "Streamflow (cfs)"; pDataGraphT.get_AxisProperties(0).Logarithmic = true; pDataGraphT.get_AxisProperties(2).Title = "Date"; pDataGraphBase.Name = layerName; } else // get graph from the opened window { pDataGraphT = (IDataGraphT)pDataGraphBase; } // create vertical line series for all measurements for the identified gage ISeriesProperties pSP = null; pSP = pDataGraphT.AddSeries("line:vertical"); pSP.ColorType = esriGraphColorType.esriGraphColorCustomAll; pSP.CustomColor = pSymbol.Color.RGB; pSP.WhereClause = whereClause; pSP.InLegend = true; pSP.Name = gageID; pSP.SourceData = pLayer; pSP.SetField(0, timefldName); pSP.SetField(1, dataFldName); IDataSortSeriesProperties pSortFlds = null; pSortFlds = (IDataSortSeriesProperties)pSP; int idx = 0; pSortFlds.AddSortingField(timefldName, true, ref idx); pDataGraphBase.UseSelectedSet = true; ITrackCancel pCancelTracker = null; pCancelTracker = new CancelTracker(); pDataGraphT.Update(pCancelTracker); // create data graph window if there is not any opened one if (pDGWin == null) { pDGWin = new DataGraphWindowClass(); pDGWin.DataGraphBase = pDataGraphBase; pDGWin.Application = ArcMap.Application; pDGWin.Show(true); pDataGraphs.AddDataGraph(pDataGraphBase); } THEEND: return; //base.OnMouseDown(arg); }