Search in sources :

Example 16 with FeatureType

use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.

the class MIFFeatureSet method features.

@Override
public Stream<Feature> features(boolean parallel) throws DataStoreException {
    final FeatureType ft = getType();
    final MIFReader reader = new MIFReader(store.manager, ft);
    final Spliterator<Feature> spliterator = Spliterators.spliteratorUnknownSize((Iterator) reader, Spliterator.ORDERED);
    final Stream<Feature> stream = StreamSupport.stream(spliterator, false);
    return stream.onClose(reader::close);
}
Also used : FeatureType(org.opengis.feature.FeatureType) Feature(org.opengis.feature.Feature)

Example 17 with FeatureType

use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.

the class OMFeatureTypes method getFeatureTypes.

public static GenericNameIndex<FeatureType> getFeatureTypes(final String name) {
    final GenericNameIndex<FeatureType> types = new GenericNameIndex<>();
    final GenericName OM_TN_SAMPLINGPOINT = NamesExt.create(OM_NAMESPACE, name);
    final FeatureTypeBuilder featureTypeBuilder = new FeatureTypeBuilder();
    featureTypeBuilder.setName(OM_TN_SAMPLINGPOINT);
    featureTypeBuilder.setSuperTypes(GMLConvention.ABSTRACTFEATURETYPE_31);
    featureTypeBuilder.addAttribute(String.class).setName(ATT_DESC).setMinimumOccurs(0).setMaximumOccurs(1);
    featureTypeBuilder.addAttribute(String.class).setName(ATT_NAME).setMinimumOccurs(1).setMaximumOccurs(Integer.MAX_VALUE);
    featureTypeBuilder.addAttribute(String.class).setName(ATT_SAMPLED).setMinimumOccurs(0).setMaximumOccurs(Integer.MAX_VALUE).addCharacteristic(GMLConvention.NILLABLE_CHARACTERISTIC);
    featureTypeBuilder.addAttribute(Geometry.class).setName(ATT_POSITION).addRole(AttributeRole.DEFAULT_GEOMETRY);
    try {
        types.add(null, OM_TN_SAMPLINGPOINT, featureTypeBuilder.build());
    } catch (IllegalNameException ex) {
        // won't happen
        throw new FeatureStoreRuntimeException(ex);
    }
    return types;
}
Also used : FeatureType(org.opengis.feature.FeatureType) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) GenericName(org.opengis.util.GenericName) GenericNameIndex(org.geotoolkit.storage.feature.GenericNameIndex) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) IllegalNameException(org.apache.sis.storage.IllegalNameException)

Example 18 with FeatureType

use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.

the class MIFStore method add.

@Override
public synchronized Resource add(Resource resource) throws DataStoreException {
    final FeatureType type;
    if (resource instanceof DefiningFeatureSet) {
        type = ((DefiningFeatureSet) resource).getType();
    } else if (resource instanceof FeatureSet) {
        type = ((FeatureSet) resource).getType();
    } else {
        throw new DataStoreException("Unexpected resource type");
    }
    try {
        manager.addSchema(type.getName(), type);
    } catch (URISyntaxException | IOException e) {
        throw new DataStoreException("We're unable to add a schema because we can't access source files.", e);
    }
    // clear cache
    components = null;
    return findResource(type.getName().toString());
}
Also used : FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureSet(org.apache.sis.storage.FeatureSet) DefiningFeatureSet(org.geotoolkit.storage.feature.DefiningFeatureSet) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) DefiningFeatureSet(org.geotoolkit.storage.feature.DefiningFeatureSet)

Example 19 with FeatureType

use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.

the class MIFCollectionBuilder method buildGeometry.

@Override
public void buildGeometry(Scanner scanner, Feature toFill, MathTransform toApply) throws DataStoreException {
    int numGeom = 0;
    try {
        numGeom = scanner.nextInt();
    } catch (Exception e) {
        throw new DataStoreException("Number of geometries in Collection is not specified", e);
    }
    final List<Feature> features = new ArrayList<>();
    for (int geomCount = 0; geomCount < numGeom; geomCount++) {
        while (scanner.hasNextLine()) {
            final MIFUtils.GeometryType enumType = MIFUtils.getGeometryType(scanner.findInLine("\\w+"));
            if (enumType != null) {
                final FeatureType type = enumType.getBinding(null, EMPTY_TYPE);
                final Feature currentFeature = type.newInstance();
                enumType.readGeometry(scanner, currentFeature, toApply);
                features.add(currentFeature);
                break;
            } else {
                scanner.nextLine();
            }
        }
    }
    toFill.setPropertyValue(GEOM_NAME.toString(), features);
    final String geomName = FeatureExt.getDefaultGeometry(toFill.getType()).getName().toString();
    toFill.setPropertyValue(geomName, getGeometry(toFill));
}
Also used : DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) InvalidPropertyValueException(org.opengis.feature.InvalidPropertyValueException) PropertyNotFoundException(org.opengis.feature.PropertyNotFoundException) DataStoreException(org.apache.sis.storage.DataStoreException) MIFUtils(org.geotoolkit.data.mapinfo.mif.MIFUtils)

