Handle 'tags' in shapefiles, and don't create dupes on pull-through.
authorRichard Fairhurst <richard@systemeD.net>
Fri, 10 Jun 2011 09:09:04 +0000 (10:09 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 10 Jun 2011 09:09:04 +0000 (10:09 +0100)
Also, we really need TagTransform for this. ;)

net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/potlatch2/utils/ShpImporter.as

index 22a16dc..31b4808 100644 (file)
@@ -462,16 +462,18 @@ package net.systemeD.halcyon {
             var action:CompositeUndoableAction = new CompositeUndoableAction("pull through");
             if (entity is Way) {
                 // copy way through to main layer
-                // ** shouldn't do this if the nodes are already in the main layer
-                //    (or maybe we should just match on lat/long to avoid ways in background having nodes in foreground)
                 var oldWay:Way=Way(entity);
                 var nodemap:Object={};
                 var nodes:Array=[];
+                var oldNode:Node, newNode:Node;
                 for (var i:uint=0; i<oldWay.length; i++) {
                     oldNode = oldWay.getNode(i);
-                    var newNode:Node = nodemap[oldNode.id] ? nodemap[oldNode.id] : target.connection.createNode(
-                        oldNode.getTagsCopy(), oldNode.lat, oldNode.lon,
-                        action.push);
+                    if (nodemap[oldNode.id])
+                        newNode=nodemap[oldNode.id];
+                    else if (target.connection.identicalNode(oldNode))
+                        newNode=target.connection.identicalNode(oldNode);
+                    else
+                        newNode = target.connection.createNode(oldNode.getTagsCopy(), oldNode.lat, oldNode.lon, action.push);
                     nodes.push(newNode);
                     nodemap[oldNode.id]=newNode;
                 }
@@ -482,7 +484,7 @@ package net.systemeD.halcyon {
 
             } else if (entity is Node && !entity.hasParentWays) {
 
-                var oldNode:Node=Node(entity);
+                oldNode=Node(entity);
 
                 var newPoiAction:CreatePOIAction = new CreatePOIAction(
                     target.connection, oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
index 3fafeae..1c57906 100644 (file)
@@ -485,6 +485,13 @@ package net.systemeD.halcyon.connection {
             return [];
         }
 
+               public function identicalNode(node:Node):Node {
+                       for each (var dupe:Node in nodePositions[node.lat+","+node.lon]) {
+                               if (node.lat==dupe.lat && node.lon==dupe.lon && node.sameTags(dupe)) return dupe;
+                       }
+                       return null;
+               }
+
                // Error-handling
                
                protected function throwConflictError(entity:Entity,serverVersion:uint,message:String):void {
index 8751249..c975324 100644 (file)
@@ -101,6 +101,16 @@ package net.systemeD.halcyon.connection {
             return false;
         }
 
+               /** Compare tags between two entities. */
+               public function sameTags(entity:Entity):Boolean {
+                       var o:Object=entity.getTagsHash();
+                       for (var k:String in tags)
+                               if (!o[k] || o[k]!=tags[k]) return false;
+                       for (k in o)
+                               if (!tags[k] || tags[k]!=o[k]) return false;
+                       return true;
+               }
+
         /** Rough function to detect entities untouched since TIGER import. */
         public function isUneditedTiger():Boolean {
             // todo: make this match the rules from the tiger edited map
index 70ded7e..95386cf 100644 (file)
@@ -30,6 +30,7 @@ package net.systemeD.potlatch2.utils {
                        }
 
                        var nodemap:Object={};
+                       var key:String, v:String;
 
                        if (shp.shapeType==ShpType.SHAPE_POLYGON || shp.shapeType==ShpType.SHAPE_POLYLINE) {
 
@@ -37,9 +38,15 @@ package net.systemeD.potlatch2.utils {
                                var polyArray:Array = ShpTools.readRecords(files[0]);
                                for (var i:uint=0; i<polyArray.length; i++) {
 
-                                       // Get attributes like this:
-                                       //              var dr:DbfRecord = DbfTools.getRecord(files[2], dbf, i);
-                                       //              var xsID:String = dr.values[idFieldName];
+                                       // Get attributes and create a tags hash
+                                       // (note that dr.values is a Dictionary)
+                                       var dr:DbfRecord = DbfTools.getRecord(files[2], dbf, i);
+                                       var tags:Object={};
+                                       for (key in dr.values) {
+                                               v=dr.values[key];
+                                               while (v.substr(v.length-1,1)==" ") v=v.substr(0,v.length-1);
+                                               if (v!='') tags[key.toLowerCase()]=v;
+                                       }
 
                                        // Do each ring in turn, then each point in the ring
                                        var way:Way;
@@ -60,14 +67,14 @@ package net.systemeD.potlatch2.utils {
                                                                        x=p.x; x=p.y;
                                                                }
 
-                                                               var key:String=x+","+y;
+                                                               key=x+","+y;
                                                                if (nodemap[key]) { node=nodemap[key]; }
                                                                else { node=connection.createNode({}, y, x, push); nodemap[key]=node; }
                                                                nodestring.push(node);
                                                        }
                                                }
                                                if (nodestring.length>0) {
-                                                       way=connection.createWay({}, nodestring, push);
+                                                       way=connection.createWay(tags, nodestring, push);
                                                        if (simplify) { Simplify.simplify(way, map, false); }
                                                }
                                        }