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: * Created on Jul 19, 2004
17: */
18: package org.geotools.data.vpf.readers;
19:
20: import java.io.File;
21: import java.io.IOException;
22: import java.sql.SQLException;
23:
24: import org.geotools.data.vpf.VPFFeatureType;
25: import org.geotools.data.vpf.file.VPFFile;
26: import org.geotools.data.vpf.file.VPFFileFactory;
27: import org.geotools.data.vpf.ifc.FileConstants;
28: import org.geotools.feature.Feature;
29: import org.geotools.feature.IllegalAttributeException;
30:
31: import com.vividsolutions.jts.geom.Geometry;
32:
33: /**
34: * DOCUMENT ME!
35: *
36: * @author <a href="mailto:jeff@ionicenterprise.com">Jeff Yutzler</a>
37: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/readers/LineGeometryFactory.java $
38: */
39: public class LineGeometryFactory extends VPFGeometryFactory implements
40: FileConstants {
41: /* (non-Javadoc)
42: * @see com.ionicsoft.wfs.jdbc.geojdbc.module.vpf.VPFGeometryFactory#createGeometry(com.ionicsoft.wfs.jdbc.geojdbc.module.vpf.VPFIterator)
43: */
44: public void createGeometry(VPFFeatureType featureType,
45: Feature values) throws SQLException, IOException,
46: IllegalAttributeException {
47: Geometry result = null;
48: int edgeId = Integer.parseInt(values.getAttribute("edg_id")
49: .toString());
50: // VPFFeatureType featureType = (VPFFeatureType) values.getFeatureType();
51:
52: // Get the right edge table
53: String baseDirectory = featureType.getFeatureClass()
54: .getDirectoryName();
55: String tileDirectory = baseDirectory;
56:
57: // If the primitive table is there, this coverage is not tiled
58: if (!new File(tileDirectory.concat(File.separator).concat(
59: EDGE_PRIMITIVE)).exists()) {
60: Short tileId = new Short(Short.parseShort(values
61: .getAttribute("tile_id").toString()));
62: tileDirectory = tileDirectory.concat(File.separator)
63: .concat(
64: featureType.getFeatureClass().getCoverage()
65: .getLibrary().getTileMap().get(
66: tileId).toString()).trim();
67: }
68:
69: String edgeTableName = tileDirectory.concat(File.separator)
70: .concat(EDGE_PRIMITIVE);
71: VPFFile edgeFile = VPFFileFactory.getInstance().getFile(
72: edgeTableName);
73: Feature row = edgeFile.getRowFromId("id", edgeId);
74: result = (Geometry) row.getAttribute("coordinates");
75: values.setDefaultGeometry(result);
76: }
77: }
|