I'm trying to import a raster grid to NetLogo but am encountering many issues. My raster file is only 57x41 pixels (I want each pixel here to represent a patch) and the world envelope is [-382875 -381135 700185 701445]. I am also trying to match my raster-dataset value to the patch variable fuel-code in a .csv file. However when I run the code (below) I encounter errors. I'm not using a set coordinate projection in netlogo since my original raster is not in an acceptable projection type for NetLogo (I removed the .prj file associated with the raster when importing the .asc file). Below is my code (with included error messages to the code I tried to edit):
extensions [ csv table gis]
globals [ fuel-type-40 fuel-code setrial1]
to dictionary-file ;put in the setup procedure
ca
;load the ascii file
set setrial1 gis:load-dataset "setrial_ascii.asc"
;match dimensions of raster to the dimensions of the Netlogo world
;I've tried each of the below codes independently, not together
resize-world 0 gis:width-of setrial1 0 gis:height-of setrial1 ;ERROR: Java Heap space error
gis:set-world-envelope gis:envelope-of setrial1 ;ERROR: can't modify a patch's coordinates
;below is visuals of width and height of setrial1
print gis:height-of setrial1 ;41
print gis:width-of setrial1 ;57
print envelope-of setrial1 ;[-382875 -381135 700185 701445]
; Load the csv
set fuel-type-40 but-first csv:from-file "fuel-type-40.csv"
;print fuel-type-40
; Pull first value (Fuel-code)
set fuel-code map first fuel-type-40
;print fuel-code
ask patches [
; Randomly set patch 'land cover' for this example. change for raster
gis:apply-raster setrial1 fuel-code
]
end
You might report which errors you are having. Remember to always read the stackoverflow guide to asking questions.
I'd suggest you to focus on using a rasterfile with all your data on it (ESRI files have a .dbf file which supports data), and thus avoid using both extensions. By having a raster file with a defined resolution (e.g. 100 x 100 m), the resize-world function should work smoothly. Try following my answer to this question.
Related
I have been trying to convert a set of GeoTIFF files into MBTiles using gdal_translate (GDAL 3.0.4). My command looks as follows:
gdal_translate -of MBTiles -ot Byte -strict -scale 0 255 bogota.tif bogota.mbtiles
The GeoTIFF image is successfully converted to MBTiles, and I am able to render it using QGIS. However, it appears that the result is somewhat compressed, or that the new image has lost some resolution. I have been experimenting with the -outsize option and trying to force it to 100% of the original size of the image, but with no success.
Is there a way to make sure that the result maintains the full resolution in the output?
Here are some screenshots to compare the results:
Before
After
Note: GeoTIFF image is taken from the following link:
https://download.osgeo.org/geotiff/samples/made_up/bogota.tif
Hello I need help to generate map file for GML file
here is my map file
MAP
IMAGETYPE PNG
EXTENT 359306.4 534654.0 362290.7 536664.3
SIZE 800 800
IMAGECOLOR 255 255 255
CONFIG "MS_ERRORFILE" "/var/log/map/ms_error.txt"
DEBUG 5
MAXSIZE 4096
LAYER
NAME "line"
TYPE LINE
STATUS ON
CONNECTIONTYPE OGR
CONNECTION "/var/www/maps/NY63NW.gml"
DUMP TRUE
MINSCALE 0
MAXSCALE 1000000
SYMBOLSCALE 1000
EXTENT 359306.4 534654.0 362290.7 536664.3
METADATA
gml_include_items "all"
wms_include_items "all"
END
CLASS
STYLE
COLOR 255 136 0
END
END
PROJECTION
"init=epsg:27700"
END
END
but image is blank when I load
http://localhost/cgi-bin/mapserv?map=/var/www/maps/polt.map&mode=map
Im new to mapserver and any help is welcome
With out access to the actual file or the error message in the log file it is almost impossible to answer this question. However, best practice is not to serve data directly from a GML file but to use ogr2ogr to convert it into a more efficient format. Ideally, this would be a database like PostGIS but if you need to keep with file formats something like GeoPackage will be much more efficient than GML.
I want to export to raster a NetLogo simulation output based on shp files, using:
to export-GIS
let patches_out nobody
ask one-of patches [set patches_out gis:patch-dataset pcolor]
gis:store-dataset patches_out (word "usos" ".asc")
end
but it outputs:
Extension exception: you must define a coordinate transformation before using any other GIS features
error while patch 17 -10 running GIS:PATCH-DATASET
called by procedure EXPORT-GIS
called by Button 'export-GIS'
How can this coordinate transformation be defined?
Solved the issue adding the following lines at the Setup phase:
set envelope gis:load-dataset "data/land.shp"
gis:set-world-envelope gis:envelope-of envelope
---- Update with what I got so far and what's left to resolve can be found in point 3 below ----
Using Octave I want to create 30 horizontal box and whisker plots without spread (x-axis) from 30 different GeoTIFF's. This is a sketch of how I would like the plot to look like:
Ideally the best solution for me would be an Octave code (workflow) that would allow me to place multiple GeoTIFFs in one directory and then with one click create a box and whisker plot for all GeotIFFs at once - just like the sketch above.
A GeoTIFF-sample with 3 GeoTIFF's can be downloaded here. The file looks like this in QGIS:
It holds elevation values on band 1 (the ones that each box and whisker plot should be based on, and no data values (-999), the no-data values should be excluded from the plot.
Right now this is what I got:
Using img = imread ("filname.tif") gets the file into Octave. Using hist (img(:), 200); shows that all cells are concentrated around 65300. imagesc (img, [65100 65600]) follwed by colorbar displays the image extent but's it's clear that this way simply doesn't import the real cell values. I can't find a working solution to import GeoTIFF's with cell values, therefor my current work-around is exporting the GeoTIFF from QGIS with gdal_translate -of aaigrid which creates a .asc-file that I manually edit to remove header rows, rename to .csv and load into Octave. That .csv can be found here.
To load it and create a box plot I'm currently using this code (thanks to #Andy and #Cris Luengo):
pkg load statistics
s = urlread ("https://drive.google.com/uc?export=download&id=1RzJ-EO0OXgfMmMRG8wiCBz-51RcwSM5h");
o = str2double (strsplit (s, ";"));
o(isnan (o)) = [];
boxplot (o)
set(gca,"xtick",[])
view([-90 90])
print out.png
The results is pretty close but I'm still failing to: A) load GeoTIFF's directly from a folder. If this is not possible I'm gonna have to modify the code to load all *.csv in a directory to the same box plot and label each plot by filename (which I'm unsure how to accomplish. B) to get the x-axis reversed (going from 200-450, not the other way around). This is caused by the view([-90 90]) that I use to make the box plot horizontal instead of vertical which is needed for layout reasons.
Anyone with any ideas on how to resolve the last adjustments?
---- Background info ----
I have 30 GeoTIFFs containing results from a viewshed analysis, for every 2x2 meter square there is a value the tells me how high a building can be (in meters) before it's visible from the viewshed point. The results cover the whole city of Stockholm but the above mentioned 30 GeoTIFFs are smaller clips of an area where new development is planned. The results help planners to understand how new development might effect each of the 30 places (that are important for cultural heritage management).
As part of a bigger PDF-report (where these results are visualized with different maps in different scales) I'm trying to produce a box and whisker plot (as a compliment to the maps) the gives the reader an overview over how much space is there is left at the planned development area, based on each of the 30 viewshed (GeoTIFF) results (one box and whisker for each of the 30 locations). Below is an example of how a map in the report can look like:
Does not directly read GeoTIFF but calls gdal_translate under the hood. Just place all your .tif in the same directory. Make sure gdal_translate is in your PATH:
pkg load statistics
clear all;
fns = glob ("*.tif");
for k=1:numel (fns)
ofn = tmpnam;
cmd = sprintf ('gdal_translate -of aaigrid "%s" "%s"', fns{k}, ofn);
[s, out] = system (cmd);
if (s != 0)
error ('calling gdal_translate failed with "%s"', out);
endif
fid = fopen (ofn, "r");
# read 6 headerlines
hdr = [];
for i=1:6
s = strsplit (fgetl (fid), " ");
hdr.(s{1}) = str2double (s{2});
endfor
d = dlmread (fid);
# check size against header
assert (size (d), [hdr.nrows hdr.ncols])
# set nodata to NA
d (d == hdr.NODATA_value) = NA;
raw{k} = d;
# create copy with existing values
raw_v{k} = d(! isna (d));
fclose (fid);
endfor
## generate plot
boxplot (raw_v)
set (gca, "xtick", 1:numel(fns),
"xticklabel", strrep (fns, ".tif", ""));
view ([-90 90])
zoom (0.95)
print ("out.png")
gives
I have a geotiff file which overlaps with a shapefile. To clip for the overlapping part of the tif file, I can do this:
gdalwarp -co compress=deflate -dstnodata 255 -cutline shapefile.shp original.tif overlap.tif
But how can I clip for the non-intersecting part? That is, I want to create the complement of "overlap.tif" w.r.t. "original.tif".
You can use gdal_rasterize to burn a value where the shapefile overlaps the file. It works on an existing file, so make sure you use a copy.
gdal_rasterize -burn 255 shapefile.shp copy_of_original.tif
This burns a value of 255, setting -a_nodata 255 doesnt work on my version of GDAL. If you need it to be a real nodata value using gdal_translate with -a_nodata 255 afterwards would do the trick.
Gdal_rasterize also has a convenient -i flag which inverts the shapefile.