annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/JTSMultiLineStringProducer.java @ 1095:c961cd9a13f7

Write svn revision to MANIFEST file while creating jar archive. gnv-artifacts/trunk@1211 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 14 Jun 2010 21:12:23 +0000
parents feae2f9d6c6f
children f953c9a559d8
rev   line source
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.raster;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
4 import com.vividsolutions.jts.geom.Geometry;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
5 import com.vividsolutions.jts.geom.GeometryFactory;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
6 import com.vividsolutions.jts.geom.LineString;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
7 import com.vividsolutions.jts.geom.MultiLineString;
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
8 import com.vividsolutions.jts.geom.Polygon;
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
9 import com.vividsolutions.jts.geom.TopologyException;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
11 import de.intevation.gnv.math.IJKey;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import de.intevation.gnv.raster.Vectorizer.Edge;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import de.intevation.gnv.utils.Pair;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
17 import gnu.trove.TIntObjectHashMap;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
19 import java.util.ArrayList;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
20 import java.util.List;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
21
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
22 import org.apache.log4j.Logger;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
23
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 /**
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
25 * Vectorizer backend to generated iso lines in form of
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
26 * JTS multi linestrings.
803
feae2f9d6c6f Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 802
diff changeset
27 *
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
28 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 */
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public class JTSMultiLineStringProducer
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 extends IsoProducer
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 private static Logger log = Logger.getLogger(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 JTSMultiLineStringProducer.class);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
36 /**
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
37 * The JTS geometry factory of this producer.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
38 */
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 protected GeometryFactory geometryFactory;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
41 /**
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
42 * The polygon used to clip the produced multe line strings.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
43 */
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
44 protected Polygon clip;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
45
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
46 /**
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
47 * Constructor to create a JTSMultiLineStringProducer with
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
48 * a given clipping polygon and a world bounding box.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
49 * @param clip The clipping polygon.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
50 * @param minX Min x coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
51 * @param minY Min y coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
52 * @param maxX Max x coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
53 * @param maxY Max y coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
54 */
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 public JTSMultiLineStringProducer(
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
56 Polygon clip,
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 double minX, double minY,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 double maxX, double maxY
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 ) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 this(
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
61 clip,
498
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
62 // XXX: Geotools crashes if only using a 2d packed data format!
4080b57dcb52 Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
63 JTSMultiPolygonProducer.createDefaultGeometryFactory(3),
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 minX, minY,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 maxX, maxY);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
68 /**
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
69 * Constructor to create a JTSMultiLineStringProducer with
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
70 * a given clipping polygon, a geometry factory
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
71 * and a world bounding box.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
72 * @param clip The clipping polygon.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
73 * @param geometryFactory The geometry factory.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
74 * @param minX Min x coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
75 * @param minY Min y coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
76 * @param maxX Max x coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
77 * @param maxY Max y coord of the world.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
78 */
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 public JTSMultiLineStringProducer(
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
80 Polygon clip,
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 GeometryFactory geometryFactory,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 double minX, double minY,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 double maxX, double maxY
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 ) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 super(minX, minY, maxX, maxY);
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
86 this.clip = clip;
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 this.geometryFactory = geometryFactory;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
90 /**
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
91 * Clips a given line string against the clippin polygon. The
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
92 * result is stored in the given list of line strings.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
93 * @param lineString The line string to be clipped.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
94 * @param lineStrings The result line string list.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
95 */
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
96 protected void clipLineString(
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
97 LineString lineString,
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
98 ArrayList<LineString> lineStrings
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
99 ) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
100 if (clip == null) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
101 lineStrings.add(lineString);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
102 return;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
103 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
104
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
105 if (!lineString.intersects(clip)) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
106 return;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
107 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
108
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
109 try {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
110 Geometry result = lineString.intersection(clip);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
111
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
112 if (result instanceof LineString) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
113 lineStrings.add((LineString)result);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
114 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
115 else if (result instanceof MultiLineString) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
116 MultiLineString mls = (MultiLineString)result;
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
117 for (int i = 0, N = mls.getNumGeometries(); i < N; ++i) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
118 Geometry g = mls.getGeometryN(i);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
119 if (g instanceof LineString) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
120 lineStrings.add((LineString)g);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
121 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
122 else {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
123 log.warn("cannot handle geometry " + g.getClass());
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
124 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
125 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
126 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
127 else {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
128 log.warn("cannot handle " + result.getClass());
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
129 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
130 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
131 catch (TopologyException te) {
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
132 log.error(te.getLocalizedMessage(), te);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
133 lineStrings.add(lineString);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
134 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
135 }
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
136
802
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
137 /**
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
138 * Returns a list of pairs attribute -&gt; multi line string.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
139 * All line strings produced are grouped by there attribute
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
140 * which is generated with the given attribute generator.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
141 * @param attributeGenerator The attribute generator.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
142 * @return The list of attribute/multi line strings.
4abe172be970 Finished Javadoc of the raster package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
143 */
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 public List<Pair<Object, MultiLineString>> getMultiLineStrings(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 AttributeGenerator attributeGenerator
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 ) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 ArrayList<Pair<Object, MultiLineString>> multiLineStrings =
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 new ArrayList<Pair<Object, MultiLineString>>();
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 double b1 = minX;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 double m1 = width != 1
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 ? (maxX - minX)/(width-1)
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 : 0d;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 double b2 = minY;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 double m2 = height != 1
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 ? (maxY - minY)/(height-1)
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 : 0d;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 ArrayList<Coordinate> coordinates = new ArrayList<Coordinate>();
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 for (IJKey key: joinPairs()) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 ArrayList<LineString> lineStrings = new ArrayList<LineString>();
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 // process complete
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 ArrayList<Edge> completeList = complete.get(key);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 if (completeList != null) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 for (Edge head: completeList) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 Edge current = head;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 do {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 coordinates.add(new Coordinate(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 m1*(current.a % width) + b1,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 m2*(current.a / width) + b2));
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 while ((current = current.next) != head);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 // add head again to close shape
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 coordinates.add(new Coordinate(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 m1*(head.a % width) + b1,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 m2*(head.a / width) + b2));
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
180
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
181 clipLineString(
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 geometryFactory.createLineString(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 coordinates.toArray(
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
184 new Coordinate[coordinates.size()])),
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
185 lineStrings);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
186
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 coordinates.clear();
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 // process open
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 TIntObjectHashMap map = commonOpen.get(key);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 if (map != null) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 for (Edge head: headList(map)) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 head = Vectorizer.simplify(head, width);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 Edge current = head, last = head;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 do {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 coordinates.add(new Coordinate(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 m1*(current.a % width) + b1,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 m2*(current.a / width) + b2));
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 last = current;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 while ((current = current.next) != null);
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 // add b from tail
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 coordinates.add(new Coordinate(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 m1*(last.b % width) + b1,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 m2*(last.b / width) + b2));
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
210
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
211 clipLineString(
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 geometryFactory.createLineString(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 coordinates.toArray(
499
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
214 new Coordinate[coordinates.size()])),
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
215 lineStrings);
e065a72f6b62 Clip "Horizontalschnitte" against given clipping polygon.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
216
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 coordinates.clear();
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 } // for all in common open
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
219 } // if map defined for key
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 if (!lineStrings.isEmpty()) {
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 MultiLineString multiLineString =
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 geometryFactory.createMultiLineString(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 lineStrings.toArray(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 new LineString[lineStrings.size()]));
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 lineStrings.clear();
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
227 Object attribute = attributeGenerator != null
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
228 ? attributeGenerator.generateAttribute(key.i, key.j)
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 : key;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230 multiLineStrings.add(new Pair<Object, MultiLineString>(
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 attribute,
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 multiLineString));
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 } // for all pairs
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 return multiLineStrings;
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org