Create stage height raster using least cost path and r - r

I have a point shapefile of Station IDs and stageheights. I would like to create a raster where each cell has the stage height value (in meters) of the closest in situ station to that cell.
I want this raster to match up with another raster. So I would like it if I could input both a raster I have created (dataset 3 described below) and my point shapefile (1).
Datasets:
1) Point Shapefile with stage heights of a river delta
2) Shapefile of the river delta extent
3) Raster of the delta where NA's represent land (could also have them be zero's if need be) and 1's are water. Two datasets 10 meter resolution and 30 meter resolution.
One conceptual issue I am having is with the amount of small streams I have.
For example (pictured in image below), station 1 (circled in blue) is technically closer to the black x region than station 2 (circled in red), but the stage height value in red is more representative of point x. There are NA's in between the two streams, does that mean that the value will not jump across streams?
How can I reassign the values in my Raster (all the 1's) to the stage height of the nearest station and make sure that these values are not jumping from stream to stream? Do I need to use least cost path? What is the best way to do this?
I would like to use R, but can use ArcMap if I must.

So I'm not sure what tools you have available to you but I think this answer may be useful:
Calculating attribute for network distance between multiple points in ArcGIS Desktop?
Here the questioner was looking to calculate distances on roads to some points, but your problem seems similar. I think the main point I would make here is that you should do your network distance classification prior to worrying about the raster layer. You may have to convert from polygon to lines or some workaround to get your data into a format that works, but this is the kind of job the tool is designed to do.
After you have reclassified your river shapefile based on their network distance to a given point, then convert the polygons to raster and use this to classify your original raster. You could do this in R or Arcmap. Arcmap will probably be faster.

Related

Lost data within a spatial polygon

Hopefully the following makes sense and apologies if not!
I have a dataset of GPS locations (of various species footprints), and am measuring the distance from where each point was found to the boundary of a national park in R. Im doing this with a series of environmental factors, (roads/villages/lakes etc), and for all other enviro variables (and kml files) Ive had no problems, however when I run my park boundary data, (using a kml file read in as a spatial polygon of the national park), I keep getting negative values for all the GPS points that occur within the park boundary? (So anything within the polygon essentially). The results output I am getting shows the correct measurements from GPS points to the boundary that occur on the OUTSIDE of the boundary, (or polygon), but anything inside the park/polygon outputs as a zero value. Ive tried to reproject the polygon as just an outline and tried removing the 'fill' etc, along with a few other tricks Ive found, but no luck so far?
Am I correct in assuming the data is just not there and that I need to recreate the boarder of the park some other way? Or is it more an issue with how Im asking r to calculate the distance measurements?
Below is an example of the code I am using
KSNP_Poly <- readOGR("KSNPboundaryexport.kml")
Points <- read.csv("AllPoints.csv")
sptsPoints = SpatialPoints(Points)
plot(KSNP_Poly)
plot(sptsPoints)
apply(gDistance(sptsPoints,KSNP_Poly,byid=TRUE),2,min)
KSNPResults <- apply(gDistance(sptsPoints,KSNP_Poly,byid=TRUE),2,min)
Hope this made sense and any advice greatly appreciated!
Thanks!
Kass

Mapping how many points are within a radius of every location in R

In R, I am trying to create a choropleth map. I have built a database of businesses, some are part of chains (e.g. McDonalds) and others are independent. I want to calculate how many businesses are within 30km of each point on the map, but treat the different locations of chains as a single business.
For example, if you a point is:
5km from a McDonalds,
10km from Taco Bell
15km from Chick-Fil-A
20km from KFC
25km from McDonalds
35km from Five Guys
The colour will show that there are 4 fast food outlets within 30km.
I am happy to use any R package but I am mostly familiar with tmaps and ggplot2 maps.
At this stage the best approach I can think of is to create polygons for each chain and stack them as transparent layers of the same colour. I don't think this would be very efficient and wouldn't create a very nice looking choropleth.
The other answers I could find were either counting points (e.g https://gis.stackexchange.com/questions/229066/counting-how-many-times-a-point-is-inside-a-set-of-intersecting-polygons-in-r) or for GIS software.
EDIT:
I have managed to create a 30km radius from every location of every chain (using rgeos gIntersection). I now have a series of polygons.
To solve my question the additional thing I need to do is create polygons for where:
Only one polygon covers the area,
Two polygons covers the area,
etc.
To try to visual is this I used the answer from https://gis.stackexchange.com/questions/229066/counting-how-many-times-a-point-is-inside-a-set-of-intersecting-polygons-in-r
In the linked question they are trying to count how many polygons cover the numbered points (the image on the right). What I am trying to do is to create the image on the left, where there are polygons of no overlap (1), two overlapping polygons (2) and so on.
I think what you are trying to accomplish would be best approached using a raster approach rather than a chloropleth. To make a chorlopleth, you define a set of (generally irregular) polygons, summarize something within each polygon, then color the polygons based on the attributes. This would be a good approach if you wanted to say how many fast food resteraunts are within each state or county, or how many fast food joints per capita by state.
From your description, however, you are looking for how many fast food joints within a set radius for all points. This is more of a raster question, since you can represent your data on a regular grid.
The raster package is a good start for working with raster data and works well with the sf package.
You need to determine what density you need to accomplish your goal, then use this to determine the resolution of your raster. Once you've got that you can use raster::rasterize() to summarize your (I'm assuming) point data.
I'm assuming you have an object that has the locations of each restaurant, I'll call this object "points".
library(raster)
library(sf)
# create raster template with 30km resolution (I'm assuming your projection is in meters)
raster_template = raster((extent(points),
resolution = 30000,
crs = st_crs(points)
)
# rasterize your point data
r = rasterize(points, raster_template, fun = "count")
This should create a grid where each cell has the number of points within each 30km cell. You should then be able to plot the raster, but may want to either clip or mask it to just show parts that are within New Zealand

Calculating the percentage of the area that a polygon covers a cell in a raster in QGIS

I'm having trouble with using QGIS.
I have a GRIB file containing meteorlogical data, this is loaded in QGIS as rasterdata if I'm not mistaken.
I also have a shape-file containing a polygon, describing regions within the area covered in the GRIB file.
What I need to know, is how many % of a raster-cell is covered by a region within the polygon. I'm using QGIS.
What I have done so far, is I rasterized the polygon, and used zonal statistics to calculate the SUM and COUNT on the shape-file, and then used the field calculator to calculate the percentage covered. This does not seem to provide the result I hoped for.
Can anyone push me in the right direction?

Using point coordinates and diameter to calculate areal projection of points

I have data on a number of ecological variables associated with spatial points. Each point has x & y coordinates relative to the bounding box, however the points represent circular areas of varying diameter. What I'm trying to achieve is to project the area occupied by each point onto the observation window so that we can subsequently pixellate the area and retrieve the extent of overlap of the area of each point with each pixel (grid cell). In the past I have been able to achieve this with transect data by converting to a psp line object and then using the pixellate function in the spatstat package but am unsure how to proceed with these circular areas. It feels like I should be using polygon classes but again I am unsure how to define them. Any suggestion would be greatly appreciated.
In the spatstat package, the function discs will take locations (x,y) and radii r (or diameters, areas etc) and generate either polygonal or pixel-mask representations of the circles, and return them either as separate objects or as a single combined object.

Vector GIS Data line-of-sight?

I have a situation where I'm only concerned with a few vector layers and two-dimensional line-of-sight. I know that line-of-sight is usually performed on raster data because the typical use is topography. Because that wording is vague and close to useless here's my situation:
I have a polygon shoreline vector shapefile, a "source" point placed in the water somewhere, and a "buffer" polygon layer that represents a large radius circle around the "source" point. I'm only interested in the parts of the buffer polygon that are "within sight" of the source point. In the image below the red dot is the source, the orange polygon is the buffer clipped with the shoreline, and the yellow polygon is what I'm interested in. Even this isn't as fine as I'd like.
Image: http://i.stack.imgur.com/IKBLv.png
I want to automate the process I use now (fairly time-consuming) and would prefer to use python/numpy/scipy/OGR/GRASS instead of ESRI's stuff.
Any idea how to trace along the line and check for "visibility"? I could rasterize everything and use a traditional radial line-of-sight script within GRASS but that seems like way dealing with too much data held in memory and running checks for pixels we know wouldn't produce a collision for the intersection of a few vectors. I want to be as light as possible while maintaining the highest accuracy possible.
How about considering (iteratively) the line between your point and each point in the shoreline shapefile? If it intersects the "land" polygon (crosses over land), then that point on shore is not visible. Take all the points that are visible, and use them to form a new polygon of the visible area.

Resources