Example 20 with FeatureType

use of org.opengis.feature.FeatureType in project geotoolkit by Geomatys.

the class MIFStoreTest method filterProperties.

/**
 * Check that we can filter data properties at read time (using {@link Query#getPropertyNames() }).
 * @throws Exception
 */
@Test
public void filterProperties() throws Exception {
    final Path tmpFile = Files.createTempFile(tempDir, "filtered", ".mif");
    try (final MIFStore store = new MIFStore(tmpFile.toUri())) {
        // create a feature type
        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
        ftb.setName("test");
        ftb.addAttribute(Integer.class).setName("integerProp");
        ftb.addAttribute(Double.class).setName("doubleProp");
        ftb.addAttribute(String.class).setName("stringProp");
        ftb.addAttribute(Point.class).setName("geometryProp").setCRS(CommonCRS.WGS84.normalizedGeographic());
        final FeatureType featureType = ftb.build();
        store.add(new DefiningFeatureSet(featureType, null));
        assertEquals(1, store.components().size());
        final WritableFeatureSet resource = (WritableFeatureSet) store.components().iterator().next();
        final FeatureType ft = resource.getType();
        final Feature feature1 = ft.newInstance();
        feature1.setPropertyValue("integerProp", 8);
        feature1.setPropertyValue("doubleProp", 3.12);
        feature1.setPropertyValue("stringProp", "hello");
        feature1.setPropertyValue("geometryProp", GF.createPoint(new Coordinate(10.3, 15.7)));
        final Feature feature2 = ft.newInstance();
        feature2.setPropertyValue("integerProp", -15);
        feature2.setPropertyValue("doubleProp", -7.1);
        feature2.setPropertyValue("stringProp", "world");
        feature2.setPropertyValue("geometryProp", GF.createPoint(new Coordinate(-1.6, -5.4)));
        List<Feature> expectedFeatures = new ArrayList<>(2);
        expectedFeatures.add(feature1);
        expectedFeatures.add(feature2);
        resource.add(expectedFeatures.iterator());
        // filter output
        final FeatureQuery query = new FeatureQuery();
        final String[] filteredProps = new String[] { "stringProp", "integerProp" };
        query.setProjection(new FeatureQuery.NamedExpression(FF.property("stringProp")), new FeatureQuery.NamedExpression(FF.property("integerProp")));
        ftb.getProperty("doubleProp").remove();
        ftb.getProperty("geometryProp").remove();
        // Modify original dataset to contain only properties kept in above query.
        final FeatureType filteredType = ftb.build();
        expectedFeatures = expectedFeatures.stream().map(f -> {
            final Feature result = filteredType.newInstance();
            for (final String prop : filteredProps) {
                result.setPropertyValue(prop, f.getPropertyValue(prop));
            }
            return result;
        }).collect(Collectors.toList());
        checkFeatures(expectedFeatures, resource, query);
    }
}
Also used : Path(java.nio.file.Path) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) WritableFeatureSet(org.apache.sis.storage.WritableFeatureSet) ArrayList(java.util.ArrayList) MIFStore(org.geotoolkit.data.mapinfo.mif.MIFStore) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) FeatureQuery(org.apache.sis.storage.FeatureQuery) Feature(org.opengis.feature.Feature) Coordinate(org.locationtech.jts.geom.Coordinate) DefiningFeatureSet(org.geotoolkit.storage.feature.DefiningFeatureSet) Test(org.junit.Test)

Aggregations

FeatureType (org.opengis.feature.FeatureType)303 Feature (org.opengis.feature.Feature)146 Test (org.junit.Test)122 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)100 GenericName (org.opengis.util.GenericName)70 ArrayList (java.util.ArrayList)65 DataStoreException (org.apache.sis.storage.DataStoreException)56 PropertyType (org.opengis.feature.PropertyType)51 Coordinate (org.locationtech.jts.geom.Coordinate)50 Point (org.locationtech.jts.geom.Point)41 FeatureSet (org.apache.sis.storage.FeatureSet)37 Query (org.geotoolkit.storage.feature.query.Query)36 AttributeType (org.opengis.feature.AttributeType)36 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)33 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)32 WritableFeatureSet (org.apache.sis.storage.WritableFeatureSet)31 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)27 Geometry (org.locationtech.jts.geom.Geometry)27 URL (java.net.URL)26 HashMap (java.util.HashMap)26