001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.property;
017:
018: import java.io.BufferedWriter;
019: import java.io.File;
020: import java.io.FileWriter;
021:
022: import junit.framework.TestCase;
023:
024: import org.geotools.data.DefaultQuery;
025: import org.geotools.data.FeatureSource;
026: import org.geotools.feature.FeatureCollection;
027: import org.geotools.feature.FeatureType;
028: import org.geotools.feature.GeometryAttributeType;
029: import org.geotools.referencing.CRS;
030: import org.opengis.filter.Filter;
031: import org.opengis.referencing.crs.CoordinateReferenceSystem;
032:
033: /**
034: * Test non functionality of PropertyDataStore.
035: *
036: * @author Jody Garnett, Refractions Research Inc.
037: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/demo/property/src/test/java/org/geotools/data/property/PropertyDataStore2Test.java $
038: */
039: public class PropertyDataStore2Test extends TestCase {
040: PropertyDataStore store;
041:
042: /**
043: * Constructor for SimpleDataStoreTest.
044: * @param arg0
045: */
046: public PropertyDataStore2Test(String arg0) {
047: super (arg0);
048: }
049:
050: protected void setUp() throws Exception {
051: File dir = new File(".", "propertyTestData");
052: dir.mkdir();
053:
054: File file = new File(dir, "road.properties");
055: if (file.exists()) {
056: file.delete();
057: }
058: BufferedWriter writer = new BufferedWriter(new FileWriter(file));
059: writer.write("_=id:Integer,*geom:Geometry,name:String");
060: writer.newLine();
061: writer.write("fid1=1|LINESTRING(0 0,10 10)|jody");
062: writer.newLine();
063: writer.write("fid2=2|LINESTRING(20 20,30 30)|brent");
064: writer.newLine();
065: writer.write("fid3=3|LINESTRING(5 0, 5 10)|dave");
066: writer.newLine();
067: writer
068: .write("fid4=4|LINESTRING(0 5, 5 0, 10 5, 5 10, 0 5)|justin");
069: writer.close();
070: store = new PropertyDataStore(dir);
071: super .setUp();
072: }
073:
074: protected void tearDown() throws Exception {
075: File dir = new File("propertyTestData");
076: File list[] = dir.listFiles();
077: for (int i = 0; i < list.length; i++) {
078: list[i].delete();
079: }
080: dir.delete();
081: super .tearDown();
082: }
083:
084: public void testSimple() throws Exception {
085: FeatureSource road = store.getFeatureSource("road");
086: FeatureCollection features = road.getFeatures();
087:
088: assertEquals(1, features.getFeatureType().getAttributeCount());
089: assertEquals(4, features.size());
090: }
091:
092: public void testQuery() throws Exception {
093: FeatureSource road = store.getFeatureSource("road");
094:
095: DefaultQuery query = new DefaultQuery("road", Filter.INCLUDE,
096: new String[] { "name" });
097:
098: FeatureCollection features = road.getFeatures(query);
099: assertEquals(1, features.getFeatureType().getAttributeCount());
100: }
101:
102: public void testQueryReproject() throws Exception {
103: CoordinateReferenceSystem world = CRS.decode("EPSG:4326"); // world lon/lat
104: CoordinateReferenceSystem local = CRS.decode("EPSG:3005"); // british columbia
105:
106: FeatureSource road = store.getFeatureSource("road");
107: FeatureType origionalType = road.getSchema();
108:
109: DefaultQuery query = new DefaultQuery("road", Filter.INCLUDE,
110: new String[] { "geom", "name" });
111:
112: query.setCoordinateSystem(local); // FROM
113: query.setCoordinateSystemReproject(world); // TO
114:
115: FeatureCollection features = road.getFeatures(query);
116: FeatureType resultType = features.getSchema();
117:
118: assertNotNull(resultType);
119: assertNotSame(resultType, origionalType);
120:
121: GeometryAttributeType resultGeometryType = resultType
122: .getDefaultGeometry();
123: assertEquals(world, resultGeometryType.getCoordinateSystem());
124: }
125: }
|