Help to import .asc file or .txt file (matrix) into NetLogo 6.2

348 views
Skip to first unread message

Rafaela Lorena

unread,
Apr 27, 2021, 7:17:59 PM4/27/21
to netlog...@googlegroups.com
Hi all,

How are you?

I am having difficulty importing matrix files into NetLogo 6.2and I hope someone in this group can help me.
I have a GIS file in .asc format. This file is a raster that contains NDVI (Normalized Difference Vegetation Index) values for a study area (bellow one example file in .asc).

ncols   3       
nrows   7       
xllcorner       0       
yllcorner       0       
cellsize        10     
NODATA_value    -9999   
0.44    0.44    0.44
0.46    0.44    0.42
0.48    0.44    0.41
0.42    0.41    0.41
0.38    0.37    0.4
0.39    0.37    0.39
0.39    0.38    0.39


I used the following code to import this .asc file into NetLogo 6.2 (bellow):

extensions [ gis ]

globals
 [
   L2_EVI02
 ]

to setup-evi
  ca
  set L2_EVI02 gis:load-dataset "C:/L2_EVI02.asc"
 end

However, when using inspect the patch, no NDVI value appears. Can someone help me understand why?

Therefore, as I was unable to import this .asc file into NetLogo 6.2. I thought about importing the file as a matrix. However, not every matrix I will know the column number and the row number. So, could someone suggest how I can do to import this matrix in NetLogo version 6.2?

Thanks all
Rafaela

Pradeesh Kumar K V

unread,
Apr 28, 2021, 11:59:49 AM4/28/21
to Rafaela Lorena, netlogo-users
Hello Rafaela,

My comments are based on the very nice GIS example provided under Extension Examples of the Models Library. The codes given below are taken from this example.

1. You may have to set the world envelope. See below code from the example 

; Load all of our datasets
  set cities-dataset gis:load-dataset "data/cities.shp"
  set rivers-dataset gis:load-dataset "data/rivers.shp"
  set countries-dataset gis:load-dataset "data/countries.shp"
  set elevation-dataset gis:load-dataset "data/world-elevation.asc"
  ; Set the world envelope to the union of all of our dataset's envelopes
  gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of cities-dataset)
                                                (gis:envelope-of rivers-dataset)
                                                (gis:envelope-of countries-dataset)
                                                (gis:envelope-of elevation-dataset))

2. To copy raster dataset into a patch variable you may have to perform apply-raster. See below code from the example:

to display-elevation-in-patches
  ; This is the preferred way of copying values from a raster dataset
  ; into a patch variable: in one step, using gis:apply-raster.
  gis:apply-raster elevation-dataset elevation
  ; Now, just to make sure it worked, we'll color each patch by its
  ; elevation value.
  let min-elevation gis:minimum-of elevation-dataset
  let max-elevation gis:maximum-of elevation-dataset
  ask patches
  [ ; note the use of the "<= 0 or >= 0" technique to filter out
    ; "not a number" values, as discussed in the documentation.
    if (elevation <= 0) or (elevation >= 0)
    [ set pcolor scale-color black elevation min-elevation max-elevation ] ]
end

Hope this helps,

Best,

Pradeesh

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/CAHs8kB9E2iHTjrkQ0XrOSrQjSpw0yrFK5fB0PnHJuakm4sLL2A%40mail.gmail.com.

Rafaela Lorena

unread,
Apr 30, 2021, 2:44:54 PM4/30/21
to Pradeesh Kumar K V, netlogo-users
Hi Pradeesh,

Thanks a lot! I will try this! 😊

Cheers
Rafaela
Reply all
Reply to author
Forward
0 new messages