Skip to content

Commit

Permalink
Read STAC value type from raster:bands
Browse files Browse the repository at this point in the history
  • Loading branch information
inigo-cobian committed Feb 27, 2024
1 parent a3b3510 commit 23653ed
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.integratedmodelling.kim.api.IParameters;
import org.integratedmodelling.klab.api.data.IGeometry;
import org.integratedmodelling.klab.api.data.IResource;
Expand Down Expand Up @@ -61,7 +59,7 @@ public Builder validate(String urn, URL url, IParameters<String> userData, IMoni
JSONObject assets = STACCollectionParser.readAssets(catalogUrl, collectionId);
JSONObject asset = STACAssetMapParser.getAsset(assets, assetId);

Type type = null;
Type type = readRasterDataType(asset);
// Currently, only files:values is supported. If needed, the classification extension could be used too.
Map<String, Object> vals = STACAssetParser.getFileValues(asset);
if (!vals.isEmpty()) {
Expand All @@ -79,6 +77,23 @@ public Builder validate(String urn, URL url, IParameters<String> userData, IMoni
return builder;
}

private Type readRasterDataType(JSONObject asset) {
if (!asset.has("raster:bands")) {
return null;
}
if (asset.getJSONArray("raster:bands").isEmpty() || asset.getJSONArray("raster:bands").getJSONObject(0).has("data_type")) {
return null;
}
String type = asset.getJSONArray("raster:bands").getJSONObject(0).getString("data_type");
// https://github.com/stac-extensions/raster?tab=readme-ov-file#data-types
final Set<String> NUMERIC_DATA_TYPES = Set.of("int8", "int16", "int32", "int64", "uint8", "unit16", "uint32", "uint64", "float16", "float32", "float64");
if (NUMERIC_DATA_TYPES.contains(type)) {
return Type.NUMBER;
}
// The rest of possible values are either complex numbers or a generic "other"
return null;
}

private Type getCodelistType(Object value) {
if (value instanceof Number) {
return Type.NUMBER;
Expand Down

0 comments on commit 23653ed

Please sign in to comment.