sascha@465: package de.intevation.gnv.raster; sascha@465: sascha@465: import java.util.List; sascha@465: import java.util.ArrayList; sascha@465: sascha@465: import org.apache.log4j.Logger; sascha@465: sascha@465: import com.vividsolutions.jts.geom.GeometryFactory; sascha@465: import com.vividsolutions.jts.geom.MultiLineString; sascha@465: import com.vividsolutions.jts.geom.LineString; sascha@465: import com.vividsolutions.jts.geom.Coordinate; sascha@465: sascha@465: import gnu.trove.TIntObjectHashMap; sascha@465: sascha@465: import de.intevation.gnv.raster.Vectorizer.Edge; sascha@465: sascha@465: import de.intevation.gnv.utils.Pair; sascha@465: sascha@465: import de.intevation.gnv.math.IJKey; sascha@465: sascha@465: /** sascha@465: * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) sascha@465: */ sascha@465: public class JTSMultiLineStringProducer sascha@465: extends IsoProducer sascha@465: { sascha@465: private static Logger log = Logger.getLogger( sascha@465: JTSMultiLineStringProducer.class); sascha@465: sascha@465: protected GeometryFactory geometryFactory; sascha@465: sascha@465: public JTSMultiLineStringProducer( sascha@465: double minX, double minY, sascha@465: double maxX, double maxY sascha@465: ) { sascha@465: this( sascha@465: JTSMultiPolygonProducer.createDefaultGeometryFactory(), sascha@465: minX, minY, sascha@465: maxX, maxY); sascha@465: } sascha@465: sascha@465: public JTSMultiLineStringProducer( sascha@465: GeometryFactory geometryFactory, sascha@465: double minX, double minY, sascha@465: double maxX, double maxY sascha@465: ) { sascha@465: super(minX, minY, maxX, maxY); sascha@465: this.geometryFactory = geometryFactory; sascha@465: } sascha@465: sascha@465: public List> getMultiLineStrings( sascha@465: AttributeGenerator attributeGenerator sascha@465: ) { sascha@465: ArrayList> multiLineStrings = sascha@465: new ArrayList>(); sascha@465: sascha@465: double b1 = minX; sascha@465: double m1 = width != 1 sascha@465: ? (maxX - minX)/(width-1) sascha@465: : 0d; sascha@465: sascha@465: double b2 = minY; sascha@465: double m2 = height != 1 sascha@465: ? (maxY - minY)/(height-1) sascha@465: : 0d; sascha@465: sascha@465: ArrayList coordinates = new ArrayList(); sascha@465: sascha@465: for (IJKey key: joinPairs()) { sascha@465: ArrayList lineStrings = new ArrayList(); sascha@465: sascha@465: // process complete sascha@465: ArrayList completeList = complete.get(key); sascha@465: if (completeList != null) { sascha@465: for (Edge head: completeList) { sascha@465: Edge current = head; sascha@465: do { sascha@465: coordinates.add(new Coordinate( sascha@465: m1*(current.a % width) + b1, sascha@465: m2*(current.a / width) + b2)); sascha@465: } sascha@465: while ((current = current.next) != head); sascha@465: // add head again to close shape sascha@465: coordinates.add(new Coordinate( sascha@465: m1*(head.a % width) + b1, sascha@465: m2*(head.a / width) + b2)); sascha@465: lineStrings.add( sascha@465: geometryFactory.createLineString( sascha@465: coordinates.toArray( sascha@465: new Coordinate[coordinates.size()]))); sascha@465: coordinates.clear(); sascha@465: } sascha@465: } sascha@465: sascha@465: // process open sascha@465: TIntObjectHashMap map = commonOpen.get(key); sascha@465: sascha@465: if (map != null) { sascha@465: for (Edge head: headList(map)) { sascha@465: sascha@465: head = Vectorizer.simplify(head, width); sascha@465: Edge current = head, last = head; sascha@465: do { sascha@465: coordinates.add(new Coordinate( sascha@465: m1*(current.a % width) + b1, sascha@465: m2*(current.a / width) + b2)); sascha@465: last = current; sascha@465: } sascha@465: while ((current = current.next) != null); sascha@465: // add b from tail sascha@465: coordinates.add(new Coordinate( sascha@465: m1*(last.b % width) + b1, sascha@465: m2*(last.b / width) + b2)); sascha@465: lineStrings.add( sascha@465: geometryFactory.createLineString( sascha@465: coordinates.toArray( sascha@465: new Coordinate[coordinates.size()]))); sascha@465: coordinates.clear(); sascha@465: } // for all in common open sascha@465: } // if map defined for key sascha@465: sascha@465: if (!lineStrings.isEmpty()) { sascha@465: MultiLineString multiLineString = sascha@465: geometryFactory.createMultiLineString( sascha@465: lineStrings.toArray( sascha@465: new LineString[lineStrings.size()])); sascha@465: lineStrings.clear(); sascha@465: Object attribute = attributeGenerator != null sascha@465: ? attributeGenerator.generateAttribute(key.i, key.j) sascha@465: : key; sascha@465: multiLineStrings.add(new Pair( sascha@465: attribute, sascha@465: multiLineString)); sascha@465: } sascha@465: } // for all pairs sascha@465: sascha@465: return multiLineStrings; sascha@465: } sascha@465: } sascha@465: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :