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.TableRow;
21: import org.geotools.feature.FeatureType;
22:
23: /*
24: * PrimitiveDataFactory.java
25: *
26: * Created on July 8, 2004, 12:10 PM
27: *
28: * @author <a href="mailto:knuterik@onemap.org">Knut-Erik Johnsen</a>, Project OneMap
29: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/util/PrimitiveDataFactory.java $
30: */
31: public class PrimitiveDataFactory {
32: protected EdgeData readEdge(TableRow edge) {
33: EdgeData ed = null;
34:
35: try {
36: ed = new EdgeData();
37: ed.put("id", new Integer(edge.get("id").intValue()));
38: ed.put("start_node", new Integer(edge.get("start_node")
39: .intValue()));
40: ed.put("end_node", new Integer(edge.get("end_node")
41: .intValue()));
42: ed.put("right_face", edge.get("right_face"));
43: ed.put("left_face", edge.get("left_face"));
44: ed.put("right_edge", edge.get("right_edge"));
45: ed.put("left_edge", edge.get("left_edge"));
46: ed.put("coordinates", edge.get("coordinates"));
47: } catch (Exception e) {
48: e.printStackTrace();
49: }
50:
51: return ed;
52: }
53:
54: protected HashMap readFeature(TableRow line, FeatureType type) {
55: HashMap tmp = new HashMap();
56:
57: String name = null;
58:
59: for (int i = 0; i < type.getAttributeCount(); i++) {
60: name = type.getAttributeType(i).getName();
61: tmp.put(name, line.get(name));
62: }
63:
64: return tmp;
65: }
66:
67: protected HashMap readFace(TableRow face) {
68: HashMap fd = new HashMap();
69: fd.put("id", face.get("id").toString());
70: fd.put("ext_id", new Integer(face.get(1).intValue()));
71: fd
72: .put("ring_ptr", new Integer(face.get("ring_ptr")
73: .intValue()));
74:
75: return fd;
76: }
77:
78: protected PointData readPoint(TableRow point) {
79: PointData pd = new PointData();
80: pd.put("id", point.get("id").toString());
81: pd.put("coordinate", point.get("coordinate").toString());
82:
83: return pd;
84: }
85:
86: protected HashMap readRing(TableRow ring) {
87: HashMap rd = new HashMap();
88: rd.put("id", ring.get("id").toString());
89: rd.put("face_id", new Integer(ring.get("face_id").intValue()));
90: rd.put("start_edge", new Integer(ring.get("start_edge")
91: .intValue()));
92:
93: return rd;
94: }
95: }
|