I am trying to apply an ascii (241 rows, 463 columns) to netlogo using the following code:
set my-dataset "data/my-folder/my-file.asc"
resize-world 0 gis:width-of (gis:load-dataset my-dataset) - 1 0 gis:height-of (gis:load-dataset my-dataset) - 1
gis:set-world-envelope-ds (gis:envelope-of (gis:load-dataset my-dataset))
gis:apply-raster (gis:load-dataset my-dataset) my-variable
In the resize-world command, I added the -1 since netlogo starts at 0, while gis:width-of starts at 1.The result is a netlogo world with min-pycor 0 max-pycor 240 and min-pxcor 0 max-pxcor 462 (a 241x463 world), which matches the size of my ascii perfectly. The gis-world envelop command makes sure that the extent is similar for the ascii en the Netlogo world. I checked this, and again it matches perfectly.
The problem I am facing is that although the netlogo rows and columns match the ascii rows and columns, the applied ascii is displaced by 1 in the y direction. The top row of the netlogo world is filled with zero's, while the top row of my ascii is filled with high values.
FIGURE: top row is red, showing 0 values, where they should not be 0.
Does anybody know what the problem is? Or how to correctly apply the ascii to the netlogo world so that one ascii value fills the corresponding netlogo patch?
Maybe additional to this: can I stop netlogo from automatically resampling, so that I know for sure that the values in netlogo are the same as those in my ascii.
Thank you for your help
More info:
ascii header
NCOLS 463
NROWS 241
XLLCORNER 2.54710299910375
YLLCORNER 49.4941766658013
CELLSIZE 0.00833333333339921
NODATA_value -9999
netlogo envelope:
show gis:world-envelope
observer: [2.5471029991037497 6.405436332467584 49.49417666580129 51.502509999150504]
my-file envelope:
show gis:envelope-of gis:load-dataset my-dataset
observer: [2.54710299910375 6.405436332467584 49.4941766658013 51.502509999150504]
Note that there is a slight rounding difference, which I just cannot erase no matter how I code the world-envelope. In any case, considering that it is such a tiny difference I don't think this is the problem.
edit: I checked what actually happened by exporting the netlogo values to a raster, and comparing them in ArcGIS. It is not a simple problem of resampling. Actually, the top row just has missing values, without shifting values. Furthermore, the middle column and row duplicate, causing everything to shift outwards from the middle towards the bottom and right. I added a simple illustration, hoping that this would clarify the problem.
I investigated it further, and I think the error originates in the code behind apply-raster similar to the problem here.
I analyzed the java code of the apply raster on github, and it seems to refer to the worlds min-pxcor and min-pycor while doing something with the gis extent. As the real edge coordinates are not similar to the patch center coordinates, this might be causing the problem? I am not a java expert though, it might be something to investigate further (and I might be wrong..).
Anyway, to get my ascii to apply nicely to my world (which was set to the size of the ascii), I now run the following code:
file-open "data/my-folder/my-file.asc"
let temp []
while [file-at-end? = false][repeat 6 [let header file-read-line] ; skip header
set temp lput file-read temp
]
file-close
(foreach sort patches temp
[ ask ?1 [ set my-variable ?2 ] ] )
Related
I'm using GDAL.rasterize to rasterize a simple shapefile of points. The shapefile points simply consists of Xco-ord, Yco-ord and an integer data value. Everything about the output file is fine except for a single row containing only No_data inserted mysteriously by the process about 3/4 way down the raster and hence all subsequent rows below that then appear misaligned by 100m southward. but data exists in shapefile for that anomalous row ?
I have tried creating other formats instead of TIFF, such as EHDr, but they all turn out the same
So, thinking it was memory related I tried reducing he extent
if I reduce the extent to only rasterise below the line of the inserted null row , the resultant output is still offset
if I reduce the extent to only rasterise above the row of the inserted null data , the resultant output is fine for that portion as it is when I do the whole extent
I took a thin sliver of the extent reducing the number of cols but keeping the rows, same thing occurred
so I don't think its memory related any longer
the output raster is a simple 6256 cols by 12361 rows tiff in 100mx100m grid
Extent is 45080,670080,4355,1240255 CRS is EPSG: 27700
this is the Gdal .rasterise switches I used
gdal_rasterize -l !fileOUT! -a OP_DATAFIELD -tr 100.0 100.0 -a_nodata -9999 -te 44780.0 4155.0 670380.0 1240255.0 -ot Int16 C:\WorkingMDT\!SHPfileIN!.shp C:\WorkingMDT\!fileOUT!.tiff
What I need to happen is a raster without the anomalous row 3/4 way down it that is offsetting all subsequent rows,
what's causing that anomalous row to be inserted ?
now I can manually correct this by converting to .asc and editing out the anomaly row but id rather find the programmatical cause
all help and consideration much appreciated. Here is a picture of the issue Green is the raster created, blue crosses the original data points, the row of no_data that has been inserted and the subsequent downward shift can be clearly seenenter image description here
When importing rasters into NetLogo, there is an additional row or column of NaN cells that are added along one of the borders of the NetLogo world, which does not exist in the raster.
Is this the same issue that was raised here: https://github.com/NetLogo/GIS-Extension/issues/5 ? In my case though, they are not random cells that have a value of NaN but cells along a border.
EDIT: Here's the code I used to import the raster layer:
set rasterLayer gis:load-dataset "x.asc"
resize-world 0 gis:width-of rasterLayer 0 gis:height-of rasterLayer
gis:set-world-envelope gis:envelope-of rasterLayer
gis: apply-raster rasterLayer
Thanks a lot Seth this comment from the thread you shared solves the mystery:
'the netlogo world starts at 0, while the gis:width-of an ascii starts at 1.'
So I think subtracting 1 while setting the width and height of the NetLogo world would help.
In ArcGIS I created a shapefile using the fishnet tool, where polygons are squares and have a string attribute and an integer attribute. I want to import the fishnet to Netlogo so that it is one to one (one GIS feature to one patch).
The NetLogo world is set to have the same dimensions as the fishnet:
resize-world 0 94 0 104
For attributes I'm using the gis:apply-coverage command with max threshold 100 and min threshold 0. The patches look as expected and all attributes are coming across as expected, apart from (patch 0 0) which is the origin at the bottom left. The orgin patch is holding NaN for both strings and integers:
Why is this patch not holding the same values as all other 'empty' patches?
To set the transformation I tried using the projection file
gis:load-coordinate-system "data/fishnet.prj"
Using the envelope
let fishnet-dataset gis:load-dataset "data/fishnet.shp" ; polygonal (squares)
gis:set-world-envelope gis:envelope-of fishnet-dataset
and hard-coding
gis:set-transformation (list -15.08 -7.48 4.35 12.75) (list 0 94 0 104)
the problem occurs in all of the above options.
EDIT:
Using gis:fill and inspecting (patch 0 2) and (patch 2 0):
I am newbie in bash programming. My problem is the following:
I have a trajectory file in xyz extension, out of a molecular dynamics calculation. In this file there are, more or less, 2000 blocks of coordinates. Each block of coordinate start with the number of atoms and end with the same number of atoms reported, e.g. of a block:
352 (starting point first block)
i = 0,
...
...
352 (ending point first block/starting point second block)
i = 10,
...
...
352
out of this file, I would like to be able to grep some of the blocks/configurations along the all trajectory file, at a fix ratio, lets say, every 10 configurations ( so that in the end I have 200 sampled structures from the beginning to the end of the trajectory file).
I thought, but again, I am not an expert, to use a for loop like:
for i in .xyz
do (grep "352
\n.*some_pattern.*
\n.*352");
done
The point is that I have no idea on 1st how to tell the script to grep the block and 2nd to extract the blocks every 10 configurations.
Can you kindly help me?
P.S. while for the first point I think after sometime I will be able to fix it, the second is the most annoying.
I am using the gis extension in netlogo. I got stuck in this point:
Using the primitive gis:property-value
The line of code looks like this:
gis:set-drawing-color scale-color red (gis:property-value ? "POPULATION") 5000000 1000
I do not know what population and 5000000 1000 means , I mean I assign that name (population) and values (5000000 1000) or they are values that are already written in the .shp file.
"POPULATION" refers to something that already exists in the .shp file. I imagine it would show up if you browsed the contents of the file using standard GIS tools.
As for 5000000 1000, these are inputs to the scale-color primitive, to translate a range of population values to a range of shades of red. See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#scale-color , and see also the Scale-color Example model in the Code Examples section of NetLogo's Models Library.
The number 500000 was apparently chosen by the model author based on their prior knowledge of the range of population values they expect to appear in the input file.
according to gis-extension manual gis:property-value is used like gis:property-value VectorFeature property-name to with this small peace of code, I guess your in a foreach loop. The ? is the shp ID in the loop for the "POPULATION" column and 5000000 1000 seem to be the value for this polygon!