Search in sources :

Example 1 with AttributesRow

use of mil.nga.geopackage.attributes.AttributesRow 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;
            }
        }
    }
}
Also used : GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) AttributesDao(mil.nga.geopackage.attributes.AttributesDao) InstanceAccessor(eu.esdihumboldt.hale.common.instance.groovy.InstanceAccessor) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) AttributesRow(mil.nga.geopackage.attributes.AttributesRow) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

InstanceAccessor (eu.esdihumboldt.hale.common.instance.groovy.InstanceAccessor)1 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 AttributesDao (mil.nga.geopackage.attributes.AttributesDao)1 AttributesRow (mil.nga.geopackage.attributes.AttributesRow)1 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)1 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)1 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1