use of mil.nga.sf.GeometryEnvelope in project joa by sebastianfrey.
the class GeoPackageService method getItems.
/**
* Return all items of a collection from a given service.
*
* @param serviceId
* @param collectionId
* @return
*/
@Override
public GeoPackageItems getItems(String serviceId, String collectionId, FeatureQuery query) throws Exception {
GeoPackageItems items = new GeoPackageItems().serviceId(serviceId).collectionId(collectionId).queryString(query.getQueryString()).offset(query.getOffset()).limit(query.getLimit());
try (GeoPackage gpkg = loadService(serviceId)) {
FeatureDao featureDao = loadCollection(gpkg, collectionId);
GeoPackageQueryResult result = new GeoPackageQuery(featureDao, query).execute();
String geometryType = null;
switch(featureDao.getGeometryType()) {
case POINT:
geometryType = "Point";
break;
case LINESTRING:
geometryType = "LineString";
break;
case POLYGON:
geometryType = "Polygon";
break;
case MULTIPOINT:
geometryType = "MultiPoint";
break;
case MULTILINESTRING:
geometryType = "MultiLineString";
break;
case MULTIPOLYGON:
geometryType = "MultiPolygon";
break;
default:
break;
}
items.numberMatched(result.getCount()).geometryType(geometryType).idColumn(featureDao.getIdColumnName());
GeometryEnvelope bbox = null;
FeatureResultSet featureResultSet = result.getFeatureResultSet();
try {
while (featureResultSet.moveToNext()) {
FeatureRow featureRow = featureResultSet.getRow();
Feature feature = createFeature(featureRow);
if (feature != null) {
items.feature(feature);
}
GeometryEnvelope envelope = createEnvelope(featureRow);
if (envelope != null) {
if (bbox == null) {
bbox = envelope.copy();
} else {
bbox = bbox.union(envelope);
}
}
}
} finally {
featureResultSet.close();
}
if (bbox != null) {
if (bbox.is3D()) {
items.bbox(List.of(bbox.getMinX(), bbox.getMinY(), bbox.getMinZ(), bbox.getMaxX(), bbox.getMaxY(), bbox.getMaxZ()));
} else {
items.bbox(List.of(bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY()));
}
}
}
return items;
}
use of mil.nga.sf.GeometryEnvelope in project joa by sebastianfrey.
the class GeoPackageService method createCollection.
public Collection createCollection(String serviceId, FeatureDao featureDao) {
Contents contents = featureDao.getContents();
String collectionId = contents.getTableName();
String title = contents.getIdentifier();
String description = contents.getDescription();
String crs = CrsUtils.epsg(contents.getSrsId());
GeometryEnvelope envelope = contents.getBoundingBox().buildEnvelope();
Bbox bbox = new Bbox().minX(envelope.getMinX()).minY(envelope.getMinY()).minZ(envelope.getMinZ()).maxX(envelope.getMaxX()).maxY(envelope.getMaxY()).maxZ(envelope.getMaxZ());
List<String> temporal = new ArrayList<String>();
temporal.add(null);
temporal.add(null);
Collection collection = new Collection().serviceId(serviceId).collectionId(collectionId).title(title).description(description).crs(crs).itemType("feature").spatial(new Spatial().bbox(bbox).crs(crs)).interval(temporal);
return collection;
}
Aggregations