即将到来的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实现的在线添加对象,供大家参考:
xmlns:esri="http://www.esri.com/2008/ags">
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=
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">
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")
}
]]>