Search in sources :

Example 1 with FeatureTypeBuilder

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

the class RegistryTestCase method testFeatureOptimization.

/**
 * Tests {@link Optimization} on an arbitrary expression on feature instances.
 */
@Test
public void testFeatureOptimization() {
    geometry = library.createPoint(10, 30);
    setGeometryCRS(HardCodedCRS.WGS84_LATITUDE_FIRST);
    function = factory.function("ST_Union", factory.property(P_NAME), factory.literal(geometry));
    final Optimization optimization = new Optimization();
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(library.pointClass).setName(P_NAME).setCRS(HardCodedCRS.WGS84);
    optimization.setFeatureType(ftb.setName("Test").build());
    final Expression<? super AbstractFeature, ?> optimized = optimization.apply(function);
    assertNotSame("Optimization should produce a new expression.", function, optimized);
    /*
         * Get the second parameter, which should be a literal, and get the point coordinates.
         * Verify that the order is swapped compared to the order at the beginning of this method.
         */
    final Object literal = optimized.getParameters().get(1).apply(null);
    final DirectPosition point = library.castOrWrap(literal).getCentroid();
    assertArrayEquals(new double[] { 30, 10 }, point.getCoordinate(), STRICT);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DirectPosition(org.opengis.geometry.DirectPosition) Optimization(org.apache.sis.filter.Optimization) Test(org.junit.Test)

Example 2 with FeatureTypeBuilder

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

the class LogicalFilterTest method testEvaluateOnFeature.

/**
 * Tests evaluation using a feature instance.
 */
@Test
public void testEvaluateOnFeature() {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(String.class).setName("attNull");
    ftb.addAttribute(String.class).setName("attNotNull");
    final AbstractFeature feature = ftb.setName("Test").build().newInstance();
    feature.setPropertyValue("attNotNull", "a value");
    final Filter<AbstractFeature> filterTrue = factory.isNull(factory.property("attNull", String.class));
    final Filter<AbstractFeature> filterFalse = factory.isNull(factory.property("attNotNull", String.class));
    assertTrue(factory.and(filterTrue, filterTrue).test(feature));
    assertFalse(factory.and(filterFalse, filterTrue).test(feature));
    assertFalse(factory.and(filterTrue, filterFalse).test(feature));
    assertFalse(factory.and(filterFalse, filterFalse).test(feature));
    assertTrue(factory.or(filterTrue, filterTrue).test(feature));
    assertTrue(factory.or(filterFalse, filterTrue).test(feature));
    assertTrue(factory.or(filterTrue, filterFalse).test(feature));
    assertFalse(factory.or(filterFalse, filterFalse).test(feature));
    assertFalse(factory.not(filterTrue).test(feature));
    assertTrue(factory.not(filterFalse).test(feature));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) AbstractFeature(org.apache.sis.feature.AbstractFeature) Test(org.junit.Test)

Example 3 with FeatureTypeBuilder

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

the class IdentifierFilterTest method testEvaluate.

/**
 * Tests on features of diffferent types. Test data are:
 * <ul>
 *   <li>A feature type with an identifier as a string.</li>
 *   <li>A feature type with an integer identifier.</li>
 *   <li>A feature type with no identifier.</li>
 * </ul>
 */
@Test
public void testEvaluate() {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.addAttribute(String.class).setName("att").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    final AbstractFeature f1 = ftb.setName("Test 1").build().newInstance();
    f1.setPropertyValue("att", "123");
    ftb.clear().addAttribute(Integer.class).setName("att").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    final AbstractFeature f2 = ftb.setName("Test 2").build().newInstance();
    f2.setPropertyValue("att", 123);
    final AbstractFeature f3 = ftb.clear().setName("Test 3").build().newInstance();
    final Filter<AbstractFeature> id = factory.resourceId("123");
    assertTrue(id.test(f1));
    assertTrue(id.test(f2));
    assertFalse(id.test(f3));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) AbstractFeature(org.apache.sis.feature.AbstractFeature) Test(org.junit.Test)

Example 4 with FeatureTypeBuilder

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

the class EnvelopeOperationTest method initialize.

/**
 * Creates a feature type containing two geometric properties in the specified CRSs, which may be null.
 * They will be specified as default CRS of each property through property type CRS characteristic only
 * if the corresponding {@code declareCRS} flag is true. The first geometry will be the default one.
 *
 * @param defaultCRS1        default CRS of first property (may be {@code null}).
 * @param defaultCRS2        default CRS of second property (may be {@code null}).
 * @param asCharacteristic1  whether to declare CRS 1 as a characteristic of first property.
 * @param asCharacteristic2  whether to declare CRS 2 as a characteristic of second property.
 */
private void initialize(final CoordinateReferenceSystem defaultCRS1, boolean asCharacteristic1, final CoordinateReferenceSystem defaultCRS2, boolean asCharacteristic2) {
    final FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("test");
    final AttributeTypeBuilder<?> g1 = builder.addAttribute(GeometryWrapper.class).setName("g1");
    final AttributeTypeBuilder<?> g2 = builder.addAttribute(GeometryWrapper.class).setName("g2");
    if (asCharacteristic1)
        g1.setCRS(defaultCRS1);
    if (asCharacteristic2)
        g2.setCRS(defaultCRS2);
    g1.addRole(AttributeRole.DEFAULT_GEOMETRY);
    type = builder.build();
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) GeometryWrapper(org.apache.sis.internal.feature.GeometryWrapper)

Example 5 with FeatureTypeBuilder

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

the class ConcatenatedFeatureSetTest method testSameType.

/**
 * Tests the concatenation of two feature sets having the same feature type.
 *
 * @throws DataStoreException if an error occurred while concatenating the feature sets.
 */
@Test
public void testSameType() throws DataStoreException {
    final FeatureTypeBuilder builder = new FeatureTypeBuilder();
    builder.setName("City");
    builder.addAttribute(String.class).setName("name");
    builder.addAttribute(Integer.class).setName("population");
    final DefaultFeatureType ft = builder.build();
    final FeatureSet cfs = ConcatenatedFeatureSet.create(new MemoryFeatureSet(null, ft, Arrays.asList(ft.newInstance(), ft.newInstance())), new MemoryFeatureSet(null, ft, Arrays.asList(ft.newInstance())));
    assertSame("getType()", ft, cfs.getType());
    assertEquals("features.count()", 3, cfs.features(false).count());
    final Metadata md = cfs.getMetadata();
    assertNotNull("getMetadata()", md);
    assertContentInfoEquals("City", 3, (FeatureCatalogueDescription) getSingleton(md.getContentInfo()));
    final Lineage lineage = getSingleton(((DefaultMetadata) md).getResourceLineages());
    assertFeatureSourceEquals("City", new String[] { "City" }, getSingleton(lineage.getSources()));
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) Lineage(org.opengis.metadata.lineage.Lineage) 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