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: import java.util.StringTokenizer;
20:
21: import com.vividsolutions.jts.geom.Coordinate;
22: import com.vividsolutions.jts.geom.GeometryFactory;
23:
24: /*
25: * AreaData.java
26: *
27: * Created on July 4, 2004, 5:35 PM
28: *
29: * @author <a href="mailto:knuterik@onemap.org">Knut-Erik Johnsen</a>, Project OneMap
30: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/util/PointData.java $
31: */
32: public class PointData extends HashMap {
33: public Object put(Object key, Object value) {
34: if (key instanceof String) {
35: String key_s = (String) key;
36:
37: if (key_s.equals("coordinate")) {
38: StringTokenizer st = new StringTokenizer(
39: (String) value, "()");
40: Coordinate[] c = new Coordinate[st.countTokens()];
41: int i = 0;
42:
43: while (st.hasMoreTokens()) {
44: StringTokenizer st2 = new StringTokenizer(st
45: .nextToken(), ",");
46: c[i] = new Coordinate(Double.parseDouble(st2
47: .nextToken()), Double.parseDouble(st2
48: .nextToken()));
49: i++;
50: }
51:
52: // System.out.println( "Antall koordinater: " + c.length);
53: GeometryFactory geofactory = new GeometryFactory();
54:
55: return super .put("coordinate", geofactory
56: .createPoint(c[0]));
57: }
58: }
59:
60: return super.put(key, value);
61: }
62: }
|