Пример #1
0
        public static IArray Identity(IFeatureClass featureclass, IGeometry geometry, string whereClause)
        {
            if (geometry == null)
            {
                return(null);
            }
            if (geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                ITopologicalOperator topop = geometry as ITopologicalOperator;
                double buffer = 0.0;
                if (double.TryParse(System.Configuration.ConfigurationManager.AppSettings["BUFFER"], out buffer))
                {
                    geometry = topop.Buffer(buffer);
                }
            }
            IFeatureLayer featureLayer = new FeatureLayerClass();

            featureLayer.FeatureClass = featureclass;
            IFeatureLayerDefinition featureLayerDefinition = featureLayer as IFeatureLayerDefinition;

            featureLayerDefinition.DefinitionExpression = whereClause;
            IFeatureLayer newfeatureLayer = featureLayerDefinition.CreateSelectionLayer(featureclass.AliasName, false, null, whereClause);
            IIdentify     identify        = featureLayer as IIdentify;
            IArray        identifyObjs    = identify.Identify(geometry);

            return(identifyObjs);
        }
Пример #2
0
        private static List <ArcmapPickCandidate> FindPickCandidates(
            IPoint mapPoint, List <IFeatureLayer> pickLayers, double mapScale, double searchTolerance)
        {
            List <ArcmapPickCandidate> result = new List <ArcmapPickCandidate>();

            if (pickLayers.Count > 0)
            {
                IEnvelope searchEnvelope = mapPoint.Envelope;
                searchEnvelope.Expand(searchTolerance, searchTolerance, false);

                foreach (IFeatureLayer pickLayer in pickLayers)
                {
                    if (ArcmapLayerUtils.LayerIsVisible(pickLayer, mapScale))
                    {
                        IIdentify identifier = pickLayer as IIdentify;
                        IArray    elements   = identifier.Identify(searchEnvelope);
                        foreach (object element in elements.Enumerate())
                        {
                            IFeature feature = (element as IRowIdentifyObject).Row as IFeature;
                            double   distance;
                            IPoint   footPoint;
                            CalculateNearestDistanceToFeature(mapPoint, feature, out distance, out footPoint);

                            ArcmapPickCandidate ranking = new ArcmapPickCandidate(element as IIdentifyObj, distance);
                            result.Add(ranking);
                        }
                    }
                }
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 查询点缓冲区以内的要素
        /// </summary>
        /// <param name="point"></param>
        /// <param name="map"></param>
        /// <param name="layer"></param>
        /// <param name="buffer_distance"></param>
        /// <returns></returns>
        public IFeature QuerySingleFeatureByPoint(IPoint point, IMap map, IFeatureLayer layer, double buffer_distance)
        {
            //为了安全在此判断是否map中是否已经包括layer
            bool isContain = false;

            for (int i = 0; i < map.LayerCount; i++)
            {
                if (map.get_Layer(i) == layer)
                {
                    isContain = true;
                    break;
                }
            }
            if (!isContain)
            {
                throw new Exception("Map中不包括该图层");
            }
            ITopologicalOperator pTopOperator = point as ITopologicalOperator;
            IGeometry            pGeometry    = pTopOperator.Buffer(buffer_distance);
            IIdentify            pIdentity    = layer as IIdentify;
            IArray   pArray   = pIdentity.Identify(pGeometry);
            IFeature pFeature = null;

            if (pArray != null)
            {
                pFeature = (pArray.get_Element(0) as IRowIdentifyObject).Row as IFeature;
            }
            return(pFeature);
        }
Пример #4
0
 /// <summary>
 /// 通过缓冲区二分查找获取点到线要素图层中的最短距离
 /// 基于二分查找和贪心算法
 /// </summary>
 /// <param name="featureLayer">要素图层</param>
 /// <param name="point">被查询点</param>
 /// <param name="thefeature">缓冲区中最近要素</param>
 /// <param name="distance">最短距离</param>
 /// <param name="disNum">在线段上的位置集合,1在右方,2在左方,0在线上</param>
 /// <param name="minSpan">最小间距</param>
 /// <returns>离点最近的单线</returns>
 public static IPoint GetNearestLineInFeatureLayerByBufferBinary(IFeatureLayer featureLayer, IPoint point, ref IFeature thefeature, ref double distance, ref int disNum, double minSpan)
 {
     #region 初始化操作
     IQueryFilter pQueryFilter = new QueryFilter();
     pQueryFilter.WhereClause = "";
     //要素个数为0则直接返回null
     int count = featureLayer.FeatureClass.FeatureCount(pQueryFilter);
     if (count == 0)
     {
         return(null);
     }
     //个数为1则直接计算
     else if (count == 1)
     {
         return(GetNearestLineInFeatureLayer(featureLayer, point, ref thefeature, ref distance, ref disNum));
     }
     #endregion
     double low    = 0;
     double high   = GetPointToTheEnvelopMax(featureLayer, point);
     IArray pArray = null;
     ////求最大缓冲区内的要素个数
     ITopologicalOperator pTopOperator = point as ITopologicalOperator;
     IGeometry            pGeometry    = pTopOperator.Buffer(high);
     ILayer    layer     = featureLayer as ILayer;
     IIdentify pIdentity = layer as IIdentify;
     pArray = pIdentity.Identify(pGeometry);
     // 如果为0或者计算错误直接返回null
     if (pArray.Count == 0 || pArray == null)
     {
         return(null);
     }
     //如果只有一个要素 则直接计算返回
     else if (pArray.Count == 1)
     {
         return(GetPointToIArrayMin(point, ref thefeature, ref distance, ref disNum, pArray));
     }
     ///////////////////////////////////////////////
     while ((high - low) < minSpan)
     {
         double buffer_distance = (low + high) / 2;
         pGeometry = pTopOperator.Buffer(buffer_distance);
         pArray    = pIdentity.Identify(pGeometry);
         if (pArray.Count == 0)
         {
             low = buffer_distance;
         }
         else
         {
             high = buffer_distance;
         }
     }
     ////此时high可以认为是最低缓冲区距离 直接求解最短距离
     pGeometry = pTopOperator.Buffer(high);
     pArray    = pIdentity.Identify(pGeometry);
     return(GetPointToIArrayMin(point, ref thefeature, ref distance, ref disNum, pArray));
 }
Пример #5
0
        public void DoLayerIdentify(ILayer layer, IGeometry geo)
        {
            if (layer != null && layer is IIdentify)
            {
                IIdentify id   = layer as IIdentify;
                IArray    objs = id.Identify(geo);

                if (objs != null)
                {
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 暴力获取点到其缓冲区中的最短距离
        /// </summary>
        /// <param name="featureLayer">要素图层</param>
        /// <param name="point">被查询点</param>
        /// <param name="thefeature">缓冲区中第一个要素</param>
        /// <param name="distance">最短距离</param>
        /// <param name="disNum">在线段上的位置集合,1在右方,2在左方,0在线上</param>
        /// <param name="buffer_distance">缓冲区距离</param>
        /// <returns>离点最近的单线</returns>
        public static IPoint GetNearestLineInFeatureLayer(IFeatureLayer featureLayer, IPoint point, ref IFeature thefeature, ref double distance, ref int disNum, double buffer_distance)
        {
            ITopologicalOperator pTopOperator = point as ITopologicalOperator;
            IGeometry            pGeometry    = pTopOperator.Buffer(buffer_distance);
            ILayer    layer     = featureLayer as ILayer;
            IIdentify pIdentity = layer as IIdentify;
            IArray    pArray    = pIdentity.Identify(pGeometry);

            if (pArray == null)
            {
                return(null);
            }
            return(GetPointToIArrayMin(point, ref thefeature, ref distance, ref disNum, pArray));
        }
Пример #7
0
 /// <summary>
 /// 通过梯级缓冲区获取点到线要素图层中的最短距离
 /// </summary>
 /// <param name="featureLayer">要素图层</param>
 /// <param name="point">被查询点</param>
 /// <param name="thefeature">缓冲区中第一个要素</param>
 /// <param name="distance">最短距离</param>
 /// <param name="disNum">在线段上的位置集合,1在右方,2在左方,0在线上</param>
 /// <param name="buffer_Span">缓冲区梯度</param>
 /// <returns>离点最近的单线</returns>
 public static IPoint GetNearestLineInFeatureLayerByBuffer(IFeatureLayer featureLayer, IPoint point, ref IFeature thefeature, ref double distance, ref int disNum, double buffer_Span)
 {
     #region 初始化操作
     IQueryFilter pQueryFilter = new QueryFilter();
     pQueryFilter.WhereClause = "";
     //要素个数为0则直接返回null
     int count = featureLayer.FeatureClass.FeatureCount(pQueryFilter);
     if (count == 0)
     {
         return(null);
     }
     //个数为1则直接计算
     else if (count == 1)
     {
         return(GetNearestLineInFeatureLayer(featureLayer, point, ref thefeature, ref distance, ref disNum));
     }
     #endregion
     double buffer_distance = 0;
     while (true)
     {
         buffer_distance += buffer_Span;
         ITopologicalOperator pTopOperator = point as ITopologicalOperator;
         IGeometry            pGeometry    = pTopOperator.Buffer(buffer_distance);
         ILayer    layer     = featureLayer as ILayer;
         IIdentify pIdentity = layer as IIdentify;
         IArray    pArray    = pIdentity.Identify(pGeometry);
         if (pArray == null)
         {
             return(null);
         }
         if (pArray.Count == 0)
         {
             continue;
         }
         return(GetPointToIArrayMin(point, ref thefeature, ref distance, ref disNum, pArray));
     }
 }
Пример #8
0
        private void MapUserIdentify(double mapX, double mapY)
        {
            try
            {
                //axMapControl1.Map.ClearSelection();
                ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = (IMapControl3)axMapControl1.Object;
                IMap        pMap        = axMapControl1.Map;
                IGroupLayer pGroupLayer = new GroupLayer();

                if (pMap.LayerCount == 0)
                {
                    return;
                }
                IEnumLayer pEnumLayer;
                ILayer     pLayer;
                pEnumLayer = pMap.get_Layers(null, true);
                if (pEnumLayer == null)
                {
                    return;
                }
                pEnumLayer.Reset();
                double dCurrScale = m_mapControl.MapScale;
                for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
                {
                    if (pLayer.Visible)
                    {
                        if (pLayer is IGroupLayer)
                        {
                            continue;
                        }
                        if (pLayer.MinimumScale != 0 && dCurrScale > pLayer.MinimumScale)
                        {
                            continue;
                        }
                        if (pLayer.MaximumScale != 0 && dCurrScale < pLayer.MaximumScale)
                        {
                            continue;
                        }
                        pGroupLayer.Add(pLayer);
                    }
                }

                IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
                pPoint.X = mapX; pPoint.Y = mapY;
                IIdentifyObj        pIdObj;
                IIdentify           pIdentify = pGroupLayer as IIdentify;
                IArray              pIDArray;
                IFeatureIdentifyObj pFeatIdObj;

                IEnvelope pEnv             = pPoint.Envelope;
                IDisplayTransformation pDT = m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation;
                pEnv.Expand(pDT.VisibleBounds.Width / 200, pDT.VisibleBounds.Height / 200, false);

                pIDArray = pIdentify.Identify(pEnv);

                if (pIDArray == null || pIDArray.Count == 0)
                {
                    return;
                }

                pFeatIdObj = pIDArray.get_Element(0) as IFeatureIdentifyObj;
                pIdObj     = pFeatIdObj as IIdentifyObj;

                IRowIdentifyObject pRowIdentifyObj = pFeatIdObj as IRowIdentifyObject;
                IFeature           pFeature        = pRowIdentifyObj.Row as IFeature;
                if (pFeature != null && pFeature.Shape != null && !pFeature.Shape.IsEmpty)
                {
                    //axMapControl1.FlashShape(pFeature.Shape);
                    axMapControl1.Map.SelectFeature(pIdObj.Layer, pFeature);
                    FlashFeature(axMapControl1, pFeature.Shape);
                }

                //  pIdObj.Flash(m_mapControl.ActiveView.ScreenDisplay);//The Flash method is not supported with ArcGIS Engine, use the IHookActions.DoActions() method with the esriHookActionsFlash for this functionality.
                ILayer pIdentiyLayer = pIdObj.Layer;

                DataTable  pTable      = new DataTable();
                DataColumn pDataColumn = pTable.Columns.Add();
                pDataColumn.ColumnName = "列名";
                pDataColumn            = pTable.Columns.Add();
                pDataColumn.ColumnName = "值";

                DataRow pFirestDataRow = pTable.Rows.Add();
                pFirestDataRow[0] = "所在层";
                pFirestDataRow[1] = pIdentiyLayer.Name;

                if (pIdentiyLayer is IFeatureLayer)
                {
                    IRowIdentifyObject pRowObj = pIdObj as IRowIdentifyObject;
                    //   IRow pRow = pRowObj.Row;

                    IFeature pRow    = pRowObj.Row as IFeature;
                    IFields  pFields = pRow.Fields;

                    for (int i = 0; i < pFields.FieldCount; i++)
                    {
                        IField  pField   = pFields.get_Field(i);
                        DataRow pDataRow = null;

                        /*
                         * switch (pField.Type)
                         * {
                         *  case esriFieldType.esriFieldTypeOID:
                         *      pDataRow = pTable.Rows.Add();
                         *      pDataRow[0] = pField.Name;
                         *      pDataRow[1] = pRow.OID.ToString();
                         *      break;
                         *  case esriFieldType.esriFieldTypeGeometry:
                         *      //pDataRow[0] = "Geometry";
                         *      //pDataRow[1] = QueryShapeType(pField.GeometryDef.GeometryType);;
                         *      break;
                         *  default:
                         *      pDataRow = pTable.Rows.Add();
                         *      pDataRow[0] = pField.Name;
                         *      pDataRow[1] = pRow.get_Value(i).ToString();
                         *      break;
                         * }
                         * * */

                        //////////////////////////////////////////////////
                        string sValue   = pRow.get_Value(i).ToString();
                        string strFName = pField.AliasName.ToUpper();
                        string strUName = strFName.ToUpper();
                        if (strUName == "SHAPE" || strUName == "LENGTH" || strUName == "OBJECTID" || strUName == "ID" || strUName == "FNODE_" || strUName == "TNODE_" || strUName == "LPOLY_" || strUName == "RPOLY_" || strUName == "SDXL_" || strUName == "SDXL_ID" || strUName == "OBJECTID_1" || strUName == "FID")
                        {
                            continue;
                        }
                        else if (strUName == "SHAPE.LEN" || strUName == "SHAPE_LENG")
                        {
                            strFName = "几何长度";
                        }
                        else if (strUName == "SHAPE_AREA" || strUName == "SHAPE.AREA")
                        {
                            strFName = "多边形面积";
                        }
                        else if (strUName == "HEIGHT")
                        {
                            strFName = "高程";
                        }
                        else if (strUName == "NAME")
                        {
                            strFName = "名称";
                        }
                        else if (strUName == "TYPE")
                        {
                            strFName = "类型";
                        }
                        else if (strUName == "SUBTYPE")
                        {
                            strFName = "子类型";
                        }

                        if (strUName == "LENGTH" || strUName == "SHAPE.LEN")
                        {
                            IUnitConverter myUnit = new UnitConverterClass();
                            sValue = Math.Round(myUnit.ConvertUnits((double)pRow.get_Value(i), esriUnits.esriMeters, esriUnits.esriKilometers), 2).ToString();
                            sValue = sValue.ToString() + "千米";
                        }
                        if (strUName == "SHAPE_AREA" || strUName == "SHAPE.AREA")
                        {
                            IGeometry pGeo = pRow.ShapeCopy;
                            pGeo.Project(axMapControl1.Map.SpatialReference);
                            IPolygon pPolygon = (IPolygon)pGeo;
                            IArea    pArea    = (IArea)pPolygon;
                            double   strValue = pArea.Area * 0.000001;
                            //// double strValue = Math.Abs((double)pFeature.get_Value(j)) * 10585;
                            strValue = Math.Round(strValue, 2);
                            sValue   = strValue.ToString() + "平方千米";
                        }
                        esriFieldType tFieldTypy = pField.Type;
                        if (tFieldTypy == esriFieldType.esriFieldTypeGeometry)
                        {
                            sValue = pField.GeometryDef.GeometryType.ToString();
                            sValue = sValue.Substring(12, sValue.Length - 12);
                        }

                        pDataRow    = pTable.Rows.Add();
                        pDataRow[0] = strFName;
                        pDataRow[1] = sValue;

                        //////////////////////////////////////////////////
                    }
                }
                else if (pIdentiyLayer is ITinLayer)
                {
                    ITinLayer   pTinLayer   = (ITinLayer)pIdentiyLayer;
                    ITinSurface pTinSurface = (ITinSurface)pTinLayer.Dataset;
                    if (pTinSurface == null)
                    {
                        return;
                    }
                    ITinSurfaceElement pTinSurfaceElement = pTinSurface.GetSurfaceElement(pPoint);

                    if (pTinSurfaceElement == null)
                    {
                        return;
                    }
                    IFields pFields  = pTinLayer.Dataset.Fields;
                    DataRow pDataRow = null;

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "高度";
                    pDataRow[1] = pTinSurfaceElement.Elevation.ToString();

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "坡度";
                    pDataRow[1] = pTinSurfaceElement.SlopeDegrees.ToString();

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "方向";
                    pDataRow[1] = pTinSurfaceElement.AspectDegrees.ToString();
                }

                if (pIdentiyLayer is IRasterLayer)
                {
                    MessageBox.Show("aa");
                }
                //ShowIndetify(pTable);
                //m_pMainform.ShowIndetify(pTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
 public override void OnMouseDown(int Button, int Shift, int X, int Y)
 {
     if (Button == 1)
     {
         List <ILayer> layers = EngineAPI.GetLayers(this.m_hookHelper.FocusMap, "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}", null);
         if (layers.Count == 0)
         {
             IdentifyManager.instance.FrmIdentify.Close();
             IdentifyManager.instance.FrmIdentify      = null;
             EnviVars.instance.MapControl.CurrentTool  = null;
             EnviVars.instance.MapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
         }
         else
         {
             foreach (ILayer current in layers)
             {
                 IIdentify identify = current as IIdentify;
                 IPoint    point    = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                 IArray    array    = identify.Identify(point);
                 if (array != null && array.Count != 0)
                 {
                     IdentifyManager.instance.FrmIdentify.treeList1.ClearNodes();
                     IIdentifyObj identifyObj = array.get_Element(0) as IIdentifyObj;
                     identifyObj.Flash(this.m_hookHelper.ActiveView.ScreenDisplay);
                     TreeListNode treeListNode = IdentifyManager.instance.FrmIdentify.treeList1.AppendNode(new object[]
                     {
                         identifyObj.Layer.Name
                     }, 0, identifyObj);
                     DataColumn column    = new DataColumn("字段", typeof(string));
                     DataColumn column2   = new DataColumn("值", typeof(string));
                     DataTable  dataTable = new DataTable();
                     dataTable.Columns.Add(column);
                     dataTable.Columns.Add(column2);
                     if (current is IFeatureLayer)
                     {
                         IFeature     feature       = (identifyObj as IRowIdentifyObject).Row as IFeature;
                         TreeListNode treeListNode2 = IdentifyManager.instance.FrmIdentify.treeList1.AppendNode(new object[]
                         {
                             feature.OID.ToString()
                         }, treeListNode);
                         int num = feature.Fields.FindField((current as IFeatureLayer).FeatureClass.ShapeFieldName);
                         for (int i = 0; i < feature.Fields.FieldCount; i++)
                         {
                             if (num != i)
                             {
                                 DataRow dataRow = dataTable.NewRow();
                                 dataRow["字段"] = feature.Fields.get_Field(i).AliasName;
                                 dataRow["值"]  = feature.get_Value(i).ToString();
                                 dataTable.Rows.Add(dataRow);
                             }
                         }
                         treeListNode2.Tag = dataTable;
                     }
                     else if (current is IRasterLayer)
                     {
                         IRasterLayer rasterLayer = current as IRasterLayer;
                         IRaster2     raster      = rasterLayer.Raster as IRaster2;
                         int          num2        = raster.ToPixelRow(point.Y);
                         int          num3        = raster.ToPixelColumn(point.X);
                         double       num4        = CommonAPI.ConvertToDouble(raster.GetPixelValue(0, num3, num2));
                         this.AddRow(dataTable, "像素值", num4);
                         this.AddRow(dataTable, "行号", num2);
                         this.AddRow(dataTable, "列号", num3);
                         IRasterIdentifyObj rasterIdentifyObj = array.get_Element(0) as IRasterIdentifyObj;
                         if (rasterLayer.BandCount != 1)
                         {
                             Regex           regex           = new Regex("\\d{2,3}");
                             MatchCollection matchCollection = regex.Matches(rasterIdentifyObj.MapTip);
                             if (matchCollection.Count == 3)
                             {
                                 this.AddRow(dataTable, "R", matchCollection[0].Value);
                                 this.AddRow(dataTable, "G", matchCollection[1].Value);
                                 this.AddRow(dataTable, "B", matchCollection[2].Value);
                             }
                         }
                         IdentifyManager.instance.FrmIdentify.treeList1.AppendNode(new object[]
                         {
                             rasterIdentifyObj.Name
                         }, treeListNode, dataTable);
                     }
                     IdentifyManager.instance.FrmIdentify.UpdateStatusText(string.Format("X:{0:0.000 },Y:{1:0.000}", point.X, point.Y));
                     IdentifyManager.instance.FrmIdentify.treeList1.ExpandAll();
                     if (treeListNode.Nodes.Count > 0)
                     {
                         IdentifyManager.instance.FrmIdentify.treeList1.FocusedNode = treeListNode.Nodes[0];
                     }
                     IdentifyManager.instance.FrmIdentify.Show();
                     break;
                 }
                 IdentifyManager.instance.FrmIdentify.Close();
                 IdentifyManager.instance.FrmIdentify = null;
             }
         }
     }
 }
Пример #11
0
        private static ValueList GetPixelData(IMap map, IEnvelope extent, HashSet <string> includeFields)
        {
            ValueList result = new ValueList();

            for (int i = 0; i < map.LayerCount; i += 1)
            {
                ILayer layer = map.get_Layer(i);
                if (!layer.Visible)
                {
                    continue;
                }
                IIdentify id = layer as IIdentify;
                if (id == null)
                {
                    continue;
                }
                IArray data = id.Identify(extent);
                if (data != null)
                {
                    for (int j = 0; j < data.Count; j += 1)
                    {
                        object foundObj            = data.get_Element(j);
                        IRasterIdentifyObj2 raster = foundObj as IRasterIdentifyObj2;
                        IRowIdentifyObject  row    = foundObj as IRowIdentifyObject;
                        if (raster != null)
                        {
                            int    propertyIndex = 0;
                            string property;
                            string value;
                            while (true)
                            {
                                try {
                                    raster.GetPropAndValues(propertyIndex, out property, out value);
                                    if ((!"NoData".Equals(value)) &&
                                        ((includeFields == null) || includeFields.Contains(property)))
                                    {
                                        result.Add(property, value);
                                    }
                                    propertyIndex += 1;
                                } catch {
                                    break;
                                }
                            }
                            continue;
                        }
                        else if (row != null)
                        {
                            IFields fields = row.Row.Fields;
                            for (int k = 0; k < fields.FieldCount; k += 1)
                            {
                                string fieldName = fields.get_Field(k).Name;
                                if ((includeFields == null) ? (!result.ContainsKey(fieldName)) : includeFields.Contains(fieldName))
                                {
                                    result.Add(fieldName, row.Row.get_Value(k));
                                }
                            }
                        }
                    }
                    break;
                }
            }
            return(result);
        }