目的:
此示例显示了一个服务器对象扩展(SOE),该扩展在缓冲区距离内查询和剪辑功能,并基于给定属性总结结果区域。SOE作为一个代表性状态传输(REST)Web服务公开。它只适用于地图服务。
部署SOE所需的所有信息都包含在这个封装在.SOE文件中的示例中。从该文件部署SOE不需要打开Visual Studio。但是,您可以打开此示例附带的visualstudio解决方案来探索SOE中使用的编码模式。
- Log in to ArcGIS Server Manager and click Site.
- Click Extensions.
- Click Add Extension.
- 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.
- Click OK.
- Start ArcMap and click File > Open.
- Browse to or type the location of Yellowstone.mxd, which is located in <ArcGIS Developer Kit Location>\Samples\data\Yellowstone.
- Click File > Share As > Service.
- Click Save a service definition and click Next.
- Choose "No available connection" and check "Include data in service definition when publishing".
- Change the Server type to ArcGIS Server.
- Leave the Service name as Yellowstone and click Next.
- Choose a location where you want to save the service definition, then click Continue.
- Click Stage to create the service definition. In the success message, note the path of your service definition (.sd).
- Copy the Yellowstone.sd file to the machine running ArcGIS Server Manager.
- On the machine running ArcGIS Server Manager, log in to Manager and click Services.
- If necessary, click the Manage Services tab.
- Click Publish Service.
- Click Browse, browse to the location of Yellowstone.sd on the local machine, and click Open. Then click Next.
- Accept the default properties for the service by clicking Next.
- Click Publish. This creates the USA map service.
- 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.
- 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).
- Click Save, then Restart to restart the service.
- 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.
- Access your services directory by opening http://<server name>:6080/arcgis/rest/services in a Web browser.
- Click Yellowstone, scroll down to the bottom of the page, and click SpatialQueryREST. You’re now at the root resource page of your SOE.
- Click the one operation available, SpatialQuery. You can test this operation by adding some simple JavaScript Object Notation (JSON) parameters in the input boxes.
- Type {x:544000,y:4900000} in the location box.
- Type 5000 in the distance box.
- 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处理:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)