@SuppressWarnings({"unchecked", "rawtypes"}) public FeatureLayer(FeatureCollection collection, Style style) { super(style); this.featureSource = DataUtilities.source(collection); this.style = style; }
@SuppressWarnings({"unchecked", "rawtypes"}) public FeatureLayer(FeatureCollection collection, Style style, String title) { super(style, title); this.featureSource = DataUtilities.source(collection); }
/** * Adapt a feature collection as a read-only DataStore. * * <p>See {@link UserLayer} for example use. * * @param features feature collection to adap * @return read-only DataStore */ public static DataStore dataStore(final SimpleFeatureCollection features) { SimpleFeatureSource source = source(features); return dataStore(source); } /**
/** * Used to access the feature collection for this layer; if available. * * <p>This is an optional method that is used to support feature based rendering systems such as * as KML. * * <p>Please note that feature based renders can be very flexible; as an example raster content * is asked to return the outline of each raster - in the event that the user has supplied a * style drawing the raster as a Polygon outlines. * * <p>Override: Implementors should override this method to provide access to a feature * representation of the layer contents if available. For DirectLayers displaying abstract * concepts like a scale bar this may not be possible (however for some that display a grid this * may in fact be possible). * * @return The features for this layer, or an an empty ArrayFeatureSource if not available. */ public synchronized FeatureSource<?, ?> getFeatureSource() { // using user data to cache this placeholder so we don't have to create it each time SimpleFeatureSource source = (SimpleFeatureSource) getUserData().get("source"); if (source == null) { // will use FeatureTypes.EMPTY source = DataUtilities.source(new SimpleFeature[0]); getUserData().put("source", source); } return source; }
/** * FetureSource representation of raster contents (in case a vector based renderer wishes to * draw a polygon outline). * <p> * This method uses {@link DataUtilities#source(org.opengis.feature.simple.SimpleFeature[]) to * wrap up the result of {@link #toFeatureCollection()} */ @Override public synchronized SimpleFeatureSource getFeatureSource() { if (this.source == null) { if (getUserData().containsKey("source")) { // we tried already and got null - toFeatureCollection is not available! return null; } SimpleFeatureCollection featureCollection = toFeatureCollection(); if (featureCollection != null) { this.source = DataUtilities.source(featureCollection); } // Note we store source in the user data map to communicate with MapLayer getUserData().put("source", source); } return source; }
/** * Wrap up an array of features as a FeatureSource. * * @param featureArray Array of features * @return FeatureSource * @throws IOException * @throws RuntimeException */ public static SimpleFeatureSource source(final SimpleFeature[] featureArray) { final SimpleFeatureType featureType; if ((featureArray == null) || (featureArray.length == 0)) { featureType = FeatureTypes.EMPTY; } else { featureType = featureArray[0].getFeatureType(); } ListFeatureCollection collection = new ListFeatureCollection(featureType, featureArray); for (SimpleFeature feature : collection) { if (feature.getFeatureType() != featureType) { String typeName = featureType.getTypeName(); throw new IllegalStateException( "Array inconsistent, expected each feature of type " + typeName); } } return source(collection); }
@Test public void testFeatureCollection() throws IOException { SimpleFeatureSource featureSource = DataUtilities.source(new SimpleFeature[] {feature}); checkTiles(featureSource); }
OrthoLineBuilder lineBuilder = new OrthoLineBuilder(bounds); lineBuilder.buildGrid(lineDefs, lineFeatureBuilder, vertexSpacing, fc); return DataUtilities.source(fc);
HexagonBuilder gridBuilder = new HexagonBuilder(bounds, sideLen, orientation); gridBuilder.buildGrid(gridFeatureBuilder, vertexSpacing, fc); return DataUtilities.source(fc);
public void testSimpleSource() { SimpleFeatureCollection collection = DataUtilities.collection(roadFeatures); FeatureSource<SimpleFeatureType, SimpleFeature> source = DataUtilities.source(collection); SimpleFeatureSource simple = DataUtilities.simple(source); assertSame(simple, source); }
OblongBuilder gridBuilder = new OblongBuilder(bounds, width, height); gridBuilder.buildGrid(gridFeatureBuilder, vertexSpacing, fc); return DataUtilities.source(fc);
public void testCreateView() throws Exception { String[] propNames = {"id", "geom"}; Query query = new Query(roadType.getTypeName(), Filter.INCLUDE, 100, propNames, null); SimpleFeatureSource source = DataUtilities.source(roadFeatures); SimpleFeatureSource view = DataUtilities.createView(source, query); assertNotNull(view); List<AttributeDescriptor> desc = view.getSchema().getAttributeDescriptors(); assertTrue(desc.size() == propNames.length); assertTrue(desc.get(0).getLocalName().equals(propNames[0])); assertTrue(desc.get(1).getLocalName().equals(propNames[1])); }
@Override public SimpleFeatureSource getFeatureSource() { return DataUtilities.source(features); }
/** * Creates a new instance of DefaultMapLayer using a non-emtpy feature * collection as a parameter * * @param collection * the source feature collection * @param style * the style used to represent this layer */ public DefaultMapLayer(FeatureCollection collection, Style style) { this(DataUtilities.source(collection), style, ""); }
"nantest.t" + (i + 1)); SimpleFeatureSource source = DataUtilities.source(testFeatures); SimpleFeatureCollection thisFC = source.getFeatures();
public void test2() throws Exception { // create a feature collection with five features values 1-5 SimpleFeatureType dataType = DataUtilities.createType("classification.test1", "id:0,value:int"); int iVal[] = new int[] {1, 2, 3, 4, 5, 6}; SimpleFeature[] myfeatures = new SimpleFeature[iVal.length]; for (int i = 0; i < iVal.length; i++) { myfeatures[i] = SimpleFeatureBuilder.build( dataType, new Object[] {Integer.valueOf(i + 1), Integer.valueOf(iVal[i])}, "classification.t" + (i + 1)); } SimpleFeatureSource source = DataUtilities.source(myfeatures); ; SimpleFeatureCollection myFeatureCollection = source.getFeatures(); // run the quantile function org.opengis.filter.expression.Expression function = ff.function("Jenks", ff.property("value"), ff.literal(5)); Classifier classifier = (Classifier) function.evaluate(myFeatureCollection); RangedClassifier range = (RangedClassifier) classifier; }
protected void setUp() throws Exception { SimpleFeatureType ft = DataUtilities.createType(typeName, "geom:Point,name:String,id:int"); ListFeatureCollection collection = new ListFeatureCollection(ft); collection.add(createFeatures(ft, 1)); collection.add(createFeatures(ft, 2)); collection.add(createFeatures(ft, 3)); collection.add(createFeatures(ft, 4)); fs = DataUtilities.source(collection); }
"classification.test1" + (i + 1)); SimpleFeatureSource source = DataUtilities.source(myfeatures); SimpleFeatureCollection myFeatureCollection = source.getFeatures();
public void testDataStore() throws IOException { SimpleFeatureSource features = DataUtilities.source(roadFeatures); Name name = features.getName(); String typeName = name.getLocalPart(); DataStore store = DataUtilities.dataStore(features); assertSame(features.getSchema(), store.getSchema(name)); assertSame(features.getSchema(), store.getSchema(typeName)); assertSame(features, store.getFeatureSource(name)); assertSame(features, store.getFeatureSource(typeName)); assertEquals(name, store.getNames().get(0)); assertEquals(typeName, store.getTypeNames()[0]); }
public void testSource() throws Exception { SimpleFeatureSource s = DataUtilities.source(roadFeatures); assertEquals(3, s.getCount(Query.ALL)); assertEquals(3, s.getFeatures().size()); assertEquals(3, s.getFeatures(Query.ALL).size()); assertEquals(3, s.getFeatures(Filter.INCLUDE).size()); assertEquals(0, s.getFeatures(Filter.EXCLUDE).size()); assertEquals(1, s.getFeatures(rd1Filter).size()); assertEquals(2, s.getFeatures(rd12Filter).size()); }