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