Flex 加载shp

至于gis格式比较常见的shp是开源的,网上开源的as代码也很多 这个支持的shp算比较好的 源码在这边https://files.cnblogs.com/files/haibalai/shp.rar,加载shp必须勾选两个文件shp和dbf,shp是存取图形geometry信息。dbf是属性信息

 我这边写了个工具类调用

 

 1 package widgetscadastre.DwgLoad 
 2 {
 3     import com.esri.ags.Graphic;
 4     import com.szpl.extension.util.shp.dbf.DbfHeader;
 5     import com.szpl.extension.util.shp.dbf.DbfRecord;
 6     import com.szpl.extension.util.shp.dbf.DbfTools;
 7     import com.szpl.extension.util.shp.shp.ShpPolygon;
 8     import com.szpl.extension.util.shp.shp.ShpReader;
 9     import com.szpl.extension.util.shp.shp.ShpSymbol;
10     import flash.events.Event;
11     import flash.utils.ByteArray;
12     import mx.collections.ArrayCollection;
13     /**
14      * ...
15      * @author haibalai
16      */
17     public class ShpLoadTool 
18     {
19         
20         public function ShpLoadTool() 
21         {
22             
23         }
24         
25         private var _callFun:Function;
26         public function shpLoad(shpByteArray:ByteArray, dbfByteArray:ByteArray,callFun:Function):void
27         {
28             _callFun = callFun; 
29             var index:int = 0;
30             const array:Array = [];
31             const shpReader:ShpReader = new ShpReader(shpByteArray);
32             const dbfHeader:DbfHeader = new DbfHeader(dbfByteArray);
33             while (shpReader.hasMore())
34             {
35                 var shpPolygon:ShpPolygon = shpReader.readShpPolygon();
36                 var dbfRecord:DbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
37                 array.push(new Graphic(shpPolygon, new ShpSymbol(), dbfRecord.values));
38             }
39         
40             _callFun.call(null,array);
41             
42         }
43         
44     }
45 
46 }

 

posted @ 2015-12-08 17:58  haibalai  阅读(396)  评论(0编辑  收藏  举报