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);
}
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();
}
}
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);
}
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;
}
}
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);
}
Aggregations