Java Code Examples for org.geotools.data.DataUtilities#createType()
The following examples show how to use
org.geotools.data.DataUtilities#createType() .
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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: GeoToolsAttributesSubsetTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException, GeoWavePluginException, SchemaException { geotoolsDataStore = createDataStore(); type = DataUtilities.createType(typeName, typeSpec); geotoolsDataStore.createSchema(type); final Transaction transaction = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = geotoolsDataStore.getFeatureWriter(type.getTypeName(), transaction); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.25, 41.25))); newFeature.setAttribute(long_attribute, 1l); newFeature.setAttribute(string_attribute, "string1"); writer.write(); newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.5, 41.5))); newFeature.setAttribute(long_attribute, 2l); newFeature.setAttribute(string_attribute, "string2"); writer.write(); newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.75, 41.75))); newFeature.setAttribute(long_attribute, 3l); newFeature.setAttribute(string_attribute, "string3"); writer.write(); writer.close(); transaction.commit(); transaction.close(); }
Example 8
Source File: TimeDescriptorsTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testJustEndTime() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,end:Date,pid:String"); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.configureFromType(schema); final TimeDescriptors td = new TimeDescriptors(schema, timeConfig); assertEquals("end", td.getTime().getLocalName()); assertNull(td.getStartRange()); assertNull(td.getEndRange()); assertTrue(td.hasTime()); }
Example 9
Source File: GeoWaveFeatureSourceTest.java From geowave with Apache License 2.0 | 5 votes |
public void testEmpty() throws Exception { final SimpleFeatureType type = DataUtilities.createType( "GeoWaveFeatureSourceTest_e", "geometry:Geometry:srid=4326,pop:java.lang.Long,pid:String,when:Date"); final DataStore dataStore = createDataStore(); dataStore.createSchema(type); final SimpleFeatureSource source = dataStore.getFeatureSource("GeoWaveFeatureSourceTest_e"); final ReferencedEnvelope env = source.getBounds(); assertEquals(90.0, env.getMaxX(), 0.0001); assertEquals(-180.0, env.getMinY(), 0.0001); final Query query = new Query("GeoWaveFeatureSourceTest_e", Filter.INCLUDE); assertEquals(0, source.getCount(query)); }
Example 10
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 11
Source File: TimeDescriptorsTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testJustStartTime() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,start:Date,pid:String"); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.configureFromType(schema); final TimeDescriptors td = new TimeDescriptors(schema, timeConfig); assertEquals("start", td.getTime().getLocalName()); assertNull(td.getStartRange()); assertNull(td.getEndRange()); assertTrue(td.hasTime()); }
Example 12
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 13
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 14
Source File: GamaOsmFile.java From gama with GNU General Public License v3.0 | 5 votes |
public OSMInfo(final URL url, final long modificationStamp) { super(modificationStamp); CoordinateReferenceSystem crs = null; ReferencedEnvelope env2 = new ReferencedEnvelope(); int number = 0; try { final File f = new File(url.toURI()); final GamaOsmFile osmfile = new GamaOsmFile(null, f.getAbsolutePath()); attributes.putAll(osmfile.getOSMAttributes(GAMA.getRuntimeScope())); final SimpleFeatureType TYPE = DataUtilities.createType("geometries", "geom:LineString"); final ArrayList<SimpleFeature> list = new ArrayList<>(); for (final IShape shape : osmfile.iterable(null)) { list.add(SimpleFeatureBuilder.build(TYPE, new Object[] { shape.getInnerGeometry() }, null)); } final SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, list); final SimpleFeatureSource featureSource = DataUtilities.source(collection); env2 = featureSource.getBounds(); number = osmfile.nbObjects; crs = osmfile.getOwnCRS(null); } catch (final Exception e) { DEBUG.ERR("Error in reading metadata of " + url); hasFailed = true; } finally { // approximation of the width and height in meters. width = env2 != null ? env2.getWidth() * (Math.PI / 180) * 6378137 : 0; height = env2 != null ? env2.getHeight() * (Math.PI / 180) * 6378137 : 0; itemNumber = number; this.crs = crs; } }
Example 15
Source File: TimeDescriptorsTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void testMixedTime() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType( "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,when:Date,start:Date,end:Date,pid:String"); final TimeDescriptorConfiguration timeConfig = new TimeDescriptorConfiguration(); timeConfig.configureFromType(schema); final TimeDescriptors td = new TimeDescriptors(schema, timeConfig); assertEquals("start", td.getStartRange().getLocalName()); assertEquals("end", td.getEndRange().getLocalName()); assertNull(td.getTime()); assertTrue(td.hasTime()); }
Example 16
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 5 votes |
private SimpleFeature createSampleFeature() { SimpleFeatureType type; try { type = DataUtilities.createType("Sample", "the_geom:Geometry"); } catch (SchemaException e) { throw new RuntimeException(e); } return SimpleFeatureBuilder.template((SimpleFeatureType) type, null); }
Example 17
Source File: ShapeFile.java From tutorials with MIT License | 4 votes |
public static void main(String[] args) throws Exception { DefaultFeatureCollection collection = new DefaultFeatureCollection(); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:Point:srid=4326," + "name:String"); SimpleFeatureType CITY = createFeatureType(); addLocations(CITY, collection); File shapeFile = getNewShapeFile(); ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); Map<String, Serializable> params = new HashMap<String, Serializable>(); ShapefileDataStore dataStore = setDataStoreParams(dataStoreFactory, params, shapeFile, CITY); writeToFile(dataStore, collection); }
Example 18
Source File: GeoWaveFeatureReaderTest.java From geowave with Apache License 2.0 | 4 votes |
@Before public void setup() throws SchemaException, CQLException, Exception { dataStore = createDataStore(); type = DataUtilities.createType( "GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String"); ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex( new SpatialIndexBuilder().createIndex()); ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex( new SpatialTemporalIndexBuilder().createIndex()); dataStore.createSchema(type); stime = DateUtilities.parseISO("2005-05-15T20:32:56Z"); mtime = DateUtilities.parseISO("2005-05-20T20:32:56Z"); etime = DateUtilities.parseISO("2005-05-25T20:32:56Z"); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", "a" + UUID.randomUUID().toString()); newFeature.setAttribute("start", stime); newFeature.setAttribute("end", mtime); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(101)); newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString()); newFeature.setAttribute("start", mtime); newFeature.setAttribute("end", etime); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); query = new Query( "GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] {"geometry", "pid"}); }
Example 19
Source File: FeatureDataAdapterTest.java From geowave with Apache License 2.0 | 4 votes |
@Test public void testInferredRange() throws SchemaException { final SimpleFeatureType schema = DataUtilities.createType( "http://foo", "sp.geostuff", "geometry:Geometry:srid=4326,pop:java.lang.Long,start:Date,end:Date,pid: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 newFeature = SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString()); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", time1); newFeature.setAttribute("end", time2); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); final FeatureDataAdapter dataAdapter = new FeatureDataAdapter( schema, new GlobalVisibilityHandler<SimpleFeature, Object>("default")); final Index spatialIndex = new SpatialDimensionalityTypeProvider().createIndex(new SpatialOptions()); dataAdapter.init(spatialIndex); final byte[] binary = dataAdapter.toBinary(); final FeatureDataAdapter dataAdapterCopy = new FeatureDataAdapter(); dataAdapterCopy.fromBinary(binary); assertEquals("http://foo", dataAdapterCopy.getFeatureType().getName().getNamespaceURI()); assertEquals(dataAdapterCopy.getTypeName(), dataAdapter.getTypeName()); assertEquals(dataAdapterCopy.getFeatureType(), dataAdapter.getFeatureType()); assertEquals( Boolean.TRUE, dataAdapterCopy.getFeatureType().getDescriptor("end").getUserData().get("end")); assertEquals( Boolean.TRUE, dataAdapterCopy.getFeatureType().getDescriptor("start").getUserData().get("start")); final List<IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object>> handlers = dataAdapterCopy.getDefaultTypeMatchingHandlers(schema); boolean found = false; for (final IndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object> handler : handlers) { found |= ((handler instanceof FeatureTimeRangeHandler) && ((((FeatureTimeRangeHandler) handler).toIndexValue( newFeature).toNumericData().getMin() - time1.getTime()) < 0.001) && ((((FeatureTimeRangeHandler) handler).toIndexValue( newFeature).toNumericData().getMax() - time2.getTime()) < 0.001)); } assertTrue(found); }
Example 20
Source File: GeoWaveFeatureSourceTest.java From geowave with Apache License 2.0 | 4 votes |
public void testFull(final Populater populater, final String ext) throws Exception { final String typeName = "GeoWaveFeatureSourceTest_full" + 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 ReferencedEnvelope env = source.getBounds(); assertEquals(43.454, env.getMaxX(), 0.0001); assertEquals(27.232, env.getMinY(), 0.0001); assertEquals(28.242, env.getMaxY(), 0.0001); final Query query = new Query(typeName, Filter.INCLUDE); assertTrue(source.getCount(query) > 2); final short internalAdapterId = ((GeoWaveGTDataStore) dataStore).getInternalAdapterStore().addTypeName(typeName); try (final CloseableIterator<InternalDataStatistics<?, ?, ?>> stats = ((GeoWaveGTDataStore) dataStore).getDataStatisticsStore().getDataStatistics( internalAdapterId)) { assertTrue(stats.hasNext()); int count = 0; BoundingBoxDataStatistics<SimpleFeature, ?> bboxStats = null; CountDataStatistics<SimpleFeature> cStats = null; FeatureTimeRangeStatistics timeRangeStats = null; FeatureNumericRangeStatistics popStats = null; while (stats.hasNext()) { final InternalDataStatistics<?, ?, ?> statsData = stats.next(); if (statsData instanceof BoundingBoxDataStatistics) { bboxStats = (BoundingBoxDataStatistics<SimpleFeature, ?>) statsData; } else if (statsData instanceof CountDataStatistics) { cStats = (CountDataStatistics<SimpleFeature>) statsData; } else if (statsData instanceof FeatureTimeRangeStatistics) { timeRangeStats = (FeatureTimeRangeStatistics) statsData; } else if (statsData instanceof FeatureNumericRangeStatistics) { popStats = (FeatureNumericRangeStatistics) statsData; } count++; } // rather than maintain an exact count on stats as we should be able // to add them more dynamically, just make sure that there is some // set of base stats found assertTrue("Unexpectedly few stats found", count > 5); assertEquals(66, popStats.getMin(), 0.001); assertEquals(100, popStats.getMax(), 0.001); assertEquals( DateUtilities.parseISO("2005-05-17T20:32:56Z"), timeRangeStats.asTemporalRange().getStartTime()); assertEquals( DateUtilities.parseISO("2005-05-19T20:32:56Z"), timeRangeStats.asTemporalRange().getEndTime()); assertEquals(43.454, bboxStats.getMaxX(), 0.0001); assertEquals(27.232, bboxStats.getMinY(), 0.0001); assertEquals(3, cStats.getCount()); } }