org.opengis.feature.type.FeatureType Java Examples
The following examples show how to use
org.opengis.feature.type.FeatureType.
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: 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 #2
Source File: ShapefileLoader.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private static Style[] createStyle(File shapeFile, FeatureType schema) { final Style[] styles = SLDUtils.loadSLD(shapeFile); if (styles != null && styles.length > 0) { return styles; } Class<?> type = schema.getGeometryDescriptor().getType().getBinding(); if (type.isAssignableFrom(Polygon.class) || type.isAssignableFrom(MultiPolygon.class)) { return new Style[]{createPolygonStyle()}; } else if (type.isAssignableFrom(LineString.class) || type.isAssignableFrom(MultiLineString.class)) { return new Style[]{createLineStyle()}; } else { return new Style[]{createPointStyle()}; } }
Example #3
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 #4
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 #5
Source File: MetadataAssert.java From sis with Apache License 2.0 | 5 votes |
/** * Verifies that the source contains the given feature type. This method expects that the given source contains * exactly one scope description and that the hierarchical level is {@link ScopeCode#FEATURE_TYPE}. * * @param name expected source identifier. * @param features expected names of feature type. * @param source the source to validate. * * @since 1.0 */ public static void assertFeatureSourceEquals(final String name, final String[] features, final Source source) { assertEquals("metadata.lineage.source.sourceCitation.title", name, String.valueOf(source.getSourceCitation().getTitle())); final DefaultScope scope = (DefaultScope) ((DefaultSource) source).getScope(); assertNotNull("metadata.lineage.source.scope", scope); assertEquals("metadata.lineage.source.scope.level", ScopeCode.FEATURE_TYPE, scope.getLevel()); final Object[] actual = CollectionsExt.toArray(getSingleton(scope.getLevelDescription()).getFeatures(), FeatureType.class); for (int i=0; i<actual.length; i++) { actual[i] = actual[i].toString(); } assertArrayEquals("metadata.lineage.source.scope.levelDescription.feature", features, actual); }
Example #6
Source File: DefaultScopeDescription.java From sis with Apache License 2.0 | 5 votes |
/** * Constructs a new instance initialized with the values from the specified metadata object. * This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the * given object are not recursively copied. * * <p>If the given object contains more than one value, then the first non-null element in the * following list has precedence (from wider scope to smaller scope): * {@linkplain #getDataset() dataset}, * {@linkplain #getFeatures() features}, * {@linkplain #getAttributes() attributes}, * {@linkplain #getFeatureInstances() feature instances}, * {@linkplain #getAttributeInstances() attribute instances} * and {@linkplain #getOther() other}.</p> * * @param object the metadata to copy values from, or {@code null} if none. * * @see #castOrCopy(ScopeDescription) */ @SuppressWarnings("unchecked") public DefaultScopeDescription(final ScopeDescription object) { super(object); if (object != null) { for (byte i=DATASET; i<=OTHER; i++) { Object candidate; switch (i) { case DATASET: candidate = object.getDataset(); break; case FEATURES: candidate = object.getFeatures(); break; case ATTRIBUTES: candidate = object.getAttributes(); break; case FEATURE_INSTANCES: candidate = object.getFeatureInstances(); break; case ATTRIBUTE_INSTANCES: candidate = object.getAttributeInstances(); break; case OTHER: candidate = object.getOther(); break; default: throw new AssertionError(i); } if (candidate != null) { switch (i) { case ATTRIBUTES: case ATTRIBUTE_INSTANCES: { candidate = copySet((Collection<AttributeType>) candidate, AttributeType.class); break; } case FEATURES: case FEATURE_INSTANCES: { candidate = copySet((Collection<FeatureType>) candidate, FeatureType.class); break; } } value = candidate; property = i; break; } } } }
Example #7
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 #8
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Clones the given schema, changing the geometry attribute to match the given dimensionality. * * @param schema schema to clone * @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons */ private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) { SimpleFeatureType simpleFt = (SimpleFeatureType) schema; SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(schema.getName()); builder.setCRS(schema.getCoordinateReferenceSystem()); for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) { if (isMixedGeometry(desc)) { GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc; GeometryType geomType = geomDescriptor.getType(); Class<?> geometryClass = getGeometryForDimensionality(dimensionality); GeometryType gt = new GeometryTypeImpl( geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription()); builder.add( new GeometryDescriptorImpl( gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue())); } else { builder.add(desc); } } schema = builder.buildFeatureType(); return schema; }
Example #9
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 #10
Source File: CreateSampleData.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Creates the sample data from the supplied schema. * * @param schema the schema * @param fieldList the field list */ public void create(FeatureType schema, List<DataSourceAttributeData> fieldList) { if (schema == null) { return; } // Put fields into map for speed Map<String, DataSourceAttributeData> fieldMap = new HashMap<>(); if (fieldList != null) { for (DataSourceAttributeData attributeData : fieldList) { fieldMap.put(attributeData.getName(), attributeData); } } SimpleFeatureType featureType = (SimpleFeatureType) schema; memory = new MemoryDataStore(); try { memory.createSchema(featureType); } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); memory = null; return; } SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); SimpleFeature feature = DataUtilities.template(featureType); createAttributes(fieldList, fieldMap, featureType, builder, feature); SimpleFeature newFeature = builder.buildFeature("1234"); memory.addFeature(newFeature); }
Example #11
Source File: ShapeFileParserGDAL.java From GeoTriples with Apache License 2.0 | 4 votes |
public List<TableDef> getTablesDefs() throws Exception { DataStore dataStore = null; List<ColumnDef> columns = null; TableDef onlytable = null; Set<Key> primkeys = new HashSet<Key>(); List<TableDef> tables = new ArrayList<TableDef>(); try { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", shapefile.toURI().toURL()); dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); for (int i = 0; i < typeNames.length; ++i) { String typeName = typeNames[i]; FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName); FeatureType ft = featureSource.getSchema(); columns = new ArrayList<ColumnDef>(); for (PropertyDescriptor property : ft.getDescriptors()) { Identifier identifier = Identifier.createDelimited(property.getName().getLocalPart()); DataType datatype = TableDefUtils .TranslateDataTypeToSQLType((property.getType().getBinding().getName())); ColumnDef col = new ColumnDef(identifier, datatype, property.isNillable()); columns.add(col); } // Identifier identifier = Identifier.createDelimited("gid"); // ColumnDef col = new ColumnDef(identifier, // TranslateDataTypeToSQLType("Int"), false); // columns.add(col); // primkeys.add(Key.create(identifier)); TableName tablename = TableName.create(null, null, Identifier.create(true, dataStore.getTypeNames()[0])); onlytable = new TableDef(tablename, columns, null, primkeys, new HashSet<ForeignKey>()); tables.add(onlytable); } } catch (Throwable e) { throw new Exception(e.getMessage()); } finally { dataStore.dispose(); } return tables; }
Example #12
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 #13
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 #14
Source File: ShapeFileParser.java From GeoTriples with Apache License 2.0 | 4 votes |
public List<TableDef> getTablesDefs() throws Exception { DataStore dataStore = null; List<ColumnDef> columns = null; TableDef onlytable = null; Set<Key> primkeys = new HashSet<Key>(); List<TableDef> tables = new ArrayList<TableDef>(); try { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", shapefile.toURI().toURL()); dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); for (int i = 0; i < typeNames.length; ++i) { String typeName = typeNames[i]; FeatureSource<?, ?> featureSource = dataStore .getFeatureSource(typeName); FeatureType ft = featureSource.getSchema(); columns = new ArrayList<ColumnDef>(); for (PropertyDescriptor property : ft.getDescriptors()) { Identifier identifier = Identifier.createDelimited(property .getName().getLocalPart()); DataType datatype = TableDefUtils.TranslateDataTypeToSQLType((property .getType().getBinding().getName())); ColumnDef col = new ColumnDef(identifier, datatype, property.isNillable()); columns.add(col); } //Identifier identifier = Identifier.createDelimited("gid"); //ColumnDef col = new ColumnDef(identifier, TranslateDataTypeToSQLType("Int"), false); //columns.add(col); //primkeys.add(Key.create(identifier)); TableName tablename = TableName.create(null, null, Identifier.create(true, dataStore.getTypeNames()[0])); onlytable = new TableDef(tablename, columns, null, primkeys, new HashSet<ForeignKey>()); tables.add(onlytable); } } catch (Throwable e) { throw new Exception(e.getMessage()); } finally { dataStore.dispose(); } return tables; }
Example #15
Source File: FeatureTypeAdapter.java From sis with Apache License 2.0 | 4 votes |
/** * Wrap the given value from {@link DefaultScopeDescription} to the elements * defined by ISO 19115-3:2016 schema. */ @Override public FeatureType unmarshal(GO_CharacterString value) { return new LegacyFeatureType(LegacyFeatureType.ADAPTER.unmarshal(value)); }
Example #16
Source File: FeatureTypeAdapter.java From sis with Apache License 2.0 | 4 votes |
/** * Unwrap the elements defined by ISO 19115-3:2016 schema to the value used by * {@link DefaultScopeDescription}. */ @Override public GO_CharacterString marshal(FeatureType value) { return LegacyFeatureType.ADAPTER.marshal(LegacyFeatureType.wrap(value)); }
Example #17
Source File: ShapefileMappingGenerator.java From GeoTriples with Apache License 2.0 | 4 votes |
public void run() throws IOException { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", new File(pathToShapefile).toURI().toURL()); DataStore dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); for (int i = 0; i < typeNames.length; ++i) { String typeName = typeNames[i]; triplesMaps.put(typeName, ""); triplesMaps.put(typeName, triplesMaps.get(typeName) + printTriplesMap(typeName)); triplesMaps.put(typeName, triplesMaps.get(typeName) + printLogicalSource(typeName)); triplesMaps.put(typeName, triplesMaps.get(typeName) + printSubjectMap(baseURI, typeName)); FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName); FeatureType ft = featureSource.getSchema(); String typeNameGeo = typeNames[i] + "_Geometry"; for (PropertyDescriptor property : ft.getDescriptors()) { String identifier = property.getName().getLocalPart(); if (identifier.equals("the_geom")) { continue; } String datatype = TranslateDataTypeToXSD((property.getType().getBinding().getName())); Query q = new Query(); triplesMaps.put(typeName, triplesMaps.get(typeName) + printPredicateObjectMap(identifier, identifier, datatype, typeName)); } // triplesMaps.put(typeName, // triplesMaps.get(typeName) + printPredicateObjectMap(true, // "hasGeometry", // baseURI + (baseURI.endsWith("/") ? "" : "/") + typeNameGeo + // "/{GeoTriplesID}", null, // typeName, true)); triplesMaps .put(typeName, triplesMaps.get(typeName) + printPredicateObjectMap(true, "hasGeometry", baseURI + (baseURI.endsWith("/") ? "" : "/") + typeName + "/Geometry/{GeoTriplesID}", null, null, "ogc", null, typeName, true, false)); triplesMaps.put(typeNameGeo, ""); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printTriplesMap(typeNameGeo)); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printLogicalSource(typeName)); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printSubjectMap(baseURI, typeName, null, true)); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printGEOPredicateObjectMaps()); } printmapping(); printontology(); }
Example #18
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); }
Example #19
Source File: DataSourceInfo.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Sets the schema. * * @param schema the schema to set */ public void setSchema(FeatureType schema) { this.schema = schema; }
Example #20
Source File: DataSourceInfo.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Sets the schema. * * @param schema the schema to set */ public void setSchema(FeatureType schema) { this.schema = schema; }
Example #21
Source File: DefaultScopeDescription.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the feature types to which the information applies. * * <div class="note"><b>Example:</b> * if an administrative area performs a complete re-survey of the road network, * the change can be recorded at {@link ScopeCode#FEATURE_TYPE} level with a * “<cite>Administrative area A — Road network</cite>” description. * </div> * * <h4>Conditions</h4> * This method returns a modifiable collection only if no other property is set. * Otherwise, this method returns an unmodifiable empty collection. * * <div class="warning"><b>Upcoming API change:</b> * The type of this property may be changed to {@code Set<CharSequence>} for ISO 19115:2014 conformance. * See <a href="http://jira.codehaus.org/browse/GEO-238">GEO-238</a> for more information.</div> * * @return feature types to which the information applies. */ @Override @XmlElement(name = "features") public Set<FeatureType> getFeatures() { return getProperty(FeatureType.class, FEATURES); }
Example #22
Source File: DefaultScopeDescription.java From sis with Apache License 2.0 | 2 votes |
/** * Sets the feature types to which the information applies. * * <h4>Effect on other properties</h4> * If and only if the {@code newValue} is non-empty, then this method automatically * discards all other properties. * * <div class="warning"><b>Upcoming API change:</b> * The type of this property may be changed to {@code Set<CharSequence>} for ISO 19115:2014 conformance. * See <a href="http://jira.codehaus.org/browse/GEO-238">GEO-238</a> for more information.</div> * * @param newValues the new feature types. */ public void setFeatures(final Set<? extends FeatureType> newValues) { setProperty(newValues, FeatureType.class, FEATURES); }
Example #23
Source File: DefaultScopeDescription.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the feature instances to which the information applies. * * <div class="note"><b>Example:</b> * If a new bridge is constructed in a road network, * the change can be recorded at {@link ScopeCode#FEATURE} level with a * “<cite>Administrative area A — New bridge</cite>” description. * </div> * * <h4>Conditions</h4> * This method returns a modifiable collection only if no other property is set. * Otherwise, this method returns an unmodifiable empty collection. * * <div class="warning"><b>Upcoming API change:</b> * The type of this property may be changed to {@code Set<CharSequence>} for ISO 19115:2014 conformance. * See <a href="http://jira.codehaus.org/browse/GEO-238">GEO-238</a> for more information.</div> * * @return feature instances to which the information applies. */ @Override @XmlElement(name = "featureInstances") public Set<FeatureType> getFeatureInstances() { return getProperty(FeatureType.class, FEATURE_INSTANCES); }
Example #24
Source File: DefaultScopeDescription.java From sis with Apache License 2.0 | 2 votes |
/** * Sets the feature instances to which the information applies. * * <h4>Effect on other properties</h4> * If and only if the {@code newValue} is non-empty, then this method automatically * discards all other properties. * * <div class="warning"><b>Upcoming API change:</b> * The type of this property may be changed to {@code Set<CharSequence>} for ISO 19115:2014 conformance. * See <a href="http://jira.codehaus.org/browse/GEO-238">GEO-238</a> for more information.</div> * * @param newValues the new feature instances. */ public void setFeatureInstances(final Set<? extends FeatureType> newValues) { setProperty(newValues, FeatureType.class, FEATURE_INSTANCES); }