Skip to content

Commit

Permalink
better error messages and inc version
Browse files Browse the repository at this point in the history
  • Loading branch information
samthiriot committed Apr 18, 2024
1 parent 126861d commit 9a75f5e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="ch.res_ear.samthiriot.knime.shapefilesaswkt.feature"
label="KNIME Spatial Processing Nodes"
version="1.3.8.qualifier"
version="1.3.9.qualifier"
provider-name="EIFER (European Institute for Energy Research)">

<description url="https://github.com/samthiriot/knime-shapefiles-as-WKT">
Expand Down Expand Up @@ -712,8 +712,6 @@ Public License instead of this License. But first, please read

<plugin
id="ch.res_ear.samthiriot.knime.shapefilesaswkt"
download-size="0"
install-size="0"
version="0.0.0"/>

</feature>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Automatic-Module-Name: ch.res.ear.samthiriot.knime.shapefilesaswkt
Bundle-Name: KNIME Spatial Processing Nodes
Bundle-SymbolicName: ch.res_ear.samthiriot.knime.shapefilesaswkt;singleton:=true
Bundle-Version: 1.3.8.qualifier
Bundle-Version: 1.3.9.qualifier
Bundle-ClassPath: .,
target/classes/,
lib/aircompressor-0.20.jar,
Expand Down Expand Up @@ -160,8 +160,7 @@ Require-Bundle: org.eclipse.core.resources,
org.knime.workbench;bundle-version="4.6.0",
org.junit,
org.json;bundle-version="20140107.0.0";visibility:=reexport,
org.knime.core,
org.eclipse.jface.notifications;bundle-version="0.5.200"
org.knime.core
Bundle-ActivationPolicy: lazy
Export-Package: ch.res_ear.samthiriot.knime.dialogs,
ch.res_ear.samthiriot.knime.shapefilesaswkt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,58 +420,71 @@ else if (maxValue * 1.001 < Double.MAX_VALUE)
exec.setProgress(0.3, "creation of the grid data");

// prepare the future data
final WritableRaster raster = RasterFactory.createBandedRaster(
WritableRaster raster = null;
try {
raster = RasterFactory.createBandedRaster(
typePrecise,
width, height,
bandsColIdx.length, null);
} catch (RuntimeException e) {
throw new RuntimeException("error when initializing a banded raster", e);
}

// set the default values (if necessary)
if (inputPopulation.size() < pixels) {
exec.setMessage("defining default value "+missingValue);
fillRasterWithDefault(exec, minX, minY, maxX, maxY, bandsColIdx, type, raster, missingValue);
try {
if (inputPopulation.size() < pixels) {
exec.setMessage("defining default value "+missingValue);
fillRasterWithDefault(exec, minX, minY, maxX, maxY, bandsColIdx, type, raster, missingValue);
}
exec.checkCanceled();
} catch (RuntimeException e) {
throw new RuntimeException("error when initializing default values", e);
}
exec.checkCanceled();


// read the data
exec.setProgress(0.4, "reading pixels");
itRow = inputPopulation.iterator();
while (itRow.hasNext()) {
DataRow row = itRow.next();
final int x = ((IntValue)row.getCell(idxColX)).getIntValue();
final int y = ((IntValue)row.getCell(idxColY)).getIntValue();

switch (type) {
case DataBuffer.TYPE_INT:
for (int b=0; b<bandsColIdx.length; b++) {
try {
raster.setSample(x, y, b, ((IntValue)row.getCell(bandsColIdx[b])).getIntValue());
} catch(ClassCastException e){
// unable to decode this, will store missing value
raster.setSample(x, y, b, missingValue.intValue());
exec.setProgress(0.4, "reading pixels");
try {
itRow = inputPopulation.iterator();
while (itRow.hasNext()) {
DataRow row = itRow.next();
final int x = ((IntValue)row.getCell(idxColX)).getIntValue();
final int y = ((IntValue)row.getCell(idxColY)).getIntValue();

switch (type) {
case DataBuffer.TYPE_INT:
for (int b=0; b<bandsColIdx.length; b++) {
try {
raster.setSample(x, y, b, ((IntValue)row.getCell(bandsColIdx[b])).getIntValue());
} catch(ClassCastException e){
// unable to decode this, will store missing value
raster.setSample(x, y, b, missingValue.intValue());
}
}
}
break;
case DataBuffer.TYPE_DOUBLE:
for (int b=0; b<bandsColIdx.length; b++) {
try {
raster.setSample(x, y, b, ((DoubleValue)row.getCell(bandsColIdx[b])).getDoubleValue());
} catch(ClassCastException e){
// unable to decode this, will store missing value
raster.setSample(x, y, b, missingValue.doubleValue());
break;
case DataBuffer.TYPE_DOUBLE:
for (int b=0; b<bandsColIdx.length; b++) {
try {
raster.setSample(x, y, b, ((DoubleValue)row.getCell(bandsColIdx[b])).getDoubleValue());
} catch(ClassCastException e){
// unable to decode this, will store missing value
raster.setSample(x, y, b, missingValue.doubleValue());
}
}
break;
default:
throw new RuntimeException("unsupported data type");
}
break;
default:
throw new RuntimeException("unsupported data type");
}

if (currentRow % 100 == 0) {
exec.setProgress(0.4 + 0.4*(double)currentRow / inputPopulation.size(), "reading pixels");
exec.checkCanceled();
}
currentRow++;
}
itRow.close();

if (currentRow % 100 == 0) {
exec.setProgress(0.4 + 0.4*(double)currentRow / inputPopulation.size(), "reading pixels");
exec.checkCanceled();
}
currentRow++;
}
itRow.close();
} catch (RuntimeException e) {
throw new RuntimeException("error when reading pixels", e);
}
exec.setProgress(0.8, "reading pixels");
exec.checkCanceled();

Expand Down Expand Up @@ -499,11 +512,17 @@ else if (maxValue * 1.001 < Double.MAX_VALUE)
}

// first create the image
GridCoverage2D gc = gcf.create(
GridCoverage2D gc = null;
try {
gc = gcf.create(
UUID.randomUUID().toString(),
raster,
referencedEnvelope
);
} catch (RuntimeException e) {
throw new RuntimeException("error when creating the raster", e);
}

// then render it with the missing value
RenderedImage img = null;
GridCoverage2D gc2 = null;
Expand All @@ -517,6 +536,8 @@ else if (maxValue * 1.001 < Double.MAX_VALUE)
null,
properties
);
} catch (RuntimeException e) {
throw new RuntimeException("error when creating the raster with properties", e);
} finally {
gc.dispose(true);
}
Expand Down Expand Up @@ -552,7 +573,6 @@ else if (maxValue * 1.001 < Double.MAX_VALUE)
}

final GeoTiffFormat format = new GeoTiffFormat();

final ParameterValueGroup params = format.getWriteParameters();
params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);

Expand All @@ -564,6 +584,8 @@ else if (maxValue * 1.001 < Double.MAX_VALUE)
writer.write(gc2,
(GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])
);
} catch (RuntimeException e) {
throw new RuntimeException("error when writing the raster into a file", e);
} finally {
writer.dispose();
gc.dispose(true);
Expand Down

0 comments on commit 9a75f5e

Please # to comment.