阅读:1477回复:2
请教:ArcGISServer中如何进行编辑
<P>比如 在一个多边形的图层中 新增一个多边形</P>
<P>我的方法是 点击toolbar中一个tool,执行画多边形的客户端代码,然后在map的polygon事件中取得我画的多边形,存如当前的多边形图层,polygon事件响应代码如下:</P> <P>private void Map1_Polygon(object sender, ESRI.ArcGIS.Server.WebControls.PolygonEventArgs args)<BR> {<BR> if (args.ToolName == "newpolygon")<BR> {<BR> ESRI.ArcGIS.Server.WebControls.WebMap webmap = Map1.CreateWebMap();<BR> IFeatureLayer flayer = (webmap.MapServer as IMapServerObjects).get_Layer(webmap.DataFrame,0) as IFeatureLayer; //获取当前活动图层了函数,这里就不贴了,就是调用GetFeatureLayer(int lyid)函数<BR> if (flayer == null) return;<BR> <BR> if (flayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) <BR> {<BR> string sc;<BR> sc = "<script language=javascript>alert('当前图层何类型不对!')</script>";<BR> Page.RegisterClientScriptBlock("ShapeTypeError",sc);<BR> return;<BR> }<BR> <BR> //生成多边形<BR> ESRI.ArcGIS.Server.IServerContext context;<BR> webmap.ManageLifetime(flayer);<BR> context = webmap.ServerContext;<BR> ESRI.ArcGIS.Geometry.IPolygon poly = context.CreateObject("esriGeometry.Polygon") as ESRI.ArcGIS.Geometry.IPolygon; //'new ag.PolygonClass();<BR> webmap.ManageLifetime(poly);<BR> ESRI.ArcGIS.Geometry.IPoint pt;<BR> ESRI.ArcGIS.Geometry.IGeometryCollection ringcol = context.CreateObject("esriGeometry.Polygon") as ESRI.ArcGIS.Geometry.IGeometryCollection;// new PolygonClass();<BR> webmap.ManageLifetime(ringcol);<BR> ESRI.ArcGIS.Geometry.IPointCollection ptcol =context.CreateObject("esriGeometry.Ring") as ESRI.ArcGIS.Geometry.IPointCollection;// new RingClass();<BR> webmap.ManageLifetime(ptcol);<BR> object obj=Type.Missing;<BR> for (int i=0;i<=args.Vectors.Length-1;i++)<BR> {<BR> pt = webmap.ToMapPoint(args.Vectors.X,args.Vectors.Y);<BR> ptcol.AddPoint(pt,ref obj,ref obj);<BR> }<BR> ringcol.AddGeometry(ptcol as IGeometry,ref obj,ref obj); <BR> poly = ringcol as IPolygon; <BR> <BR> <BR> //将多边形写入到图层中<BR> ESRI.ArcGIS.Geodatabase.IDataset dataset=flayer.FeatureClass as IDataset;<BR> ESRI.ArcGIS.Geodatabase.IWorkspaceEdit edit=dataset.Workspace as IWorkspaceEdit;<BR> edit.StartEditOperation();<BR> <FONT color=#ff3300>ESRI.ArcGIS.Geodatabase.IFeature feature = flayer.FeatureClass.CreateFeature();<BR></FONT> feature.Shape = poly as IGeometry;<BR> feature.Store();<BR> edit.StopEditOperation();<BR> webmap.Refresh();</P> <P> webmap.Dispose();</P> <P> }<BR> }</P> <P>程序在红色处报错,麻烦各位帮忙看看</P> |
|
1楼#
发布于:2006-07-11 09:46
数据必须要用SDE来连接?
|
|
2楼#
发布于:2006-07-11 09:33
<P>ding 看看我.做的,我已经发到上面了.你找找看.</P>
|
|