use of mil.nga.geopackage.features.user.FeatureRow in project hale by halestudio.
the class GeopackageInstanceWriter method writeInstances.
/**
* Write instances to the GeoPackage.
*
* @param geoPackage the GeoPackage
* @param instances the instances to write
* @param progress the progress indicator
* @param reporter the reporter
* @throws SQLException if an error occurs creating a database table
*/
protected void writeInstances(GeoPackage geoPackage, InstanceCollection instances, ProgressIndicator progress, IOReporter reporter) throws SQLException {
try (ResourceIterator<Instance> it = instances.iterator()) {
while (it.hasNext() && !progress.isCanceled()) {
Instance instance = it.next();
TypeDefinition type = instance.getDefinition();
// TODO only specific types? (e.g. ignore some kinds of types?)
String tableName = type.getName().getLocalPart();
// determine table for type (and create if necessary)
GeopackageTableType tableType = createTableIfNecessary(geoPackage, tableName, type, instance, reporter);
switch(tableType) {
case ATTRIBUTE:
AttributesDao attributes = geoPackage.getAttributesDao(tableName);
AttributesRow arow = attributes.newRow();
populateRow(arow, instance, reporter);
attributes.insert(arow);
break;
case FEATURE:
FeatureDao features = geoPackage.getFeatureDao(tableName);
FeatureRow frow = features.newRow();
populateRow(frow, instance, reporter);
// set geometry
String geometryColumn = features.getGeometryColumnName();
// XXX instead of using value traverse (GeometryFinder) for
// geometry?
Object geom = new InstanceAccessor(instance).findChildren(geometryColumn).value();
GeoPackageGeometryData geomData = convertGeometry(geom, features.getGeometryColumns(), reporter);
frow.setGeometry(geomData);
features.insert(frow);
break;
}
}
}
}
Aggregations