amw269756
路人甲
路人甲
  • 注册日期2005-01-30
  • 发帖数58
  • QQ
  • 铜币258枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2952回复:6

Arcgis server .net(vs2003) 绘制直线, 折线,多边形的方法(webgis)

楼主#
更多 发布于:2006-06-30 10:25
<P> Arcgis server .net(vs2003) 绘制直线, 折线,多边形的方法(空间数据SDE Oracle)</P>
<P>    开发语言: c# (Webgis)</P>
<P><STRONG> 1. 绘直线</STRONG></P>
<P>     private void Map1_Line(object sender, LineEventArgs args)<BR>  {<BR>   <BR>   if (args.ToolName == "Line")<BR>   {<BR>    IFeatureLayer flayer = GetFeatureLayer(ddlLayers.SelectedIndex);        //获取当前活动图层了函数,就是调用GetFeatureLayer(int lyid)函数<BR>    if (flayer == null) return;<BR>    <BR>    if (flayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) <BR>    {<BR>     string sc;<BR>     sc = "<script language=javascript>alert('当前图层类型不对!')</script>";<BR>     Page.RegisterClientScriptBlock("ShapeTypeError",sc);<BR>     return;<BR>    }</P>
<P>    //生成直线<BR>    ESRI.ArcGIS.Server.IServerContext context;<BR>    ESRI.ArcGIS.Server.WebControls.WebMap webmap = Map1.CreateWebMap();<BR>    webmap.ManageLifetime(flayer);<BR>    context = webmap.ServerContext;<BR>    ESRI.ArcGIS.Geometry.IPolyline Polyline = context.CreateObject("esriGeometry.Polyline") as ESRI.ArcGIS.Geometry.IPolyline;<BR>    webmap.ManageLifetime(Polyline);<BR>    ESRI.ArcGIS.Geometry.IPoint pt;</P>
<P>    ESRI.ArcGIS.Geometry.IGeometryCollection ringcol = context.CreateObject("esriGeometry.Polyline") as ESRI.ArcGIS.Geometry.IGeometryCollection;<BR>    webmap.ManageLifetime(ringcol);</P>
<P>    ESRI.ArcGIS.Geometry.IPointCollection ptcol =context.CreateObject("esriGeometry.Path") as ESRI.ArcGIS.Geometry.IPointCollection;// new PathClass();<BR>    webmap.ManageLifetime(ptcol);<BR>    object obj=Type.Missing;</P>
<P>    <BR>    pt = webmap.ToMapPoint(args.BeginPoint.X,args.BeginPoint.Y);<BR>    ptcol.AddPoint(pt,ref obj,ref obj);</P>
<P>    pt = webmap.ToMapPoint(args.EndPoint.X,args.EndPoint.Y);<BR>    ptcol.AddPoint(pt,ref obj,ref obj);</P>
<P><BR>    <BR>    ringcol.AddGeometry(ptcol as IGeometry,ref obj,ref obj);    <BR>    Polyline =ringcol as IPolyline;    </P>
<P><BR>    //将多直线到图层中<BR>    ESRI.ArcGIS.Geodatabase.IFeature feature =  flayer.FeatureClass.CreateFeature();<BR>    feature.Shape = Polyline as IGeometry;<BR>    feature.Store();<BR>    webmap.Refresh();</P>
<P>    webmap.Dispose();<BR>   }</P>

<P><BR>  }</P>
<P><STRONG>  2. 绘折线</STRONG></P>
<P>private void Map1_Polyline(object sender, PolylineEventArgs args)<BR>  {<BR>   if (args.ToolName == "Polyline")<BR>   {<BR>    IFeatureLayer flayer = GetFeatureLayer(ddlLayers.SelectedIndex);        //获取当前活动图层了函数,就是调用GetFeatureLayer(int lyid)函数<BR>    if (flayer == null) return;<BR>    <BR>    if (flayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) <BR>    {<BR>     string sc;<BR>     sc = "<script language=javascript>alert('当前图层类型不对!')</script>";<BR>     Page.RegisterClientScriptBlock("ShapeTypeError",sc);<BR>     return;<BR>    }</P>
<P>    //生成直线<BR>    ESRI.ArcGIS.Server.IServerContext context;<BR>    ESRI.ArcGIS.Server.WebControls.WebMap webmap = Map1.CreateWebMap();<BR>    webmap.ManageLifetime(flayer);<BR>    context = webmap.ServerContext;<BR>    ESRI.ArcGIS.Geometry.IPolyline Polyline = context.CreateObject("esriGeometry.Polyline") as ESRI.ArcGIS.Geometry.IPolyline;<BR>    webmap.ManageLifetime(Polyline);<BR>    ESRI.ArcGIS.Geometry.IPoint pt;</P>
<P>    ESRI.ArcGIS.Geometry.IGeometryCollection ringcol = context.CreateObject("esriGeometry.Polyline") as ESRI.ArcGIS.Geometry.IGeometryCollection;<BR>    webmap.ManageLifetime(ringcol);</P>
<P>    ESRI.ArcGIS.Geometry.IPointCollection ptcol =context.CreateObject("esriGeometry.Path") as ESRI.ArcGIS.Geometry.IPointCollection;// new PathClass();<BR>    webmap.ManageLifetime(ptcol);<BR>    object obj=Type.Missing;</P>
<P>    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>    Polyline =ringcol as IPolyline;    </P>
<P><BR>    //将折线保存到图层中<BR>    ESRI.ArcGIS.Geodatabase.IFeature feature =  flayer.FeatureClass.CreateFeature();<BR>    feature.Shape = Polyline as IGeometry;<BR>    feature.Store();<BR>    webmap.Refresh();</P>
<P>    webmap.Dispose();<BR>   }</P>

<P>  }</P>

