http://blog.csdn.net/arcgisserver_book/article/details/7816711
soe插件进行生成点、线、面的缓冲区的功能
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SOESupport;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace cwgisRestSOE1041.RestOperationEx
{
/// <summary>
/// 缓冲区生成功能
/// vp:hsg
/// create date:2019-08-12
/// </summary>
public class BufferCreateHandler : absOperationHandler
{
public BufferCreateHandler(cwgisRestSOE1041 Container)
{
this.Container = Container;
}
//
public override string Name
{
get { return "BufferCreate"; }
}
public override string[] Parameters
{
get { return new string[] { "geotype", "geometry", "bufferRadius" }; }
}
public override string[] supportedFormats
{
get { return new string[] { "json" }; }
}
//
//rest 操作实现 (操作的核心代码)
public override byte[] executeHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
//此行为调试测试用代码
//System.Diagnostics.Debugger.Launch();
//
responseProperties = null;
//获取输入参数
//获取几何类型 OK
string geotype;
bool found = operationInput.TryGetString("geotype", out geotype);
if (!found || string.IsNullOrEmpty(geotype))
{
throw new ArgumentNullException("geotype is null");
}
//获取缓冲区半径 OK
double? bufferRadius;
found = operationInput.TryGetAsDouble("bufferRadius", out bufferRadius);
if (!found || !bufferRadius.HasValue)
{
throw new ArgumentNullException("bufferRadius is null");
}
//获取原几何对象 geometry OK 集合
JsonObject geo_obj = null;
found = operationInput.TryGetJsonObject("geometry", out geo_obj);
if (!found || geo_obj == null)
{
throw new ArgumentNullException("geometry json object is null ");
}
//转为arcgis ao geometry object by JsonObject
//生成缓冲区
IGeometry tGeo = null;
IGeometry buf_geo = null;
IGeometry display_bufgeo = null;
if (geo_obj != null)
{
switch (geotype)
{
case "point":
tGeo = Conversion.ToGeometry(geo_obj, esriGeometryType.esriGeometryPoint) as IGeometry;
//buf_geo = (tGeo as ITopologicalOperator).Buffer((double)bufferRadius);
//点缓冲为圆(增密点集合) 为b/s显示使用
buf_geo = soeUtil.createCircleGeometry(tGeo as IPoint, (double)bufferRadius) as IGeometry;
break;
case "polyline":
tGeo = Conversion.ToGeometry(geo_obj, esriGeometryType.esriGeometryPolyline) as IGeometry;
buf_geo = (tGeo as ITopologicalOperator5).Buffer((double)bufferRadius);
break;
case "polygon":
tGeo = Conversion.ToGeometry(geo_obj, esriGeometryType.esriGeometryPolygon) as IGeometry;
buf_geo = (tGeo as ITopologicalOperator4).Buffer((double)bufferRadius);
break;
case "geometrybag":
tGeo = Conversion.ToGeometry(geo_obj, esriGeometryType.esriGeometryBag) as IGeometry;
buf_geo = (tGeo as ITopologicalOperator4).Buffer((double)bufferRadius);
break;
default:
break;
}
}
//
//返回结果
JsonObject resultJson = new JsonObject();
resultJson.AddString("geotype", geotype);
resultJson.AddString("bufferRadius", bufferRadius.ToString());
//----
JsonObject bufGeo_json = null;
if (buf_geo != null)
{
(buf_geo as ITopologicalOperator).Simplify();
(buf_geo as IPolycurve2).Densify(1, 1); //线或面有曲线问题 需要加密点处理 OK
//
JsonObject jo = new JsonObject();
bufGeo_json = Conversion.ToJsonObject(buf_geo);
//jo.TryGetJsonObject(soeUtil.toJsonStrByGeometry(buf_geo),out bufGeo_json);
}
resultJson.AddJsonObject("bufferGeometry", bufGeo_json);
//----
return this.GetByteByJsonObject(resultJson);
}
//
}
}