Say we have a route.shp from ESRI/ArcGIS origin representing the path or route of a hike or a stream, and a corresponding topographic raster file in a dem.tif with matching spatial coordinate system and projection info.
How can we quickly print both the map view and elevation profile in one static or ideally dynamic image? This is a classic view in navigation/outdoor/fitness apps (eg, Strava, or simplified below static image and more detailed below), of say a trip a user went on.
Ideal products would be both a ggplot2-like style w/ 1 column by 2 row plot.png (like below), and a plot.html with an interactive slider tool that scrolls simultaneously through map location and elevation (and ignore the red/green gradient in the profile). I'm looking more for convenience of plotly R than doing aShiny page, so more "off the shelf" than highly customizable, but I understand it seems a tall order to do concisely in open source environment?
library(rgdal)
library(raster)
library(tiff)
#other libraries?
route <- readOGR(".", "route")
topofile <- "dem.tif"
Related
I am working on a Shiny application where I am required to plot positions of ships on a map. Currently I am using leaflet and the OpenSeaMap as the base layer on which I am plotting the positions (addProviderTiles(providers$OpenSeaMap)). However, when the map is rendered the various cities and ports appear in the local language as shown below:
That's not very useful as the users are mostly English speaking. Is there any way in changing the tiles to display only English names? I have already had a look at this. I am restricted to using the OpenSeaMap tiles only because of the traffic separation schemes displayed in those tiles.
If you have to stick to OpenSeaMap tiles then no, you can't change the language of the labels. Unfortunately these Labels are part of the raster images, they are not a separate layer.
However OpenSeaMap is composed of a base layer and a seamark layer (https://tiles.openseamap.org/seamark/). The base layer containing the map, city labels and so on is the OSM standard style and can be replaced by any other layer. So you can use a tile server with English labels plus the seamark layer on top of it.
If this is not a solution for you then how about adding an additional layer with English labels? So your users can at least switch to a layer with labels they can read, browse to the area they want to view, then switch back to OpenSeaMap tiles to see sea marks. Not a nice solution but it works.
I would like to use ggmap to plot several data points on top of a koppen-geiger climate map.
The kopper-geiger data and GIS/KMZ maps can be downloaded here:
http://koeppen-geiger.vu-wien.ac.at/present.htm
I've managed to have a code to plot the points on regular maps, obtained through the get_map function but I fail to use other maps such as koppen-geiger.
Any help will be appreaciated!
Your basic problem is that the map you are attmepting to use is an image file that is not georeferenced. So unless you want to go through the unnecessary and probably time consuming process of georeferencing this image yourself, you will be better taking an alternative approach. There are perhaps a few ways to do this. But, unless you have very few data points to overlay on the map which you can place manually using the lat-long grid of the image, then the least painful method will certainly be to redraw the map yourself using the shapefile.
This is not the right place to give you an introductory lesson on GIS, but the basic steps are to
Download shapefile (which is available at the same website as the image you linked)
Project map to desired coordinate system
Plot map, coloring by climate class
Color the ocean layer
Add labels, legend, and graticule, as desired
Overplot with your own climate data, and legend for these.
If you are unsure how to approach any of these steps, then take an introductory course on GIS, and search the Web for instructional materials. You may find this resource useful.
https://cran.r-project.org/doc/contrib/intro-spatial-rl.pdf
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.
I have the following SpatialPolygonsDataFrame.
require(raster)
usa <- getData('GADM', country='USA', level=2)
metro <- subset(usa, NAME_1=="Nebraska" & NAME_2 %in% c("Dodge","Douglas","Sarpy","Washington"))
plot(metro)
I would like to be able to replicate the following map boundaries (defined by the colors):
Does anyone know a good plan of attack? I realize this is a somewhat manual process. I have already downloaded all US Census files that are of a more detailed geography. I was hoping that a more detailed level of geography could be aggregated to answer the above question, but unfortunately the districts do not line up the same.
Is there a R function already out there that would be helpful in assisting this manual process? At the very minimum, I would like to be able to leverage the perimeter of the 4-county area.
Use writeOGR from the rgdal package to create a shapefile of your metro object. Then install QGIS (http://www.qgis.org/), a free and open-source GIS, and load the shapefile as a new layer.
Then you can edit the layer, add new polygons, edit lines etc, then save as a shapefile to read back into R.
Additionally, you may be able to "georeference" your image (by identifying known lat-long points on the image) and load that into QGIS as a raster layer. That makes it easier to digitise your new areas. All you need for that is a few lat-long coordinates of specific points, such as the corners of polygons or line intersections, and then QGIS has a georeferencing plugin that can do it.
I don't think you'll find any R code as suitable for digitising new geometries over an image as good as QGIS.
After half an hour (and twenty years experience, not all of which you'll need) I've got this:
I didn't precisely digitise your new boundaries though, just roughly for speed. That QGIS screen cap shows the five coloured areas under the four metro areas.
Step one was georeferencing. This screengrab shows how the PNG has been georeferenced - the red line is the metro area shapefile drawn with transparency over the PNG after the PNG has been converted to a GeoTIFF by matching control points.
Step two was then using QGIS editing tools to split, join, and create new polygons. Then I just coloured them and added labelling to pretty it up.
I could probably bundle these files all up for you to neaten, but it really doesn't take that long and you'll learn a lot from doing it. Also, this is probably a gis.stackexchange.com question...
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.