01: package org.geotools.data.store;
02:
03: import java.net.URI;
04:
05: import junit.framework.TestCase;
06:
07: import org.geotools.feature.AttributeType;
08: import org.geotools.feature.AttributeTypeFactory;
09: import org.geotools.feature.DefaultFeatureCollection;
10: import org.geotools.feature.DefaultFeatureTypeFactory;
11: import org.geotools.feature.FeatureCollection;
12: import org.geotools.feature.FeatureType;
13: import org.geotools.feature.FeatureTypeBuilder;
14: import org.geotools.feature.GeometryAttributeType;
15: import org.geotools.referencing.CRS;
16: import org.opengis.referencing.crs.CoordinateReferenceSystem;
17:
18: import com.vividsolutions.jts.geom.Coordinate;
19: import com.vividsolutions.jts.geom.GeometryFactory;
20: import com.vividsolutions.jts.geom.LineString;
21: import com.vividsolutions.jts.geom.Point;
22:
23: public class FeatureCollectionWrapperTestSupport extends TestCase {
24:
25: protected CoordinateReferenceSystem crs;
26: protected FeatureCollection delegate;
27:
28: protected void setUp() throws Exception {
29: crs = CRS
30: .parseWKT("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");
31: FeatureTypeBuilder typeBuilder = new DefaultFeatureTypeFactory();
32:
33: typeBuilder.setName("test");
34: typeBuilder.setNamespace(new URI("test"));
35:
36: AttributeType defaultGeometry = AttributeTypeFactory
37: .newAttributeType("defaultGeom", Point.class, true,
38: null, null, crs);
39: typeBuilder.addType(defaultGeometry);
40: typeBuilder.addType(AttributeTypeFactory.newAttributeType(
41: "someAtt", Integer.class));
42: typeBuilder.addType(AttributeTypeFactory.newAttributeType(
43: "otherGeom", LineString.class, true, null, null, crs));
44:
45: typeBuilder
46: .setDefaultGeometry((GeometryAttributeType) defaultGeometry);
47:
48: FeatureType featureType = typeBuilder.getFeatureType();
49:
50: GeometryFactory gf = new GeometryFactory();
51: delegate = new DefaultFeatureCollection("test", featureType) {
52: };
53:
54: double x = -140;
55: double y = 45;
56: final int features = 5;
57: for (int i = 0; i < features; i++) {
58:
59: Point point = gf.createPoint(new Coordinate(x + i, y + i));
60: point.setUserData(crs);
61:
62: LineString line = gf.createLineString(new Coordinate[] {
63: new Coordinate(x + i, y + i),
64: new Coordinate(x + i + 1, y + i + 1) });
65: line.setUserData(crs);
66:
67: delegate.add(featureType.create(new Object[] { point,
68: new Integer(i), line }, i + ""));
69: }
70:
71: delegate
72: .add(featureType.create(new Object[] { null,
73: new Integer(features + 1), null },
74: (features + 1) + ""));
75: }
76: }
|