org.geotools.data.DataUtilities Java Examples
The following examples show how to use
org.geotools.data.DataUtilities.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: geoUtils.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
public static String getFileLayerAction(String layerUrl) throws JSONException, IOException, EMFUserError { IFeaturesProviderFileDAO featuresProvider = DAOFactory.getFeaturesProviderFileDAO(); FeatureCollection outputFeatureCollection = featuresProvider.getAllFeatures(layerUrl); FeatureIterator it = outputFeatureCollection.features(); List<SimpleFeature> list = new ArrayList<SimpleFeature>(); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); list.add(f); } FeatureCollection<SimpleFeatureType, SimpleFeature> filteredOutputFeatureCollection = DataUtilities.collection(list); Monitor.start("GetTargetLayerAction.flushResponse"); FeatureJSON featureJSON = new FeatureJSON(); String responseFeature = featureJSON.toString(filteredOutputFeatureCollection); return responseFeature; }
Example #2
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Creates a sample Feature instance in the hope that it can be used in the rendering of the * legend graphic. * * @param schema the schema for which to create a sample Feature instance * @throws ServiceException */ private Feature createSampleFeature(FeatureType schema) throws ServiceException { Feature sampleFeature; try { if (schema instanceof SimpleFeatureType) { if (hasMixedGeometry((SimpleFeatureType) schema)) { // we can't create a sample for a generic Geometry type sampleFeature = null; } else { sampleFeature = SimpleFeatureBuilder.template((SimpleFeatureType) schema, null); } } else { sampleFeature = DataUtilities.templateFeature(schema); } } catch (IllegalAttributeException e) { throw new ServiceException(e); } return sampleFeature; }
Example #3
Source File: SimpleFeatureCentroidExractorTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void test() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType("testGeo", "location:Point:srid=4326,name:String"); final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature feature = SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString()); final GeometryFactory geoFactory = new GeometryFactory(); feature.setAttribute("location", geoFactory.createPoint(new Coordinate(-45, 45))); final Point point = extractor.getCentroid(feature); assertEquals(4326, point.getSRID()); }
Example #4
Source File: QueryOptionsIT.java From geowave with Apache License 2.0 | 6 votes |
private static SimpleFeatureType getSimpleFeatureType(final String typeName) { SimpleFeatureType type = null; try { type = DataUtilities.createType( typeName, CITY_ATTRIBUTE + ":String," + STATE_ATTRIBUTE + ":String," + POPULATION_ATTRIBUTE + ":Double," + LAND_AREA_ATTRIBUTE + ":Double," + GEOMETRY_ATTRIBUTE + ":Geometry"); } catch (final SchemaException e) { System.out.println("Unable to create SimpleFeatureType"); } return type; }
Example #5
Source File: AttributesSubsetQueryIT.java From geowave with Apache License 2.0 | 6 votes |
private static SimpleFeatureType getSimpleFeatureType() { SimpleFeatureType type = null; try { type = DataUtilities.createType( "testCityData", CITY_ATTRIBUTE + ":String," + STATE_ATTRIBUTE + ":String," + POPULATION_ATTRIBUTE + ":Double," + LAND_AREA_ATTRIBUTE + ":Double," + GEOMETRY_ATTRIBUTE + ":Geometry"); } catch (final SchemaException e) { LOGGER.error("Unable to create SimpleFeatureType", e); } return type; }
Example #6
Source File: BandFeatureIterator.java From geowave with Apache License 2.0 | 6 votes |
private void init(final Filter cqlFilter) throws NoSuchAuthorityCodeException, FactoryException { final SimpleFeatureTypeBuilder typeBuilder = sceneIterator.getProvider().bandFeatureTypeBuilder(); final SimpleFeatureType bandType = typeBuilder.buildFeatureType(); Iterator<SimpleFeature> featureIterator = new FeatureIteratorIterator<>(sceneIterator); featureIterator = Iterators.concat( Iterators.transform(featureIterator, new SceneToBandFeatureTransform(bandType))); if ((cqlFilter != null) && !cqlFilter.equals(Filter.INCLUDE)) { final String[] attributes = DataUtilities.attributeNames(cqlFilter, bandType); // we can rely on the scene filtering if we don't have to check any // specific band filters if (ArrayUtils.contains(attributes, BAND_ATTRIBUTE_NAME)) { featureIterator = Iterators.filter( featureIterator, new SceneFeatureIterator.CqlFilterPredicate(cqlFilter)); } } iterator = featureIterator; }
Example #7
Source File: GeoWaveGeoIndexer.java From rya with Apache License 2.0 | 6 votes |
private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException { SimpleFeatureType featureType; final String[] datastoreFeatures = dataStore.getTypeNames(); if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) { featureType = dataStore.getSchema(FEATURE_NAME); } else { featureType = DataUtilities.createType(FEATURE_NAME, SUBJECT_ATTRIBUTE + ":String," + PREDICATE_ATTRIBUTE + ":String," + OBJECT_ATTRIBUTE + ":String," + CONTEXT_ATTRIBUTE + ":String," + GEOMETRY_ATTRIBUTE + ":Geometry:srid=4326," + GEO_ID_ATTRIBUTE + ":String"); dataStore.createSchema(featureType); } return featureType; }
Example #8
Source File: TimeDescriptorsTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testOneTime() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,whennot:Date,pid:String"); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.configureFromType(schema); final TimeDescriptors td = new TimeDescriptors(schema, timeConfig); assertEquals("when", td.getTime().getLocalName()); assertNull(td.getStartRange()); assertNull(td.getEndRange()); assertTrue(td.hasTime()); }
Example #9
Source File: FeatureWritable.java From geowave with Apache License 2.0 | 6 votes |
@Override public void write(final DataOutput output) throws IOException { output.writeUTF( featureType.getName().getNamespaceURI() == null ? "-" : featureType.getName().getNamespaceURI()); output.writeUTF(featureType.getTypeName()); output.writeUTF(DataUtilities.encodeType(featureType)); output.writeUTF(FeatureDataUtils.getAxis(featureType.getCoordinateReferenceSystem())); // write feature id output.writeUTF(feature.getID()); // write the attributes for (final AttributeDescriptor ad : featureType.getAttributeDescriptors()) { final Object value = feature.getAttribute(ad.getLocalName()); writeAttribute(output, ad, value); } }
Example #10
Source File: FeatureDataAdapterTest.java From geowave with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Before public void setup() throws SchemaException, CQLException, ParseException { time1 = DateUtilities.parseISO("2005-05-19T18:33:55Z"); time2 = DateUtilities.parseISO("2005-05-19T19:33:55Z"); schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,whennot:Date,pid:String"); newFeature = FeatureDataUtils.buildFeature( schema, new Pair[] { Pair.of("geometry", factory.createPoint(new Coordinate(27.25, 41.25))), Pair.of("pop", Long.valueOf(100)), Pair.of("when", time1), Pair.of("whennot", time2)}); }
Example #11
Source File: JsonDefinitionColumnVisibilityManagementTest.java From geowave with Apache License 2.0 | 6 votes |
@Before public void setup() throws SchemaException, CQLException { type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,vis:java.lang.String,pop:java.lang.Long,pid:String"); descriptors = type.getAttributeDescriptors(); defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } newFeature = SimpleFeatureBuilder.build(type, defaults, UUID.randomUUID().toString()); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("vis", "{\"pid\":\"TS\", \"geo.*\":\"S\"}"); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 128.232))); }
Example #12
Source File: WFSSpatialTest.java From geowave with Apache License 2.0 | 6 votes |
@Before public void setup() throws SchemaException, CQLException, IOException, GeoWavePluginException { dataStore = createDataStore(); type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String"); dataStore.createSchema(type); query = new Query( "geostuff", CQL.toFilter( "BBOX(geometry,27.20,41.30,27.30,41.20) and when during 2005-05-19T20:32:56Z/2005-05-19T21:32:56Z"), new String[] {"geometry", "pid"}); }
Example #13
Source File: GeoWaveFeatureSourceTest.java From geowave with Apache License 2.0 | 6 votes |
public void testPartial(final Populater populater, final String ext) throws CQLException, Exception { final String typeName = "GeoWaveFeatureSourceTest_p" + ext; final SimpleFeatureType type = DataUtilities.createType( typeName, "geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date"); final DataStore dataStore = createDataStore(); populater.populate(type, dataStore); final SimpleFeatureSource source = dataStore.getFeatureSource(typeName); final Query query = new Query( typeName, CQL.toFilter( "BBOX(geometry,42,28,44,30) and when during 2005-05-01T20:32:56Z/2005-05-29T21:32:56Z"), new String[] {"geometry", "when", "pid"}); final ReferencedEnvelope env = source.getBounds(query); assertEquals(43.454, env.getMaxX(), 0.0001); assertEquals(28.232, env.getMinY(), 0.0001); assertEquals(28.242, env.getMaxY(), 0.0001); assertEquals(2, source.getCount(query)); }
Example #14
Source File: MultiPolygons.java From amodeus with GNU General Public License v2.0 | 6 votes |
private static Set<MultiPolygon> initializeFrom(File shapeFile) throws IOException { URL shapeFileURL = shapeFile.toURI().toURL(); Map<String, URL> inputMap = new HashMap<>(); inputMap.put("url", shapeFileURL); DataStore dataStore = DataStoreFinder.getDataStore(inputMap); SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]); SimpleFeatureCollection collection = DataUtilities.collection(featureSource.getFeatures()); dataStore.dispose(); Set<MultiPolygon> polygons = new HashSet<>(); SimpleFeatureIterator iterator = collection.features(); while (iterator.hasNext()) polygons.add((MultiPolygon) iterator.next().getDefaultGeometry()); return polygons; }
Example #15
Source File: TimeDescriptorsTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testWhenAndStartTime() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,start:Date,pid:String"); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.configureFromType(schema); final TimeDescriptors td = new TimeDescriptors(schema, timeConfig); assertEquals("when", td.getTime().getLocalName()); assertNull(td.getStartRange()); assertNull(td.getEndRange()); assertTrue(td.hasTime()); }
Example #16
Source File: PropertyIgnoringFilterVisitor.java From geowave with Apache License 2.0 | 5 votes |
private boolean usesProperty(final Filter filter) { final String[] attributes = DataUtilities.attributeNames(filter, type); // rely on best scene aggregation at a higher level if the filter is // using attributes not contained in the scene for (final String attr : attributes) { if (!ArrayUtils.contains(validPropertyNames, attr)) { return false; } } return true; }
Example #17
Source File: SceneFeatureIterator.java From geowave with Apache License 2.0 | 5 votes |
private boolean hasOtherProperties(final Filter cqlFilter) { final String[] attributes = DataUtilities.attributeNames(cqlFilter, type); for (final String attribute : attributes) { if (type.getDescriptor(attribute) == null) { return true; } } return false; }
Example #18
Source File: FeatureSerializationTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void test() throws SchemaException { final Kryo kryo = new Kryo(); kryo.register(SimpleFeatureImpl.class, new FeatureSerializer()); final SimpleFeatureType schema = DataUtilities.createType("testGeo", "location:Point:srid=4326,name:String"); final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature feature = SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString()); final GeometryFactory geoFactory = new GeometryFactory(); feature.setAttribute("location", geoFactory.createPoint(new Coordinate(-45, 45))); final Output output = new OutputChunked(); kryo.getSerializer(SimpleFeatureImpl.class).write(kryo, output, feature); final Input input = new InputChunked(); input.setBuffer(output.getBuffer()); final SimpleFeature f2 = (SimpleFeature) kryo.getSerializer(SimpleFeatureImpl.class).read( kryo, input, SimpleFeatureImpl.class); assertEquals(feature, f2); }
Example #19
Source File: PolygonDataIdQueryIT.java From geowave with Apache License 2.0 | 5 votes |
private static SimpleFeatureType getSimpleFeatureType() { SimpleFeatureType type = null; try { type = DataUtilities.createType("data", GEOMETRY_ATTRIBUTE + ":Geometry"); } catch (final SchemaException e) { LOGGER.error("Unable to create SimpleFeatureType", e); } return type; }
Example #20
Source File: FeatureNumericHistogramStaticticsTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, ParseException { schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,whennot:Date,somewhere:Polygon,pid:String"); dataAdapter = new FeatureDataAdapter( schema, new GlobalVisibilityHandler<SimpleFeature, Object>("default")); }
Example #21
Source File: FeatureHyperLogLogStaticticsTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, ParseException { schema = DataUtilities.createType("sp.geostuff", "geometry:Geometry:srid=4326,pid:String"); dataAdapter = new FeatureDataAdapter( schema, new GlobalVisibilityHandler<SimpleFeature, Object>("default")); }
Example #22
Source File: StatsManagerTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, ParseException { schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,whennot:Date,somewhere:Polygon,pid:String"); dataAdapter = new InternalDataAdapterWrapper<>( new FeatureDataAdapter( schema, new GlobalVisibilityHandler<SimpleFeature, Object>("default")), (short) -1); }
Example #23
Source File: LegendGraphicServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private SimpleFeature createSampleFeature(VectorLayer vectorLayer) { SimpleFeatureType type; try { String geomName = "the_geom"; if (vectorLayer != null) { geomName = vectorLayer.getLayerInfo().getFeatureInfo().getGeometryType().getName(); } type = DataUtilities.createType("Sample", geomName + ":Geometry"); } catch (SchemaException e) { throw new IllegalStateException(e.getMessage(), e); } return SimpleFeatureBuilder.template(type, null); }
Example #24
Source File: FeatureCountMinSketchStaticticsTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, ParseException { schema = DataUtilities.createType("sp.geostuff", "geometry:Geometry:srid=4326,pid:String"); dataAdapter = new FeatureDataAdapter( schema, new GlobalVisibilityHandler<SimpleFeature, Object>("default")); }
Example #25
Source File: FeatureFixedBinNumericStaticticsTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, ParseException { schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Double,when:Date,whennot:Date,somewhere:Polygon,pid:String"); dataAdapter = new FeatureDataAdapter( schema, new GlobalVisibilityHandler<SimpleFeature, Object>("default")); }
Example #26
Source File: FilterToCQLToolTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException { type = DataUtilities.createType( "geostuff", "geom:Geometry:srid=4326,pop:java.lang.Long,pid:String"); }
Example #27
Source File: CQLQueryTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void init() throws SchemaException { type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,pid:String"); adapter = new FeatureDataAdapter(type); adapter.init(SPATIAL_INDEX, SPATIAL_TEMPORAL_INDEX); }
Example #28
Source File: CQLQueryFilterTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException { type = DataUtilities.createType( "geostuff", "geom:Geometry:srid=4326,pop:java.lang.Long,pid:String"); final List<AttributeDescriptor> descriptors = type.getAttributeDescriptors(); defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } }
Example #29
Source File: TemporalRangeTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws SchemaException, CQLException, IOException, GeoWavePluginException { dataStore = createDataStore(); type = DataUtilities.createType( "geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date"); dataStore.createSchema(type); }
Example #30
Source File: GeoWaveAvroFeatureDataAdapterTest.java From geowave with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Before public void setup() throws SchemaException, CQLException, ParseException { final StoreFactoryFamilySpi storeFactoryFamily = new MemoryStoreFactoryFamily(); final StoreFactoryOptions opts = storeFactoryFamily.getDataStoreFactory().createOptionsInstance(); opts.setGeoWaveNamespace("test_avro"); dataStore = storeFactoryFamily.getDataStoreFactory().createStore(opts); try { time1 = DateUtilities.parseISO("2005-05-19T18:33:55Z"); time2 = DateUtilities.parseISO("2005-05-19T19:33:55Z"); schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,whennot:Date,pid:String"); // typeBuilder.buildFeatureType(); newFeature = FeatureDataUtils.buildFeature( schema, new Pair[] { Pair.of("geometry", factory.createPoint(new Coordinate(27.25, 41.25))), Pair.of("pop", Long.valueOf(100)), Pair.of("when", time1), Pair.of("whennot", time2)}); } catch (final Exception e) { e.printStackTrace(); } }