Java or scala, GeoTools or GeoTrellis, how to convert sentinel 2 data to Multiband geotif - raster

I am trying to process Sentinel 2 data from (example)
http://sentinel-s2-l1c.s3-website.eu-central-1.amazonaws.com/#tiles/10/S/EG/2016/10/12/0/
The jp2 files are not georeferenced, and I need to put all the jp2 files as bands in a geotif. I have googled aplenty and find no way to do this in Java or Scala.
I am pretty familiar with Geotools, i've done a lot of geotif processing with geotools, but I can't figure out how to
a. Make a geotif raster out of a jp2 file (given coords for the envelope), and
b. take those and make a multiband geotif out of them
I am decent with Scala, so I've looked at geotrellis, but don't see a solution with that either.
Does anyone know how to make geotifs out of JP2 files (given a polygon) and then make a multiband geotif?
thanks

I've never tried this, but, I would break the problem down to:
Import JP2 image
GeoReference the image
For each band in the image data, convert to GeoTiff
Step 1 will need you to make sure that you have the JP2K plugin, that page also gives some sample code showing how to use it.
Step 2 should just be a case of building a GridCoverage using a GridCoverageFactory - see the user guide for an example (I am assuming you know where the bounds of the grid are and it's projection etc).
Step 3 is a simple CoverageWriter, there is an example here.

Related

How to turn a spatial plot in R into an ArcGIS layer

So I hope I can clearly communicate my issue. Since I'm fairly new to R and ArcGIS I may miss some obvious things.
Basically, I'm using R to process spatial data to make a canopy height model and detect tree tops. That parts fine. I then make a watershed segment plot using forestTools package, and visually it looks great, but how do I export that as a file I can add into ArcGIS?
I'll copy some of the code that goes into what I'm discussing.
Basically, I just followed this guide's supplemental material to get the tree detection https://www.degruyter.com/document/doi/10.1515/geo-2020-0290/html?lang=en.
With that done, I then used the forestTools package to creat an interesting segmentation polygon grid on the map. https://www.rdocumentation.org/packages/ForestTools/versions/0.2.5/topics/mcws
This is quickly the plotting code to get visualized what I want.
[1]: https://i.stack.imgur.com/7Y0EF.png
This is what the map looks like with those plotted.
[2]: https://i.stack.imgur.com/Kdfl6.png
The layer that I want to bring solo to ArcGIS is that last plot the mcws one. I'll show a pic of that as well here.
[3]: https://i.stack.imgur.com/3PKfk.png
Is there a way that I can export that as a .shp or .tif?
Any help would be wonderful and much appreciated!
Nvmd I figured it out.
What you have to do is use the Raster package to export a shapefile.
raster::shapefile(site2_ttops,"Products/site2plot_ttops.shp")

Converting rectangular pixels to square pixels in R

I'm working with an asc file in R and trying to run it through some GIS processing on a script that was written by someone else. The current chunk of code I'm working on is
asc <- (raster(inputRas))
asc.extent <- extent(asc)
head <- read.ascii.grid.header(inputRas)
writeRaster(asc, "outputRas", format="SAGA", overwrite=TRUE)
which works until the last line. It's failing here because my raster is in rectangular coordinates, which SAGA doesn't like. I've spent a lot of time googling and trying different functions, but nothing has worked that didn't cause other problems down the line. I considered using projectRaster() for a while because the resolution can be changed within it, but I don't actually want to change the projection. Any help would be appreciated, thanks.
Instead of raster::projectRaster, you can use raster::resample

Is it possible to import a raster of a PDF file?

Our office does scanning of data entry forms, and we lack any proprietary software that is able to do automated double-entry (primary entry is done by hand, of course). We are hoping to provide a tool for researchers to highlight regions on forms and use scanned versions to determine what participant entry was.
To do this, all I need for a very rough attempt is a file to read in PDFs as raster files, with coordinates as X, Y components, and B&W white "intensities" as a Z-axis.
We use R mainly for statistical analysis and data management, so options in R would be great.
You could use the raster package from R. However, it doesnt support .pdf files, but .tif,.jpg,.png (among many others).
But coverting your pdfs into pngs shouldn't be a big problem: Look here for more information.
Once you have your png files ready, you can do the following:
png <- raster("your/png/file.png")
and then use the extract() function to get your brigthness value from the picture. I.e. let's say your png is 200x200px and you want to extract a pixel value from row 100 and column 150:
value <- extract(png, c(150,100))

Successive pictures on R

I have a code to plot a world map with a meteorological field for one moment (or one measure).
Is it possible to successively plot the map for different moments (for i from 1 to 125) in order to view a sort of video when we run the code?
Yes, look at the animation package.
It can creates an animated gif for you (as well as other tricks). There are live examples you can look at as eg Buffon's needle, a CLT demo and much more.
The package abstracts away some of the OS-dependent layers. If you know the basics, you can of course just call the corresponding tool from the imagemagick project which is likely to be available on OS of choice too.

SVGAnnotation to create tool tips for each value in R heatmaps

I'd like to create a heat map in R that I want to use on a website. I stumbled upon the SVGAnnotation package which seems to be very nice to process SVG graphics in R to make them more interactive. First, I was planning to add tool tips for each cell in the heatmap - if the user hovers over the cell, the value of this cell should pop up. However, I am fighting with SVGAnnotation for more than 3 hours now, reading and trying things, and I can't get it to work.
I would appreciate any help on the SVGAnnotation tool tip function. But I would also very much appreciate alternatives to SVGAnnotation to add some activity to my R SVG heatmap.
So, what I have got so far looks like this:
library(SVGAnnotation)
data(mtcars)
cars <- as.matrix(mtcars)
map <- svgPlot(heatmap(cars))
addToolTips(map, ...) # problem
saveXML(map, "cars.svg")
My problem is the addToolTips function itself, I guess. Intuitively, I would simply insert the data matrix, i.e., cars, but this does not work and R gets stuck (it's calculating, but doesn't return anything, I waited 50 minutes)
EDIT:
After some more online research, I found a good example of what I want to achieve: http://online.wsj.com/article/SB125993225142676615.html#articleTabs=interactive
This heat map looks really great, and the interactive features (tool tips) work very well. I am wondering how they did that. To me, it looks like the graphic was done in R using the ggplot package.
I wrote a command line tool that can do exactly that if you are still interested to add tool tips to your heat map. It runs in Windows/Linux/MacOS terminals. All you need as input is the heat map as svg file and the data table/matrix that you used as input to create your heat map as csv or other text file.

Resources