我的github

目的:

This sample shows a server object extension (SOE) that queries and clips features within a buffer distance and summarizes the resulting area based on a given attribute. The SOE is exposed as a representational state transfer (REST) Web service. It works with map services only.
All the information needed to deploy the SOE is included in this sample encapsulated in a .soe file. Deploying the SOE from this file does not require you to open Visual Studio. However, you can open the Visual Studio solution included with this sample to explore the coding patterns used in the SOE.

此示例显示了一个服务器对象扩展(SOE),该扩展在缓冲区距离内查询和剪辑功能,并基于给定属性总结结果区域。SOE作为一个代表性状态传输(REST)Web服务公开。它只适用于地图服务。
部署SOE所需的所有信息都包含在这个封装在.SOE文件中的示例中。从该文件部署SOE不需要打开Visual Studio。但是,您可以打开此示例附带的visualstudio解决方案来探索SOE中使用的编码模式。

This sample also includes a simple JavaScript application that consumes the SOE. It lets the user specify a buffer distance and a point on the map. In response, the application draws the clipped geometries and displays a summarized table of areas for the clipped polygons, based on vegetation type. The application assumes you have deployed the SOE on the Yellowstone sample map from the .NET ArcObjects software development kit (SDK). Instructions for testing the SOE based with this dataset are given below.
此示例还包括一个使用SOE的简单JavaScript应用程序。它允许用户在地图上指定缓冲区距离和点。作为响应,应用程序绘制裁剪的几何图形,并根据植被类型显示裁剪多边形的面积汇总表。应用程序假定您已经在黄石公园的.NET ArcObjects软件开发工具包(SDK)样例地图上部署了SOE。下面给出了使用此数据集测试SOE的说明。
The instructions below assume that you have installed the developer kit on the machine running ArcGIS Server Manager. If you installed the developer kit on some other machine, you'll need to copy the .soe file to the machine running Manager, or otherwise make the .soe file visible to Manager by placing it in a shared folder.
以下说明假定您已在运行ArcGIS Server Manager的计算机上安装了开发人员工具包。如果在其他计算机上安装了开发人员工具包,则需要将.soe文件复制到运行Manager的计算机上,或者将.soe文件放在共享文件夹中,使其对Manager可见。
 
Deploy the SOE
  1. Log in to ArcGIS Server Manager and click Site.
  2. Click Extensions.
  3. Click Add Extension.
  4. Click Browse and navigate to the .soe file, which by default is located at <ArcGIS DeveloperKit install location>\Samples\ArcObjectsNet\ServerSpatialQueryRESTSOE\CSharp\SpatialQueryREST\bin\Debug\SpatialQueryREST.soe.
  5. Click OK.
Enable the SOE on a service
  1. Start ArcMap and click File > Open.
  2. Browse to or type the location of Yellowstone.mxd, which is located in <ArcGIS Developer Kit Location>\Samples\data\Yellowstone.
  3. Click File > Share As > Service.
  4. Click Save a service definition and click Next.
  5. Choose "No available connection" and check "Include data in service definition when publishing".
  6. Change the Server type to ArcGIS Server.
  7. Leave the Service name as Yellowstone and click Next.
  8. Choose a location where you want to save the service definition, then click Continue.
  9. Click Stage to create the service definition. In the success message, note the path of your service definition (.sd).
  10. Copy the Yellowstone.sd file to the machine running ArcGIS Server Manager.
  11. On the machine running ArcGIS Server Manager, log in to Manager and click Services.
  12. If necessary, click the Manage Services tab.
  13. Click Publish Service.
  14. Click Browse, browse to the location of Yellowstone.sd on the local machine, and click Open. Then click Next.
  15. Accept the default properties for the service by clicking Next.
  16. Click Publish. This creates the USA map service.
  17. On the Services tab of Manager, select the USA map service, then select Capabilities. In the list of available capabilities, find SpatialQueryREST and check the box to enable it. If there is a list of available operations allowed, select all of them.
  18. Click Capabilities and click SpatialQueryREST (be careful not to uncheck the box). You are now viewing the properties page for the service. Ensure that the LayerName is "veg" (no quotes) and that the FieldName is "PRIMARY_" (no quotes).
  19. Click Save, then Restart to restart the service.
Test the SOE in the ArcGIS Server Services Directory
  1. Clear the Representational State Transfer (REST) cache of your Services directory. You can find cache clearing options if you open a web browser and log into http://<server name>:6080/arcgis/rest/admin. Click REST Cache, then click Clear Cache Now.
  2. Access your services directory by opening http://<server name>:6080/arcgis/rest/services in a Web browser.
  3. Click Yellowstone, scroll down to the bottom of the page, and click SpatialQueryREST. You’re now at the root resource page of your SOE.
  4. Click the one operation available, SpatialQuery. You can test this operation by adding some simple JavaScript Object Notation (JSON) parameters in the input boxes.
  5. Type {x:544000,y:4900000} in the location box.
  6. Type 5000 in the distance box.
  7. Click either the SpatialQuery (GET) or SpatialQuery (POST) button. You should see a long JSON response containing the clipped polygon geometries from the spatial query. Scroll to the bottom of the response and you’ll see a list of the total areas for each vegetation type.

下面一段核心代码能不能在ArcEngine中跑起来。。。

        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_QueryFeatureClass.ShapeFieldName;
            IFeatureCursor resultsFeatureCursor = m_QueryFeatureClass.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_QueryFeatureClass.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.剪切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;
        }

>>C#与json处理:

posted on 2021-03-11 10:00  XiaoNiuFeiTian  阅读(81)  评论(0编辑  收藏  举报