Search in sources :

Example 6 with DefaultFeatureType

use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.

the class FeatureTypeBuilderTest method testCreateFromTemplateWithRoles.

/**
 * Tests creation of a builder from an existing feature type with some attributes having {@link AttributeRole}s.
 */
@Test
@DependsOnMethod("testCreateFromTemplate")
public void testCreateFromTemplateWithRoles() {
    FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("City");
    builder.addAttribute(String.class).setName("name").roles().add(AttributeRole.IDENTIFIER_COMPONENT);
    builder.addAttribute(Integer.class).setName("population");
    builder.addAttribute(Geometry.class).setName("area").roles().add(AttributeRole.DEFAULT_GEOMETRY);
    final DefaultFeatureType type = builder.build();
    builder = new FeatureTypeBuilder(type);
    assertEquals("name", "City", builder.getName().toString());
    assertEquals("superTypes", 0, builder.getSuperTypes().length);
    final Iterator<PropertyTypeBuilder> it = builder.properties().iterator();
    final AttributeTypeBuilder<?> a0 = (AttributeTypeBuilder<?>) it.next();
    final AttributeTypeBuilder<?> a1 = (AttributeTypeBuilder<?>) it.next();
    final AttributeTypeBuilder<?> a2 = (AttributeTypeBuilder<?>) it.next();
    assertFalse("properties count", it.hasNext());
    assertEquals("name", "name", a0.getName().toString());
    assertEquals("name", "population", a1.getName().toString());
    assertEquals("name", "area", a2.getName().toString());
    assertEquals("type", String.class, a0.getValueClass());
    assertEquals("type", Integer.class, a1.getValueClass());
    assertEquals("type", Geometry.class, a2.getValueClass());
    assertTrue("roles", a1.roles().isEmpty());
    assertEquals("roles", AttributeRole.IDENTIFIER_COMPONENT, TestUtilities.getSingleton(a0.roles()));
    assertEquals("roles", AttributeRole.DEFAULT_GEOMETRY, TestUtilities.getSingleton(a2.roles()));
}
Also used : Geometry(com.esri.core.geometry.Geometry) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultFeatureTypeTest(org.apache.sis.feature.DefaultFeatureTypeTest) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 7 with DefaultFeatureType

use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.

the class FeatureTypeBuilderTest method testOverrideByOperation.

/**
 * Tests overriding an attribute by an operation.
 * This is the converse of {@link #testEnvelopeOverride()}.
 */
@Test
public void testOverrideByOperation() {
    FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("Parent").setAbstract(true);
    final DefaultAttributeType<Integer> pa = builder.addAttribute(Integer.class).setName("A").build();
    builder.addAttribute(Integer.class).setName("B");
    final DefaultFeatureType parentType = builder.build();
    builder = new FeatureTypeBuilder().setName("Child").setSuperTypes(parentType);
    builder.addProperty(FeatureOperations.link(Collections.singletonMap(AbstractOperation.NAME_KEY, "B"), pa));
    final DefaultFeatureType childType = builder.build();
    final Iterator<? extends AbstractIdentifiedType> it = childType.getProperties(true).iterator();
    assertPropertyEquals("A", Integer.class, it.next());
    assertPropertyEquals("B", Integer.class, it.next());
    assertFalse(it.hasNext());
}
Also used : DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultFeatureTypeTest(org.apache.sis.feature.DefaultFeatureTypeTest) Test(org.junit.Test)

Example 8 with DefaultFeatureType

use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.

the class FeatureTypeBuilderTest method testInitialization.

/**
 * Tests with the minimum number of parameters (no property and no super type).
 */
