用vs 建立一点状要素服务图层,设计输入要素的程序
时间: 2024-06-08 07:05:23 浏览: 152
以下是使用C#语言,在Visual Studio中创建点要素服务图层并设计输入要素的示例程序:
1. 在Visual Studio中新建一个控制台应用程序项目。
2. 在解决方案资源管理器中,右键单击项目名称,选择“添加”->“引用”,在“COM”选项卡中勾选ESRI.ArcGIS.Server和ESRI.ArcGIS.System组件,并单击确定。
3. 在项目中添加一个类文件,命名为“AddPointFeature.cs”。
4. 在类文件中添加以下代码:
```
using System;
using ESRI.ArcGIS.SOESupport;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
namespace PointFeatureSOE
{
public class AddPointFeature : IServerObjectExtension, IRESTRequestHandler
{
private string soeName;
private IServerObjectHelper serverObjectHelper;
public void Init(IServerObjectHelper pSOH)
{
this.serverObjectHelper = pSOH;
this.soeName = this.GetType().Name;
}
public void Shutdown()
{
this.serverObjectHelper = null;
}
public string GetSchema()
{
return "";
}
public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
if (operationName.ToLower() == "addpointfeature")
{
IFeatureWorkspace featureWorkspace = serverObjectHelper.ServerObject as IFeatureWorkspace;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(resourceName);
IPoint point = new PointClass();
point.X = Convert.ToDouble(operationInput.Split(',')[0]);
point.Y = Convert.ToDouble(operationInput.Split(',')[1]);
IFeature feature = featureClass.CreateFeature();
feature.Shape = point;
feature.Store();
return Encoding.UTF8.GetBytes("Point feature added successfully!");
}
else
{
return Encoding.UTF8.GetBytes("Invalid operation!");
}
}
public void HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, System.IO.Stream outputStream)
{
byte[] result = HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out string responseProperties);
outputStream.Write(result, 0, result.Length);
}
public string GetResourceName(string operationName, string operationInput)
{
return "";
}
public RESTCapabilities GetRESTCapabilities()
{
RESTCapabilities restCapabilities = new RESTCapabilities();
restCapabilities.SupportsGET = false;
restCapabilities.SupportsPOST = true;
restCapabilities.SupportsPUT = false;
restCapabilities.SupportsDELETE = false;
restCapabilities.SupportsQuery = false;
restCapabilities.SupportsREST = true;
return restCapabilities;
}
}
}
```
5. 在项目中添加一个配置文件,命名为“AddPointFeatureSOE.cfg”,并将以下内容复制到文件中:
```
<?xml version="1.0" encoding="utf-8" ?>
<SOEConfig>
<Description>Sample SOE to add point features to a feature class</Description>
<Capabilities>
<RESTSupport>true</RESTSupport>
<SoapSupport>false</SoapSupport>
</Capabilities>
<Resources>
<Resource name="Points" isCollection="true"/>
</Resources>
<Parameters>
<Parameter name="WorkspaceConnectionString" type="System.String" defaultValue=""/>
<Parameter name="WorkspaceFactoryProgID" type="System.String" defaultValue="esriDataSourcesGDB.FileGDBWorkspaceFactory.1"/>
<Parameter name="FeatureClassName" type="System.String" defaultValue=""/>
</Parameters>
</SOEConfig>
```
6. 在项目中添加一个ESRI.ArcGIS.SOESupport的类库,命名为“ESRI.ArcGIS.SOESupport.dll”,并将其引用到程序中。
7. 编译并发布程序,将生成的AddPointFeature.dll和AddPointFeatureSOE.cfg文件复制到ArcGIS Server的SOE目录下。
8. 在ArcGIS Server Manager中创建一个新的要素服务,选择“从现有数据创建”,并选择包含点要素的要素类作为数据源。
9. 在要素服务的“服务”选项卡中,单击“扩展”按钮,在“添加扩展”对话框中选择“AddPointFeature”并单击确定。
10. 使用Postman或其他HTTP客户端发送以下请求:
URL: http://<server>/arcgis/rest/services/<service>/MapServer/exts/AddPointFeature/addpointfeature
Method: POST
Headers: Content-Type: application/x-www-form-urlencoded
Body: -117.1956,34.0572
其中,<server>是ArcGIS Server的主机名或IP地址,<service>是要素服务的名称。
11. 如果一切顺利,应该会返回“Point feature added successfully!”的消息,并在要素类中添加一个新的点要素。
以上就是使用C#语言,在Visual Studio中创建点要素服务图层并设计输入要素的示例程序。
阅读全文