Search in sources :

Example 1 with AttributeType

use of org.opengis.feature.type.AttributeType in project GeoGig by boundlessgeo.

the class FormatCommonV2 method readAttributeDescriptor.

private static AttributeDescriptor readAttributeDescriptor(DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    final Name name = readName(in);
    final boolean nillable = in.readBoolean();
    final int minOccurs = in.readInt();
    final int maxOccurs = in.readInt();
    final AttributeType type = readAttributeType(in, typeFactory);
    if (type instanceof GeometryType)
        return typeFactory.createGeometryDescriptor((GeometryType) type, name, minOccurs, maxOccurs, nillable, null);
    else
        return typeFactory.createAttributeDescriptor(type, name, minOccurs, maxOccurs, nillable, null);
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) AttributeType(org.opengis.feature.type.AttributeType) Name(org.opengis.feature.type.Name)

Example 2 with AttributeType

use of org.opengis.feature.type.AttributeType in project activityinfo by bedatadriven.

the class FeatureQueryBuilder method converterForAttribute.

private Function<Object, FieldValue> converterForAttribute(int attributeIndex) {
    AttributeDescriptor descriptor = featureSource.getSchema().getAttributeDescriptors().get(attributeIndex);
    AttributeType type = descriptor.getType();
    if (type instanceof GeometryType) {
        return new GeometryConverter((GeometryType) type);
    } else {
        return new StringAttributeConverter();
    }
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) AttributeType(org.opengis.feature.type.AttributeType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 3 with AttributeType

use of org.opengis.feature.type.AttributeType in project sldeditor by robward-scisys.

the class CreateSampleData method create.

/**
 * 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<String, DataSourceAttributeData>();
    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);
    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++;
    }
    SimpleFeature newFeature = builder.buildFeature("1234");
    memory.addFeature(newFeature);
}
Also used : DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) HashMap(java.util.HashMap) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ExamplePointInterface(com.sldeditor.datasource.example.ExamplePointInterface) GeometryTypeImpl(org.geotools.feature.type.GeometryTypeImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeType(org.opengis.feature.type.AttributeType) ExampleLineInterface(com.sldeditor.datasource.example.ExampleLineInterface) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) ExamplePolygonInterface(com.sldeditor.datasource.example.ExamplePolygonInterface)

Example 4 with AttributeType

use of org.opengis.feature.type.AttributeType in project hale by halestudio.

the class XmlTypeUtil method configureXsdSimpleType.

/**
 * Configure the given type as XML schema simple type if possible
 *
 * @param type the type to configure
 * @return if the type could be configured as XSD simple type
 */
@SuppressWarnings("unchecked")
private static boolean configureXsdSimpleType(XmlTypeDefinition type) {
    Name typeName = new NameImpl(type.getName().getNamespaceURI(), type.getName().getLocalPart());
    AttributeType ty = xsSchema.get(typeName);
    // special case: ID etc. - assure String binding
    if (ty != null && XS_STRING_TYPES.contains(typeName.getLocalPart())) {
        ty = new AttributeTypeImpl(typeName, java.lang.String.class, false, false, Collections.EMPTY_LIST, ty.getSuper(), null);
    }
    // only enable hasValue if the type is not anyType
    // anyType has special treatment in
    // XmlSchemaReader.setMetadataAndConstraints(TypeDefinition, ...)
    boolean hasValue = !typeName.getLocalPart().equals("anyType");
    if (ty != null) {
        // configure type
        // set binding
        type.setConstraint(Binding.get(ty.getBinding()));
        // simple type flag
        if (hasValue) {
            type.setConstraint(HasValueFlag.ENABLED);
        }
        // not abstract
        type.setConstraint(AbstractFlag.DISABLED);
        // not mappable
        type.setConstraint(MappingRelevantFlag.DISABLED);
        type.setConstraint(MappableFlag.DISABLED);
        type.setLocation(URI.create(XMLConstants.W3C_XML_SCHEMA_NS_URI));
        if (ty.getDescription() != null) {
            type.setDescription(ty.getDescription().toString());
        }
        return true;
    } else {
        return false;
    }
}
Also used : NameImpl(org.geotools.feature.NameImpl) AttributeType(org.opengis.feature.type.AttributeType) AttributeTypeImpl(org.geotools.feature.type.AttributeTypeImpl) QName(javax.xml.namespace.QName) Name(org.opengis.feature.type.Name)

Example 5 with AttributeType

use of org.opengis.feature.type.AttributeType in project GeoGig by boundlessgeo.

the class FormatCommonV1 method readAttributeDescriptor.

private static AttributeDescriptor readAttributeDescriptor(DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    final Name name = readName(in);
    final boolean nillable = in.readBoolean();
    final int minOccurs = in.readInt();
    final int maxOccurs = in.readInt();
    final AttributeType type = readAttributeType(in, typeFactory);
    if (type instanceof GeometryType)
        return typeFactory.createGeometryDescriptor((GeometryType) type, name, minOccurs, maxOccurs, nillable, null);
    else
        return typeFactory.createAttributeDescriptor(type, name, minOccurs, maxOccurs, nillable, null);
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) AttributeType(org.opengis.feature.type.AttributeType) Name(org.opengis.feature.type.Name)

Aggregations

AttributeType (org.opengis.feature.type.AttributeType)8 GeometryType (org.opengis.feature.type.GeometryType)5 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)3 Name (org.opengis.feature.type.Name)3 IOException (java.io.IOException)2 NameImpl (org.geotools.feature.NameImpl)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 ExampleLineInterface (com.sldeditor.datasource.example.ExampleLineInterface)1 ExamplePointInterface (com.sldeditor.datasource.example.ExamplePointInterface)1 ExamplePolygonInterface (com.sldeditor.datasource.example.ExamplePolygonInterface)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 ParseException (com.vividsolutions.jts.io.ParseException)1 File (java.io.File)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 FileDataStore (org.geotools.data.FileDataStore)1 MemoryDataStore (org.geotools.data.memory.MemoryDataStore)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1