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 Sep 22, 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: * Builds text primities
35: *
36: * @author John Meagher
37: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/readers/TextGeometryFactory.java $
38: */
39: public class TextGeometryFactory extends VPFGeometryFactory implements
40: FileConstants {
41:
42: public void createGeometry(VPFFeatureType featureType,
43: Feature values) throws SQLException, IOException,
44: IllegalAttributeException {
45:
46: Geometry result = null;
47:
48: int textId = Integer.parseInt(values.getAttribute("txt_id")
49: .toString());
50:
51: // Get the right text table
52: String baseDirectory = featureType.getFeatureClass()
53: .getDirectoryName();
54: String tileDirectory = baseDirectory;
55:
56: // If the primitive table is there, this coverage is not tiled
57: if (!new File(tileDirectory.concat(File.separator).concat(
58: TEXT_PRIMITIVE)).exists()) {
59: Short tileId = new Short(Short.parseShort(values
60: .getAttribute("tile_id").toString()));
61: tileDirectory = tileDirectory.concat(File.separator)
62: .concat(
63: featureType.getFeatureClass().getCoverage()
64: .getLibrary().getTileMap().get(
65: tileId).toString()).trim();
66: }
67:
68: String textTableName = tileDirectory.concat(File.separator)
69: .concat(TEXT_PRIMITIVE);
70: VPFFile textFile = VPFFileFactory.getInstance().getFile(
71: textTableName);
72: Feature row = textFile.getRowFromId("id", textId);
73: result = (Geometry) row.getAttribute("shape_line");
74:
75: values.setDefaultGeometry(result);
76: }
77: }
|