ArcGIS Flex API进行缓冲分析的讨论
在ArcGIS Flex API中可以通过GeometryService服务来进行缓冲分析,下面我们来探讨一下缓冲分析的实现。API中有<esri:GeometryService />专门用于处理Geometry服务,要进行缓冲分析,首先我们需要在ArcCatalog里面建立一个Geometry服务,建立好了我们就可以在Flex中进行代码编写了。我设想在地图中先添加地图文件,我们可以前面我们说的LibertyGIS来添加本地shapfile文件到GraphicLayer,也可以自己代码绘制一个多边形在GraphicLayer上,我们点击这个多边形即进行缓冲分析,将分析结果添加到GraphicLayer上,操作完成。然而值得我们注意的是,缓冲分析中点和多点的处理方式与线和多边形不同,在网上找到下面这句话:
点(Points)和多点(Multipoints):若单位(unit)是长度的,如:米、英尺等,测地线缓冲(geodesic buffering)分析将执行 is performed.
线(Polylines)和多边形(Polygons):单位(unit)必须是角度的,如:十进制度数,缓冲区分析才能执行。
首先我们来看看点的缓冲分析,代码如下:
[java]
private function mouseClickHandler(e:MouseEvent):void
{
var myMapCenterPoint:MapPoint = MapPoint(map.extent.center);
var bufferParm:BufferParameters=new BufferParameters();
bufferParm.bufferSpatialReference = map.spatialReference;
bufferParm.outSpatialReference=map.spatialReference;
bufferParm.unit=GeometryService.UNIT_KILOMETER;
bufferParm.distances=[50]; //这里采用的是长度单位
bufferParm.geometries=[myMapCenterPoint];
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
myGeometryService.buffer(bufferParm);
}
function bufferCompleteHandler(event:GeometryServiceEvent):void
{
var sfs:SimpleFillSymbol=new SimpleFillSymbol("solid",0xff0000,1,sls);
myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
for each (var geometry:Polygon in event.result)
{
var graphic:Graphic = new Graphic();
graphic.geometry = geometry;
graphic.symbol = sfs;
graphicsLayer.add(graphic);
}
}
private function mouseClickHandler(e:MouseEvent):void
{
var myMapCenterPoint:MapPoint = MapPoint(map.extent.center);
var bufferParm:BufferParameters=new BufferParameters();
bufferParm.bufferSpatialReference = map.spatialReference;
bufferParm.outSpatialReference=map.spatialReference;
bufferParm.unit=GeometryService.UNIT_KILOMETER;
bufferParm.distances=[50]; //这里采用的是长度单位
bufferParm.geometries=[myMapCenterPoint];
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
myGeometryService.buffer(bufferParm);
}
function bufferCompleteHandler(event:GeometryServiceEvent):void
{
var sfs:SimpleFillSymbol=new SimpleFillSymbol("solid",0xff0000,1,sls);
myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
for each (var geometry:Polygon in event.result)
{ www.zzzyk.com
var graphic:Graphic = new Graphic();
graphic.geometry = geometry;
graphic.symbol = sfs;
graphicsLayer.add(graphic);
}
}结果如下图:
线和多边形进行缓冲分析需要对线或多边形设定参考坐标系,并且以弧度作为距离单位,下面我们以多边形为例,代码如下:
[java]
private function mouseClickHandler(e:MouseEvent):void
{
var gra:Graphic=e.currentTarget as Graphic;
var polygon:Polygon=gra.geometry as Polygon;
polygon.spatialReference=map.spatialReference;//设定参考坐标系
var bufferParm:BufferParameters=new BufferParameters();
bufferParm.bufferSpatialReference = map.spatialReference;
bufferParm.outSpatialReference=map.spatialReference;
bufferParm.unit=GeometryService.UNIT_KILOMETER;
bufferParm.distances=[50/6378137.0 * 180.0/Math.PI];//单位转换为弧度单位
bufferParm.geometries=[polygon];
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
myGeometryService.buffer(bufferParm);
}
private function mouseClickHandler(e:MouseEvent):void
{
var gra:Graphic=e.currentTarget as Graphic;
var polygon:Polygon=gra.geometry as Polygon;
polygon.spatialReference=map.spatialReference;//设定参考坐标系
var bufferParm:BufferParameters=new BufferParameters();
bufferParm.bufferSpatialReference = map.spatialReference;
bufferParm.outSpatialReference=map.spatialReference;
bufferParm.unit=GeometryService.UNIT_KILOMETER;
bufferParm.distances=[50/6378137.0 * 180.0/Math.PI];//单位转换为弧度单位
bufferParm.geometries=[polygon];
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
myGeometryService.buffer(bufferParm);
}
结果如下图:
补充:软件开发 , Java ,