Search in sources :

Example 1 with GeoPackageDataType

use of mil.nga.geopackage.db.GeoPackageDataType in project hale by halestudio.

the class GeopackageSchemaBuilder method getOrCreatePropertyType.

private TypeDefinition getOrCreatePropertyType(UserColumn column, GeometryColumns geomColumns, DefaultSchema schema) {
    String localName;
    if (column instanceof FeatureColumn && ((FeatureColumn) column).isGeometry()) {
        localName = ((FeatureColumn) column).getGeometryType().getName();
    } else {
        localName = column.getDataType().name();
    }
    QName typeName = new QName(defaultNamespace, localName);
    TypeDefinition type = schema.getType(typeName);
    if (type != null) {
        // use existing type
        return type;
    } else {
        DefaultTypeDefinition typeDef = new DefaultTypeDefinition(typeName);
        typeDef.setConstraint(MappingRelevantFlag.DISABLED);
        typeDef.setConstraint(MappableFlag.DISABLED);
        // simple type
        typeDef.setConstraint(HasValueFlag.ENABLED);
        if (column instanceof FeatureColumn && ((FeatureColumn) column).isGeometry()) {
            mil.nga.sf.GeometryType geomType = ((FeatureColumn) column).getGeometryType();
            typeDef.setConstraint(Binding.get(GeometryProperty.class));
            Class<? extends Geometry> geomClass = Geometry.class;
            switch(geomType) {
                case LINESTRING:
                    geomClass = LineString.class;
                    break;
                case MULTIPOINT:
                    geomClass = MultiPoint.class;
                    break;
                case MULTILINESTRING:
                    geomClass = MultiLineString.class;
                    break;
                case MULTIPOLYGON:
                    geomClass = MultiPolygon.class;
                    break;
                case POINT:
                    geomClass = Point.class;
                    break;
                case POLYGON:
                    geomClass = Polygon.class;
                    break;
                default:
                    break;
            }
            typeDef.setConstraint(GeometryType.get(geomClass));
            SpatialReferenceSystem srs = geomColumns.getSrs();
            if (srs != null) {
                String code = String.valueOf(srs.getOrganizationCoordsysId());
                int dimension = GeometryMetadata.UNKNOWN_DIMENSION;
                String srsText = srs.getDefinition();
                String auth_name = srs.getOrganization();
                typeDef.setConstraint(new GeometryMetadata(code, dimension, srsText, auth_name));
            }
        } else {
            GeoPackageDataType dataType = column.getDataType();
            Class<?> binding;
            switch(dataType) {
                case DATETIME:
                    binding = Instant.class;
                    break;
                case DATE:
                    binding = LocalDate.class;
                    break;
                default:
                    binding = dataType.getClassType();
            }
            typeDef.setConstraint(Binding.get(binding));
        }
        return typeDef;
    }
}
Also used : GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) GeometryMetadata(eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryMetadata) QName(javax.xml.namespace.QName) GeoPackageDataType(mil.nga.geopackage.db.GeoPackageDataType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) Geometry(org.locationtech.jts.geom.Geometry) FeatureColumn(mil.nga.geopackage.features.user.FeatureColumn) SpatialReferenceSystem(mil.nga.geopackage.core.srs.SpatialReferenceSystem)

Aggregations

GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1 GeometryMetadata (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryMetadata)1 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)1 QName (javax.xml.namespace.QName)1 SpatialReferenceSystem (mil.nga.geopackage.core.srs.SpatialReferenceSystem)1 GeoPackageDataType (mil.nga.geopackage.db.GeoPackageDataType)1 FeatureColumn (mil.nga.geopackage.features.user.FeatureColumn)1 Geometry (org.locationtech.jts.geom.Geometry)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1 Point (org.locationtech.jts.geom.Point)1