ArcGIS Server flex实现在线数据编辑

第一种方案

即将到来的arcgis 10,据说已经提供了数据修改的REST接口,但远水解不了近渴,通过flex客户端实现用户录入数据仍然是一个棘手的问题,本文提供了一种思路。

以点数据的录入为例:

arcgis服务器端通过AO实现数据的插入

 public void savePoint(double x,double y) throws utomationException,IOException
 {

  IServerContext serverContext = getServerContext(ARCGIS_SERVER_NAME,ARCGIS_SERVER_USER,ARCGIS_SERVER_PASSWORD,ARCGIS_MAP_NAME,ARCGIS_SERVICE_NAME);
  MapServer mapServer = (MapServer) serverContext.getServerObject();
  ILayer editLayer = mapServer.getLayer("", LAYERID);
  IFeatureLayer featureLayer = new IFeatureLayerProxy(editLayer);
  IFeatureClass featureClass = featureLayer.getFeatureClass();
  IFeature feature = featureClass.createFeature();
  IPoint point = (IPoint)serverContext.createObject(Point.getClsid());
  point.setX(x);
  point.setY(y);
  feature.setShapeByRef(point);
  feature.store(); 
  serverContext.releaseContext();

}

将AO逻辑包装成REST接口

 @POST @Path("/save")
 @Consumes("application/x-www-form-urlencoded")
 @Produces("text/xml")
 public String savePosition(@FormParam("x") double x,@FormParam("y") double y) throws UnknownHostException, IOException
 {
  aoService.savePoint(x,y);
  return "ok";
 }

flex端调用REST接口

private function drawEnd(event:DrawEvent):void

{

    var outSR:SpatialReference = new SpatialReference(spatialref);
    var geom:Geometry = event.graphic.geometry;
    var gra:Graphic = new Graphic(geom);

   var ptSym:SimpleMarkerSymbol = new SimpleMarkerSymbol("circle", numGraphic.value, cpGraphic.selectedColor);
                   gra.symbol = ptSym;
                   measurePt = geom as MapPoint;
                   savePoint(measurePt.x,measurePt.y);

}

 

   private function savePoint(x:Number, y:Number):void
   {
    var aoService:HTTPService=new HTTPService();
    var request:Object=new Object();
    request.x=x;
    request.y=y;
    aoService.url="http://192.168.1.188:8080/rest/service/save";
    aoService.request=request;
    aoService.method="POST";
    aoService.addEventListener(ResultEvent.RESULT, onSavePoint);
    aoService.send();


 }

需要注意的是,这种解决方案没有考虑多用户使用环境。

第二种方案:

目前在ArcGIS10没有正式推出之前,除了可以使用ADF做数据的在线编辑之外,可以使用OGC的WFS-T的服务来做在线编辑。
        ESRI提供一整套的解决方案,大家可以参考以下相关教程

http://webhelp.esri.com/arcgisserver/9.3/dotNet/index.htm#tutorial_wfst_service.htm来发布WFS-T的服务。
       然后参考wfs-t服务的白皮书,来编码实现地理数据的在线编辑,具体可以到OGC的网站上下载最新的包皮书,http://www.opengeospatial.org/standards/wfs,目前最新的版本是1.1.0.
       以下是使用FLEX实现的在线添加对象,供大家参考:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:esri="http://www.esri.com/2008/ags">
   
    <mx:Script>
     <![CDATA[
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      import com.esri.ags.geometry.MapPoint;
      import mx.controls.Alert;
    
      private function onmapclick(event:MouseEvent):void
      {
       var mp:MapPoint = mymap.toMapFromStage(event.stageX,event.stageY);
      
       var insert:XML=<wfs:Transaction
       version="1.1.0"
       service="WFS"
       xmlns="http://nick/arcgis"
       xmlns:gml="http://www.opengis.net/gml"
       xmlns:ogc="http://www.opengis.net/ogc"
       xmlns:wfs="http://www.opengis.net/wfs"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://nick/arcgis/services/Hospital/MapServer/WFSServerhttp://nick/arcgis/services/Hospital/MapServer/WFSServer?request=describefeaturetype&;typename=Hospital.xshttp://www.opengis.net/wfshttp://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
            <wfs:Insert>
                <Hospital>
                     <SHAPE>
                         <gml:Point srsName="urn:ogc:def:crs:EPSG:6.9:4326">
                              <gml:pos>{mp.x} {mp.y}</gml:pos>
                         </gml:Point>
                     </SHAPE>
                     <shanghai_4>test01</shanghai_4>
                </Hospital>
            </wfs:Insert>
       </wfs:Transaction>;
    hs.send(insert);
      }
     
      private function onresult(event:ResultEvent) : void
          {
            var result:Object = event.result;
           
            //Alert.show(result.toLocaleString() + "onResult")
            
           var numInserted:int = result.TransactionResponse.TransactionSummary.totalInserted;
           if( numInserted>0 )
           {
            mymap.getLayer("sh").refresh();
            Alert.show("共"+numInserted+"个数据提交成功");
            }
     this.cursorManager.removeBusyCursor();
    }
   
           private function onfault(event:FaultEvent) : void
           {
            var result:Object = event.fault;
            //Alert.show(result.toString()+ "onfault")
           }
     ]]>
    </mx:Script>
   
   
    <mx:HTTPService id="hs" url="http://nick/arcgis/services/Hospital/MapServer/WFSServer" contentType="application/xml"
     result="onresult(event)" fault="onfault(event)"/>
   
   
    <esri:Map id="mymap" mapClick="onmapclick(event)">
     <esri:ArcGISDynamicMapServiceLayer id="sh">
      <esri:url>http://nick/ArcGIS/rest/services/Hospital/MapServer</esri:url>
     </esri:ArcGISDynamicMapServiceLayer>
    </esri:Map>
   
   
</mx:Application>

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值