org.opengis.feature.type.AttributeType Java Examples

The following examples show how to use org.opengis.feature.type.AttributeType. 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: OpenSpaceNetworkImporter.java    From TomboloDigitalConnector with MIT License 6 votes vote down vote up
@Override
public List<Attribute> getFixedValueAttributes(String datasourceId) {
    Iterator<AttributeType> typeIterator;
    try {
        typeIterator = getAttributesForDatasource(new Datasource(datasourceSpec)).iterator();
    } catch (IOException ioe) {
        log.error("Could not get the list of fixed value attributes for {}, {}", datasourceId, ioe.getMessage());
        return Collections.emptyList();
    }
    List<Attribute> fixedValueAttributes = new ArrayList<>();

    while (typeIterator.hasNext()) {
        AttributeType type = typeIterator.next();
        String columnName = type.getName().toString();
        if (NON_ATTRIBUTE_COLUMNS.contains(columnName)) { continue; }
        fixedValueAttributes.add(new Attribute(
                getProvider(),
                columnName,
                null != type.getDescription() ? type.getDescription().toString() : columnName)
        );
    }

    return fixedValueAttributes;
}
 
Example #2
Source File: SeparateGeometriesDialog.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public SeparateGeometriesDialog(Window mainFrame, VectorDataNode vectorDataNode, String helpId, String text) {
    super(mainFrame, "Import Geometry", ModalDialog.ID_YES_NO_HELP, helpId);
    JPanel content = new JPanel(new BorderLayout());
    content.add(new JLabel(text), BorderLayout.NORTH);

    List<AttributeType> types = vectorDataNode.getFeatureType().getTypes();
    ArrayList<String> names = new ArrayList<String>();
    for (AttributeType type : types) {
        if (type.getBinding().equals(String.class)) {
            names.add(type.getName().getLocalPart());
        }
    }
    comboBox = new JComboBox(names.toArray(new String[names.size()]));
    if (names.size() > 0) {
        JPanel content2 = new JPanel(new BorderLayout());
        content2.add(new JLabel("Attribute for mask/layer naming: "), BorderLayout.WEST);
        content2.add(comboBox, BorderLayout.CENTER);
        content.add(content2, BorderLayout.SOUTH);
    }
    setContent(content);

}
 
Example #3
Source File: DataSourceInfo.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the property descriptor list.
 *
 * @return the property descriptor list
 */
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
    if (schema != null) {
        return schema.getDescriptors();
    } else {
        if (geometryType == GeometryTypeEnum.RASTER) {
            if (rasterPropertyDescriptorList == null) {
                rasterPropertyDescriptorList = new ArrayList<>();

                CoordinateReferenceSystem crs = null;
                boolean isIdentifiable = false;
                boolean isAbstract = false;
                List<Filter> restrictions = null;
                AttributeType superType = null;
                InternationalString description = null;
                GeometryType type =
                        featureTypeFactory.createGeometryType(
                                new NameImpl(RASTER_GEOMETRY_FIELD),
                                GridCoverage2D.class,
                                crs,
                                isIdentifiable,
                                isAbstract,
                                restrictions,
                                superType,
                                description);
                GeometryDescriptor descriptor =
                        featureTypeFactory.createGeometryDescriptor(
                                type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);

                rasterPropertyDescriptorList.add(descriptor);
            }

            return rasterPropertyDescriptorList;
        }
    }
    return null;
}
 
Example #4
Source File: DefaultScopeDescription.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #5
Source File: GeotoolsconverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testLayerBeanstoSimpleFeatureType() throws LayerException {
	SimpleFeatureType type = service.toSimpleFeatureType(layer.getLayerInfo());
	Assert.assertEquals("org.geomajas.layer.bean.FeatureBean", type.getName().getLocalPart());
	AttributeType doubleType = type.getType("doubleAttr");
	Assert.assertEquals(Double.class, doubleType.getBinding());
	Assert.assertEquals("doubleAttr", doubleType.getName().getLocalPart());
}
 
Example #6
Source File: CreateSampleData.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the attributes.
 *
 * @param fieldList the field list
 * @param fieldMap the field map
 * @param featureType the feature type
 * @param builder the builder
 * @param feature the feature
 */
