AO调用挂载soe的server服务的,指定图层的指定范围的图片

实现效果如下:

最开始说要写这个功能的时候,还挺烦躁的。因为好久没有没有动脑子写AO功能了,习惯了搬砖~(万年也写一篇博客,今天实在没啥事觉得写一篇,嘿嘿嘿~)

然后百度了网上的一些案例,发现多多少烧走到某一步的时候,就发现不是少了这个参数就是少了哪个参数。然后自己要去补全这些东西,它们到底是怎么来的,然后就补全了。

因为soe测试比较麻烦,其他的功能我都再测试程序调试好,再保class放到真正的soe程序里边直接运行的。

一、既然是导出server中的指定图层指定范围的图片,那soe所挂载的这个server必须有这个图层名称,名称必须是SDE库原来的名称!

二、再然后就是导出的时候,控制server图层的显示。

三、就是范围了,不能直接整个指定范围导出吧,就像我上边的截图,也需要周边的一些内容,还需要画出范围本身的这个红线。

        /// <summary>
        /// 调用soe挂载的server服务地图,并导出为图片流
        /// </summary>
        /// <param name="serverObjectHelper">当前SOE挂载在的server服务</param>
        /// <param name="pGeometry">当前地块的几何范围</param>
        /// <param name="pFeatClsNames">当前调用服务使用到的图层名称</param>
        /// <returns></returns>
        public static string fnExportImgbyte(IServerObjectHelper  serverObjectHelper, IGeometry pGeometry, List<string> pFeatClsNames)
        {
            try
            {
                string imgbyte = string.Empty;
                //--------1、获取soe挂载的地图服务
                IMapServer3 pMapServer =  (IMapServer3)serverObjectHelper.ServerObject;
                //--------2、设置输出图片格式,并导出服务图片流----功能有效
                #region 设置输出图片格式
                IImageType imgtype = new ImageTypeClass();
                imgtype.Format = esriImageFormat.esriImagePNG;
                imgtype.ReturnType = esriImageReturnType.esriImageReturnMimeData;
                //imgtype.ReturnType = esriImageReturnType.esriImageReturnURL;
                IImageDisplay imgdisp = new ImageDisplayClass();
                imgdisp.Height = 400;
                imgdisp.Width = 500;
                imgdisp.DeviceResolution = 150;
                IImageDescription imgdesc = new ImageDescriptionClass();
                imgdesc.Display = imgdisp;
                imgdesc.Type = imgtype;
                #endregion
                IMapServerInfo pMapServerInfo =  pMapServer.GetServerInfo(pMapServer.DefaultMapName);
                IMapDescription pMapDescription =  pMapServerInfo.DefaultMapDescription;
                IMapLayerInfos layerInfos =  pMapServer.GetServerInfo(pMapServer.DefaultMapName).MapLayerInfos;//获取当前服务的所有图层
                //IMapServerDataAccess dataAccess =  (IMapServerDataAccess)pMapServer;//获取指定id的图层的矢量数据
                //IFeatureClass pfeatureclass =  (IFeatureClass)dataAccess.GetDataSource(pMapServer.DefaultMapName,  Layerindex);//获取指定id的图层的矢量数据
                //--------3、设置导出图片的范围为地块范围
                #region 设置导出图片的范围为地块范围----功能有效
                IMapArea pMapArea = pMapDescription.MapArea;
                IEnvelope pExtent = (pGeometry as IPolygon).Envelope;
                pExtent.Expand(1.1, 1.1, true);
                IMapExtent pMapExtent = (IMapExtent)pMapArea;
                pMapExtent.Extent = pExtent;
                pMapDescription.MapArea = pMapArea;
                #endregion
                //--------4、控制图层显示
                #region 控制图层显示----功能有效
                //--------4-1、获取每个矢量图层的名称SDE.--
                List<int> pLayerIDs = new List<int>();//当前调用服务参数,使用到的图层id
                IMapLayerInfo layerInfo;
                for (int i = 0; i < layerInfos.Count; i++)
                {
                    layerInfo = layerInfos.get_Element(i);
                    foreach (string str in pFeatClsNames)
                    {
                        if (str.Trim().ToUpper() == layerInfo.Name.ToUpper())
                        {
                            pLayerIDs.Add(i);
                        }
                    }
                }
                //--------4-2、当前soe使用的图层显示,其他隐藏
                ILayerDescriptions pLayerDescriptions =  pMapDescription.LayerDescriptions;
                for (int i = 0; i < pLayerDescriptions.Count; i++)
                {
                    bool flage = false;
                    foreach (int id in pLayerIDs)
                    {
                        if (i == id)
                        {
                            flage = true;
                        }
                    }
                    ILayerDescription pLayerDescription =  pLayerDescriptions.get_Element(i);
                    pLayerDescription.Visible = flage;
                }
                #endregion
                //5、导出图片前,添加地块元素
                #region 添加地块元素
                IPolygonElement PolygonElement = new PolygonElementClass();
                IElement pElement = PolygonElement as IElement;
                pElement.Geometry = pGeometry;
                //设置地块元素样式
                IFillShapeElement pFillShapeElement = (IFillShapeElement)pElement;
                ISymbol pSymbol = CreateSimpleFillSymbol(Color.Red, 100,  esriSimpleFillStyle.esriSFSNull);
                pFillShapeElement.Symbol = (IFillSymbol)pSymbol;
                //新增到地图服务
                IGraphicElements pGraphicElements = new GraphicElementsClass();
                pGraphicElements.Add(pElement as IGraphicElement);
                pMapDescription.CustomGraphics = pGraphicElements;
                #endregion
                IImageResult pImageResult =  pMapServer.ExportMapImage(pMapDescription, imgdesc);
                byte[] pMimeData = pImageResult.MimeData;//图片流
                imgbyte = Convert.ToBase64String(pMimeData);//图片流转字符串
                //imgbyte = pImageResult.URL;//图片地址
                return imgbyte;
            }
            catch (Exception ex) { return "fnExportImgbyte方法报错:" +  ex.ToString(); }
        }
        /// <summary>
        /// 设置面元素样式
        /// </summary>
        /// <param name="fillColor"></param>
        /// <param name="oLineWidth"></param>
        /// <param name="fillStyle"></param>
        /// <returns></returns>
        public static ISymbol CreateSimpleFillSymbol(Color fillColor, int  oLineWidth, esriSimpleFillStyle fillStyle)
        {
            ISimpleFillSymbol pSimpleFillSymbol;
            pSimpleFillSymbol = new SimpleFillSymbol();
            pSimpleFillSymbol.Style = fillStyle;
            pSimpleFillSymbol.Color = GetColor(fillColor.R, fillColor.G,  fillColor.B);
            pSimpleFillSymbol.Outline =  (ILineSymbol)CreateSimpleLineSymbol(fillColor, 1,  esriSimpleLineStyle.esriSLSDash);
            return (ISymbol)pSimpleFillSymbol;
        }
        /// <summary>
        /// 获取颜色
        /// </summary>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static IRgbColor GetColor(int r, int g, int b)
        {
            RgbColor color = new RgbColor();
            color.Red = r;
            color.Green = g;
            color.Blue = b;
            return color;
        }
        /// <summary>
        /// 新建线样式
        /// </summary>
        /// <param name="color"></param>
        /// <param name="width"></param>
        /// <param name="style"></param>
        /// <returns></returns>
        public static ISymbol CreateSimpleLineSymbol(Color color, int width,  esriSimpleLineStyle style)
        {
            ISimpleLineSymbol pSimpleLineSymbol;
            pSimpleLineSymbol = new SimpleLineSymbol();
            pSimpleLineSymbol.Width = width;
            pSimpleLineSymbol.Color = GetColor(color.R, color.G, color.B);
            pSimpleLineSymbol.Style = style;
            return (ISymbol)pSimpleLineSymbol;
        }

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Visual Studio建立点要素服务图层并设计输入要素的程序示例: 1. 首先,打开Visual Studio并创建一个新的C#控制台应用程序项目。 2. 在解决方案资源管理器中,右键单击项目名称并选择“添加”>“新建项”。 3. 在“添加新项”对话框中,选择“ArcGIS”>“Geoprocessing Tool”。 4. 在“新建工具”对话框中,输入工具名称并选择“点要素服务”作为工具类型。 5. 在“参数”选项卡中,添加需要的参数。例如,添加一个名为“x_coord”的Double类型参数,表示要素的X坐标;添加一个名为“y_coord”的Double类型参数,表示要素的Y坐标。 6. 在“代码”选项卡中,编写程序代码来创建点要素服务图层并添加输入要素。例如: ```csharp using System; using System.Collections.Generic; using System.Text; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Server; using ESRI.ArcGIS.SOESupport; namespace PointFeatureService { class PointFeatureService : SOE { private IServerObjectHelper _soHelper; private ServerLogger _serverLog; public PointFeatureService() { _serverLog = new ServerLogger(); } public override void Init(IServerObjectHelper pSOH) { _soHelper = pSOH; } public override byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; switch (operationName.ToLower()) { case "addpoint": return AddPoint(operationInput); default: throw new Exception("Unsupported operation."); } } private byte[] AddPoint(string operationInput) { JsonObject input = new JsonObject(operationInput); double xCoord = input.GetAsDouble("x_coord"); double yCoord = input.GetAsDouble("y_coord"); IPoint point = new PointClass(); point.X = xCoord; point.Y = yCoord; IFeatureClass featureClass = GetFeatureClass(); IFeature feature = featureClass.CreateFeature(); feature.Shape = point; feature.Store(); JsonObject result = new JsonObject(); result.AddString("status", "success"); return Encoding.UTF8.GetBytes(result.ToJson()); } private IFeatureClass GetFeatureClass() { IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.OpenFromFile(@"C:\data.gdb", 0); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; return featureWorkspace.OpenFeatureClass("Points"); } } } ``` 7. 在“生成”菜单中选择“生成解决方案”以生成程序集。 8. 在ArcGIS Server管理器中创建一个新的SOEServer Object Extension)并将其指向程序集。 9. 在ArcMap中创建一个点要素类,并将其存储在一个文件地理数据库中。将要素类命名为“Points”。 10. 使用ArcGIS Server管理器中的“发布”向服务器发布点要素服务。在“发布服务”对话框中,选择“点要素服务”作为服务类型,选择点要素类作为数据源。 11. 使用ArcGIS Server管理器中的“测试”功能测试点要素服务。可以使用Postman或类似的工具向服务发送POST请求来添加输入要素。例如,使用以下JSON字符串向服务添加一个具有x坐标值为10和y坐标值为20的新要素: ```json { "x_coord": 10, "y_coord": 20 } ``` 以上就是使用Visual Studio建立点要素服务图层并设计输入要素的程序示例。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值