diff gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java @ 465:f7038820df2e

Added support to trace rasters to JTS multi polygons and multi line strings. Write them to shape files with GeoTools. gnv-artifacts/trunk@526 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 11 Jan 2010 00:29:45 +0000
parents 3cb2bea50456
children 1bf058f1a2d1
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java	Sat Jan 09 17:55:45 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java	Mon Jan 11 00:29:45 2010 +0000
@@ -1,19 +1,13 @@
 package de.intevation.gnv.raster;
 
-import java.util.List;
-import java.util.HashSet;
-import java.util.HashMap;
 import java.util.ArrayList;
 import java.util.Collection;
 
 import org.apache.log4j.Logger;
 
-import gnu.trove.TIntHashSet;
 import gnu.trove.TIntObjectHashMap;
 import gnu.trove.TDoubleArrayList;
-import gnu.trove.TObjectProcedure;
 
-import de.intevation.gnv.raster.Vectorizer.RingsHandler;
 import de.intevation.gnv.raster.Vectorizer.Edge;
 
 import de.intevation.gnv.math.IJKey;
@@ -25,114 +19,20 @@
  * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
  */
 public class IsoPolygonSeriesProducer
-implements   RingsHandler
+extends      IsoProducer
 {
     private static Logger log = Logger.getLogger(
         IsoPolygonSeriesProducer.class);
 
 	public static final Float LINE_WIDTH = Float.valueOf(0.1f);
 
-    public interface AttributeGenerator {
-
-        Object generateAttribute(int neighbor1, int neighbor2);
-
-    } // interface AttributeGenerator
-
-    protected HashMap<Edge, Integer>            open;
-    protected HashMap<IJKey, TIntObjectHashMap> commonOpen;
-    protected HashMap<IJKey, ArrayList<Edge>>   complete;
-
-    protected int    width;
-    protected int    height;
-
-    protected double minX;
-    protected double minY;
-    protected double maxX;
-    protected double maxY;
-
     public IsoPolygonSeriesProducer(
         double minX, double minY,
         double maxX, double maxY
     ) {
-        this.minX = minX;
-        this.minY = minY;
-        this.maxX = maxX;
-        this.maxY = maxY;
-
-        open       = new HashMap<Edge, Integer>();
-        commonOpen = new HashMap<IJKey, TIntObjectHashMap>();
-        complete   = new HashMap<IJKey, ArrayList<Edge>>();
+        super(minX, minY, maxX, maxY);
     }
 
-    public void handleRings(
-        List<Edge> rings, 
-        int        value, 
-        int        width,
-        int        height
-    ) {
-        if (value == -1) {
-            return;
-        }
-        this.width  = width;
-        this.height = height;
-
-        Integer v = Integer.valueOf(value);
-
-        for (Edge head: rings) {
-            Edge current = head;
-            do {
-                Integer neighbor = open.remove(current);
-
-                if (neighbor != null) {
-                    IJKey pair = new IJKey(value, neighbor.intValue());
-                    pair.sort();
-
-                    TIntObjectHashMap co = commonOpen.get(pair);
-
-                    if (co == null) {
-                        commonOpen.put(pair, co = new TIntObjectHashMap());
-                    }
-
-                    Edge edge = new Edge(current);
-
-                    Edge otherA = (Edge)co.remove(edge.a);
-                    if (otherA != null) {
-                        otherA.chain(edge, edge.a);
-                    }
-
-                    Edge otherB = (Edge)co.remove(edge.b);
-                    if (otherB != null) {
-                        otherB.chain(edge, edge.b);
-                    }
-
-                    if (edge.isComplete()) {
-                        ArrayList list = complete.get(pair);
-                        if (list == null) {
-                            complete.put(pair, list = new ArrayList());
-                        }
-                        list.add(Vectorizer.simplify(edge, width));
-                    }
-                    else {
-                        if (otherA == null) {
-                            co.put(edge.a, edge);
-                        }
-                        if (otherB == null) {
-                            co.put(edge.b, edge);
-                        }
-                    }
-                }
-                else {
-                    Edge edge = new Edge(current.b, current.a);
-                    open.put(edge, v);
-                }
-
-                current = current.next;
-            }
-            while (current != head);
-        } // for all rings
-
-    } // handleRings
-
     public Collection<PolygonSeries> getSeries() {
         return getSeries(null);
     }
@@ -152,18 +52,9 @@
             ? (maxY - minY)/(height-1)
             : 0d;
 
-        // join keys of complete and open polygons
-        HashSet<IJKey> pairs = new HashSet<IJKey>();
-        for (IJKey key: complete.keySet()) {
-            pairs.add(key);
-        }
-        for (IJKey key: commonOpen.keySet()) {
-            pairs.add(key);
-        }
-
         TDoubleArrayList vertices = new TDoubleArrayList();
 
-        for (IJKey key: pairs) {
+        for (IJKey key: joinPairs()) {
             PolygonSeries ps = new PolygonSeries();
 
             // process complete
@@ -188,19 +79,7 @@
             TIntObjectHashMap map = commonOpen.get(key);
 
             if (map != null) {
-                final ArrayList<Edge> headList = new ArrayList<Edge>();
-                map.forEachValue(new TObjectProcedure() {
-                    TIntHashSet headSet = new TIntHashSet();
-                    public boolean execute(Object value) {
-                        Edge head = ((Edge)value).head();
-                        if (headSet.add(head.a)) {
-                            headList.add(head);
-                        }
-                        return true;
-                    }
-                });
-
-                for (Edge head: headList) {
+                for (Edge head: headList(map)) {
 
                     head = Vectorizer.simplify(head, width);
                     Edge current = head, last = head;
@@ -234,11 +113,5 @@
 
         return series;
     }
-
-    public void clear() {
-        open.clear();
-        complete.clear();
-        commonOpen.clear();
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org