start of vector import support
authorRichard Fairhurst <richard@systemed.net>
Thu, 17 Dec 2009 01:32:44 +0000 (01:32 +0000)
committerRichard Fairhurst <richard@systemed.net>
Thu, 17 Dec 2009 01:32:44 +0000 (01:32 +0000)
25 files changed:
net/systemeD/halcyon/ExtendedURLLoader.as [new file with mode: 0755]
net/systemeD/halcyon/ImageURLLoader.as [deleted file]
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/TileSet.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/styleparser/RuleSet.as
net/systemeD/potlatch2/utils/Importer.as [new file with mode: 0644]
net/systemeD/potlatch2/utils/ShpImporter.as [new file with mode: 0644]
org/vanrijkom/dbf/DbfError.as [new file with mode: 0644]
org/vanrijkom/dbf/DbfField.as [new file with mode: 0644]
org/vanrijkom/dbf/DbfFilter.as [new file with mode: 0644]
org/vanrijkom/dbf/DbfHeader.as [new file with mode: 0644]
org/vanrijkom/dbf/DbfRecord.as [new file with mode: 0644]
org/vanrijkom/dbf/DbfTools.as [new file with mode: 0644]
org/vanrijkom/shp/ShpError.as [new file with mode: 0644]
org/vanrijkom/shp/ShpHeader.as [new file with mode: 0644]
org/vanrijkom/shp/ShpObject.as [new file with mode: 0644]
org/vanrijkom/shp/ShpPoint.as [new file with mode: 0644]
org/vanrijkom/shp/ShpPointZ.as [new file with mode: 0644]
org/vanrijkom/shp/ShpPolygon.as [new file with mode: 0644]
org/vanrijkom/shp/ShpPolyline.as [new file with mode: 0644]
org/vanrijkom/shp/ShpRecord.as [new file with mode: 0644]
org/vanrijkom/shp/ShpTools.as [new file with mode: 0644]
org/vanrijkom/shp/ShpType.as [new file with mode: 0644]
potlatch2.mxml

