beginning of vector background layers. And a whole load of other stuff too
[potlatch2.git] / net / systemeD / potlatch2 / utils / ShpImporter.as
1 package net.systemeD.potlatch2.utils {
2
3         import org.vanrijkom.shp.*;
4         import org.vanrijkom.dbf.*;
5         import net.systemeD.halcyon.MapPaint;
6         import net.systemeD.halcyon.Globals;
7         import net.systemeD.halcyon.connection.Node;
8
9         public class ShpImporter extends Importer {
10
11                 public function ShpImporter(container:*, paint:MapPaint, filenames:Array) {
12                         super(container,paint,filenames);
13                 }
14
15                 override protected function doImport(): void {
16                         // we load .shp as files[0], .shx as files[1], .dbf as files[2]
17                         var shp:ShpHeader=new ShpHeader(files[0]);
18                         var dbf:DbfHeader=new DbfHeader(files[2]);
19
20                         if (shp.shapeType==ShpType.SHAPE_POLYGON || shp.shapeType==ShpType.SHAPE_POLYLINE) {
21
22                                 // Loop through all polylines in the shape
23                                 var polyArray:Array = ShpTools.readRecords(files[0]);
24                                 for (var i:uint=0; i<polyArray.length; i++) {
25
26                                         // Get attributes like this:
27                                         //              var dr:DbfRecord = DbfTools.getRecord(files[2], dbf, i);
28                                         //              var xsID:String = dr.values[idFieldName];
29
30                                         // Do each ring in turn, then each point in the ring
31                                         for (var j:int=0; j < polyArray[i].shape.rings.length; j++) {
32                                                 var nodestring:Array=[];
33                                                 var points:Array = polyArray[i].shape.rings[j];
34                                                 if (points!=null) {
35                                                         for (var k:int=0; k < points.length; k++) {
36                                                                 var p:ShpPoint = ShpPoint(points[k]);
37                                                                 nodestring.push(container.createNode({}, p.y, p.x));
38                                                         }
39                                                 }
40                                                 if (nodestring.length>0) {
41                                                         paint.createWayUI(container.createWay({}, nodestring));
42                                                 }
43                                         }
44                                 }
45                         }
46                 }
47
48         }
49 }