<P>  <STRONG>3. 绘多边形</STRONG></P>
<P>private void Map1_Polygon(object sender, PolygonEventArgs args)<BR>  {<BR>   if (args.ToolName == "Polygon")<BR>   {<BR>    IFeatureLayer flayer = GetFeatureLayer(ddlLayers.SelectedIndex);        //获取当前活动图层了函数,就是调用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>    }</P>
<P>    //生成多边形<BR>    ESRI.ArcGIS.Server.IServerContext context;<BR>    ESRI.ArcGIS.Server.WebControls.WebMap webmap = Map1.CreateWebMap();<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;    </P>
<P>    //将多边形写入到图层中<BR>    ESRI.ArcGIS.Geodatabase.IFeature feature =  flayer.FeatureClass.CreateFeature();<BR>    feature.Shape = poly as IGeometry;<BR>    feature.Store();<BR>    webmap.Refresh();</P>
<P>    webmap.Dispose();<BR>   }</P>
<P>  }</P>
<P><STRONG>4. GetFeatureLayer(int lyid) 函数</STRONG></P>
<P>private IFeatureLayer GetFeatureLayer(int lyid)<BR>  {<BR>   WebMap webmap = Map1.CreateWebMap();<BR>   try<BR>   {<BR>    ILayer layer = (webmap.MapServer as IMapServerObjects).get_Layer(webmap.DataFrame,lyid);<BR>    if (layer==null)<BR>     return null;<BR>    else<BR>    {<BR>     return (layer as IFeatureLayer);<BR>    }<BR>   }<BR>   finally<BR>   {<BR>    webmap.Dispose();<BR>   }<BR>      <BR>  }</P>
<P><STRONG>5. 工作区编辑函数 StartEdit()</STRONG></P>
<P>private void StartEdit()<BR>  {<BR>     <BR>   <BR>   using (WebMap webMap =Map1.CreateWebMap() ) <BR>   {<BR>    IServerContext sc=webMap.ServerContext;</P>
<P>    IMapServer map = sc.ServerObject as IMapServer;<BR>    IMapServerObjects mapobj = map as IMapServerObjects;<BR>    IMap fgmap = mapobj.get_Map(webMap.DataFrame);<BR>    IFeatureLayer fl = fgmap.get_Layer(ddlLayers.SelectedIndex) as IFeatureLayer;<BR>    IDataset ds = fl.FeatureClass as IDataset;<BR>    IWorkspaceEdit ws = ds.Workspace as IWorkspaceEdit;</P>
<P>    ws.StartEditing(true);<BR>    ws.StartEditOperation();</P>
<P>    <BR>   } </P>
<P>   <BR>   }<BR><STRONG>6. 工作区停止编辑数据保存函数SaveEdit();</STRONG></P>
<P>private void SaveEdit()<BR>  {<BR>   using (WebMap webMap =Map1.CreateWebMap() ) <BR>   {<BR>    IServerContext sc=webMap.ServerContext;</P>
<P>    IMapServer map = sc.ServerObject as IMapServer;<BR>    IMapServerObjects mapobj = map as IMapServerObjects;<BR>    IMap fgmap = mapobj.get_Map(webMap.DataFrame);<BR>    IFeatureLayer fl = fgmap.get_Layer(ddlLayers.SelectedIndex) as IFeatureLayer;<BR>    IDataset ds = fl.FeatureClass as IDataset;<BR>    IWorkspaceEdit ws = ds.Workspace as IWorkspaceEdit;<BR>    ws.StartEditOperation();<BR>    ws.StopEditing(true);<BR>   } </P>
<P>  }<BR><STRONG>7. 绘图方法初始化设置</STRONG></P>
<P>private void InitializeComponent()<BR>  {    <BR>   this.Toolbar1.CommandClick += new ESRI.ArcGIS.Server.WebControls.ToolbarCommandClickEventHandler(this.Toolbar1_CommandClick);<BR>   this.Map1.Polygon += new ESRI.ArcGIS.Server.WebControls.MapPolygonEventHandler(this.Map1_Polygon);<BR>   this.Map1.Polyline += new ESRI.ArcGIS.Server.WebControls.MapPolylineEventHandler(this.Map1_Polyline);<BR>   this.Map1.Line += new ESRI.ArcGIS.Server.WebControls.MapLineEventHandler(this.Map1_Line);<BR>   this.Load += new System.EventHandler(this.Page_Load);<BR>   this.Map1.Point+=new MapPointEventHandler(Map1_Point);</P>
<P>  }</P>
<P>作其它图形,待续. </P>
喜欢0 评分0
amw269756
路人甲
路人甲
  • 注册日期2005-01-30
  • 发帖数58
  • QQ
  • 铜币258枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-07-11 09:38