@Test
@DependsOnMethod({ "testSetAbstract", "testSetDeprecated", "testSetNameSpace" })
public void testInitialization() {
    final FeatureTypeBuilder builder = new FeatureTypeBuilder();
    try {
        builder.build();
        fail("Builder should have failed if there is not at least a name set.");
    } catch (IllegalArgumentException ex) {
        final String message = ex.getMessage();
        assertTrue(message, message.contains("name"));
    }
    assertSame(builder, builder.setName("scope", "test"));
    final DefaultFeatureType type = builder.build();
    assertEquals("name", "scope:test", type.getName().toString());
    assertFalse("isAbstract", type.isAbstract());
    assertEquals("properties count", 0, type.getProperties(true).size());
    assertEquals("super-types count", 0, type.getSuperTypes().size());
}
Also used : DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultFeatureTypeTest(org.apache.sis.feature.DefaultFeatureTypeTest) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 9 with DefaultFeatureType

use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.

the class FeatureTypeBuilderTest method testEnvelopeOverride.

/**
 * Tests overriding the "sis:envelope" property. This may happen when the user wants to specify
 * envelope himself instead than relying on the automatically computed value.
 */
@Test
public void testEnvelopeOverride() {
    FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("CoverageRecord").setAbstract(true);
    builder.addAttribute(Geometry.class).setName(AttributeConvention.GEOMETRY_PROPERTY).addRole(AttributeRole.DEFAULT_GEOMETRY);
    final DefaultFeatureType parentType = builder.build();
    builder = new FeatureTypeBuilder().setName("Record").setSuperTypes(parentType);
    builder.addAttribute(Envelope.class).setName(AttributeConvention.ENVELOPE_PROPERTY);
    final DefaultFeatureType childType = builder.build();
    final Iterator<? extends AbstractIdentifiedType> it = childType.getProperties(true).iterator();
    assertPropertyEquals("sis:envelope", Envelope.class, it.next());
    assertPropertyEquals("sis:geometry", Geometry.class, it.next());
    assertFalse(it.hasNext());
}
Also used : DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) Envelope(org.opengis.geometry.Envelope) DefaultFeatureTypeTest(org.apache.sis.feature.DefaultFeatureTypeTest) Test(org.junit.Test)

Example 10 with DefaultFeatureType

use of org.apache.sis.feature.DefaultFeatureType in project sis by apache.

the class FeatureTypeBuilderTest method testAddIdentifierAndGeometry.

/**
 * Tests {@link FeatureTypeBuilder#addAttribute(Class)} where one property is an identifier
 * and another property is the geometry.
 */
@Test
@DependsOnMethod("testAddAttribute")
public void testAddIdentifierAndGeometry() {
    final FeatureTypeBuilder builder = new FeatureTypeBuilder();
    assertSame(builder, builder.setName("scope", "test"));
    assertSame(builder, builder.setIdentifierDelimiters("-", "pref.", null));
    builder.addAttribute(String.class).setName("name").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    builder.addAttribute(Geometry.class).setName("shape").setCRS(HardCodedCRS.WGS84).addRole(AttributeRole.DEFAULT_GEOMETRY);
    final DefaultFeatureType type = builder.build();
    assertEquals("name", "scope:test", type.getName().toString());
    assertFalse("isAbstract", type.isAbstract());
    final Iterator<? extends AbstractIdentifiedType> it = type.getProperties(true).iterator();
    final AbstractIdentifiedType a0 = it.next();
    final AbstractIdentifiedType a1 = it.next();
    final AbstractIdentifiedType a2 = it.next();
    final AbstractIdentifiedType a3 = it.next();
    final AbstractIdentifiedType a4 = it.next();
    assertFalse("properties count", it.hasNext());
    assertEquals("name", AttributeConvention.IDENTIFIER_PROPERTY, a0.getName());
    assertEquals("name", AttributeConvention.ENVELOPE_PROPERTY, a1.getName());
    assertEquals("name", AttributeConvention.GEOMETRY_PROPERTY, a2.getName());
    assertEquals("name", "name", a3.getName().toString());
    assertEquals("name", "shape", a4.getName().toString());
}
Also used : Geometry(com.esri.core.geometry.Geometry) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) AbstractIdentifiedType(org.apache.sis.feature.AbstractIdentifiedType) DefaultFeatureTypeTest(org.apache.sis.feature.DefaultFeatureTypeTest) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

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