Beispiel #1
0
        private byte[] QueryPoint(ESRI.ArcGIS.Geometry.IPoint location, double distance)
        {
            if (distance <= 0.0)
                throw new ArgumentOutOfRangeException("distance");
            // Buffer the point.
            ITopologicalOperator topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)location;
            IGeometry queryGeometry = topologicalOperator.Buffer(distance);
            // Query the feature class.
            ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
            spatialFilter.Geometry = queryGeometry;
            spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
            spatialFilter.GeometryField = m_fcToQuery.ShapeFieldName;
            IFeatureCursor resultsFeatureCursor = m_fcToQuery.Search(spatialFilter, true);
            // Loop through the features, clip each geometry to the buffer
            // and total areas by attribute value.
            topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)queryGeometry;
            int classFieldIndex = m_fcToQuery.FindField(m_mapFieldToQuery);
            // System.Collections.Specialized.ListDictionary summaryStatsDictionary = new System.Collections.Specialized.ListDictionary();
            Dictionary<string, double> summaryStatsDictionary = new Dictionary<string, double>();
            // Initialize a list to hold JSON geometries.
            List<JsonObject> jsonGeometries = new List<JsonObject>();

            IFeature resultsFeature = null;
            while ((resultsFeature = resultsFeatureCursor.NextFeature()) != null)
            {
                // Clip the geometry.
                IPolygon clippedResultsGeometry = (IPolygon)topologicalOperator.Intersect(resultsFeature.Shape,
                    ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
                clippedResultsGeometry.Densify(0, 0); // Densify to maintain curved appearance when converted to JSON. 
                // Convert the geometry to JSON and add it to the list.
                JsonObject jsonClippedResultsGeometry = Conversion.ToJsonObject(clippedResultsGeometry);
                jsonGeometries.Add(jsonClippedResultsGeometry);
                // Get statistics.
                IArea area = (IArea)clippedResultsGeometry;
                string resultsClass = resultsFeature.get_Value(classFieldIndex) as string;
                // If the class is already in the dictionary, add the current feature's area to the existing entry.
                if (summaryStatsDictionary.ContainsKey(resultsClass))
                    summaryStatsDictionary[resultsClass] = (double)summaryStatsDictionary[resultsClass] + area.Area;
                else
                    summaryStatsDictionary[resultsClass] = area.Area;
            }
            // Use a helper method to get a JSON array of area records.
            JsonObject[] areaResultJson = CreateJsonRecords(summaryStatsDictionary) as JsonObject[];
            // Create a JSON object of the geometry results and the area records.
            JsonObject resultJsonObject = new JsonObject();
            resultJsonObject.AddArray("geometries", jsonGeometries.ToArray());
            resultJsonObject.AddArray("records", areaResultJson);
            // Get byte array of json and return results.
            byte[] result = Encoding.UTF8.GetBytes(resultJsonObject.ToJson());
            return result;
        }
Beispiel #2
0
 //鼠标点击事件
 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     if (pMouseOperate == "ZoomIn")
     {
         axMapControl1.Extent = axMapControl1.TrackRectangle();
     }
     if (pMouseOperate == "ZoomOut")
     {
         IEnvelope penv = axMapControl1.Extent;
         penv.Expand(2, 2, true);
         axMapControl1.Extent = penv;
     }
     if (pMouseOperate == "Pan")
     {
         axMapControl1.Pan();
     }
     if (pMouseOperate == "Identify")
     {
         IPoint point = new ESRI.ArcGIS.Geometry.Point();
         point.PutCoords(e.mapX, e.mapY);
         IFeatureLayer pFeatureLayer  = axMapControl1.get_Layer(0) as IFeatureLayer;
         IFeatureClass pFeatureClass  = pFeatureLayer.FeatureClass;
         string        shapefieldname = pFeatureClass.ShapeFieldName;
         ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
         pSpatialFilter.Geometry   = point;
         pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
         pSpatialFilter.set_OutputSpatialReference(shapefieldname, axMapControl1.SpatialReference);
         pSpatialFilter.GeometryField = shapefieldname;
         ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);
         ESRI.ArcGIS.Geodatabase.IFeature       pFeature       = pFeatureCursor.NextFeature();
         if (pFeature != null)
         {
             axMapControl1.FlashShape(pFeature.Shape);
         }
         IFields pField = pFeature.Fields;
         listFields.Items.Clear();
         for (int i = 0; i <= pField.FieldCount - 1; i++)
         {
             listFields.Items.Add(pField.get_Field(i).Name + "=" + pFeature.get_Value(i));
         }
     }
 }
