R plot background map from Geotiff with ggplot2
Date : March 29 2020, 07:55 AM
may help you . With the R base plot, I can plot any geotiff with the following command: , Here is an alternative using function gplot from rasterVis package. library(rasterVis)
library(ggplot2)
setwd("C:/download") # same folder as the ZIP-File
map <- raster("smr25musterdaten/SMR_25/SMR_25KGRS_508dpi_LZW/SMR25_LV03_KGRS_Mosaic.tif")
gplot(map, maxpixels = 5e5) +
geom_tile(aes(fill = value)) +
facet_wrap(~ variable) +
scale_fill_gradient(low = 'white', high = 'black') +
coord_equal()
coltab <- colortable(map)
coltab <- coltab[(unique(map))+1]
gplot(map, maxpixels=5e5) +
geom_tile(aes(fill = value)) +
facet_wrap(~ variable) +
scale_fill_gradientn(colours=coltab, guide=FALSE) +
coord_equal()
|
how to plot geotiff data in python by imshow
Date : March 29 2020, 07:55 AM
Does that help In case you still needed a clean solution to this question, I believe what you are looking for is a masked array from numpy.ma like: import gdal
import numpy as np
from mayavi import mlab
ds = gdal.Open('data.tif')
dem = ds.ReadAsArray()
msk = dem==-9999 # boolean array with True at elements to be masked
dem = np.ma.array(data=dem, mask=msk, fill_value=np.nan)
gt = ds.GetGeoTransform()
ds = None
mlab.imshow(dem)
mlab.colorbar()
mlab.show()
|
plot LAT/LON coordinates on geotiff in R
Date : March 29 2020, 07:55 AM
this one helps. Geo-sp's solution would work, but is sub-optimal (slow and imprecise). You should always (re-)project your vector (points in this case) data and not your raster data. Projecting raster data changes values, while this is not the case with vector data. Projecting raster data is also much more computationally intensive. Thus, you should do something like this: library(raster)
r <- raster("asi-AMSR2-n6250-20150101-v5.tif")
crs(r)
# CRS arguments:
# +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
df <- data.frame(longitude = rep(22,7), latitude = seq(60,90,5), ID=1:7)
spdf <- SpatialPointsDataFrame(coords = df[,1:2], data = df,
proj4string = CRS("+proj=longlat +datum=WGS84"))
library(rgdal)
p <- spTransform(spdf, crs(r))
extract(r, p)
spdf <- SpatialPointsDataFrame(coords = xy, data = mydf, proj4string =
CRS("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m"))
|
Octave: Box and whisker plot without spread from GeoTIFF
Date : March 29 2020, 07:55 AM
seems to work fine 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")
|
Writing Multiple GeoTiff File in R
Tag : r , By : clifton anderson
Date : March 29 2020, 07:55 AM
|