forked from systemed/potlatch2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,388 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.