From f99d18ca601f1db13e999c4e682712ebaa7091bd Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sat, 31 Aug 2024 10:24:51 +0700 Subject: [PATCH] Addresses #187 by correctly outputting a matrix from an asc file From now on (refer to the issue for context): - write grid_data.contents will return a geometry (the enclosing envelope) - write grid_data as matrix will return the matrix of the values - write grid_data as field will return the same values --- gama.core/src/gama/core/util/file/GamaGridFile.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gama.core/src/gama/core/util/file/GamaGridFile.java b/gama.core/src/gama/core/util/file/GamaGridFile.java index f49a3c3d68..3b00b7f07d 100644 --- a/gama.core/src/gama/core/util/file/GamaGridFile.java +++ b/gama.core/src/gama/core/util/file/GamaGridFile.java @@ -64,6 +64,7 @@ import gama.core.util.matrix.GamaField; import gama.core.util.matrix.GamaFloatMatrix; import gama.core.util.matrix.IField; +import gama.core.util.matrix.IMatrix; import gama.gaml.statements.Facets; import gama.gaml.types.GamaGeometryType; import gama.gaml.types.IType; @@ -353,7 +354,7 @@ private void customAscReader(final IScope scope) { ascInfo[2] = xCorner; } else if (yCorner == null && yCenter == null && line.contains("yllcorner")) { yCorner = doubleVal(line); - //TODO: very suspicious, probably xllcenter and yllcenter + // TODO: very suspicious, probably xllcenter and yllcenter } else if (xCorner == null && xCenter == null && line.contains("xllcorner")) { // AD To verify: the // conditions are // the same as two @@ -849,4 +850,11 @@ public double[] getBand(final IScope scope, final int index) { return Arrays.copyOf(records.bands.get(index), length(scope)); } + @Override + protected IMatrix _matrixValue(final IScope scope, final IType contentsType, final GamaPoint preferredSize, + final boolean copy) throws GamaRuntimeException { + getContents(scope); + return new GamaField(scope, this); + } + }