多好的东西啊.怎么没有支持呢.这年头难到没有人用这个工具开发.
举报 回复(0) 喜欢(0)     评分
cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5913
  • QQ14265545
  • 铜币29655枚
  • 威望213点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
2楼#
发布于:2006-07-11 09:55
<P>net现在用的人慢慢多了</P>
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
举报 回复(0) 喜欢(0)     评分
reinamco
路人甲
路人甲
  • 注册日期2006-05-17
  • 发帖数6
  • QQ
  • 铜币134枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-07-24 10:14
支持啊 现在正在学习ARCGIS SERVER就是觉得资料太少了<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
4楼#
发布于:2006-07-24 10:46
<P>在用arcgis server,不过使用java adf</P>
<P>复杂的编辑和分析功能,要在网上实现,对硬件的要求是否太高?:)</P>
举报 回复(0) 喜欢(0)     评分
amw269756
路人甲
路人甲
  • 注册日期2005-01-30
  • 发帖数58
  • QQ
  • 铜币258枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2006-08-14 12:47
<P>是啊. 现在的机子配置越来越高啊.服务器好一点就行啦.</P>
举报 回复(0) 喜欢(0)     评分
zhmzhgis
路人甲
路人甲
  • 注册日期2005-03-31
  • 发帖数20
  • QQ
  • 铜币214枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2006-10-11 14:14
谢谢楼主,写了这么好的东西
举报 回复(0) 喜欢(0)     评分
游客

返回顶部