org.opengis.feature.Feature Java Examples
The following examples show how to use
org.opengis.feature.Feature.
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: OaImporter.java From TomboloDigitalConnector with MIT License | 6 votes |
@Override protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception { InputStream inputStream = downloadUtils.fetchInputStream(new URL(OaType.valueOf(datasource.getDatasourceSpec().getId()).datafile), getProvider().getLabel(), ".json"); FeatureIterator<SimpleFeature> featureIterator = new FeatureJSON().streamFeatureCollection(inputStream); List<Subject> subjects = new ArrayList<Subject>(); while(featureIterator.hasNext()) { Feature feature = featureIterator.next(); Geometry geometry = (Geometry) feature.getDefaultGeometryProperty().getValue(); geometry.setSRID(Subject.SRID); subjects.add(new Subject( datasource.getUniqueSubjectType(), getFeatureSubjectLabel(feature), getFeatureSubjectName(feature), geometry )); } saveAndClearSubjectBuffer(subjects); }
Example #2
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets a numeric value for the given graphic * * @param feature sample to be used for evals * @param pointSymbolizer symbolizer * @param defaultSize size to use is none can be taken from the graphic */ private double getGraphicSize(Feature feature, Graphic graphic, int defaultSize) { if (graphic != null) { Expression sizeExp = graphic.getSize(); if (sizeExp instanceof Literal) { Object size = sizeExp.evaluate(feature); if (size != null) { if (size instanceof Double) { return (Double) size; } try { return Double.parseDouble(size.toString()); } catch (NumberFormatException e) { return defaultSize; } } } } return defaultSize; }
Example #3
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets a numeric value for the given graphic * * @param feature sample to be used for evals * @param pointSymbolizer symbolizer * @param defaultSize size to use is none can be taken from the graphic */ private double getWidthSize(Feature feature, Expression widthExp, int defaultSize) { if (widthExp != null) { if (widthExp instanceof Literal) { Object size = widthExp.evaluate(feature); if (size != null) { if (size instanceof Double) { return (Double) size; } try { return Double.parseDouble(size.toString()); } catch (NumberFormatException e) { return defaultSize; } } } } return defaultSize; }
Example #4
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Returns a sample feature for the given rule, with the following criteria: - if a sample is * given in input is returned in output - if a sample is not given in input, scan the rule * symbolizers to find the one with the max dimensionality, and return a sample for that * dimensionality. * * @param featureType featureType used to create a sample, if none is given as input * @param sample feature sample to be returned as is in output, if defined * @param rule rule containing symbolizers to scan for max dimensionality */ private Feature getSampleFeatureForRule( FeatureType featureType, Feature sample, final Rule rule) { Symbolizer[] symbolizers = rule.getSymbolizers(); // if we don't have a sample as input, we need to create a sampleFeature // looking at the requested symbolizers (we chose the one with the max // dimensionality and create a congruent sample) if (sample == null) { int dimensionality = 1; for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) { final Symbolizer symbolizer = symbolizers[sIdx]; if (LineSymbolizer.class.isAssignableFrom(symbolizer.getClass())) { dimensionality = 2; } if (PolygonSymbolizer.class.isAssignableFrom(symbolizer.getClass())) { dimensionality = 3; } } return createSampleFeature(featureType, dimensionality); } else { return sample; } }
Example #5
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 #6
Source File: GamaGisGeometry.java From gama with GNU General Public License v3.0 | 6 votes |
public GamaGisGeometry(final Geometry g, final Feature feature) { super(g); if (feature != null) { // We filter out the geometries (already loaded before) for (final Property p : feature.getProperties()) { if (!(p.getType() instanceof GeometryType)) { final String type = p.getDescriptor().getType().getBinding().getSimpleName(); if ("String".equals(type)) { String val = (String) p.getValue(); if (val != null && ((val.startsWith("'") && val.endsWith("'")) || (val.startsWith("\"") && val.endsWith("\"")))) val = val.substring(1, val.length() - 1); setAttribute(p.getName().getLocalPart(), val); } else setAttribute(p.getName().getLocalPart(), p.getValue()); } } } }
Example #7
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Calculates a global rescaling factor for all the symbols to be drawn in the given rules. This * is to be sure all symbols are drawn inside the given w x h box. * * @param width horizontal constraint * @param height vertical constraint * @param featureType FeatureType to be used for size extraction in expressions (used to create * a sample if feature is null) * @param feature Feature to be used for size extraction in expressions (if null a sample * Feature will be created from featureType) * @param rules set of rules to scan for symbols * @param minimumSymbolSize lower constraint for the symbols size */ private double calcSymbolScale( int width, int height, FeatureType featureType, Feature feature, final Rule[] rules, double minimumSymbolsSize) { // check for max and min size in rendered symbols double minSize = Double.MAX_VALUE; double maxSize = 0.0; final int ruleCount = rules.length; for (int i = 0; i < ruleCount; i++) { Feature sample = getSampleFeatureForRule(featureType, feature, rules[i]); final Symbolizer[] symbolizers = rules[i].getSymbolizers(); for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) { final Symbolizer symbolizer = symbolizers[sIdx]; if (symbolizer instanceof PointSymbolizer) { double size = getGraphicSize( sample, ((PointSymbolizer) symbolizer).getGraphic(), Math.min(width, height)); if (size < minSize) { minSize = size; } if (size > maxSize) { maxSize = size; } } } } if (minSize != maxSize) { return (maxSize - minSize + 1) / (Math.min(width, height) - minimumSymbolsSize); } else { return maxSize / (Math.min(width, height) - minimumSymbolsSize); } }
Example #8
Source File: GamaSqlConnection.java From gama with GNU General Public License v3.0 | 5 votes |
private void readTable(final IScope scope, final String tableName, final String filterStr) { final IList list = getBuffer(); final QueryInfo queryInfo = new QueryInfo(scope, this.dataStore, tableName, filterStr); try (SimpleFeatureIterator reader = queryInfo.getRecordSet().features()) { final int size = queryInfo.getSize(); final Envelope3D env = queryInfo.getEnvelope(); int index = 0; computeProjection(scope, env); // ?? // reader = store.getFeatureReader(); // final int i = 0; while (reader.hasNext()) { scope.getGui().getStatus(scope).setSubStatusCompletion(index++ / (double) size); final Feature feature = reader.next(); // DEBUG.LOG("Record " + i++ + ": " + // feature.getValue().toString()); Geometry g = (Geometry) feature.getDefaultGeometryProperty().getValue(); if (g != null && !g.isEmpty()) { g = gis.transform(g); list.add(new GamaGisGeometry(g, feature)); } else { GAMA.reportError(scope, GamaRuntimeException.warning( "GamaSqlConnection.fillBuffer; geometry could not be added : " + feature.getIdentifier(), scope), false); } } } catch (final Exception e) { throw GamaRuntimeException.create(e, scope); } finally { scope.getGui().getStatus(scope).endSubStatus("Reading table " + tableName); } }
Example #9
Source File: ElasticFeatureTypeCallback.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Override public boolean initialize(FeatureTypeInfo info, DataAccess<? extends FeatureType, ? extends Feature> dataAccess, Name temporaryName) { ElasticLayerConfiguration layerConfig; layerConfig = (ElasticLayerConfiguration) info.getMetadata().get(KEY); if (layerConfig == null) { layerConfig = new ElasticLayerConfiguration(info.getName()); } ((ElasticDataStore) dataAccess).setLayerConfiguration(layerConfig); return false; }
Example #10
Source File: ElasticFeatureTypeCallback.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
@Override public void dispose(FeatureTypeInfo info, DataAccess<? extends FeatureType, ? extends Feature> dataAccess, Name temporaryName) { final ElasticLayerConfiguration layerConfig = (ElasticLayerConfiguration) info.getMetadata().get(KEY); if (layerConfig != null) { layerConfig.getAttributes().stream() .filter(attr -> attr.getName().equals(info.getName())) .findFirst() .ifPresent(attribute -> layerConfig.getAttributes().remove(attribute)); ((ElasticDataStore) dataAccess).getDocTypes().remove(info.getQualifiedName()); } }
Example #11
Source File: OaImporter.java From TomboloDigitalConnector with MIT License | 4 votes |
private String getFeatureSubjectLabel(Feature feature) { return (String) feature.getProperties().stream().filter( property -> property.getName().toString().toUpperCase().endsWith("CD") ).findFirst().get().getValue(); }
Example #12
Source File: OaImporter.java From TomboloDigitalConnector with MIT License | 4 votes |
private String getFeatureSubjectName(Feature feature) { return (String) feature.getProperties().stream().filter(property -> property.getName().toString().toUpperCase().endsWith("NM") ).findFirst().get().getValue(); }
Example #13
Source File: GamaShapeFile.java From gama with GNU General Public License v3.0 | 4 votes |
protected void readShapes(final IScope scope) { scope.getGui().getStatus(scope).beginSubStatus("Reading file " + getName(scope)); ShapefileDataStore store = null; final File file = getFile(scope); final IList list = getBuffer(); int size = 0; try { store = getDataStore(file.toURI().toURL()); final ContentFeatureSource source = store.getFeatureSource(); final Envelope3D env = Envelope3D.of(source.getBounds()); size = source.getCount(Query.ALL); int index = 0; computeProjection(scope, env); try (FeatureReader reader = store.getFeatureReader()) { while (reader.hasNext()) { index++; if (index % 20 == 0) { scope.getGui().getStatus(scope).setSubStatusCompletion(index / (double) size); } final Feature feature = reader.next(); Geometry g = (Geometry) feature.getDefaultGeometryProperty().getValue(); if (g != null && !g.isEmpty() /* Fix for Issue 725 && 677 */ ) { if (!with3D && !g.isValid()) { g = GeometryUtils.cleanGeometry(g); } g = gis.transform(g); if (!with3D) { g.apply(ZERO_Z); g.geometryChanged(); } g = multiPolygonManagement(g); GamaGisGeometry gt = new GamaGisGeometry(g, feature); if (gt.getInnerGeometry() != null) list.add(gt); } else if (g == null) { // See Issue 725 GAMA.reportError(scope, GamaRuntimeException .warning("GamaShapeFile.fillBuffer; geometry could not be added as it is " + "nil: " + feature.getIdentifier(), scope), false); } } } } catch (final IOException e) { throw GamaRuntimeException.create(e, scope); } finally { if (store != null) { store.dispose(); } scope.getGui().getStatus(scope).endSubStatus("Reading file " + getName(scope)); } if (size > list.size()) { GAMA.reportError(scope, GamaRuntimeException.warning("Problem with file " + getFile(scope) + ": only " + list.size() + " of the " + size + " geometries could be added", scope), false); } }
Example #14
Source File: ElasticFeatureTypeCallback.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
@Override public boolean canHandle(FeatureTypeInfo info, DataAccess<? extends FeatureType, ? extends Feature> dataAccess) { return dataAccess instanceof ElasticDataStore; }
Example #15
Source File: ElasticFeatureTypeCallback.java From elasticgeo with GNU General Public License v3.0 | 4 votes |
@Override public void flush(FeatureTypeInfo info, DataAccess<? extends FeatureType, ? extends Feature> dataAccess) { // nothing to do }
Example #16
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 3 votes |
/** * Creates a sample Feature instance in the hope that it can be used in the rendering of the * legend graphic, using the given dimensionality for the geometry attribute. * * @param schema the schema for which to create a sample Feature instance * @param dimensionality the geometry dimensionality required (ovverides the one defined in the * schema) 1= points, 2= lines, 3= polygons * @throws ServiceException */ private Feature createSampleFeature(FeatureType schema, int dimensionality) throws ServiceException { if (schema instanceof SimpleFeatureType) { schema = cloneWithDimensionality(schema, dimensionality); } return createSampleFeature(schema); }