multiple-polygonal for clip area - google-earth-engine

How do I use the multiple-polygonal of dust's sources in a wide area at google earth engine? (This polygon is separate and unmatched) The program runs but does not output the error occurred:
A region must be a GeoJSON Polygon or LinearRing. Got: 'GeometryCollection'.
I cannot use from box around area, because that area is big

From what i understand of your question you are trying to clip an image using multiple polygons in a same object. If that is the case, then it should not be an issue. You can clip the image with your multiple-polygons as follows
image = image.clip(multigeometry);
However, I assume that you are getting your error during exporting the clipped image. If this is the case then you probably got the error because u used the multi-geometry in "region" argument in the Export function. This is because the export REQUIRES you to have a polygon or linearRing to get the extents of your raster. So you need to use the box in this case. However, the exported image will have the pixels you clipped out as masked pixels.
If you would like to have a different image for different polygons then you could iterate through the polygons to create a clipped raster for each polygon and then export them.

Related

Edge detection on stars raster in R with cropped raster

I have a stars raster object called raster. I am trying to run edge detection on it like:
image(rot90c(edge.detect(raster[[1]], thresh1=1, thresh2=80, noise="gaussian", noise.s=3, method="Canny")))
This works fine, but when I try to crop the raster against an sf object other_object using:
image(rot90c(edge.detect(st_crop(raster,other_object)[[1]], thresh1=1, thresh2=80, noise="gaussian", noise.s=3, method="Canny")))
I get errors due to NAs. Is there any way to create a cropped raster such that the edge detection method doesn't throw an error due to missing regions from the image?

How to fill map boundaries with external images?

I am creating a map of Brazil with its state boundaries, which is straight forward to achieve using ggplot2 and geom_sf.
However, this time around, instead of color filling each state with data, I want to fill each state's boundaries with an external image (png), similar to this example of the largest employer in each state.
I have tried a few settings of geom_image and even geom_flag to no avail (hence why I am not posting any code here).
Are there any suggestions on how to approach this problem?
You can try cartography::getPngLayer/pngLayer. These two functions takes a png as input, geotag and crop it to the shape of a given polygon and creates a rasterbrick object (as a tile) that you can manipulate and plot:
https://dieghernan.github.io/cartographyvignette#png-layer

How to create interactive online map with contour (filled) plot layer?

I would like to create an online interactive map with filled contour plot layer like the ones can be seen on openweathermaps (I would like to use my own data for the plots).
What I need is also similar to the Leaflet heatmap (heatmap.js) but without dynamically changing the colors and the extent of the graphical objects (as in case of heatmap.js). Let's call them static heat maps.
I would like to know which mapping code/library can be used to produce such maps.
I am really newbie to these things, so please bear with me.
I tried Leaflet but did not find any plugin which would create filled contour map layers (static heatmap). I created the following map with Leaflet where the rectangles are geojson polylines and the color is based on some assigned values to every rectangle (elevation)
my leaflet attempt
The problem with this approach is that if higher resolution (smaller and more rectangles) is needed the site would really slow down.
I checked OpenLayers but did not see any similar examples.
I have the data in a matrix format:
Lat; Long; Value
.
.
Values are given in every gridpoints.
(if needed I would convert into other formats, like in case of the above attempt into geojson format)
The data is static, would be saved on the server.
So what I basically want to accomplish is a site where some spatial data is represented as filled contour map (static heatmap) and it is plotted over a map.
Here is my solution to the problem using open-source programs and free, online service:
(1) Processing the data in a GIS program. I used QGIS. I interpolated my data which is in grid points to get a high resolution raster map.
(2) Save the post-processed raster map as a georeferenced *.tif image.
(3) Import the image into TileMill. Remove the basemap and keep only the image as the only layer (style it).
(4) Export the 'map' from TileMill as MBTiles. This will save numerous *.png files (tiles) corresponding to different zoom levels. These are the same type as google or openstreetmap use for their online maps.
(5) Create a free account at Mapbox and create a new map project. Upload the MBTiles created by TileMill (can be directly uploaded from it). Style it.
(6) Use the Map ID corresponding to your created project to embed the map into html sites, e.g. the javascript code:
// Provide your access token
L.mapbox.accessToken = 'Mapbox will generate this for you';
// Create a map in the div #map
var map = L.mapbox.map('map', 'username.mapid', {
minZoom: 5,
maxZoom: 10
}).setView([47, 20], 8);
Example hosted on Mapbox
Sample image(I do not how long will the above link live):
In retrospect, the question would have been better fit to GIS stack exchange.

Defining polygon coordinates with a predefined image and plotting in R

Here is what I need: I have an image and want to plot on specific rectangle-shaped parts of it (e.g., imagine having a picture of a chessboard and wanting to fill every square with a different color). I would like to be able to easily specify the coordinates for these parts and take these coordinates into R for plotting.
I don't have any experience with making such plots. I've thought of simply inserting an image into a plot with rasterImage (), then plotting with polygon (), but the task of setting up the coordinates for the polygon function seemed too time consuming - hence the question above.
If you have any better ideas than using a set of coordinates for the polygon function, please share. Any leads or packages suggestions would also be helpful.
thank you. Marko.

using ggplot's "annotation_raster" and reached R's "memory ceiling"

I am using R to create a floorplan of a house with several layers like below, starting from the bottom layer:
basemap: a scanned version of the floorplan which I put it at the bottom layer to aid the reading
bed: the house have several dozens of beds, scattered in different rooms of the house, they have different colours based on the characteristics of the residents
piechart: each bed has a piechart of top of it, again the piecharts are created based on the residents' other set of characteristics, some beds have piecharts, some don't.
The bed and piechart were created based on the shp file created based on the basemap (i.e. I use Mapwindow the create a vector layer, import the basemap as raster layer and put it at the bottom, then draw the beds one by one. The bed shp file is then imported into R, the bed polygons' centroid are calculated and that centroid helps to position the piecharts)
I used read.jpeg to import the basemap to imagematrix object, then use the new annotation_raster function in ggplot2 0.9 to put the basemap at the bottom map layer, since the bed layer is created based on the basemap also, the bed layer superimpose on the basemap layer perfectly in ggplot2.
I can create the map without problem - if the basemap is small enough (3000 x 3000 pixels), now I have a basemap of 8000+ x 3000+ pixels (object.size 241823624 bytes), I did not aware of the R memory issue when I was creating the shp file, the ggplot object can be compiled if I have the annotation_raster disabled, but R keeps saying that I can allocate memory with xxxMB when I try to include the basemap into the ggplot object.
I think this is nothing to do with the compression of the jpg files, as the dimension is not changed even I further compress the jpg file. But I can't resize the jpg file as my bed layer is created based on the original jpg file's dimension.
Can anyone help to shrink the size of the basemap's imagematrix, without changing the jpeg's dimension, or some other tricks to deal the R's memory limitation? Thanks.
I fixed it.
I first created a new basemap image file with width and height halved, then in the annotation_raster I did the following:
chart <- chart + annotation_raster(db$temp.basemap,
xmin=0,
xmax=basemap.xlength*2, # I stretched the image in R
ymin=0,
ymax=basemap.ylength*2) # I stretched the image in R
Now the map can be compiled within R's memory limit, the drawback I can think of is the reduce in image quality, but that is bearable, as it was 8000 x 3000 originally.

Resources