Search in sources :

Example 6 with FeatureTypeBuilder

use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.

the class RegistryTestCase method createFeatureWithGeometry.

/**
 * Creates a feature with a single property named {@value #P_NAME}.
 * The current {@link #geometry} value is assigned to that feature.
 *
 * @param  type  the type of value in the property.
 * @return a feature with a property of the given type.
 */
private AbstractFeature createFeatureWithGeometry(final Class<?> type) {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(type).setName(P_NAME);
    final DefaultFeatureType mockType = ftb.setName("Test").build();
    final AbstractFeature feature = mockType.newInstance();
    feature.setPropertyValue(P_NAME, geometry);
    return feature;
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) AbstractFeature(org.apache.sis.feature.AbstractFeature)

Example 7 with FeatureTypeBuilder

use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.

the class LeafExpressionTest method testReferenceEvaluation.

/**
 * Tests evaluation of "ValueReference", including with type conversion.
 */
@Test
public void testReferenceEvaluation() {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(String.class).setName("some_property");
    final AbstractFeature f = ftb.setName("Test").build().newInstance();
    Expression<AbstractFeature, ?> ref = factory.property("some_property");
    assertNull(ref.apply(f));
    assertNull(ref.apply(null));
    f.setPropertyValue("some_property", "road");
    assertEquals("road", ref.apply(f));
    ref = factory.property("some_property", String.class);
    assertEquals("road", ref.apply(f));
    f.setPropertyValue("some_property", "45.1");
    assertEquals("45.1", ref.apply(f));
    ref = factory.property("some_property", Double.class);
    assertEquals(45.1, ref.apply(f));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) AbstractFeature(org.apache.sis.feature.AbstractFeature) Test(org.junit.Test)

Example 8 with FeatureTypeBuilder

use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.

the class LogicalFilterTest method testFeatureOptimization.

/**
 * Tests {@link Optimization} applied on logical filters when the {@link DefaultFeatureType} is known.
 */
@Test
public void testFeatureOptimization() {
    final String attribute = "population";
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(String.class).setName(attribute);
    final DefaultFeatureType type = ftb.setName("Test").build();
    final AbstractFeature instance = type.newInstance();
    instance.setPropertyValue("population", "1000");
    /*
         * Prepare an expression which divide the population value by 5.
         */
    final Expression<AbstractFeature, Number> e = factory.divide(factory.property(attribute, Integer.class), factory.literal(5));
    final Optimization optimization = new Optimization();
    // No optimization.
    assertSame(e, optimization.apply(e));
    assertEquals(200, e.apply(instance).intValue());
    /*
         * Notify the optimizer that property values will be of `String` type.
         * The optimizer should compute an `ObjectConverter` in advance.
         */
    optimization.setFeatureType(type);
    final Expression<? super AbstractFeature, ? extends Number> opt = optimization.apply(e);
    assertEquals(200, e.apply(instance).intValue());
    assertNotSame(e, opt);
    final PropertyValue<?> p = (PropertyValue<?>) opt.getParameters().get(0);
    assertEquals(String.class, p.getSourceClass());
    assertEquals(Number.class, p.getValueClass());
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) AbstractFeature(org.apache.sis.feature.AbstractFeature) Test(org.junit.Test)

Example 9 with FeatureTypeBuilder

use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.

the class IdentifierFilterTest method testEvaluateCombined.

/**
 * Tests evaluation of two identifiers combined by a OR logical operator.
 */
@Test
public void testEvaluateCombined() {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(String.class).setName("att").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    final DefaultFeatureType type = ftb.setName("Test").build();
    final AbstractFeature f1 = type.newInstance();
    f1.setPropertyValue("att", "123");
    final AbstractFeature f2 = type.newInstance();
    f2.setPropertyValue("att", "abc");
    final AbstractFeature f3 = type.newInstance();
    f3.setPropertyValue("att", "abc123");
    final Filter<AbstractFeature> id = factory.or(factory.resourceId("abc"), factory.resourceId("123"));
    assertTrue(id.test(f1));
    assertTrue(id.test(f2));
    assertFalse(id.test(f3));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) AbstractFeature(org.apache.sis.feature.AbstractFeature) Test(org.junit.Test)

Example 10 with FeatureTypeBuilder

use of org.apache.sis.feature.builder.FeatureTypeBuilder in project sis by apache.

the class ConcatenatedFeatureSetTest method lackOfInput.

/**
 * Tests that no concatenated transform is created from less than 2 types.
 *
 * @throws DataStoreException if an error occurred while invoking the create method.
 */
@Test
public void lackOfInput() throws DataStoreException {
    try {
        final FeatureSet set = ConcatenatedFeatureSet.create();
        fail("An empty concatenation has been created:\n" + set);
    } catch (IllegalArgumentException e) {
    // This is the expected exception.
    }
    final FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("mock");
    final DefaultFeatureType mockType = builder.build();
    final FeatureSet fs1 = new MemoryFeatureSet(null, mockType, Collections.emptyList());
    final FeatureSet set = ConcatenatedFeatureSet.create(fs1);
    assertSame("A concatenation has been created from a single type.", fs1, set);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) FeatureSet(org.apache.sis.storage.FeatureSet) Test(org.junit.Test)

Aggregations

FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)13 Test (org.junit.Test)10 AbstractFeature (org.apache.sis.feature.AbstractFeature)7 DefaultFeatureType (org.apache.sis.feature.DefaultFeatureType)7 FeatureSet (org.apache.sis.storage.FeatureSet)4 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)2 DataStoreException (org.apache.sis.storage.DataStoreException)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Metadata (org.opengis.metadata.Metadata)2 Lineage (org.opengis.metadata.lineage.Lineage)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 PropertyTypeBuilder (org.apache.sis.feature.builder.PropertyTypeBuilder)1 Optimization (org.apache.sis.filter.Optimization)1 GeometryWrapper (org.apache.sis.internal.feature.GeometryWrapper)1 ValueReference (org.apache.sis.internal.geoapi.filter.ValueReference)1 MetadataAssert (org.apache.sis.test.MetadataAssert)1 TestCase (org.apache.sis.test.TestCase)1 TestUtilities.getSingleton (org.apache.sis.test.TestUtilities.getSingleton)1