private void createAttributes(
        List<DataSourceAttributeData> fieldList,
        Map<String, DataSourceAttributeData> fieldMap,
        SimpleFeatureType featureType,
        SimpleFeatureBuilder builder,
        SimpleFeature feature) {
    builder.init((SimpleFeature) feature);
    int index = 0;
    for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
        AttributeType attributeType = descriptor.getType();
        Object value = null;
        Class<?> fieldType = attributeType.getBinding();
        if (attributeType instanceof GeometryTypeImpl) {
            geometryType = GeometryTypeMapping.getGeometryType(fieldType);

            switch (geometryType) {
                case POLYGON:
                    ExamplePolygonInterface examplePolygon =
                            DataSourceFactory.createExamplePolygon(null);
                    value = examplePolygon.getPolygon();
                    break;
                case LINE:
                    ExampleLineInterface exampleLine =
                            DataSourceFactory.createExampleLine(null);
                    value = exampleLine.getLine();
                    break;
                case POINT:
                default:
                    ExamplePointInterface examplePoint =
                            DataSourceFactory.createExamplePoint(null);
                    value = examplePoint.getPoint();
                    break;
            }
        } else {
            if ((fieldList != null) && (index < fieldList.size())) {
                DataSourceAttributeData attrData = fieldMap.get(descriptor.getLocalName());

                if (attrData != null) {
                    value = attrData.getValue();
                }
            }

            value =
                    getFieldTypeValue(
                            index, attributeType.getName().getLocalPart(), fieldType, value);
        }
        builder.add(value);
        index++;
    }
}
 
Example #7
Source File: OmsVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * You cannot call this once the dialog is closed, see the okPressed method.
 * @param originalFeatureType 
 * @param expressions 
 * @param names 
 * @return a SimpleFeatureType created based on the contents of Text
 */
private SimpleFeatureType createFeatureType( String expressionString, SimpleFeatureType originalFeatureType,
        List<String> names, List<Expression> expressions ) throws SchemaException {

    SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();

    for( int i = 0; i < names.size(); i++ ) {
        String name = names.get(i);

        Expression expression = expressions.get(i);

        Object value = expression.evaluate(sample);

        // hack because sometimes expression returns null. I think the real bug is with
        // AttributeExpression
        Class< ? > binding = null;
        if (value == null) {
            if (expression instanceof PropertyName) {
                String path = ((PropertyName) expression).getPropertyName();
                AttributeType attributeType = sample.getFeatureType().getType(path);
                if (attributeType == null) {
                    throw new ModelsIllegalargumentException("Attribute type is null", this.getClass().getSimpleName(), pm);
                }
                binding = attributeType.getClass();
            }
        } else {
            binding = value.getClass();
        }

        if (binding == null) {
            throw new ModelsIllegalargumentException("Binding is null", this.getClass().getSimpleName(), pm);
        }

        if (Geometry.class.isAssignableFrom(binding)) {
            CoordinateReferenceSystem crs;
            AttributeType originalAttributeType = originalFeatureType.getType(name);
            if (originalAttributeType instanceof GeometryType) {
                crs = ((GeometryType) originalAttributeType).getCoordinateReferenceSystem();
            } else {
                crs = originalFeatureType.getCoordinateReferenceSystem();
            }
            build.crs(crs);

            build.add(name, binding);
        } else {
            build.add(name, binding);
        }
    }
    build.setName(getNewTypeName(originalFeatureType.getTypeName()));

    return build.buildFeatureType();
}
 
Example #8
Source File: OmsMeltonNumber.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inElev, inFans);

    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
    int cols = regionMap.getCols();
    int rows = regionMap.getRows();
    double west = regionMap.getWest();
    double east = regionMap.getEast();
    double south = regionMap.getSouth();
    double north = regionMap.getNorth();

    AttributeType type = inFans.getSchema().getType(fId);
    if (type == null) {
        throw new ModelsIllegalargumentException(MessageFormat.format("The attribute {0} does not exist in the vector map.",
                fId), this, pm);
    }

    List<SimpleFeature> fansList = FeatureUtilities.featureCollectionToList(inFans);

    outMelton = new String[fansList.size()][2];

    int index = 0;
    pm.beginTask("Calculating Melton number for fans...", fansList.size());
    for( SimpleFeature fan : fansList ) {
        Object attribute = fan.getAttribute(fId);

        // rasterize the fan
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        newCollection.add(fan);

        OmsScanLineRasterizer rasterizer = new OmsScanLineRasterizer();
        rasterizer.inVector = newCollection;
        rasterizer.pCols = cols;
        rasterizer.pRows = rows;
        rasterizer.pNorth = north;
        rasterizer.pSouth = south;
        rasterizer.pEast = east;
        rasterizer.pWest = west;
        rasterizer.pValue = 1.0;
        rasterizer.pm = new DummyProgressMonitor();
        rasterizer.process();

        GridCoverage2D rasterizedFan = rasterizer.outRaster;

        GridCoverage2D fanElev = CoverageUtilities.coverageValuesMapper(inElev, rasterizedFan);

        // extract min and max
        OmsRasterSummary summary = new OmsRasterSummary();
        summary.pm = new DummyProgressMonitor();
        summary.inRaster = fanElev;
        summary.process();

        double min = summary.outMin;
        double max = summary.outMax;

        // get the suface of the fan
        Geometry geometry = (Geometry) fan.getDefaultGeometry();
        double area = geometry.getArea();

        // calculate Melton
        double melton = (max - min) / sqrt(area);

        outMelton[index][0] = attribute.toString();
        outMelton[index][1] = String.valueOf(melton);
        index++;

        pm.message(MessageFormat.format("id: {0} gave Melton number: {1}", attribute.toString(), melton));
        pm.message("Based on max: " + max + " min: " + min + " and area: " + area);

        pm.worked(1);
    }
    pm.done();

}
 
