阅读:2955回复:2
浅谈WebGIS编辑和更新(ArcIMS4.0)
<P align=center>浅谈<FONT face="Times New Roman">WebGIS</FONT>编辑和更新<FONT face="Times New Roman">(ArcIMS4.0)</FONT></P>
<P align=center><p><FONT face="Times New Roman"> </FONT></p></P> <P >众所周知,<FONT face="Times New Roman">ArcIMS4.0</FONT>不能实现空间数据的编辑和更新(正而八经的开讲了<FONT face="Times New Roman"> :))</FONT>,但聪明的<FONT face="Times New Roman">WebGIS</FONT>开发工程师并不会囿于<FONT face="Times New Roman">ArcIMS</FONT>所提供的功能接口来简单的实现我们实际需要的系统,因为如果你不聪明,那么你开发的<FONT face="Times New Roman">WebGIS</FONT>系统将显得非常呆板和不足,当然了,也不能实现用户的需求——一定的编辑功能了。我在此抛砖引玉,简单谈谈我在<FONT face="Times New Roman">WebGIS</FONT>数据有限的编辑功能的实现上的一些经验,并尽可能地详细,以供各位同行们参考。</P> <P >虽然<FONT face="Times New Roman">ArcIMS</FONT>不能编辑,但其类库却是非常丰富的,在此引出实现数据编辑的关键角色<FONT face="Times New Roman">AcetateLayer</FONT>,<FONT face="Times New Roman">IMS</FONT>在客户端展示的<FONT face="Times New Roman">GIS</FONT>图片(<FONT face="Times New Roman">ImageServer</FONT>方式),每一层都是按一个<FONT face="Times New Roman">AcetateLayer</FONT>来组装的,因此我的思路是,对于客户要求能够编辑的<FONT face="Times New Roman">GIS</FONT>图层(比如点层),把这个图层的数据按照一定的数据结构,把它的坐标(地理坐标)存进数据库,数据加载时创建一个活动图层,并按照坐标产生要素(<FONT face="Times New Roman">Acetate</FONT>),并添加其它属性即可,编辑时,在坐标数据结构和属性数据表中添加或修改记录就<FONT face="Times New Roman">ok</FONT>了,简单,方便,速度也快。当然了,这种方式对于简单的要素(点,线)比较容易实现,但对复杂要素实现就比较困难了(主要是数据结构的负责,具体自己想吧)。</P> <P >数据库的存取在此不在赘述,这里我主要说说动态图层的创建,首先,存在一个坐标转化的问题,因为存取的是地理坐标,而在<FONT face="Times New Roman">web </FONT>上展示的是屏幕坐标,而且你每次刷新的时候,都要根据地理坐标重新生成一个屏幕坐标,故这个坐标转换是非常必要的,在此提供我写的坐标转换原程序<FONT face="Times New Roman">(</FONT>基于<FONT face="Times New Roman">java connector)</FONT>:</P> <P ><FONT face="Times New Roman">//</FONT>坐标转换<FONT face="Times New Roman">(</FONT>地理坐标<FONT face="Times New Roman">-></FONT>屏幕坐标<FONT face="Times New Roman">)</FONT></P> <P ><FONT face="Times New Roman">private double[] mapCoords2ImgCoords(MyMap myMap,double mapX,double mapY)</FONT></P> <P ><FONT face="Times New Roman">{ </FONT></P> <P ><FONT face="Times New Roman">double[] xy = new double[2]; </FONT></P> <P ><FONT face="Times New Roman">//</FONT>坐标转换系数</P> <P ><FONT face="Times New Roman">Envelope mapEnv = myMap.getEnvelope();</FONT></P> <P ><FONT face="Times New Roman">double mapMinX = mapEnv.getMinX();</FONT></P> <P ><FONT face="Times New Roman">double mapMinY = mapEnv.getMinY();</FONT></P> <P ><FONT face="Times New Roman">double mapWidth = mapEnv.getMaxX() - mapEnv.getMinX();</FONT></P> <P ><FONT face="Times New Roman">double mapHeight = mapEnv.getMaxY() - mapEnv.getMinY();</FONT></P> <P ><FONT face="Times New Roman">double imgWidth = myMap.getWidth();</FONT></P> <P ><FONT face="Times New Roman">double imgHeight = myMap.getHeight();</FONT></P> <P ><FONT face="Times New Roman">xy[0] = MathUtils.round(((mapX - mapMinX) / mapWidth) * imgWidth,2);</FONT></P> <P ><FONT face="Times New Roman">xy[1] = MathUtils.round(((mapY - mapMinY) / mapHeight) * imgHeight + 20,2); //</FONT>加一偏移量</P> <P ><FONT face="Times New Roman">return xy;</FONT></P> <P ><FONT face="Times New Roman">}</FONT></P> <P >在此做一简单说明,<FONT face="Times New Roman">MyMap</FONT>是继承于<FONT face="Times New Roman">Map</FONT>的一个类,并根据需要添加了自己的方法,<FONT face="Times New Roman">MathUtils</FONT>是个工具包,是<FONT face="Times New Roman">Math</FONT>中一些方法的封装,其中<FONT face="Times New Roman">mapX</FONT>,<FONT face="Times New Roman">mapY</FONT>是地理坐标,<FONT face="Times New Roman">xy</FONT>是屏幕坐标数据,其它的一看就明白。</P> <P ><FONT face="Times New Roman"> </FONT>当提供了坐标转换后,我们看看活动图层的产生:</P> <P ><FONT face="Times New Roman">//</FONT>根据坐标添加活动图层</P> <P ><FONT face="Times New Roman">private void createActate(double[][] xy,String[] strLabel,MyMap myMap)</FONT></P> <P ><FONT face="Times New Roman">{</FONT></P> <P ><FONT face="Times New Roman"> int featureCount = strLabel.length;</FONT></P> <P >注意<FONT face="Times New Roman">strLabel</FONT>是一个字串数组,我在此以数组的长度来标识要素的个数,</P> <P ><FONT face="Times New Roman"> //</FONT>定义文本标签</P> <P ><FONT face="Times New Roman"> Text[] text = new Text[featureCount];</FONT></P> <P ><FONT face="Times New Roman"> //</FONT>定义标签符号</P> <P ><FONT face="Times New Roman"> TextMarkerSymbol ts[] = new TextMarkerSymbol[featureCount];</FONT></P> <P ><FONT face="Times New Roman"> //</FONT>活动要素</P> <P ><FONT face="Times New Roman"> Acetate[] aObject = new Acetate[featureCount];</FONT></P> <P >循环内渲染要素:</P> <P ><FONT face="Times New Roman"> for (int j = 0;j < featureCount;j++)</FONT></P> <P ><FONT face="Times New Roman"> {</FONT></P> <P ><FONT face="Times New Roman"> text[j] = new Text();</FONT></P> <P ><FONT face="Times New Roman"> ts[j] = new TextMarkerSymbol();</FONT></P> <P ><FONT face="Times New Roman"> //</FONT>文本标签符号</P> <P ><FONT face="Times New Roman"> ts[j].setAntialiasing(true);</FONT></P> <P ><FONT face="Times New Roman"> ts[j].setFont("</FONT>幼圆<FONT face="Times New Roman">");</FONT></P> <P ><FONT face="Times New Roman"> ts[j].setFontColor("255,0,0");</FONT></P> <P ><FONT face="Times New Roman"> ts[j].setFontStyle("bold");</FONT></P> <P ><FONT face="Times New Roman"> ts[j].setFontSize(12);</FONT></P> <P ><FONT face="Times New Roman"> ts[j].setGlowing("255,200,0");</FONT></P> <P ><FONT face="Times New Roman"> aObject[j] = new Acetate();</FONT></P> <P ><FONT face="Times New Roman"> aObject[j].setUnits("pixel");</FONT></P> <P ><FONT face="Times New Roman"> }</FONT></P> <P ><FONT face="Times New Roman"> //</FONT>活动图层</P> <P ><FONT face="Times New Roman"> AcetateLayer al = new AcetateLayer("AcetateLayer" ,null,null);</FONT></P> <P ><FONT face="Times New Roman"> for(int i = 0;i < featureCount;i++)</FONT></P> <P ><FONT face="Times New Roman"> {</FONT></P> <P ><FONT face="Times New Roman"> text.setX(xy[0]); </FONT></P> <P ><FONT face="Times New Roman"> text.setY(xy[1]);</FONT></P> <P ><FONT face="Times New Roman"> text.setLabel(strLabel);</FONT></P> <P ><FONT face="Times New Roman"> text.setSymbol(ts);</FONT></P> <P ><FONT face="Times New Roman"> aObject.setAcetateElement(text); </FONT></P> <P ><FONT face="Times New Roman"> al.addAcetate(aObject); //</FONT>添加要素</P> <P ><FONT face="Times New Roman"> }</FONT></P> <P ><FONT face="Times New Roman"> al.setVisible(true);</FONT></P> <P ><FONT face="Times New Roman"> al.setName("AcetateLayer");</FONT></P> <P ><FONT face="Times New Roman"> myMap.getLayers().add(al); //</FONT>添加图层</P> <P ><FONT face="Times New Roman">}</FONT></P> <P >上面的方法主要功能就是根据坐标和<FONT face="Times New Roman">map</FONT>来生成要素图层,其中<FONT face="Times New Roman">AcetateLayer</FONT>的名称尤其要注意,因为在以后的刷新等操作中,你要根据这个名称来擦除这个图层来画一个新的图层。</P> <P ><FONT face="Times New Roman"> </FONT>掌握了图层的创建和坐标的转换后,其余的就顺利成章,根据我前面说的思路,数据的编辑功能就比较容易的完成了。</P> <P ><FONT face="Times New Roman"> </FONT>闲话:回过头来开<FONT face="Times New Roman">IMS</FONT>,其实是比较简单的,无非就是后台服务产生你操作的图片,<FONT face="Times New Roman">awt </FONT>的<FONT face="Times New Roman">BufferedImage</FONT>不就能实现吗,<FONT face="Times New Roman">shape</FONT>文件的读取难道能难住你吗,数据的存取,坐标的转换,分析等等,想想吧。</P> <P ><FONT face="Times New Roman"> 别扔鸡蛋,tomato就忍了 :)</FONT></P> |
|
1楼#
发布于:2006-01-27 14:39
<P>难道没有人用java connector开发web GIS吗?遗憾急了</P>
|
|
2楼#
发布于:2006-02-07 23:39
<P>我打算学。顶</P>
|
|