use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class JDBCFeatureWriterUpdate method write.
@Override
public void write() throws FeatureStoreRuntimeException {
if (last == null) {
throw new FeatureStoreRuntimeException("Cursor is not on a record.");
}
try {
// figure out what the fid is
final PrimaryKey key = store.getDatabaseModel().getPrimaryKey(type.getName().toString());
final String fid = key.encodeFID(rs);
final FilterFactory ff = store.getFilterFactory();
final ResourceId filter = ff.resourceId(fid);
// figure out which attributes changed
final Map<String, Object> changes = new HashMap<>();
for (final PropertyType att : type.getProperties(true)) {
if (att instanceof FeatureAssociationRole || att instanceof Operation || AttributeConvention.contains(att.getName())) {
// not a writable property
continue;
}
changes.put(att.getName().tip().toString(), last.getPropertyValue(att.getName().toString()));
}
// do the write
store.updateSingle(type, changes, filter, st.getConnection());
} catch (Exception e) {
throw new FeatureStoreRuntimeException(e);
}
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class GridCoverageFeatureSet method voxels.
/**
* FeatureSet of all coverage voxels.
*/
public FeatureSet voxels() throws DataStoreException {
final FeatureType type = getType();
final FeatureAssociationRole role = (FeatureAssociationRole) type.getProperty(TypeConventions.RANGE_ELEMENTS_PROPERTY.toString());
final FeatureType valueType = role.getValueType();
return new AbstractFeatureSet(null) {
@Override
public FeatureType getType() {
return valueType;
}
@Override
public Stream<Feature> features(boolean parallel) {
final Stream<Feature> dataStream = create(valueType, gcr);
return parallel ? dataStream.parallel() : dataStream;
}
};
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class GridCoverageFeatureSet method features.
@Override
public Stream<Feature> features(boolean parallal) throws DataStoreException {
final FeatureType type = getType();
final FeatureAssociationRole role = (FeatureAssociationRole) type.getProperty(TypeConventions.RANGE_ELEMENTS_PROPERTY.toString());
final Feature feature = type.newInstance();
final GridGeometry gridGeom = gcr.getGridGeometry();
Envelope envelope = gridGeom.getEnvelope();
if (envelope != null) {
Geometry geom = GeometricUtilities.toJTSGeometry(envelope, GeometricUtilities.WrapResolution.SPLIT);
if (geom != null) {
geom = JTSMapping.convertType(geom, MultiPolygon.class);
JTS.setCRS(geom, gridGeom.getCoordinateReferenceSystem());
feature.setPropertyValue(AttributeConvention.GEOMETRY, geom);
}
}
feature.setProperty(coverageRecords(gcr, role));
return Stream.of(feature);
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class GridCoverageFeatureSetTest method coverageRecord3DTest.
/**
* Test coverage 3D mapped as a feature.
*
* @throws DataStoreException
*/
@Ignore
@Test
public void coverageRecord3DTest() throws DataStoreException, IOException, TransformException, FactoryException {
// create CRS
final CoordinateReferenceSystem crs3d = new DefaultCompoundCRS(Collections.singletonMap("name", "crs3d"), CommonCRS.WGS84.normalizedGeographic(), CommonCRS.Vertical.DEPTH.crs());
// create sample dimensions
SampleDimension.Builder sdb = new SampleDimension.Builder();
sdb.setName("values");
sdb.addQuantitative("valuesCat", NumberRange.create(0, true, 1000, true), (MathTransform1D) MathTransforms.linear(10, -5), null);
final SampleDimension sdim1 = sdb.build();
sdb.clear();
sdb.setName("quality");
sdb.addQuantitative("qualityCat", NumberRange.create(0, true, 100, true), (MathTransform1D) MathTransforms.linear(1, 0), null);
final SampleDimension sdim2 = sdb.build();
final int width = 2, height = 2, depth = 2, nbSamples = 2;
// Cube geometry
final GridExtent cubeGrid = new GridExtent(new DimensionNameType[] { DimensionNameType.COLUMN, DimensionNameType.ROW, DimensionNameType.VERTICAL }, new long[3], new long[] { width, height, depth }, false);
final MathTransform cubeGrid2Crs = MathTransforms.linear(Matrices.create(4, 4, new double[] { 2, 0, 0, 31, 0, 2, 0, 11, 0, 0, 1, 100, 0, 0, 0, 1 }));
final GridGeometry domain = new GridGeometry(cubeGrid, PixelInCell.CELL_CENTER, cubeGrid2Crs, crs3d);
final int[] values = { // z = 0
10, 2, 30, 4, 50, 6, 70, 8, // z = 1
20, 3, 40, 5, 60, 7, 80, 9 };
final GridCoverage coverage3D = new BufferedGridCoverage(domain, Arrays.asList(sdim1, sdim2), new DataBufferInt(values, values.length));
// test mapped feature type
final FeatureType coverageType = GridCoverageFeatureSet.createCoverageType(coverage3D);
final FeatureAssociationRole role = (FeatureAssociationRole) coverageType.getProperty(TypeConventions.RANGE_ELEMENTS_PROPERTY.toString());
final FeatureType recordType = role.getValueType();
assertEquals("Coverage3D", coverageType.getName().toString());
assertTrue(TypeConventions.COVERAGE_TYPE.isAssignableFrom(coverageType));
assertEquals("Coverage3DRecord", recordType.getName().toString());
assertTrue(TypeConventions.COVERAGE_RECORD_TYPE.isAssignableFrom(recordType));
// convert coverage to feature
final Feature feature = coverageType.newInstance();
feature.setProperty(GridCoverageFeatureSet.coverageRecords(coverage3D, role));
// check records
final Collection col = (Collection) feature.getPropertyValue(TypeConventions.RANGE_ELEMENTS_PROPERTY.toString());
assertEquals(4 * 2, col.size());
final Iterator<Feature> ite = col.iterator();
final Feature r1 = ite.next();
final Feature r2 = ite.next();
final Feature r3 = ite.next();
final Feature r4 = ite.next();
final Feature r5 = ite.next();
final Feature r6 = ite.next();
final Feature r7 = ite.next();
final Feature r8 = ite.next();
assertFalse(ite.hasNext());
assertEquals(10.0 * 10 - 5, r1.getPropertyValue("values"));
assertEquals(2.0, r1.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 30, 12, 32, 12, 32, 14, 30, 14, 30, 12 })), r1.getProperty("geometry").getValue());
assertEquals(30.0 * 10 - 5, r2.getPropertyValue("values"));
assertEquals(4.0, r2.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 32, 12, 34, 12, 34, 14, 32, 14, 32, 12 })), r2.getProperty("geometry").getValue());
assertEquals(50.0 * 10 - 5, r3.getPropertyValue("values"));
assertEquals(6.0, r3.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 30, 14, 32, 14, 32, 16, 30, 16, 30, 14 })), r3.getProperty("geometry").getValue());
assertEquals(70.0 * 10 - 5, r4.getPropertyValue("values"));
assertEquals(8.0, r4.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 32, 14, 34, 14, 34, 16, 32, 16, 32, 14 })), r4.getProperty("geometry").getValue());
assertEquals(20.0 * 10 - 5, r5.getPropertyValue("values"));
assertEquals(3.0, r5.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 30, 12, 32, 12, 32, 14, 30, 14, 30, 12 })), r5.getProperty("geometry").getValue());
assertEquals(40.0 * 10 - 5, r6.getPropertyValue("values"));
assertEquals(5.0, r6.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 32, 12, 34, 12, 34, 14, 32, 14, 32, 12 })), r6.getProperty("geometry").getValue());
assertEquals(60.0 * 10 - 5, r7.getPropertyValue("values"));
assertEquals(7.0, r7.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 30, 14, 32, 14, 32, 16, 30, 16, 30, 14 })), r7.getProperty("geometry").getValue());
assertEquals(80.0 * 10 - 5, r8.getPropertyValue("values"));
assertEquals(9.0, r8.getPropertyValue("quality"));
assertEquals(GF.createPolygon(new LiteCoordinateSequence(new double[] { 32, 14, 34, 14, 34, 16, 32, 16, 32, 14 })), r8.getProperty("geometry").getValue());
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class DefaultJDBCFeatureStore method recursiveDelete.
private void recursiveDelete(FeatureType featureType, Set<FeatureType> visited) throws DataStoreException {
// search properties which are complex types
for (PropertyType pt : featureType.getProperties(true)) {
if (pt instanceof DBRelationOperation) {
final RelationMetaModel relation = ((DBRelationOperation) pt).getRelation();
if (!relation.isImported()) {
// a table point toward this one.
final FeatureAssociationRole refType = (FeatureAssociationRole) (((DBRelationOperation) pt).getResult());
recursiveDelete(refType.getValueType(), visited);
}
} else if (pt instanceof FeatureAssociationRole) {
recursiveDelete(((FeatureAssociationRole) pt).getValueType(), visited);
}
}
if (visited.contains(featureType))
return;
visited.add(featureType);
final GenericName typeName = featureType.getName();
Connection cnx = null;
Statement stmt = null;
String sql = null;
try {
cnx = getDataSource().getConnection();
stmt = cnx.createStatement();
sql = getQueryBuilder().dropSQL(featureType);
stmt.execute(sql);
// reset the type name cache, will be recreated when needed.
dbmodel.clearCache();
} catch (SQLException ex) {
throw new DataStoreException("Failed to drop table " + typeName.tip() + "," + ex.getMessage() + "\n Query: " + sql, ex);
} finally {
JDBCFeatureStoreUtilities.closeSafe(getLogger(), cnx, stmt, null);
}
}
Aggregations