ArcObjects中的IGeometry转成Json

ArcObjects中的IGeometry转成Json

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);
        }
        //
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值