Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java @ 484:823e4f808418
Generate JTS geometries (multi polygons and multi linestrings) from
interpolation with external palette indices.
gnv-artifacts/trunk@559 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 18 Jan 2010 11:25:52 +0000 |
parents | f7038820df2e |
children | 1bf058f1a2d1 |
line wrap: on
line source
package de.intevation.gnv.raster; import java.util.ArrayList; import java.util.Collection; import org.apache.log4j.Logger; import gnu.trove.TIntObjectHashMap; import gnu.trove.TDoubleArrayList; import de.intevation.gnv.raster.Vectorizer.Edge; import de.intevation.gnv.math.IJKey; import de.intevation.gnv.jfreechart.PolygonSeries; import de.intevation.gnv.jfreechart.CompactXYItems; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class IsoPolygonSeriesProducer extends IsoProducer { private static Logger log = Logger.getLogger( IsoPolygonSeriesProducer.class); public static final Float LINE_WIDTH = Float.valueOf(0.1f); public IsoPolygonSeriesProducer( double minX, double minY, double maxX, double maxY ) { super(minX, minY, maxX, maxY); } public Collection<PolygonSeries> getSeries() { return getSeries(null); } public Collection<PolygonSeries> getSeries( AttributeGenerator attributeGenerator ) { ArrayList<PolygonSeries> series = new ArrayList<PolygonSeries>(); double b1 = minX; double m1 = width != 1 ? (maxX - minX)/(width-1) : 0d; double b2 = minY; double m2 = height != 1 ? (maxY - minY)/(height-1) : 0d; TDoubleArrayList vertices = new TDoubleArrayList(); for (IJKey key: joinPairs()) { PolygonSeries ps = new PolygonSeries(); // process complete ArrayList<Edge> completeList = complete.get(key); if (completeList != null) { for (Edge head: completeList) { Edge current = head; do { vertices.add(m1*(current.a % width) + b1); vertices.add(m2*(current.a / width) + b2); } while ((current = current.next) != head); // add head again to close shape vertices.add(m1*(head.a % width) + b1); vertices.add(m2*(head.a / width) + b2); ps.addRing(new CompactXYItems(vertices.toNativeArray())); vertices.clear(); } } // process open TIntObjectHashMap map = commonOpen.get(key); if (map != null) { for (Edge head: headList(map)) { head = Vectorizer.simplify(head, width); Edge current = head, last = head; do { vertices.add(m1*(current.a % width) + b1); vertices.add(m2*(current.a / width) + b2); last = current; } while ((current = current.next) != null); // add b from tail vertices.add(m1*(last.b % width) + b1); vertices.add(m2*(last.b / width) + b2); ps.addRing(new CompactXYItems(vertices.toNativeArray())); vertices.clear(); } // for all in common open } // if map defined for key if (ps.getItemCount() > 0) { series.add(ps); if (attributeGenerator != null) { Object attribute = attributeGenerator .generateAttribute(key.i, key.j); if (attribute != null) { ps.setAttribute("label", attribute); } } ps.setAttribute("line.width", LINE_WIDTH); } } // for all pairs return series; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: