org.opengis.feature.simple.SimpleFeature Java Examples
The following examples show how to use
org.opengis.feature.simple.SimpleFeature.
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: QueryIndexHelper.java From geowave with Apache License 2.0 | 6 votes |
private static TemporalRange getStatsRange( final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> statsMap, final AttributeDescriptor attr) { final TemporalRange timeRange = new TemporalRange(); if (attr != null) { final TimeRangeDataStatistics stat = ((TimeRangeDataStatistics) statsMap.get( VectorStatisticsQueryBuilder.newBuilder().factory().timeRange().fieldName( attr.getLocalName()).build().getId())); if (stat != null) { timeRange.setStartTime(new Date(stat.getMin())); timeRange.setEndTime(new Date(stat.getMax())); } } return timeRange; }
Example #2
Source File: GeoMesaGeoIndexer.java From rya with Apache License 2.0 | 6 votes |
@Override public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException { // create a feature collection final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); for (final RyaStatement ryaStatement : ryaStatements) { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); // if the predicate list is empty, accept all predicates. // Otherwise, make sure the predicate is on the "valid" list final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate()); if (isValidPredicate && (statement.getObject() instanceof Literal)) { try { final SimpleFeature feature = createFeature(featureType, statement); featureCollection.add(feature); } catch (final ParseException e) { logger.warn("Error getting geo from statement: " + statement.toString(), e); } } } // write this feature collection to the store if (!featureCollection.isEmpty()) { featureStore.addFeatures(featureCollection); } }
Example #3
Source File: BoundaryPartitioner.java From geowave with Apache License 2.0 | 6 votes |
@Override public List<PartitionData> getCubeIdentifiers(final Object entry) { final Geometry geom = extractor.getGeometry((SimpleFeature) entry); final Coordinate[] coords = (geom.getCoordinates()); System.out.println(geom.toString()); if (coords.length < 2) { return super.getCubeIdentifiers(geom); } else { final List<PartitionData> r = new ArrayList<>(); for (int i = 0; i < (coords.length - 1); i++) { r.addAll( super.getCubeIdentifiers( geom.getFactory().createLineString(new Coordinate[] {coords[i], coords[i + 1]}))); } return r; } }
Example #4
Source File: PixelExtractionParametersForm.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
public Coordinate[] getCoordinates() { Coordinate[] coordinates = new Coordinate[coordinateTableModel.getRowCount()]; for (int i = 0; i < coordinateTableModel.getRowCount(); i++) { final Placemark placemark = coordinateTableModel.getPlacemarkAt(i); SimpleFeature feature = placemark.getFeature(); final Date dateTime = (Date) feature.getAttribute(Placemark.PROPERTY_NAME_DATETIME); final Coordinate.OriginalValue[] originalValues = PixExOp.getOriginalValues(feature); if (placemark.getGeoPos() == null) { final Point point = (Point) feature.getDefaultGeometry(); coordinates[i] = new Coordinate(placemark.getName(), point.getY(), point.getX(), dateTime, originalValues); } else { coordinates[i] = new Coordinate(placemark.getName(), placemark.getGeoPos().getLat(), placemark.getGeoPos().getLon(), dateTime, originalValues); } } return coordinates; }
Example #5
Source File: TxtParser.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public void write(SimpleFeatureCollection obj, OutputStream output) throws IOException { SimpleFeatureIterator it = obj.features(); PrintStream printStream = new PrintStream(output); while (it.hasNext()) { SimpleFeature ft = it.next(); printStream.print(ft.getID() + " ["); boolean first = true; for (AttributeDescriptor ad : ft.getType().getAttributeDescriptors()) { if (!first) { printStream.print(", "); } printStream.print(ad.getLocalName() + ": " + ft.getAttribute(ad.getName())); first = false; } printStream.println("]"); } }
Example #6
Source File: TestVectorFilter.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("nls") public void testVectorFilter() throws Exception { SimpleFeatureCollection testFC = HMTestMaps.getTestFC(); OmsVectorFilter filter = new OmsVectorFilter(); filter.inVector = testFC; filter.pCql = "cat > 2"; filter.process(); SimpleFeatureCollection outFC = filter.outVector; assertTrue(outFC.size() == 1); FeatureIterator<SimpleFeature> featureIterator = outFC.features(); SimpleFeature feature = featureIterator.next(); assertNotNull(feature); Integer attribute = (Integer) feature.getAttribute("cat"); assertEquals(3, attribute.intValue()); featureIterator.close(); }
Example #7
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 #8
Source File: QueryIndexHelperTest.java From geowave with Apache License 2.0 | 6 votes |
@Test public void testBBOXStatReprojection() { // create a EPSG:3785 feature (units in meters) final SimpleFeature mercFeat = createGeoMercFeature(factory.createPoint(new Coordinate(19971868.8804, 20037508.3428))); // convert from EPSG:3785 to EPSG:4326 (convert to degrees lon/lat) // approximately 180.0, 85.0 final SimpleFeature defaultCRSFeat = GeometryUtils.crsTransform(mercFeat, geoType, transform); final FeatureBoundingBoxStatistics geoStats = new FeatureBoundingBoxStatistics("geometry", geoType, transform); geoStats.entryIngested(mercFeat); final Coordinate coord = ((Point) defaultCRSFeat.getDefaultGeometry()).getCoordinate(); // coordinate should match reprojected feature assertEquals(coord.x, geoStats.getMinX(), 0.0001); assertEquals(coord.x, geoStats.getMaxX(), 0.0001); assertEquals(coord.y, geoStats.getMinY(), 0.0001); assertEquals(coord.y, geoStats.getMaxY(), 0.0001); }
Example #9
Source File: FeatureLayer.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc, PropertySet configuration) { super(layerType, configuration); crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem(); if (crs == null) { // todo - check me! Why can this happen??? (nf) crs = DefaultGeographicCRS.WGS84; } final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs); modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight()); mapContext = new DefaultMapContext(crs); final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE); mapContext.addLayer(fc, style); renderer = new StreamingRenderer(); workaroundLabelCacheBug(); style.accept(new RetrievingStyleVisitor()); renderer.setContext(mapContext); }
Example #10
Source File: AbstractTransactionManagement.java From geowave with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> getDataStatistics() { final Map<StatisticsId, InternalDataStatistics<SimpleFeature, ?, ?>> stats = new HashMap<>(); final GeotoolsFeatureDataAdapter adapter = components.getAdapter(); final short internalAdapterId = components.getGTstore().getInternalAdapterStore().getAdapterId(adapter.getTypeName()); try (CloseableIterator<InternalDataStatistics<?, ?, ?>> it = components.getStatsStore().getDataStatistics(internalAdapterId, composeAuthorizations())) { while (it.hasNext()) { final InternalDataStatistics<?, ?, ?> stat = it.next(); stats.put( new StatisticsId(stat.getType(), stat.getExtendedId()), (InternalDataStatistics<SimpleFeature, ?, ?>) stat); } } catch (final Exception e) { GeoWaveTransactionManagement.LOGGER.error("Failed to access statistics from data store", e); } return stats; }
Example #11
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Extracts features from a {@link FeatureCollection} into an {@link STRtree}. * * @param collection the feature collection. * @return the tree containing the features. */ public static STRtree featureCollectionToSTRtree( SimpleFeatureCollection collection ) { STRtree tree = new STRtree(); SimpleFeatureIterator featureIterator = collection.features(); while( featureIterator.hasNext() ) { SimpleFeature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); tree.insert(geometry.getEnvelopeInternal(), feature); } featureIterator.close(); return tree; }
Example #12
Source File: SplitsProviderIT.java From geowave with Apache License 2.0 | 6 votes |
private void ingestWithDistribution(final Distribution distr) { final DataStore dataStore = dataStorePluginOptions.createDataStore(); dataStore.addType(fda, idx); try (final Writer<SimpleFeature> writer = dataStore.createWriter(fda.getTypeName())) { switch (distr) { case UNIFORM: createUniformFeatures(new SimpleFeatureBuilder(sft), writer, 100000); break; case BIMODAL: createBimodalFeatures(new SimpleFeatureBuilder(sft), writer, 400000); break; case SKEWED: default: createSkewedFeatures(new SimpleFeatureBuilder(sft), writer, 700000); break; } } }
Example #13
Source File: TimeUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Interval getInterval(final SimpleFeature entry, final String fieldName) { final Object o = entry.getAttribute(fieldName); final Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); if (o == null) { return null; } if (o instanceof Date) { c.setTime((Date) o); } else if (o instanceof Calendar) { c.setTime(c.getTime()); } else if (o instanceof Number) { c.setTimeInMillis(((Number) o).longValue()); } final Instant time = Instant.ofEpochMilli(c.getTimeInMillis()); return Interval.of(time, time); }
Example #14
Source File: OmsGridsGenerator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private void createPolygons( CoordinateReferenceSystem crs, GeometryFactory gf, List<Geometry> polygons ) { outMap = new DefaultFeatureCollection(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(POLYGON); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add("id", Long.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type); long index = 0; int numGeometries = polygons.size(); for( int i = 0; i < numGeometries; i++ ) { Geometry geometry = polygons.get(i); Object[] values = new Object[]{geometry, index++}; fbuilder.addAll(values); SimpleFeature feature = fbuilder.buildFeature(null); ((DefaultFeatureCollection) outMap).add(feature); } }
Example #15
Source File: TestFeatureUtils.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("nls") public void testFeatureUtils() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("typename"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("AttrName", String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{GeometryUtilities.gf().createPoint(new Coordinate(0, 0)), "test"}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName()); Object attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrname"); assertEquals("test", attr.toString()); attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrnam"); assertNull(attr); }
Example #16
Source File: GeometryDataSetGenerator.java From geowave with Apache License 2.0 | 5 votes |
public List<SimpleFeature> addRandomNoisePoints( final List<SimpleFeature> pointSet, final int minSetSize, final double[] minAxis, final double[] maxAxis) { while (pointSet.size() < minSetSize) { pointSet.add(createNewFeature(minAxis, maxAxis)); } return pointSet; }
Example #17
Source File: GeoWaveAvroFeatureDataAdapter.java From geowave with Apache License 2.0 | 5 votes |
@Override public FieldWriter<SimpleFeature, Object> getWriter(final String fieldName) { if (fieldName.equals(GeoWaveAvroFeatureAttributeHandler.FIELD_NAME)) { return new GeoWaveAvroFeatureWriter(); } return super.getWriter(fieldName); }
Example #18
Source File: GeoToolsFilterTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testTouchesFilter() throws Exception { Geometry geom = (Geometry) ((SimpleFeature) layer.read("filtertest.1")).getDefaultGeometry(); Filter filter = filterCreator.createTouchesFilter(geom, "the_geom"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { it.next(); t++; } Assert.assertEquals(1, t); }
Example #19
Source File: GeometryTranslator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private SimpleFeature createPointTextFeature( String typeName, String layerName, int id, Coordinate coord, String textString ) { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName(typeName); b.setCRS(crs); b.add(THE_GEOM, Point.class); b.add("text", String.class); b.add(LAYER, String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Geometry point = gF.createPoint(coord); Object[] values = new Object[]{point, textString, layerName}; builder.addAll(values); return builder.buildFeature(typeName + "." + id); }
Example #20
Source File: GeometryDataSetGenerator.java From geowave with Apache License 2.0 | 5 votes |
public GeometryDataSetGenerator( final DistanceFn<SimpleFeature> distanceFunction, final SimpleFeatureBuilder builder) { super(); this.distanceFunction = distanceFunction; this.builder = builder; init(); }
Example #21
Source File: QueryOptionsIT.java From geowave with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void ingestSampleData( final SimpleFeatureBuilder builder, final DataTypeAdapter<?> adapter) throws IOException { final DataStore store = dataStoreOptions.createDataStore(); store.addType(adapter, TestUtils.DEFAULT_SPATIAL_INDEX); try (@SuppressWarnings("rawtypes") Writer writer = store.createWriter(adapter.getTypeName())) { for (final SimpleFeature sf : buildCityDataSet(builder)) { writer.write(sf); } } }
Example #22
Source File: DownloadRunner.java From geowave with Apache License 2.0 | 5 votes |
/** * Remove all downloaded files of the scene in the specified workspace directory */ protected static void cleanDownloadedFiles( final SimpleFeature scene, final String workspaceDirectory) { final File sceneDir = getSceneDirectory(scene, workspaceDirectory); if (sceneDir.isDirectory()) { FileUtil.fullyDelete(sceneDir); } }
Example #23
Source File: UpdateCentroidCostJobRunner.java From geowave with Apache License 2.0 | 5 votes |
@Override public void configure(final Job job) throws Exception { job.setMapperClass(UpdateCentroidCostMapReduce.UpdateCentroidCostMap.class); job.setMapOutputKeyClass(GroupIDText.class); job.setMapOutputValueClass(CountofDoubleWritable.class); job.setCombinerClass(UpdateCentroidCostMapReduce.UpdateCentroidCostCombiner.class); job.setReducerClass(UpdateCentroidCostMapReduce.UpdateCentroidCostReducer.class); job.setReduceSpeculativeExecution(false); job.setOutputKeyClass(GeoWaveOutputKey.class); job.setOutputValueClass(SimpleFeature.class); }
Example #24
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Override @Transactional(rollbackFor = { Throwable.class }) public Object create(Object feature) throws LayerException { SimpleFeatureSource source = getFeatureSource(); if (source instanceof SimpleFeatureStore) { SimpleFeatureStore store = (SimpleFeatureStore) source; DefaultFeatureCollection collection = new DefaultFeatureCollection(); collection.add((SimpleFeature) feature); transactionSynchronization.synchTransaction(store); try { List<FeatureId> ids = store.addFeatures(collection); // fetch it again to get the generated values !!! if (ids.size() == 1) { return read(ids.get(0).getID()); } } catch (IOException ioe) { featureModelUsable = false; throw new LayerException(ioe, ExceptionCode.LAYER_MODEL_IO_EXCEPTION); } return feature; } else { log.error("Don't know how to create or update " + getFeatureSourceName() + ", class " + source.getClass().getName() + " does not implement SimpleFeatureStore"); throw new LayerException(ExceptionCode.CREATE_OR_UPDATE_NOT_IMPLEMENTED, getFeatureSourceName(), source .getClass().getName()); } }
Example #25
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Read attributes. * * @param attributeData the attribute data */ /* (non-Javadoc) * @see com.sldeditor.datasource.DataSourceInterface#updateAttributes(com.sldeditor.render.iface.RenderAttributeDataInterface) */ @Override public void readAttributes(DataSourceAttributeListInterface attributeData) { if(attributeData == null) { return; } List<DataSourceAttributeData> valueMap = new ArrayList<DataSourceAttributeData>(); SimpleFeatureCollection featureCollection = dataSourceInfo.getFeatureCollection(); if(featureCollection != null) { SimpleFeatureIterator iterator = featureCollection.features(); if(iterator.hasNext()) { SimpleFeature feature = iterator.next(); List<Object> attributes = feature.getAttributes(); for (int i = 0; i < attributes.size(); i++) { Name fieldName = fieldNameMap.get(i); DataSourceAttributeData data = new DataSourceAttributeData(fieldName, fieldTypeMap.get(i), attributes.get(i)); valueMap.add(data); } } } attributeData.setData(valueMap); }
Example #26
Source File: AttributesSubsetQueryIT.java From geowave with Apache License 2.0 | 5 votes |
@Before public void ingestSampleData() throws IOException { LOGGER.info("Ingesting canned data..."); final DataStore store = dataStore.createDataStore(); store.addType(dataAdapter, TestUtils.DEFAULT_SPATIAL_INDEX); try (Writer writer = store.createWriter(dataAdapter.getTypeName())) { for (final SimpleFeature sf : buildCityDataSet()) { writer.write(sf); } } LOGGER.info("Ingest complete."); }
Example #27
Source File: OmsKriging.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Extract the coordinate of a FeatureCollection in a HashMap with an ID as * a key. * * @param nStaz * @param collection * @throws Exception * if a fiel of elevation isn't the same of the collection */ private LinkedHashMap<Integer, Coordinate> getCoordinate( int nStaz, SimpleFeatureCollection collection, String idField ) throws Exception { LinkedHashMap<Integer, Coordinate> id2CoordinatesMap = new LinkedHashMap<Integer, Coordinate>(); FeatureIterator<SimpleFeature> iterator = collection.features(); Coordinate coordinate = null; try { while( iterator.hasNext() ) { SimpleFeature feature = iterator.next(); int name = ((Number) feature.getAttribute(idField)).intValue(); coordinate = ((Geometry) feature.getDefaultGeometry()).getCentroid().getCoordinate(); double z = 0; if (fPointZ != null) { try { z = ((Number) feature.getAttribute(fPointZ)).doubleValue(); } catch (NullPointerException e) { pm.errorMessage(msg.message("kriging.noPointZ")); throw new Exception(msg.message("kriging.noPointZ")); } } coordinate.z = z; id2CoordinatesMap.put(name, coordinate); } } finally { iterator.close(); } return id2CoordinatesMap; }
Example #28
Source File: GeoDbTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testBbox() throws LayerException { Iterator<?> it = pointLayer.getElements( filterService.createBboxFilter("EPSG:4326", new Envelope(-0.5, 1.5, -0.5, 0.5), "GEOM"), 0, 0); Map<String, SimpleFeature> filtered = new HashMap<String, SimpleFeature>(); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); filtered.put(f.getID(), f); } Assert.assertEquals(2, filtered.size()); Assert.assertTrue(filtered.containsKey("POINT.1")); Assert.assertTrue(filtered.containsKey("POINT.2")); }
Example #29
Source File: GeoWaveDataStoreComponents.java From geowave with Apache License 2.0 | 5 votes |
public void remove(final SimpleFeature feature, final GeoWaveTransaction transaction) throws IOException { final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder(); dataStore.delete( bldr.setAuthorizations(transaction.composeAuthorizations()).addTypeName( adapter.getTypeName()).constraints( bldr.constraintsFactory().dataIds(adapter.getDataId(feature))).build()); }
Example #30
Source File: OmsEpanetFeaturesSynchronizer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private Object getElevation( SimpleFeature nearestFirst ) { Object elevObj = nearestFirst.getAttribute(junctionElevatioAttributeName); if (elevObj == null) { // try tank elevObj = nearestFirst.getAttribute(tanksElevationAttributeName); } if (elevObj == null) { // try elevObj = nearestFirst.getAttribute(reservoirHeadAttributeName); } return elevObj; }