基于ArcGIS Server对ShapeFile文件的编辑功能实现 .

2024-01-23 10:38

本文主要是介绍基于ArcGIS Server对ShapeFile文件的编辑功能实现 .,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这是添加点的代码

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using System.Collections;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
using ESRI.ArcGIS.Geodatabase;
/// <summary>
/// AddPointFeature 的摘要说明
/// </summary>
public class AddPointFeature : IMapServerToolAction
{
public AddPointFeature()
{
  //
  // TODO: 在此处添加构造函数逻辑
  //
}
    #region IMapServerToolAction 成员
    void IMapServerToolAction.ServerAction(ToolEventArgs args)
    {
        //Step1: 取到地图点击画的那个点
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl;
        mapCtrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;
        PointEventArgs pea = (PointEventArgs)args;
        System.Drawing.Point screen_point = pea.ScreenPoint;
        MapFunctionality mapFunc = (MapFunctionality)mapCtrl.GetFunctionality(0);
        MapResourceLocal mapResLocal = mapFunc.Resource as MapResourceLocal;        
        IServerContext pSOC;
        IMapServer pMapServer;
        IMap pMap;
        
        pSOC = mapResLocal.ServerContextInfo.ServerContext;
        pMapServer = pSOC.ServerObject as IMapServer;
        IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;
        pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);
        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesp = mapFunc.MapDescription;
        ESRI.ArcGIS.ADF.Web.Geometry.Point adf_map_point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point, mapCtrl.Extent, mapFunc.DisplaySettings.ImageDescriptor.Width, mapFunc.DisplaySettings.ImageDescriptor.Height);
        PointN ags_map_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_map_point);

        //Step2:插入点到Shp文件中去。要打开WS
        //第一个图层是点,第二个图层是线,第三个图层是面。这里就不判断,主要在于功能的实现
        ILayer pLayer = pMap.get_Layer(0);
        IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;
        IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;
        IDataset pDataset = pFeatCls as IDataset;
        IWorkspace pWS = pDataset.Workspace;
        IWorkspaceEdit pWorkspaceEdit = pWS as IWorkspaceEdit;
        pWorkspaceEdit.StartEditing(false);
        pWorkspaceEdit.StartEditOperation();
        IFeatureBuffer pFeatureBuffer;
        IFeatureCursor pFeatureCuror;
        IFeature pFeature;
        IPoint pPoint;
        pFeatureBuffer = pFeatCls.CreateFeatureBuffer();
        pFeatureCuror = pFeatCls.Insert(true);
        pFeature = pFeatureBuffer as IFeature;
        pPoint =(IPoint) pSOC.CreateObject("esriGeometry.Point");
        pPoint.X = ags_map_point.X;
        pPoint.Y = ags_map_point.Y;
        IGeometry pPointGeo = pPoint as IGeometry;
        pFeature.Shape = pPointGeo;
        pFeatureCuror.InsertFeature(pFeatureBuffer);
        
        pWorkspaceEdit.StopEditOperation();
        pWorkspaceEdit.StopEditing(true);        
        mapCtrl.Refresh();     
    }
    #endregion
}
 
添加线的代码

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using System.Collections;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
using ESRI.ArcGIS.Geodatabase;
/// <summary>
/// AddPolylineFeature 的摘要说明
/// </summary>
public class AddPolylineFeature : IMapServerToolAction
{
public AddPolylineFeature()
{
  //
  // TODO: 在此处添加构造函数逻辑
  //
}
    #region IMapServerToolAction 成员
    public void ServerAction(ToolEventArgs args)
    {
        //Step1:根据客户端定义的动作,将屏幕坐标点转换成地图坐标点
        //并初始化一些常用的参数
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl;
        mapCtrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;
        PolylineEventArgs peal = (PolylineEventArgs)args;
        System.Drawing.Point[] screen_points = peal.Vectors;
        MapFunctionality mapFunc = (MapFunctionality)mapCtrl.GetFunctionality(0);
        MapResourceLocal mapResLocal = mapFunc.Resource as MapResourceLocal;
        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc;
        mapDesc = mapFunc.MapDescription;
        IServerContext pSOC;
        IMapServer pMapServer;
        IMap pMap;
        pSOC = mapResLocal.ServerContextInfo.ServerContext;
        pMapServer = pSOC.ServerObject as IMapServer;
        IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;
        pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);

