use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.
the class AttributeConventionTest method testGetCrsCharacteristic.
/**
* Tests {@code AttributeConvention.characterizedByCRS(IdentifiedType)} and
* {@code AttributeConvention.getCRSCharacteristic(Property)} methods.
*/
@Test
public void testGetCrsCharacteristic() {
final Map<String, ?> properties = Collections.singletonMap(DefaultAttributeType.NAME_KEY, "geometry");
DefaultAttributeType<Point> type = new DefaultAttributeType<>(properties, Point.class, 1, 1, null);
assertFalse("characterizedByCRS", AttributeConvention.characterizedByCRS(type));
assertNull("getCRSCharacteristic", AttributeConvention.getCRSCharacteristic(type.newInstance()));
/*
* Creates an attribute associated to an attribute (i.e. a "characteristic") for storing
* the Coordinate Reference System of the "geometry" attribute. Then test again.
*/
final DefaultAttributeType<CoordinateReferenceSystem> characteristic = new DefaultAttributeType<>(Collections.singletonMap(DefaultAttributeType.NAME_KEY, AttributeConvention.CRS_CHARACTERISTIC), CoordinateReferenceSystem.class, 1, 1, HardCodedCRS.WGS84);
type = new DefaultAttributeType<>(properties, Point.class, 1, 1, null, characteristic);
assertTrue("characterizedByCRS", AttributeConvention.characterizedByCRS(type));
assertEquals(HardCodedCRS.WGS84, AttributeConvention.getCRSCharacteristic(type.newInstance()));
assertEquals(HardCodedCRS.WGS84, AttributeConvention.getCRSCharacteristic(null, type));
/*
* Test again AttributeConvention.getCRSCharacteristic(…, PropertyType), but following link.
*/
final AbstractOperation link = FeatureOperations.link(Collections.singletonMap(DefaultAttributeType.NAME_KEY, "geom"), type);
final DefaultFeatureType feat = new DefaultFeatureType(Collections.singletonMap(DefaultAttributeType.NAME_KEY, "feat"), false, null, type, link);
assertEquals(HardCodedCRS.WGS84, AttributeConvention.getCRSCharacteristic(feat, link));
assertNull(AttributeConvention.getCRSCharacteristic(null, link));
}
use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.
the class FeatureTypeBuilder method toStringInternal.
/**
* Formats a string representation of this builder for debugging purpose.
*/
@Override
final void toStringInternal(final StringBuilder buffer) {
if (isAbstract()) {
buffer.insert(buffer.indexOf("[") + 1, "abstract ");
}
String separator = " : ";
for (final DefaultFeatureType parent : superTypes) {
buffer.append(separator).append('“').append(parent.getName()).append('”');
separator = ", ";
}
buffer.append(" {");
separator = System.lineSeparator();
for (final PropertyTypeBuilder p : properties) {
p.toString(buffer.append(separator).append(" ").append(p.getClass().getSimpleName()));
}
buffer.append(separator).append('}');
}
use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.
the class Writer method write.
/**
* Writes the given feature.
*
* @param feature the feature to write, or {@code null} if none.
* @throws DataStoreException if the given feature is not a recognized type.
* @throws XMLStreamException if underlying STAX writer encounter an error.
* @throws JAXBException if underlying JAXB marshaller encounter an error.
*/
@Override
public void write(final AbstractFeature feature) throws DataStoreException, XMLStreamException, JAXBException {
if (feature != null) {
final Types types = ((Store) owner).types;
final DefaultFeatureType type = feature.getType();
if (types.wayPoint.isAssignableFrom(type)) {
writeWayPoint(feature, Tags.WAY_POINT);
} else {
final boolean isRoute = types.route.isAssignableFrom(type);
if (!isRoute && !types.track.isAssignableFrom(type)) {
throw new IllegalFeatureTypeException(owner.getLocale(), owner.getFormatName(), type.getName());
}
writer.writeStartElement(isRoute ? Tags.ROUTES : Tags.TRACKS);
writeSingleValue(Tags.NAME, feature.getPropertyValue(Tags.NAME));
writeSingleValue(Tags.COMMENT, feature.getPropertyValue(Tags.COMMENT));
writeSingleValue(Tags.DESCRIPTION, feature.getPropertyValue(Tags.DESCRIPTION));
writeSingleValue(Tags.SOURCE, feature.getPropertyValue(Tags.SOURCE));
writeLinks((Collection<?>) feature.getPropertyValue(Tags.LINK));
writeSingleValue(Tags.NUMBER, feature.getPropertyValue(Tags.NUMBER));
if (version != 0) {
writeSingleValue(Tags.TYPE, feature.getPropertyValue(Tags.TYPE));
}
if (isRoute) {
for (Object prop : (Collection<?>) feature.getPropertyValue(Tags.ROUTE_POINTS)) {
writeWayPoint((AbstractFeature) prop, Tags.ROUTE_POINTS);
}
} else {
for (Object segment : (Collection<?>) feature.getPropertyValue(Tags.TRACK_SEGMENTS)) {
if (segment != null) {
writer.writeStartElement(Tags.TRACK_SEGMENTS);
for (Object prop : (Collection<?>) ((AbstractFeature) segment).getPropertyValue(Tags.TRACK_POINTS)) {
writeWayPoint((AbstractFeature) prop, Tags.TRACK_POINTS);
}
writer.writeEndElement();
}
}
}
writer.writeEndElement();
}
}
}
Aggregations