gama-platform / gama

Main repository for developing the 2024+ versions of GAMA
https://gama-platform.org
GNU General Public License v3.0
11 stars 4 forks source link

access to values of a grid_file #187

Open benoitgaudou opened 1 month ago

benoitgaudou commented 1 month ago

Describe the bug with GAMA 1.9.3, I load an asc / tif file as a grid_file object. I would be interested to get its contents values, as a matrix of float for example. I tried:

global {
    //definiton of the file to import
    grid_file  grid_data <- grid_file('../includes/hab10.asc') ;

    //computation of the environment size from the geotiff file
    geometry shape <- envelope(grid_data);  

    reflex v {
        write grid_data.contents;
        write grid_data as matrix;  
        write (grid_data as field) as matrix;
    }
}

What I get: write grid_data.contents;. --> nil write grid_data as matrix; --> I get an Exception write (grid_data as field) as matrix; --> I get the expected result

The exception I get:

1 occurence in Simulation 0 at cycle 0: Java error: nil value detected
in Simulation 0
in write matrix<geometry>(grid_data) ;
NullPointerException: Cannot invoke "msi.gama.util.IAddressableContainer.matrixValue(msi.gama.runtime.IScope, msi.gaml.types.IType, msi.gama.metamodel.shape.GamaPoint, boolean)" because the return value of "msi.gama.util.file.GamaFile.getBuffer()" is null
msi.gama.util.file.GamaFile._matrixValue(GamaFile.java:565)
msi.gama.util.file.GamaFile.matrixValue(GamaFile.java:544)
msi.gama.util.file.GamaFile.matrixValue(GamaFile.java:538)
msi.gaml.types.GamaMatrixType.staticCast(GamaMatrixType.java:71)
msi.gaml.types.GamaMatrixType.cast(GamaMatrixType.java:85)
msi.gaml.types.GamaMatrixType.cast(GamaMatrixType.java:1)
msi.gaml.types.ParametricType.cast(ParametricType.java:160)
when applying the as operator on file('/Applications/Gama1.9.3.app/Contents/Eclipse/configuration/org.eclipse.osgi/21/0/.cp/models/Data/Data Importation/includes/hab10.asc') and matrix<geometry>
in write matrix<geometry>(grid_data) ;
in reflex v  {
    write grid_data.contents ;
    write matrix<geometry>(grid_data) ;
    write matrix<float>(field(grid_data)) ;
}

in agent Simulation 0

To Reproduce Steps to reproduce the behavior:

  1. Example in the Data Importaion model librayr.

Expected behavior

Desktop (please complete the following information):