        IPointCollection pPointColl;
        pPointColl = (IPointCollection)pSOC.CreateObject("esriGeometry.Polyline");
        for (int i = 0; i < screen_points.Length; i++)
        {
            IPoint pPoint;
            ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points , mapCtrl.Extent, (int)mapCtrl.Width.Value, (int)mapCtrl.Height.Value);
            pPoint = (IPoint)pSOC.CreateObject("esriGeometry.Point");
            pPoint.X = mappnt.X;
            pPoint.Y = mappnt.Y;
            object missingVal = System.Reflection.Missing.Value;
            pPointColl.AddPoint(pPoint, ref missingVal, ref missingVal);
        }
        IGeometry pPolylineGeo = pPointColl as IGeometry;

        //Step2:插入点到Shp文件中去。要打开WS
        //第一个图层是点(0),第二个图层是线(1),第三个图层是面(2)。这里就不判断,主要在于功能的实现
        ILayer pLayer = pMap.get_Layer(1);
        IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;
        IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;
        IDataset pDataset = pFeatCls as IDataset;
        IWorkspace pWS = pDataset.Workspace;
        IWorkspaceEdit pWorkspaceEdit = pWS as IWorkspaceEdit;
        pWorkspaceEdit.StartEditing(false);
        pWorkspaceEdit.StartEditOperation();
        IFeatureBuffer pFeatureBuffer;
        IFeatureCursor pFeatureCuror;
        IFeature pFeature;
        pFeatureBuffer = pFeatCls.CreateFeatureBuffer();
        pFeatureCuror = pFeatCls.Insert(true);
        pFeature = pFeatureBuffer as IFeature;
        pFeature.Shape = pPolylineGeo;
        pFeatureCuror.InsertFeature(pFeatureBuffer);
        pWorkspaceEdit.StopEditOperation();
        pWorkspaceEdit.StopEditing(true);
        mapCtrl.Refresh();     
    }
    #endregion
}
 
 
编辑面的代码

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using System.Collections;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
using ESRI.ArcGIS.Geodatabase;
/// <summary>
/// AddPolygonFeature 的摘要说明
/// </summary>
public class AddPolygonFeature : IMapServerToolAction
{
public AddPolygonFeature()
{
  //
  // TODO: 在此处添加构造函数逻辑
  //
}
    #region IMapServerToolAction 成员
    public void ServerAction(ToolEventArgs args)
    {
        //Step1:根据客户端定义的动作,将屏幕坐标点转换成地图坐标点
        //并初始化一些常用的参数
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl;
        mapCtrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;
        PolygonEventArgs peag = (PolygonEventArgs)args;
        System.Drawing.Point[] screen_points = peag.Vectors;
        MapFunctionality mapFunc = (MapFunctionality)mapCtrl.GetFunctionality(0);
        MapResourceLocal mapResLocal = mapFunc.Resource as MapResourceLocal;
        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc;
        mapDesc = mapFunc.MapDescription;
        IServerContext pSOC;
        IMapServer pMapServer;
        IMap pMap;
        pSOC = mapResLocal.ServerContextInfo.ServerContext;
        pMapServer = pSOC.ServerObject as IMapServer;
        IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;
        pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);


        IPointCollection pPointColl;
        pPointColl = (IPointCollection)pSOC.CreateObject("esriGeometry.Polygon");
        for (int i = 0; i < screen_points.Length; i++)
        {
            IPoint pPoint;
            ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points , mapCtrl.Extent, (int)mapCtrl.Width.Value, (int)mapCtrl.Height.Value);
            pPoint = (IPoint)pSOC.CreateObject("esriGeometry.Point");
            pPoint.X = mappnt.X;
            pPoint.Y = mappnt.Y;
            object missingVal = System.Reflection.Missing.Value;
            pPointColl.AddPoint(pPoint, ref missingVal, ref missingVal);
        }
        IGeometry pPolylineGeo = pPointColl as IGeometry;

        //Step2:插入点到Shp文件中去。要打开WS
        //第一个图层是点(0),第二个图层是线(1),第三个图层是面(2)。这里就不判断,主要在于功能的实现
        ILayer pLayer = pMap.get_Layer(2);
        IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;
        IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;
        IDataset pDataset = pFeatCls as IDataset;
        IWorkspace pWS = pDataset.Workspace;
        IWorkspaceEdit pWorkspaceEdit = pWS as IWorkspaceEdit;
        pWorkspaceEdit.StartEditing(false);
        pWorkspaceEdit.StartEditOperation();
        IFeatureBuffer pFeatureBuffer;
        IFeatureCursor pFeatureCuror;
        IFeature pFeature;
        pFeatureBuffer = pFeatCls.CreateFeatureBuffer();
        pFeatureCuror = pFeatCls.Insert(true);
        pFeature = pFeatureBuffer as IFeature;
        pFeature.Shape = pPolylineGeo;
        pFeatureCuror.InsertFeature(pFeatureBuffer);
        pWorkspaceEdit.StopEditOperation();
        pWorkspaceEdit.StopEditing(true);
        mapCtrl.Refresh();     
    }
    #endregion

