01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.vpf.util;
17:
18: import java.util.HashMap;
19:
20: import org.geotools.data.vpf.io.RowField;
21: import org.geotools.data.vpf.io.TripletId;
22: import org.opengis.geometry.DirectPosition;
23:
24: import com.vividsolutions.jts.geom.Coordinate;
25: import com.vividsolutions.jts.geom.GeometryFactory;
26:
27: /*
28: * EdgeData.java
29: *
30: * Created on 6. april 2004, 14:54
31: *
32: * @author <a href="mailto:knuterik@onemap.org">Knut-Erik Johnsen</a>, Project OneMap
33: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/util/EdgeData.java $
34: */
35: public class EdgeData extends HashMap {
36: public Object put(Object key, Object value) {
37: if (key instanceof String) {
38: GeometryFactory geofactory = new GeometryFactory();
39: String key_s = (String) key;
40:
41: if (key_s.equals("coordinates")) {
42: Coordinate[] c = null;
43: if (value instanceof RowField) {
44: value = ((RowField) value).getValue();
45: if (value instanceof DirectPosition[]) {
46: DirectPosition[] coords = (DirectPosition[]) value;
47: c = new Coordinate[coords.length];
48: double[] c_pair = null;
49: for (int i = 0; i < coords.length; i++) {
50: c_pair = coords[i].getCoordinates();
51: if (coords[i].getDimension() == 2) {
52: c[i] = new Coordinate(c_pair[0],
53: c_pair[1]);
54: } else if (coords[i].getDimension() == 3) {
55: c[i] = new Coordinate(c_pair[0],
56: c_pair[1], c_pair[2]);
57: }
58: }
59: }
60: }
61:
62: return super .put(key_s, geofactory.createLineString(c));
63: } else if (key_s.equals("right_face")
64: || key_s.equals("left_face")
65: || key_s.equals("right_edge")
66: || key_s.equals("left_edge")) {
67: if (value != null) {
68: Object tmp = ((RowField) value).getValue();
69:
70: if (tmp instanceof TripletId) {
71: return super .put(key_s, (TripletId) tmp);
72: } else if (tmp instanceof Integer) {
73: return super .put(key_s, ((Integer) tmp));
74: } else {
75: System.out
76: .println("DYNGE I TRIPLETGENERERING!!!");
77: }
78: } else {
79: return super.put(key_s, null);
80: }
81: }
82: }
83:
84: return super.put(key, value);
85: }
86: }
|