Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access to values of a grid_file #187

Closed
benoitgaudou opened this issue May 30, 2024 · 1 comment
Closed

access to values of a grid_file #187

benoitgaudou opened this issue May 30, 2024 · 1 comment
Labels
About Data Data files, data exportation, databases 😱 Bug The issue reveals a bug in GAMA 👍 Fix to be tested

Comments

@benoitgaudou
Copy link
Contributor

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

  • to get something in grid_data.contents
  • having a matrix of float either in grid_data.contents as matrix or ``grid_data.contents as matrix`

Desktop (please complete the following information):

  • GAMA version: 1.9.3
@benoitgaudou benoitgaudou added 😱 Bug The issue reveals a bug in GAMA About Data Data files, data exportation, databases labels May 30, 2024
@lesquoyb lesquoyb removed this from GAMA 2024-11 Jun 14, 2024
AlexisDrogoul added a commit that referenced this issue Aug 31, 2024
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<float> of the values
- write grid_data as field will return the same values
@AlexisDrogoul
Copy link
Member

Fix has been coded in #305. Please test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
About Data Data files, data exportation, databases 😱 Bug The issue reveals a bug in GAMA 👍 Fix to be tested
Projects
Status: Done
Development

No branches or pull requests

3 participants