这篇关于基于ArcGIS Server对ShapeFile文件的编辑功能实现 .的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/636136

相关文章

使用Python实现一个优雅的异步定时器

《使用Python实现一个优雅的异步定时器》在Python中实现定时器功能是一个常见需求,尤其是在需要周期性执行任务的场景下,本文给大家介绍了基于asyncio和threading模块,可扩展的异步定... 目录需求背景代码1. 单例事件循环的实现2. 事件循环的运行与关闭3. 定时器核心逻辑4. 启动与停

基于Python实现读取嵌套压缩包下文件的方法

《基于Python实现读取嵌套压缩包下文件的方法》工作中遇到的问题,需要用Python实现嵌套压缩包下文件读取,本文给大家介绍了详细的解决方法,并有相关的代码示例供大家参考,需要的朋友可以参考下... 目录思路完整代码代码优化思路打开外层zip压缩包并遍历文件:使用with zipfile.ZipFil

Python实现word文档内容智能提取以及合成

《Python实现word文档内容智能提取以及合成》这篇文章主要为大家详细介绍了如何使用Python实现从10个左右的docx文档中抽取内容,再调整语言风格后生成新的文档,感兴趣的小伙伴可以了解一下... 目录核心思路技术路径实现步骤阶段一:准备工作阶段二:内容提取 (python 脚本)阶段三:语言风格调

C#实现将Excel表格转换为图片(JPG/ PNG)

《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

基于Java实现回调监听工具类

《基于Java实现回调监听工具类》这篇文章主要为大家详细介绍了如何基于Java实现一个回调监听工具类,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录监听接口类 Listenable实际用法打印结果首先,会用到 函数式接口 Consumer, 通过这个可以解耦回调方法,下面先写一个

使用Java将DOCX文档解析为Markdown文档的代码实现

《使用Java将DOCX文档解析为Markdown文档的代码实现》在现代文档处理中,Markdown(MD)因其简洁的语法和良好的可读性,逐渐成为开发者、技术写作者和内容创作者的首选格式,然而,许多文... 目录引言1. 工具和库介绍2. 安装依赖库3. 使用Apache POI解析DOCX文档4. 将解析

Qt中QGroupBox控件的实现

《Qt中QGroupBox控件的实现》QGroupBox是Qt框架中一个非常有用的控件,它主要用于组织和管理一组相关的控件,本文主要介绍了Qt中QGroupBox控件的实现,具有一定的参考价值,感兴趣... 目录引言一、基本属性二、常用方法2.1 构造函数 2.2 设置标题2.3 设置复选框模式2.4 是否

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

springboot整合阿里云百炼DeepSeek实现sse流式打印的操作方法

《springboot整合阿里云百炼DeepSeek实现sse流式打印的操作方法》:本文主要介绍springboot整合阿里云百炼DeepSeek实现sse流式打印,本文给大家介绍的非常详细,对大... 目录1.开通阿里云百炼,获取到key2.新建SpringBoot项目3.工具类4.启动类5.测试类6.测

pytorch自动求梯度autograd的实现

《pytorch自动求梯度autograd的实现》autograd是一个自动微分引擎,它可以自动计算张量的梯度,本文主要介绍了pytorch自动求梯度autograd的实现,具有一定的参考价值,感兴趣... autograd是pytorch构建神经网络的核心。在 PyTorch 中,结合以下代码例子,当你