Search in sources :

Example 1 with GeometryEnvelope

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;
}
Also used : FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureResultSet(mil.nga.geopackage.features.user.FeatureResultSet) GeometryEnvelope(mil.nga.sf.GeometryEnvelope) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) GeoPackage(mil.nga.geopackage.GeoPackage) Feature(mil.nga.sf.geojson.Feature)

Example 2 with GeometryEnvelope

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;
}
Also used : Contents(mil.nga.geopackage.contents.Contents) Spatial(com.github.sebastianfrey.joa.models.Spatial) Bbox(com.github.sebastianfrey.joa.models.Bbox) GeometryEnvelope(mil.nga.sf.GeometryEnvelope) ArrayList(java.util.ArrayList) Collection(com.github.sebastianfrey.joa.models.Collection)

Aggregations

GeometryEnvelope (mil.nga.sf.GeometryEnvelope)2 Bbox (com.github.sebastianfrey.joa.models.Bbox)1 Collection (com.github.sebastianfrey.joa.models.Collection)1 Spatial (com.github.sebastianfrey.joa.models.Spatial)1 ArrayList (java.util.ArrayList)1 GeoPackage (mil.nga.geopackage.GeoPackage)1 Contents (mil.nga.geopackage.contents.Contents)1 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)1 FeatureResultSet (mil.nga.geopackage.features.user.FeatureResultSet)1 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)1 Feature (mil.nga.sf.geojson.Feature)1