基于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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值