Beispiel #3
0
        // get features that intersect the buffered mouse click and return them as a list of IFeature
        public List <IFeature> checkForIntersectingSegments(IPoint mousePoint, double buffer, IFeatureClass featureClass)
        {
            var envelope = mousePoint.Envelope;

            envelope.Expand(buffer, buffer, false);
            var    geodataset     = (IGeoDataset)featureClass;
            string shapeFieldName = featureClass.ShapeFieldName;

            ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
            spatialFilter.Geometry   = envelope;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;  // website for other options edndoc.esri.com/arcobjects/9.2/ComponentHelp/esrigeodatabase/esrispatialrelenum.htm
            spatialFilter.set_OutputSpatialReference(shapeFieldName, geodataset.SpatialReference);

            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

            var features = new List <IFeature>();

            ESRI.ArcGIS.Geodatabase.IFeature feature;
            while ((feature = featureCursor.NextFeature()) != null)
            {
                features.Add(feature);
            }
            return(features);
        }
        private byte[] QueryPoint(ESRI.ArcGIS.Geometry.IPoint location, double distance)
        {
            if (distance <= 0.0)
                throw new ArgumentOutOfRangeException("distance");
            // Buffer the point.
            ITopologicalOperator topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)location;
            IGeometry queryGeometry = topologicalOperator.Buffer(distance);
            // Query the feature class.
            ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
            spatialFilter.Geometry = queryGeometry;
            spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
            spatialFilter.GeometryField = m_fcToQuery.ShapeFieldName;
            IFeatureCursor resultsFeatureCursor = m_fcToQuery.Search(spatialFilter, true);
            // Loop through the features, clip each geometry to the buffer
            // and total areas by attribute value.
            topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)queryGeometry;
            int classFieldIndex = m_fcToQuery.FindField(m_mapFieldToQuery);
            // System.Collections.Specialized.ListDictionary summaryStatsDictionary = new System.Collections.Specialized.ListDictionary();
            Dictionary<string, double> summaryStatsDictionary = new Dictionary<string, double>();
            // Initialize a list to hold JSON geometries.
            List<JsonObject> jsonGeometries = new List<JsonObject>();

            IFeature resultsFeature = null;
            while ((resultsFeature = resultsFeatureCursor.NextFeature()) != null)
            {
                // Clip the geometry.
                IPolygon clippedResultsGeometry = (IPolygon)topologicalOperator.Intersect(resultsFeature.Shape,
                    ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
                clippedResultsGeometry.Densify(0, 0); // Densify to maintain curved appearance when converted to JSON. 
                // Convert the geometry to JSON and add it to the list.
                JsonObject jsonClippedResultsGeometry = Conversion.ToJsonObject(clippedResultsGeometry);
                jsonGeometries.Add(jsonClippedResultsGeometry);
                // Get statistics.
                IArea area = (IArea)clippedResultsGeometry;
                string resultsClass = resultsFeature.get_Value(classFieldIndex) as string;
                // If the class is already in the dictionary, add the current feature's area to the existing entry.
                if (summaryStatsDictionary.ContainsKey(resultsClass))
                    summaryStatsDictionary[resultsClass] = (double)summaryStatsDictionary[resultsClass] + area.Area;
                else
                    summaryStatsDictionary[resultsClass] = area.Area;
            }
            // Use a helper method to get a JSON array of area records.
            JsonObject[] areaResultJson = CreateJsonRecords(summaryStatsDictionary) as JsonObject[];
            // Create a JSON object of the geometry results and the area records.
            JsonObject resultJsonObject = new JsonObject();
            resultJsonObject.AddArray("geometries", jsonGeometries.ToArray());
            resultJsonObject.AddArray("records", areaResultJson);
            // Get byte array of json and return results.
            byte[] result = Encoding.UTF8.GetBytes(resultJsonObject.ToJson());
            return result;
        }