I'm not sure what I'm doing wrong here, I am trying to ingest and query a DEM raster file. I first converted it to a geotiff and the ingest seemed successful (I'm trying to do it all programmatically). The problem is I can't seem to query it afterwards - I get nothing in the returned iterator.
private void ingestUDem()
throws IOException {
final GDALGeoTiffReader reader = new GDALGeoTiffReader(new File(geoTiffPath));
GridCoverage2D coverage = reader.read(null);
reader.dispose();
final Map<String, String> metadata = new HashMap<String, String>();
final String[] mdNames = reader.getMetadataNames();
if ((mdNames != null) && (mdNames.length > 0)) {
for (final String mdName : mdNames) {
System.out.println(mdName + ":" + reader.getMetadataValue(mdName));
metadata.put(mdName, reader.getMetadataValue(mdName));
}
}
final RasterDataAdapter adapter = new RasterDataAdapter(coverageName, metadata, coverage);
try (IndexWriter writer = dataStore.createWriter(adapter, index)) {
writer.write(coverage);
}
System.out.println("Ingest complete.");
}
The geotiff has these properties:
cov env: GeneralEnvelope[(428000.0, 4512000.0), (430000.0, 4514000.0)]
cov ref: PROJCS["NAD_1983_2011_UTM_Zone_12N",
GEOGCS["GCS_NAD_1983_2011",
DATUM["NAD_1983_2011",
SPHEROID["GRS_1980", 6378137.0, 298.257222101]],
PRIMEM["Greenwich", 0.0],
UNIT["degree", 0.017453292519943295],
AXIS["Longitude", EAST],
AXIS["Latitude", NORTH]],
PROJECTION["Transverse_Mercator"],
PARAMETER["central_meridian", -111.0],
PARAMETER["latitude_of_origin", 0.0],
PARAMETER["scale_factor", 0.9996],
PARAMETER["false_easting", 500000.0],
PARAMETER["false_northing", 0.0],
UNIT["m", 1.0],
AXIS["x", EAST],
AXIS["y", NORTH]]
private void rasterQuery() {
final ByteArrayId bfAdId = new ByteArrayId(coverageName);
final RasterDataAdapter bfAdapter = (RasterDataAdapter) adapterStore.getAdapter(bfAdId);
System.out.println("adapter exists: " + adapterStore.adapterExists(bfAdId));
// Define the geometry to query. We'll find all points that fall inside
// that geometry
//final String queryPolygonDefinition = "POLYGON (( " + "-180 -90, " + "-180 90, " + "180 90, " + "180 -90, "
// + "-180 -90" + "))";
final String queryPolygonDefinition = "POLYGON (( " + "428000 4512000, " + "428000 4514000, " + "430000 4514000, " + "430000 4512000, "
+ "428000 4512000" + "))";
try {
final Geometry queryPolygon = new WKTReader(
JTSFactoryFinder.getGeometryFactory()).read(queryPolygonDefinition);
final QueryOptions options = new QueryOptions(
bfAdapter,
new SpatialIndexBuilder().createIndex());
int count = 0;
System.out.println("Performing Query");
try (final CloseableIterator<GridCoverage2D> iterator = dataStore.query(
options,
new SpatialQuery(
queryPolygon))) {
while (iterator.hasNext()) {
final GridCoverage2D sf = iterator.next();
System.out.println("Obtained coverage " + sf.getName().toString());
count++;
}
System.out.println("Should have obtained 1 features. -> " + (count));
} catch (IOException e) {
e.printStackTrace();
}
} catch (com.vividsolutions.jts.io.ParseException e) {
e.printStackTrace();
}
I tried using geographic coordinates for the query as well, but no dice. Any help would be great, thank you