comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/JTSMultiPolygonProducer.java @ 802:4abe172be970

Finished Javadoc of the raster package. gnv-artifacts/trunk@884 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 07 Apr 2010 07:49:12 +0000
parents c4156275c1e1
children feae2f9d6c6f
comparison
equal deleted inserted replaced
801:d766fe2d917a 802:4abe172be970
22 import java.util.TreeMap; 22 import java.util.TreeMap;
23 23
24 import org.apache.log4j.Logger; 24 import org.apache.log4j.Logger;
25 25
26 /** 26 /**
27 * Vectorizer backend to generated polygons in form of
28 * JTS multi multi polygons.
29 *
27 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> 30 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
28 */ 31 */
29 public class JTSMultiPolygonProducer 32 public class JTSMultiPolygonProducer
30 extends AbstractProducer 33 extends AbstractProducer
31 { 34 {
32 private static Logger log = Logger.getLogger( 35 private static Logger log = Logger.getLogger(
33 JTSMultiPolygonProducer.class); 36 JTSMultiPolygonProducer.class);
34 37
38 /**
39 * The reference system of used coordinates: {@value}
40 */
35 public static final int SRID_WGS84 = 4326; 41 public static final int SRID_WGS84 = 4326;
36 42
43 /**
44 * Interface to decouple the conversion of the internal
45 * index scheme of the polygons to an external one.
46 */
37 public interface ValueConverter { 47 public interface ValueConverter {
38 48
49 /**
50 * Maps integer index schemes.
51 * @param value The input value.
52 * @return The resulting index.
53 */
39 Integer convert(Integer value); 54 Integer convert(Integer value);
40 55
41 } // interface ValueConverter 56 } // interface ValueConverter
42 57
58 /**
59 * The JTS geometry factory.
60 */
43 protected GeometryFactory geometryFactory; 61 protected GeometryFactory geometryFactory;
44 62
63 /**
64 * The clipping polygon.
65 */
45 protected Polygon clip; 66 protected Polygon clip;
46 67
68 /**
69 * Internal map to map the internal polygons indices to a
70 * list of generated polygons.
71 */
47 protected HashMap<Integer, ArrayList<Polygon>> valueToPolygons; 72 protected HashMap<Integer, ArrayList<Polygon>> valueToPolygons;
48 73
74 /**
75 * Default constructor.
76 */
49 public JTSMultiPolygonProducer() { 77 public JTSMultiPolygonProducer() {
50 } 78 }
51 79
80 /**
81 * Constructor to create a JTSMultiPolygonProducer with a
82 * given clipping polygon and a world bounding box.
83 * @param clip The clipping polygon.
84 * @param minX Min x coord of the world.
85 * @param minY Min y coord of the world.
86 * @param maxX Max x coord of the world.
87 * @param maxY Max y coord of the world.
88 */
52 public JTSMultiPolygonProducer( 89 public JTSMultiPolygonProducer(
53 Polygon clip, 90 Polygon clip,
54 double minX, double minY, 91 double minX, double minY,
55 double maxX, double maxY 92 double maxX, double maxY
56 ) { 93 ) {
59 createDefaultGeometryFactory(), 96 createDefaultGeometryFactory(),
60 minX, minY, 97 minX, minY,
61 maxX, maxY); 98 maxX, maxY);
62 } 99 }
63 100
101 /**
102 * Constructor to create a JTSMultiPolygonProducer with a
103 * given clipping polygon, a geometry factory and a world bounding box.
104 * @param clip The clipping polygon.
105 * @param geometryFactory The geometry factory.
106 * @param minX Min x coord of the world.
107 * @param minY Min y coord of the world.
108 * @param maxX Max x coord of the world.
109 * @param maxY Max y coord of the world.
110 */
64 public JTSMultiPolygonProducer( 111 public JTSMultiPolygonProducer(
65 Polygon clip, 112 Polygon clip,
66 GeometryFactory geometryFactory, 113 GeometryFactory geometryFactory,
67 double minX, double minY, 114 double minX, double minY,
68 double maxX, double maxY 115 double maxX, double maxY
71 this.clip = clip; 118 this.clip = clip;
72 this.geometryFactory = geometryFactory; 119 this.geometryFactory = geometryFactory;
73 valueToPolygons = new HashMap<Integer, ArrayList<Polygon>>(); 120 valueToPolygons = new HashMap<Integer, ArrayList<Polygon>>();
74 } 121 }
75 122
123 /**
124 * Creates a 3D geometry factory via
125 * {@link #createDefaultGeometryFactory(int)}.
126 * @return The new geometry factory.
127 */
76 public static GeometryFactory createDefaultGeometryFactory() { 128 public static GeometryFactory createDefaultGeometryFactory() {
77 return createDefaultGeometryFactory(3); 129 return createDefaultGeometryFactory(3);
78 } 130 }
79 131
132 /**
133 * Creates a geometry factory with a given dimension.
134 * @param dim The dimension.
135 * @return The new geometry factory.
136 */
80 public static GeometryFactory createDefaultGeometryFactory(int dim) { 137 public static GeometryFactory createDefaultGeometryFactory(int dim) {
81 return new GeometryFactory( 138 return new GeometryFactory(
82 new PrecisionModel( 139 new PrecisionModel(
83 PrecisionModel.FLOATING), 140 PrecisionModel.FLOATING),
84 SRID_WGS84, 141 SRID_WGS84,
160 217
161 polygons.add(polygon); 218 polygons.add(polygon);
162 } 219 }
163 } 220 }
164 221
222 /**
223 * Returns a index -&gt; multi polyon map. The internal index scheme
224 * is retained.
225 * {@link #getMultiPolygons(de.intevation.gnv.raster.JTSMultiPolygonProducer.ValueConverter)}
226 * @return The new map.
227 */
165 public Map<Integer, MultiPolygon> getMultiPolygons() { 228 public Map<Integer, MultiPolygon> getMultiPolygons() {
166 return getMultiPolygons(null); 229 return getMultiPolygons(null);
167 } 230 }
168 231
232 /**
233 * Flattend a JTS geometry to a multi polygon if possible
234 * @param result The geometry to be flattend
235 * @return The resulting multi polygon.
236 */
169 protected MultiPolygon flattenCollection(Geometry result) { 237 protected MultiPolygon flattenCollection(Geometry result) {
170 238
171 if (result instanceof MultiPolygon) { 239 if (result instanceof MultiPolygon) {
172 return (MultiPolygon)result; 240 return (MultiPolygon)result;
173 } 241 }
180 log.warn("cannot handle " + result.getClass()); 248 log.warn("cannot handle " + result.getClass());
181 249
182 return null; 250 return null;
183 } 251 }
184 252
253 /**
254 * Returns a index -&gt; multi polyon map. The internal index scheme
255 * is remapped with the given value converter.
256 * @param valueConverter Converter to remap the index scheme. Maybe null
257 * if no remapping is required.
258 * @return The new map.
259 */
185 public Map<Integer, MultiPolygon> getMultiPolygons( 260 public Map<Integer, MultiPolygon> getMultiPolygons(
186 ValueConverter valueConverter 261 ValueConverter valueConverter
187 ) { 262 ) {
188 TreeMap<Integer, MultiPolygon> multiPolygons = 263 TreeMap<Integer, MultiPolygon> multiPolygons =
189 new TreeMap<Integer, MultiPolygon>(); 264 new TreeMap<Integer, MultiPolygon>();
216 } 291 }
217 292
218 return multiPolygons; 293 return multiPolygons;
219 } 294 }
220 295
296 /**
297 * Empties internal temporary data structures to save some memory.
298 */
221 public void clear() { 299 public void clear() {
222 valueToPolygons.clear(); 300 valueToPolygons.clear();
223 } 301 }
224 } 302 }
225 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 303 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org