Search in sources :

Example 11 with DefaultFeatureType

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));
}
Also used : AbstractOperation(org.apache.sis.feature.AbstractOperation) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) Point(com.esri.core.geometry.Point) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 12 with DefaultFeatureType

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('}');
}
Also used : DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType)

Example 13 with DefaultFeatureType

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();
        }
    }
}
Also used : DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) Collection(java.util.Collection) IllegalFeatureTypeException(org.apache.sis.storage.IllegalFeatureTypeException)

Aggregations

DefaultFeatureType (org.apache.sis.feature.DefaultFeatureType)13 Test (org.junit.Test)10 DefaultFeatureTypeTest (org.apache.sis.feature.DefaultFeatureTypeTest)9 DependsOnMethod (org.apache.sis.test.DependsOnMethod)7 AbstractIdentifiedType (org.apache.sis.feature.AbstractIdentifiedType)4 Geometry (com.esri.core.geometry.Geometry)2 DefaultAttributeType (org.apache.sis.feature.DefaultAttributeType)2 Point (com.esri.core.geometry.Point)1 Collection (java.util.Collection)1 AbstractOperation (org.apache.sis.feature.AbstractOperation)1 IllegalFeatureTypeException (org.apache.sis.storage.IllegalFeatureTypeException)1 CorruptedObjectException (org.apache.sis.util.CorruptedObjectException)1 Envelope (org.opengis.geometry.Envelope)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 FactoryException (org.opengis.util.FactoryException)1