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);
}
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;
}
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());
}
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));
}
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);
}
}
Aggregations