use of mil.nga.sf.geojson.Feature 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.geojson.Feature in project joa by sebastianfrey.
the class GeoPackageService method getItem.
/**
* Return a specific item by its id from a given service.
*
* @param serviceId
* @param collectionId
* @return
*/
@Override
public GeoPackageItem getItem(String serviceId, String collectionId, Long featureId) {
try (GeoPackage gpkg = loadService(serviceId)) {
FeatureDao featureDao = loadCollection(gpkg, collectionId);
FeatureResultSet featureResultSet = featureDao.queryForId(featureId);
try {
while (featureResultSet.moveToNext()) {
FeatureRow featureRow = featureResultSet.getRow();
Feature feature = createFeature(featureRow);
return new GeoPackageItem().serviceId(serviceId).collectionId(collectionId).feature(feature);
}
} finally {
featureResultSet.close();
}
}
throw new NotFoundException("Feature with ID '" + featureId + "' does not exist.");
}
use of mil.nga.sf.geojson.Feature in project geopackage-core-java by ngageoint.
the class OAPIFeatureCoreGenerator method createFeatures.
/**
* Create features from the feature collection
*
* @param featureCollection
* feature collection
* @return features created
*/
protected int createFeatures(FeatureCollection featureCollection) {
int count = 0;
geoPackage.beginTransaction();
try {
for (Feature feature : featureCollection.getFeatureCollection().getFeatures()) {
if (!isActive()) {
break;
}
try {
createFeature(feature);
count++;
if (progress != null) {
progress.addProgress(1);
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to create feature: " + feature.getId(), e);
}
if (count > 0 && count % transactionLimit == 0) {
geoPackage.commit();
}
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to create features", e);
geoPackage.failTransaction();
} finally {
geoPackage.endTransaction();
}
Integer numberReturned = featureCollection.getNumberReturned();
if (numberReturned != null && numberReturned != count) {
LOGGER.log(Level.WARNING, "Feature Collection number returned does not match number of features created. Number Returned: " + numberReturned + ", Created: " + count);
}
featureCollection.setNumberReturned(count);
return count;
}
use of mil.nga.sf.geojson.Feature in project joa by sebastianfrey.
the class GeoPackageService method createFeature.
public Feature createFeature(FeatureRow featureRow) {
Feature feature = null;
GeoPackageGeometryData geometryData = featureRow.getGeometry();
if (geometryData != null && !geometryData.isEmpty()) {
feature = FeatureConverter.toFeature(geometryData.getGeometry());
feature.setProperties(new HashMap<>());
for (Map.Entry<String, ColumnValue> entry : featureRow.getAsMap()) {
ColumnValue value = entry.getValue();
String key = entry.getKey();
if (!key.equals(featureRow.getGeometryColumnName())) {
feature.getProperties().put(key, value.getValue());
}
}
feature.setId(String.valueOf(featureRow.getId()));
}
return feature;
}
Aggregations