- public class PointEdit {
- private WebContext webContext;
- public void AddPoint (MapEvent event){
- try {
- //得到地图事件所对应的地图对象
- WebMap webmap=webContext.getWebMap();
- WebPoint webpoint=(WebPoint) event.getWebGeometry().toMapGeometry(webmap);
- AGSLocalMapResource mapResource = (AGSLocalMapResource) MapResourceClass.getMapResource(webContext, 1 );
- IServerContext context = mapResource.getServerContext();
- MapServer mapServer = mapResource.getLocalMapServer();
- //IMap maps= mapServer.getMap("");
- //ILayer firstLayer = maps.getLayer(Otid);
- //得到图层的空间编辑对象
- IMap maps= mapServer.getMap( "" );
- ILayer layer=maps.getLayer( 0 );
- IFeatureLayer fLayer = (IFeatureLayer) layer;
- IFeatureClass fc = fLayer.getFeatureClass();
- IDataset ds1= new IDatasetProxy(fc);
- IWorkspace pWorkSpace = ds1.getWorkspace();
- IWorkspaceEdit pWorkspaceEdit= new IWorkspaceEditProxy(pWorkSpace);
- //开始编辑
- pWorkspaceEdit.startEditing( true );
- pWorkspaceEdit.startEditOperation();
- //创建新的地图对象
- IFeature pFeature=fc.createFeature();
- //将web地图对象转成地图对象
- Point p=(Point)context.createObject( "esriGeometry.Point" );
- IPoint pt=(IPoint)context.createObject( "esriGeometry.Point" );
- pt.setX(webpoint.getX());
- pt.setY(webpoint.getY());
- pt.setM( 0 );
- pt.setZ( 0 );
- p=(Point)pt;
- //地图对象赋值
- pFeature.setShapeByRef(p);
- //字段赋值
- pFeature.setValue(fc.findField( "code" ), 1 );
- //保存对象
- pFeature.store();
- //停止编辑
- pWorkspaceEdit.stopEditOperation();
- pWorkspaceEdit.stopEditing( true );
- //刷新地图
- mapServer.refreshServerObjects();
- webContext.refresh();
- } catch (Exception gise) {
- System.out.print( "添加点" + gise.toString() + "\n" );
- gise.printStackTrace();
- }
- }
- }
- 这是添加点的代码
- 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
- }
(责任编辑:admin)