diff --git a/net/systemeD/halcyon/ExtendedURLLoader.as b/net/systemeD/halcyon/ExtendedURLLoader.as
new file mode 100755 (executable)
index 0000000..1a58319
--- /dev/null
@@ -0,0 +1,19 @@
+package net.systemeD.halcyon {
+
+       /*
+               === ExtendedURLLoader ===
+
+               This simply allows us to store arbitrary data (e.g. a filename) in the URLLoader object,
+               so that the responder knows which image has just been loaded.
+
+       */
+
+       import flash.events.*;
+       import flash.net.*;
+       import flash.display.*;
+
+       public class ExtendedURLLoader extends URLLoader {
+               public var info:Object=new Object();
+       }
+
+}
\ No newline at end of file
diff --git a/net/systemeD/halcyon/ImageURLLoader.as b/net/systemeD/halcyon/ImageURLLoader.as
deleted file mode 100755 (executable)
index 2379e48..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-package net.systemeD.halcyon {
-
-       /*
-               === ImageLoader ===
-
-               This simply allows us to store a filename in the URLLoader object,
-               so that the responder knows which image has just been loaded.
-
-       */
-
-       import flash.events.*;
-       import flash.net.*;
-       import flash.display.*;
-
-       public class ImageURLLoader extends URLLoader {
-               public var filename:*;
-       }
-
-}
\ No newline at end of file
index 6f64898..d826782 100755 (executable)
@@ -17,7 +17,7 @@ package net.systemeD.halcyon {
     import net.systemeD.halcyon.connection.EntityEvent;
        import net.systemeD.halcyon.styleparser.*;
        import net.systemeD.halcyon.Globals;
-
+       
 //     for experimental export function:
 //     import flash.net.FileReference;
 //     import com.adobe.images.JPGEncoder;
index 3c979d2..54eb3e5 100755 (executable)
@@ -5,8 +5,6 @@ package net.systemeD.halcyon {
        import flash.net.*;
        import flash.system.LoaderContext;
        
-       import net.systemeD.halcyon.ImageURLLoader;
-       
     public class TileSet extends Sprite {
 
                public var tile_l:int;
index 5ecbba8..0b84724 100644 (file)
@@ -10,6 +10,7 @@ package net.systemeD.halcyon.connection {
         private var modified:Boolean = false;
                private var _loaded:Boolean = true;
                private var parents:Dictionary = new Dictionary();
+               private var locked:Boolean = false;
 
         public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean) {
             this._id = id;
index 8e2df5a..d21706d 100644 (file)
@@ -3,7 +3,7 @@ package net.systemeD.halcyon.styleparser {
        import flash.events.*;
        import flash.net.*;
        import net.systemeD.halcyon.Map;
-       import net.systemeD.halcyon.ImageURLLoader;
+       import net.systemeD.halcyon.ExtendedURLLoader;
     import net.systemeD.halcyon.connection.Entity;
 
     import net.systemeD.halcyon.connection.*;
@@ -82,9 +82,9 @@ package net.systemeD.halcyon.styleparser {
                                
                                        iconsToLoad++;
                                        var request:URLRequest=new URLRequest(filename);
-                                       var loader:ImageURLLoader=new ImageURLLoader();
+                                       var loader:ExtendedURLLoader=new ExtendedURLLoader();
                                        loader.dataFormat=URLLoaderDataFormat.BINARY;
-                                       loader.filename=filename;
+                                       loader.info['filename']=filename;
                                        loader.addEventListener(Event.COMPLETE,                                         loadedImage,                    false, 0, true);
                                        loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler,              false, 0, true);
                                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler,   false, 0, true);
@@ -97,7 +97,7 @@ package net.systemeD.halcyon.styleparser {
                // data handler
 
                private function loadedImage(event:Event):void {
-                       images[event.target.filename]=event.target.data;
+                       images[event.target.info['filename']]=event.target.data;
                        iconsToLoad--;
                        if (iconsToLoad==0 && iconCallback!=null) { iconCallback(); }
                }
diff --git a/net/systemeD/potlatch2/utils/Importer.as b/net/systemeD/potlatch2/utils/Importer.as
new file mode 100644 (file)
index 0000000..4bf94fc
--- /dev/null
@@ -0,0 +1,53 @@
+package net.systemeD.potlatch2.utils {
+
+       import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.ExtendedURLLoader;
+       import flash.display.LoaderInfo;
+       import flash.events.*;
+       import flash.net.*;
+
+       import net.systemeD.halcyon.Globals;
+
+       public class Importer {
+
+               protected var map:Map;
+               protected var files:Array=[];
+               protected var filenames:Array;
+               protected var filesloaded:uint=0;
+
+               public function Importer(map:Map, filenames:Array) {
+                       Globals.vars.root.addDebug("starting importer"); 
+                       this.map = map;
+                       this.filenames=filenames;
+
+                       var sp:uint=0;
+                       for each (var fn:String in filenames) {
+                               Globals.vars.root.addDebug("requesting file "+fn); 
+
+                               var loader:ExtendedURLLoader = new ExtendedURLLoader();
+                               loader.info['file']=sp;
+                               loader.dataFormat=URLLoaderDataFormat.BINARY;
+                               loader.addEventListener(Event.COMPLETE,                                         fileLoaded,                             false, 0, true);
+                               loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler,              false, 0, true);
+                               loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler,   false, 0, true);
+                               loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler,                 false, 0, true);
+                               loader.load(new URLRequest(fn));
+                               sp++;
+                       }
+               }
+               
+               protected function fileLoaded(e:Event):void {
+                       Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
+                       files[e.target.info['file']]=e.target.data;
+                       filesloaded++;
+                       if (filesloaded==filenames.length) { doImport(); }
+               }
+               
+               protected function doImport():void { }
+
+               protected function httpStatusHandler( event:HTTPStatusEvent ):void { }
+               protected function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
+               protected function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
+
+       }
+}
diff --git a/net/systemeD/potlatch2/utils/ShpImporter.as b/net/systemeD/potlatch2/utils/ShpImporter.as
new file mode 100644 (file)
index 0000000..88229ae
--- /dev/null
@@ -0,0 +1,60 @@
+package net.systemeD.potlatch2.utils {
+
+       import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.connection.*;
+       import org.vanrijkom.shp.*;
+       import org.vanrijkom.dbf.*;
+
+       import net.systemeD.halcyon.Globals;
+
+       // SHP class docs and examples:
+       //              http://vanrijkom.org/shp/index.html
+       //              http://www.boxshapedworld.com/blog/post/Shapefiles-Actionscript-30-and-Google-Maps.aspx
+       //              http://web.archive.org/web/20071119113250rn_1/vanrijkom.org/samples/fsd-mexico/srcview/
+       // we load .shp as files[0], .shx as files[1], .dbf as files[2]
+
+       // See http://www.actionscript.org/forums/showthread.php3?t=185320 for tips on avoiding time-outs with big files -
+       // probably needs to be asynchronous
+               
+       public class ShpImporter extends Importer  {
+
+               public function ShpImporter(map:Map, filenames:Array) {
+                       super(map, filenames);
+               }
+               
+               // All data is loaded, so do the import
+
+               override protected function doImport():void {
+                       Globals.vars.root.addDebug("importing");
+                       var shp:ShpHeader=new ShpHeader(files[0]);
+                       var dbf:DbfHeader=new DbfHeader(files[2]);
+
+                       if (shp.shapeType==ShpType.SHAPE_POLYGON || shp.shapeType==ShpType.SHAPE_POLYLINE) {
+
+                               // Loop through all polylines in the shape
+                               var polyArray:Array = ShpTools.readRecords(files[0]);
+                               for (var i:uint=0; i<Math.min(polyArray.length,50); i++) {
+
+                                       // Get attributes like this:
+                                       //              var dr:DbfRecord = DbfTools.getRecord(files[2], dbf, i);
+                                       //              var xsID:String = dr.values[idFieldName];
+
+                                       // Do each ring in turn, then each point in the ring
+                                       for (var j:int=0; j < Math.min(polyArray[i].shape.rings.length,50); j++) {
+                                               var nodes:Array=[];
+                                               var points:Array = polyArray[i].shape.rings[j];
+                                               if (points!=null) {
+                                                       for (var k:int=0; k < Math.min(points.length,50); k++) {
+                                                               var p:ShpPoint = ShpPoint(points[k]);
+                                               var node:Node = map.connection.createNode({}, p.y, p.x);
+                                                               nodes.push(node);
+                                                               Globals.vars.root.addDebug("point "+p.x+","+p.y);
+                                                       }
+                                               }
+                                               if (nodes.length>0) { var way:Way = map.connection.createWay({}, nodes); }
+                                       }
+                               }
+                       }
+               }
+       }
+}
diff --git a/org/vanrijkom/dbf/DbfError.as b/org/vanrijkom/dbf/DbfError.as
new file mode 100644 (file)
index 0000000..c94a4de
--- /dev/null
@@ -0,0 +1,45 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  DBF (XBase File Reader)                                                                                            */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+/**
+ * Instances of the DbfError class are thrown from the DBF library classes
+ * on encountering errors.
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class DbfError extends Error
+{
+       /**
+        * Defines the identifier value of an undefined error.  
+        */     
+       public static const ERROR_UNDEFINED             : int = 0;
+       /**
+        * Defines the identifier value of a 'out of bounds' error, which is thrown
+        * when an invalid item index is passed.
+        */     
+       public static const ERROR_OUTOFBOUNDS   : int = 1;
+       
+       public function DbfError(msg: String, id: int=0) {
+               super(msg,id);
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/dbf/DbfField.as b/org/vanrijkom/dbf/DbfField.as
new file mode 100644 (file)
index 0000000..545d55b
--- /dev/null
@@ -0,0 +1,101 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  DBF (XBase File Reader)                                                                                            */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+       
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+
+/**
+ * The DbfField class parses a field definition from a DBF file loaded to a
+ * ByteArray.
+ * @author Edwin van Rijkom
+ * 
+ */
+public class DbfField
+{
+       /**
+        * Field name. 
+        */     
+       public var name: String;
+       /**
+        * Field type. 
+        */     
+       public var type: uint;
+       /**
+        * Field address.
+        */     
+       public var address: uint;
+       /**
+        * Field lenght. 
+        */     
+       public var length: uint;
+       /**
+        * Field decimals.
+        */     
+       public var decimals: uint;
+       /**
+        * Field id.
+        */     
+       public var id: uint;
+       /**
+        * Field set flag. 
+        */     
+       public var setFlag: uint;
+       /**
+        * Field index flag. 
+        */     
+       public var indexFlag: uint;
+       
+       /**
+        * Constructor.
+        * @param src
+        * @return 
+        * 
+        */                     
+       public function DbfField(src: ByteArray) {
+       
+               name = DbfTools.readZeroTermANSIString(src);
+               
+               // fixed length: 10, so:
+               src.position += (10-name.length);
+       
+               type = src.readUnsignedByte();
+               address = src.readUnsignedInt();
+               length = src.readUnsignedByte();
+               decimals = src.readUnsignedByte();
+               
+               // skip 2:
+               src.position += 2;
+               
+               id = src.readUnsignedByte();
+               
+               // skip 2:
+               src.position += 2;
+               
+               setFlag = src.readUnsignedByte();
+               
+               // skip 7:
+               src.position += 7;
+               
+               indexFlag = src.readUnsignedByte();             
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/dbf/DbfFilter.as b/org/vanrijkom/dbf/DbfFilter.as
new file mode 100644 (file)
index 0000000..fd7adca
--- /dev/null
@@ -0,0 +1,67 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  DBF (XBase File Reader)                                                                                            */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+import flash.utils.ByteArray;
+
+/**
+ * The DbfFilter class is a utility class that allows for collecting records
+ * that match on one of the given values for a field.
+ * @author Edwin
+ * 
+ */    
+public class DbfFilter
+{
+       /**
+        * Array containing DbfRecord typed values that match on one of the given 
+        * values for a field. 
+        */     
+       public var matches: Array;
+       
+       /**
+        * Constructor.
+        * @param src ByteArray containing the DBF file to filter.
+        * @param header DbfHeader instance previously read from the ByteArray.
+        * @param field Field to filter on.
+        * @param values Array of values to match field against.
+        * @param append If specified, the found records will be added to the specified Array instead of to the instance's matches array.
+        * @return 
+        * @see DbfHeader
+        * 
+        */     
+       public function DbfFilter(src: ByteArray, header: DbfHeader, field: String, values: Array, append: Array=null) {
+               matches = append || [];
+               src.position = header.recordsOffset;
+               var record: DbfRecord;
+               var i: uint, j: uint;
+               for (i= 0; i<header.recordCount; i++) {
+                       record = DbfTools.getRecord(src,header,i);
+                       for (j=0; j<values.length; j++) {
+                               if (record.values[field.toString()].match(values[j])) {
+                                       matches.push(record);                           
+                                       break;
+                               }
+                       }                       
+               }                               
+       }
+       
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/dbf/DbfHeader.as b/org/vanrijkom/dbf/DbfHeader.as
new file mode 100644 (file)
index 0000000..da26210
--- /dev/null
@@ -0,0 +1,137 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  DBF (XBase File Reader)                                                                                            */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+
+/**
+ * The DbfHeader class parses a DBF file loaded to a ByteArray
+ * @author Edwin van Rijkom
+ * 
+ */
+public class DbfHeader
+{
+       /**
+        * File length
+        */     
+       public var fileLength: int;
+       /**
+        * File version
+        */
+       public var version: int;
+       /**
+        * Date of last update, Year.
+        */
+       public var updateYear: int;
+       /**
+        * Date of last update, Month. 
+        */     
+       public var updateMonth: int;
+       /**
+        * Data of last update, Day. 
+        */     
+       public var updateDay: int;
+       /**
+        * Number of records on file. 
+        */     
+       public var recordCount: uint;
+       /**
+        * Header structure size. 
+        */     
+       public var headerSize: uint;
+       /**
+        * Size of each record.
+        */     
+       public var recordSize: uint;
+       /**
+        * Incomplete transaction flag 
+        */     
+       public var incompleteTransaction: uint;
+       /**
+        * Encrypted flag.
+        */     
+       public var encrypted: uint;
+       /**
+        * DBase IV MDX flag. 
+        */     
+       public var mdx: uint;
+       /**
+        * Language driver.
+        */     
+       public var language: uint;
+       
+       /**
+        * Array of DbfFields describing the fields found
+        * in each record. 
+        */     
+       public var fields: Array;
+               
+       private  var _recordsOffset: uint;
+                               
+       /**
+        * Constructor
+        * @param src
+        * @return 
+        * 
+        */     
+       public function DbfHeader(src: ByteArray) {
+               // endian:
+               src.endian = Endian.LITTLE_ENDIAN;      
+               
+               version = src.readByte();
+               updateYear = 1900+src.readUnsignedByte();
+               updateMonth = src.readUnsignedByte();
+               updateDay = src.readUnsignedByte();
+               recordCount = src.readUnsignedInt();
+               headerSize = src.readUnsignedShort();
+               recordSize = src.readUnsignedShort();
+               
+               //skip 2:
+               src.position += 2;
+               
+               incompleteTransaction = src.readUnsignedByte();
+               encrypted = src.readUnsignedByte();
+               
+               // skip 12:
+               src.position += 12;
+               
+               mdx = src.readUnsignedByte();
+               language = src.readUnsignedByte();
+               
+               // skip 2;
+               src.position += 2;
+               
+               // iterate field descriptors:
+               fields = [];
+               while (src.readByte() != 0X0D){
+                       src.position--;
+                       fields.push(new DbfField(src));
+               }
+               
+               _recordsOffset = headerSize+1;                                  
+       }
+       
+       internal function get recordsOffset(): uint {
+               return _recordsOffset;
+       }       
+}                      
+
+}  // package
\ No newline at end of file
diff --git a/org/vanrijkom/dbf/DbfRecord.as b/org/vanrijkom/dbf/DbfRecord.as
new file mode 100644 (file)
index 0000000..33bd6d4
--- /dev/null
@@ -0,0 +1,51 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  DBF (XBase File Reader)                                                                                            */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Dictionary;
+
+/**
+ * The DbfRecord class parses a record from a DBF file loade to a ByteArray.
+ * To do so it requires a DbfHeader instance previously read from the 
+ * ByteArray.
+ * @author Edwin van Rijkom
+ * @see DbfHeader
+ * 
+ */    
+public class DbfRecord
+{
+       /**
+        * Record field values. Use values["fieldname"] to get a value. 
+        */     
+       public var values: Dictionary;
+       
+       private var offset: uint;
+       
+       public function DbfRecord(src: ByteArray, header: DbfHeader) {
+               offset = src.position;
+               values = new Dictionary();
+               for each(var field: DbfField in header.fields) {
+                       values[field.name]=src.readUTFBytes(field.length);                                      
+               }               
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/dbf/DbfTools.as b/org/vanrijkom/dbf/DbfTools.as
new file mode 100644 (file)
index 0000000..a4b37b4
--- /dev/null
@@ -0,0 +1,83 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  DBF (XBase File Reader)                                                                                            */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.dbf
+{
+
+import flash.utils.ByteArray;
+import org.vanrijkom.dbf.DbfHeader;
+import org.vanrijkom.dbf.DbfRecord;
+
+/**
+ * The DbfTools class bundles a utility functions used by the remainder of
+ * the DBF library.
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class DbfTools
+{
+       /**
+        * Read a zero terminated ANSI string from a ByteArray.
+        * @param src ByteArray instance to read from.
+        * @return 
+        * 
+        */     
+       public static function readZeroTermANSIString(src: ByteArray): String {
+               var r: String = "";
+               var b: int;
+               while (b=src.readUnsignedByte()) {
+                       r+= String.fromCharCode(b);
+               }
+               return r;
+       }
+       
+       /**
+        * Read a fixed length ANSI string from a ByteArray.
+        * @param src ByteArray instance to read from.
+        * @param length Number of character to read.
+        * @return 
+        * 
+        */     
+       public static function readANSIString(src: ByteArray, length: uint): String {
+               var r: String = "";
+               while(length--) {
+                       r+= String.fromCharCode(src.readUnsignedByte());
+               }
+               return r;
+       }
+       
+       /**
+        * Read a DBF record from a DBF file.
+        * @param src ByteArray instance to read from.
+        * @param header DbfHeader instance previously read from the ByteArray.
+        * @param index Index of the record to read.
+        * @return 
+        * @see DbfHeader
+        * 
+        */     
+       public static function getRecord(src: ByteArray, header: DbfHeader, index: uint): DbfRecord {
+               
+               if (index > header.recordCount) 
+                       throw(new DbfError("",DbfError.ERROR_OUTOFBOUNDS));
+                                       
+               src.position = header.recordsOffset + index * header.recordSize;
+               return new DbfRecord(src, header);
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpError.as b/org/vanrijkom/shp/ShpError.as
new file mode 100644 (file)
index 0000000..a0bf334
--- /dev/null
@@ -0,0 +1,51 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+       
+/**
+ * Instances of the ShpError class are thrown from the SHP library classes
+ * on encountering errors.
+ * @author Edwin van Rijkom 
+ */    
+public class ShpError extends Error
+{
+       /**
+        * Defines the identifier value of an undefined error.  
+        */     
+       public static const ERROR_UNDEFINED             : int = 0;
+       /**
+        * Defines the identifier value of a 'no data' error, which is thrown
+        * when a ByteArray runs out of data.
+        */     
+       public static const ERROR_NODATA                : int = 1;
+       
+       /**
+        * Constructor.
+        * @param msg
+        * @param id
+        * @return 
+        * 
+        */     
+       public function ShpError(msg: String, id: int=0) {
+               super(msg,id);
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpHeader.as b/org/vanrijkom/shp/ShpHeader.as
new file mode 100644 (file)
index 0000000..945c069
--- /dev/null
@@ -0,0 +1,110 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+       
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+import flash.geom.Rectangle;
+import flash.geom.Point;
+
+/**
+ * The ShpHeader class parses an ESRI Shapefile Header from a ByteArray.
+ * @author Edwin van Rijkom
+ * 
+ */
+public class ShpHeader
+{
+       /**
+        * Size of the entire Shapefile as stored in the Shapefile, in bytes.
+        */     
+       public var fileLength: int;
+       /**
+        * Shapefile version. Expected value is 1000. 
+        */             
+       public var version: int;
+       /**
+        * Type of the Shape records contained in the remainder of the
+        * Shapefile. Should match one of the constant values defined
+        * in the ShpType class.
+        * @see ShpType
+        */     
+       public var shapeType: int;
+       /**
+        * The cartesian bounding box of all Shape records contained
+        * in this file.
+        */     
+       public var boundsXY: Rectangle;
+       /**
+        * The minimum (Point.x) and maximum Z (Point.y) value expected
+        * to be encountered in this file.
+        */     
+       public var boundsZ: Point;
+       /**
+        * The minimum (Point.x) and maximum M (Point.y) value expected
+        * to be encountered in this file.
+        */     
+       public var boundsM: Point;
+       
+       /**
+        * Constructor.
+        * @param src
+        * @return
+        * @throws ShpError Not a valid shape file header
+        * @throws ShpError Not a valid signature
+        * 
+        */                     
+       public function ShpHeader(src: ByteArray) {
+               // endian:
+               src.endian = Endian.BIG_ENDIAN;         
+               
+               // check length:
+               if (src.length-src.position<100)
+                       throw (new ShpError("Not a valid shape file header (too small)"));
+               
+               // check signature      
+               if (src.readInt() != 9994)
+                       throw (new ShpError("Not a valid signature. Expected 9994"));
+               
+                // skip 5 integers;
+               src.position += 5*4;
+               
+               // read file-length:
+               fileLength = src.readInt();
+               
+               // switch endian:
+               src.endian = Endian.LITTLE_ENDIAN;
+               
+               // read version:
+               version = src.readInt();
+                               
+               // read shape-type:
+               shapeType = src.readInt();
+               
+               // read bounds:
+               boundsXY = new Rectangle
+                       ( src.readDouble(), src.readDouble()
+                       , src.readDouble(), src.readDouble()
+                       );
+               boundsZ = new Point( src.readDouble(), src.readDouble() );
+               boundsM = new Point( src.readDouble(), src.readDouble() );                              
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpObject.as b/org/vanrijkom/shp/ShpObject.as
new file mode 100644 (file)
index 0000000..999dd79
--- /dev/null
@@ -0,0 +1,41 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+       
+/**
+ * The ShpObject class is the base class of all specialized Shapefile
+ * record type parsers.
+ * @author Edwin van Rijkom
+ * @see ShpPoint
+ * @see ShpPointZ
+ * @see ShpPolygon
+ * @see ShpPolyline
+ */    
+public class ShpObject
+{
+       /**
+        * Type of this Shape object. Should match one of the constant 
+        * values defined in the ShpType class.
+        * @see ShpType
+        */     
+       public var type: int;   
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpPoint.as b/org/vanrijkom/shp/ShpPoint.as
new file mode 100644 (file)
index 0000000..def712c
--- /dev/null
@@ -0,0 +1,52 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+
+/**
+ * The ShpPoint class parses an ESRI Shapefile Point record from a ByteArray.
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class ShpPoint extends ShpObject
+{
+       /**
+        * Constructor
+        * @throws ShpError Not a Point record 
+        */     
+       public var x: Number; 
+       public var y: Number;
+       
+       public function ShpPoint(src: ByteArray = null, size: uint = 0) {
+               type = ShpType.SHAPE_POINTZ;
+               if (src) {                      
+                       if (src.length - src.position < size)
+                               throw(new ShpError("Not a Point record (to small)"));
+                       
+                       x = (size > 0)  ? src.readDouble() : NaN;
+                       y = (size > 8)  ? src.readDouble() : NaN;                       
+               }
+               //trace("Point", x,y);          
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpPointZ.as b/org/vanrijkom/shp/ShpPointZ.as
new file mode 100644 (file)
index 0000000..4fa99fb
--- /dev/null
@@ -0,0 +1,58 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+
+/**
+ * The ShpPointZ class parses an ESRI Shapefile PointZ record from a ByteArray. 
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class ShpPointZ extends ShpPoint
+{
+       /**
+        * Z value
+        */
+       public var z: Number;
+       /**
+        * M value (measure)
+        */ 
+       public var m: int; // Measure;
+       
+       /**
+        * Constructor
+        * @param src
+        * @param size
+        * @return       
+        * 
+        */     
+       public function ShpPointZ(src: ByteArray = null, size: uint = 0) {
+               super();
+               type = ShpType.SHAPE_POINT;
+               if (src) {                      
+                       z = (size > 16) ? src.readDouble() : NaN;                       
+                       m = (size > 24) ? src.readDouble() : NaN;
+               }               
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpPolygon.as b/org/vanrijkom/shp/ShpPolygon.as
new file mode 100644 (file)
index 0000000..18f4d8f
--- /dev/null
@@ -0,0 +1,92 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+import flash.geom.Rectangle;
+import flash.geom.Point;
+
+/**
+ * The ShpPoint class parses an ESRI Shapefile Polygon record from a ByteArray.
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class ShpPolygon extends ShpObject
+{
+       /**
+        * Cartesian bounding box of all the rings found in this Polygon record.
+        */     
+       public var box: Rectangle;
+       /**
+        * Array containing zero or more Arrays containing zero or more ShpPoint
+        * typed values, constituting the rings found in this Polygon record.
+        * @see ShpPoint 
+        */     
+       public var rings: Array;
+       
+       /**
+        * Constructor.
+        * @param src
+        * @param size
+        * @return 
+        * @throws ShpError Not a Polygon record
+        */     
+       public function ShpPolygon(src: ByteArray = null, size: uint = 0) {
+               type = ShpType.SHAPE_POLYGON;
+               rings = [];             
+               if (src) {                      
+                       if (src.length - src.position < size)
+                               throw(new ShpError("Not a Polygon record (to small)"));
+                       
+                       src.endian = Endian.LITTLE_ENDIAN;
+                       
+                       box = new Rectangle
+                               ( src.readDouble(), src.readDouble()
+                               , src.readDouble(), src.readDouble()
+                               );
+                               
+                       var rc: int = src.readInt();
+                       var pc: int = src.readInt();                    
+                       var ringOffsets: Array = [];
+                       while(rc--) {
+                               ringOffsets.push(src.readInt());
+                       }
+                       
+                       var points: Array = [];                 
+                       while(pc--) {
+                               points.push(new ShpPoint(src,16));
+                       }
+                       
+                       // convert points, and ringOffsets arrays to an array of rings:
+                       var removed: uint = 0;
+                       var split: int;
+                       ringOffsets.shift();                    
+                       while(ringOffsets.length) {
+                               split = ringOffsets.shift();
+                               rings.push(points.splice(0,split-removed));
+                               removed = split;
+                       }       
+                       rings.push(points);                                     
+               }               
+       }
+}
+
+} // package;
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpPolyline.as b/org/vanrijkom/shp/ShpPolyline.as
new file mode 100644 (file)
index 0000000..3bebb9b
--- /dev/null
@@ -0,0 +1,48 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+import flash.geom.Rectangle;
+import flash.geom.Point;
+
+/**
+ * The ShpPoint class parses an ESRI Shapefile Polyline record from a ByteArray.
+ * @author Edwin van Rijkom
+ * 
+ */    
+final public class ShpPolyline extends ShpPolygon
+{
+       /**
+        * Constructor.
+        * @inherit
+        * @param src
+        * @param size
+        * @return 
+        * 
+        */     
+       public function ShpPolyline(src: ByteArray = null, size: uint = 0) {
+               super(src,size);
+               type = ShpType.SHAPE_POLYLINE;          
+       }
+}
+
+} // package;
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpRecord.as b/org/vanrijkom/shp/ShpRecord.as
new file mode 100644 (file)
index 0000000..8640bf6
--- /dev/null
@@ -0,0 +1,122 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+import flash.utils.ByteArray;
+import flash.utils.Endian;
+import org.vanrijkom.shp.ShpPointZ;
+import org.vanrijkom.shp.ShpError;
+import org.vanrijkom.shp.ShpPoint;
+
+/**
+ * The ShpPoint class parses an ESRI Shapefile Record Header from a ByteArray
+ * as well as its associated Shape Object. The parsed object is stored as a 
+ * ShpObject that can be cast to a specialized ShpObject deriving class using 
+ * the found shapeType value.
+ * @author Edwin van Rijkom
+ * 
+ */
+public class ShpRecord
+{
+       /**
+        * Record number 
+        */     
+       public var number: int;
+       /**
+        * Content length in 16-bit words 
+        */
+       public var contentLength: int;
+       /**
+        * Content length in bytes 
+        */
+       public var contentLengthBytes: uint;
+       /**
+        * Type of the Shape Object associated with this Record Header.
+        * Should match one of the constant values defined in the ShpType class.
+        * @see ShpType
+        */     
+       public var shapeType: int;
+       /**
+        * Parsed Shape Object. Cast to the specialized ShpObject deriving class
+        * indicated by the shapeType property to obtain Shape type specific
+        * data. 
+        */     
+       public var shape: ShpObject;
+       
+       /**
+        * Constructor.
+        * @param src
+        * @return 
+        * @throws ShpError Not a valid header
+        * @throws Shape type is currently unsupported by this library
+        * @throws Encountered unknown shape type
+        * 
+        */     
+       public function ShpRecord(src: ByteArray) {
+               var availableBytes: int = src.length - src.position;
+               
+               if (availableBytes == 0) 
+                       throw(new ShpError("",ShpError.ERROR_NODATA));
+                       
+               if (src.length - src.position < 8)
+                       throw(new ShpError("Not a valid record header (too small)"));
+       
+               src.endian = Endian.BIG_ENDIAN;
+
+               number = src.readInt();
+               contentLength = src.readInt();
+               contentLengthBytes = contentLength*2 - 4;                       
+               src.endian = Endian.LITTLE_ENDIAN;
+               var shapeOffset: uint = src.position;
+               shapeType = src.readInt();
+                               
+               switch(shapeType) {
+                       case ShpType.SHAPE_POINT:
+                               shape = new ShpPoint(src,contentLengthBytes);
+                               break;
+                       case ShpType.SHAPE_POINTZ:
+                               shape = new ShpPointZ(src,contentLengthBytes);
+                               break;
+                       case ShpType.SHAPE_POLYGON:
+                               shape = new ShpPolygon(src, contentLengthBytes);
+                               break;
+                       case ShpType.SHAPE_POLYLINE:
+                               shape = new ShpPolyline(src, contentLengthBytes);
+                               break;
+                       case ShpType.SHAPE_MULTIPATCH:
+                       case ShpType.SHAPE_MULTIPOINT:
+                       case ShpType.SHAPE_MULTIPOINTM:
+                       case ShpType.SHAPE_MULTIPOINTZ:
+                       case ShpType.SHAPE_POINTM:
+                       case ShpType.SHAPE_POLYGONM:
+                       case ShpType.SHAPE_POLYGONZ:
+                       case ShpType.SHAPE_POLYLINEZ:
+                       case ShpType.SHAPE_POLYLINEM:
+                               throw(new ShpError(shapeType+" Shape type is currently unsupported by this library"));
+                               break;  
+                       default:        
+                               throw(new ShpError("Encountered unknown shape type ("+shapeType+")"));
+                               break;
+               }
+                                       
+       }
+}
+
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpTools.as b/org/vanrijkom/shp/ShpTools.as
new file mode 100644 (file)
index 0000000..289982c
--- /dev/null
@@ -0,0 +1,88 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+import flash.utils.ByteArray;
+import flash.display.Graphics;
+
+/**
+ * The ShpTools class contains static tool methods for working with
+ * ESRI Shapefiles.
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class ShpTools
+{
+       /**
+        * Reads all available ESRI Shape records from the specified ByteArray.
+        * Reading starts at the ByteArrays current offset.
+        * 
+        * @param src ByteArray to read ESRI Shape records from.
+        * @return An Array containing zoomero or more ShpRecord typed values.
+        * @see ShpRecord 
+        */     
+       public static function readRecords(src: ByteArray): Array {
+               var record: ShpRecord;
+               var records: Array = []
+               while (true) {                  
+                       try {           
+                               record = new ShpRecord(src);
+                               records.push(record);                           
+                       } catch (e: ShpError) {
+                               if (e.errorID == ShpError.ERROR_NODATA)
+                                       break;
+                               else    
+                                       throw(e);                               
+                       }                       
+               }
+               return records;
+       }
+       
+       /**
+       * Draw all Polygon Shape records from an ESRI Shapefile using the
+       * Flash drawing API.
+       * @param        src
+       * @param        dest
+       * @param        zoom    
+       * @return       Number of lines drawn.
+       */
+       public static function drawPolyShpFile(src: ByteArray, dest: Graphics, zoom: Number=1): ShpHeader {
+               var shp: ShpHeader = new ShpHeader(src);
+               if      (       shp.shapeType != ShpType.SHAPE_POLYGON 
+                       &&      shp.shapeType != ShpType.SHAPE_POLYLINE
+                       ) 
+                       throw(new ShpError("Shapefile does not contain Polygon records (found type: "+shp.shapeType+")"));
+                       
+               var records: Array = ShpTools.readRecords(src);                         
+               var i: uint;
+               
+               for each(var p: ShpRecord in records) {                 
+                       for each(var r: Array in (p.shape as ShpPolygon).rings) {
+                               if (r.length) {
+                                       dest.moveTo(r[0].x*zoom,-r[0].y*zoom);
+                               }
+                               for (i=1; i<r.length; i++)
+                                       dest.lineTo(r[i].x*zoom,-r[i].y*zoom);                          
+                       }
+               }
+               return shp;             
+       }
+}
+} // package
\ No newline at end of file
diff --git a/org/vanrijkom/shp/ShpType.as b/org/vanrijkom/shp/ShpType.as
new file mode 100644 (file)
index 0000000..5b86242
--- /dev/null
@@ -0,0 +1,100 @@
+/* ************************************************************************ */
+/*                                                                                                                                                     */
+/*  SHP (ESRI ShapeFile Reader)                                                                                                */
+/*  Copyright (c)2007 Edwin van Rijkom                                                                         */
+/*  http://www.vanrijkom.org                                                                                           */
+/*                                                                                                                                                     */
+/* This library is free software; you can redistribute it and/or                       */
+/* modify it under the terms of the GNU Lesser General Public                          */
+/* License as published by the Free Software Foundation; either                                */
+/* version 2.1 of the License, or (at your option) any later version.          */
+/*                                                                                                                                                     */
+/* This library is distributed in the hope that it will be useful,                     */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of                      */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
+/* Lesser General Public License or the LICENSE file for more details.         */
+/*                                                                                                                                                     */
+/* ************************************************************************ */
+
+package org.vanrijkom.shp
+{
+
+/**
+ * The ShpType class is a place holder for the ESRI Shapefile defined
+ * shape types.
+ * @author Edwin van Rijkom
+ * 
+ */    
+public class ShpType
+{      
+       /**
+        * Unknow Shape Type (for internal use) 
+        */
+       public static const SHAPE_UNKNOWN               : int = -1;
+       /**
+        * ESRI Shapefile Null Shape shape type.
+        */     
+       public static const SHAPE_NULL                  : int = 0;
+       /**
+        * ESRI Shapefile Point Shape shape type.
+        */
+       public static const SHAPE_POINT                 : int = 1;
+       /**
+        * ESRI Shapefile PolyLine Shape shape type.
+        */
+       public static const SHAPE_POLYLINE              : int = 3;
+       /**
+        * ESRI Shapefile Polygon Shape shape type.
+        */
+       public static const SHAPE_POLYGON               : int = 5;
+       /**
+        * ESRI Shapefile Multipoint Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_MULTIPOINT    : int = 8;
+       /**
+        * ESRI Shapefile PointZ Shape shape type.
+        */
+       public static const SHAPE_POINTZ                : int = 11;
+       /**
+        * ESRI Shapefile PolylineZ Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_POLYLINEZ     : int = 13;
+       /**
+        * ESRI Shapefile PolygonZ Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_POLYGONZ              : int = 15;
+       /**
+        * ESRI Shapefile MultipointZ Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_MULTIPOINTZ   : int = 18;
+       /**
+        * ESRI Shapefile PointM Shape shape type
+        */
+       public static const SHAPE_POINTM                : int = 21;
+       /**
+        * ESRI Shapefile PolyLineM Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_POLYLINEM             : int = 23;
+       /**
+        * ESRI Shapefile PolygonM Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_POLYGONM              : int = 25;
+       /**
+        * ESRI Shapefile MultiPointM Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_MULTIPOINTM   : int = 28;
+       /**
+        * ESRI Shapefile MultiPatch Shape shape type
+        * (currently unsupported).
+        */
+       public static const SHAPE_MULTIPATCH    : int = 31;
+}
+
+} // package
\ No newline at end of file
index 234c957..668388a 100755 (executable)
@@ -87,6 +87,7 @@
                import net.systemeD.potlatch2.save.SaveManager;
                import net.systemeD.potlatch2.help.*;
                import net.systemeD.potlatch2.options.*;
+               import net.systemeD.potlatch2.utils.*;
                import mx.managers.PopUpManager;
                import flash.system.Security;
                import flash.net.*;
             var conn:Connection = Connection.getConnectionInstance();
             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
+
+                       // and to import a shapefile...
+//                     var importer:ShpImporter = new ShpImporter(theMap, ["http://127.0.0.1/~richard/shp/wildrnp020.shp","http://127.0.0.1/~richard/shp/wildrnp020.shx","http://127.0.0.1/~richard/shp/wildrnp020.dbf"]);
                }
 
         public function onResizeMap():void {