Example #9
Source File: CorrelativeFieldSelector.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public AttributeType getType() {
    return null;
}
 
Example #10
Source File: AttributeTypeAdapter.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Wrap the given value from {@link DefaultScopeDescription} to the elements
 * defined by ISO 19115-3:2016 schema.
 */
@Override
public AttributeType unmarshal(GO_CharacterString value) {
    return new LegacyFeatureType(LegacyFeatureType.ADAPTER.unmarshal(value));
}
 
Example #11
Source File: AttributeTypeAdapter.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Unwrap the elements defined by ISO 19115-3:2016 schema to the value used by
 * {@link DefaultScopeDescription}.
 */
@Override
public GO_CharacterString marshal(AttributeType value) {
    return LegacyFeatureType.ADAPTER.marshal(LegacyFeatureType.wrap(value));
}
 
Example #12
Source File: AbstractGeotoolsDataStoreImporter.java    From TomboloDigitalConnector with MIT License 3 votes vote down vote up
/**
 * getAttributesForDatasource
 * Returns a list of attribute types for a datasource. If your DataStore was
 * a database, this would return the columns in the table to be imported.
 * You will probably use this when setting up the attributes on the Datasource.
 * Note that these are Geotools AttributeTypes and have nothing to do with
 * Tombolo's Attribute objects.
 * @param datasource The datasource being imported
 * @return A list of attributes for the datasource
 * @throws IOException
 */
protected List<AttributeType> getAttributesForDatasource(Datasource datasource) throws IOException {
    DataStore dataStore = null;
    try {
        dataStore = getDataStoreForDatasource(datasource);
        SimpleFeatureType schema = dataStore.getSchema(getTypeNameForDatasource(datasource));
        return schema.getTypes();
    } finally {
        if (null != dataStore) dataStore.dispose();
    }
}
 
Example #13
Source File: DefaultScopeDescription.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the attribute types to which the information applies.
 *
 * <div class="note"><b>Example:</b>
 * if an administrative area detects an anomaly in all overhead clearance of the road survey,
 * the correction can be recorded at {@link ScopeCode#ATTRIBUTE_TYPE} level with a
 * “<cite>Administrative area A — Overhead clearance</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 attribute types to which the information applies.
 */
@Override
@XmlElement(name = "attributes")
public Set<AttributeType> getAttributes() {
    return getProperty(AttributeType.class, ATTRIBUTES);
}
 
Example #14
Source File: DefaultScopeDescription.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the attribute 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 attribute types.
 */
public void setAttributes(final Set<? extends AttributeType> newValues) {
    setProperty(newValues, AttributeType.class, ATTRIBUTES);
}
 
Example #15
Source File: DefaultScopeDescription.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the attribute instances to which the information applies.
 *
 * <div class="note"><b>Example:</b>
 * If the overhead clearance of a new bridge was wrongly recorded,
 * the correction can be recorded at {@link ScopeCode#ATTRIBUTE} level with a
 * “<cite>Administrative area A — New bridge — Overhead clearance</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 attribute instances to which the information applies.
 */
@Override
@XmlElement(name = "attributeInstances")
public Set<AttributeType> getAttributeInstances() {
    return getProperty(AttributeType.class, ATTRIBUTE_INSTANCES);
}
 
Example #16
Source File: DefaultScopeDescription.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the attribute 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 attribute instances.
 */
public void setAttributeInstances(final Set<? extends AttributeType> newValues) {
    setProperty(newValues, AttributeType.class, ATTRIBUTE_INSTANCES);
}