Sampling points on raster layer with specific patterns - r

I new on using R with spatial data and I don't understand how to fix my issue.
My goal is to test differents pattern to make soil sample for quantifying soil organic carbon. I have a raster layer which represent the carbon stock with a grid of 1m*1m.
On this raster I want to randomly chose 20 points across the diagonal of the plot (which is rectangular). And I want each point separated by 20 meters.
Then I would like to repeat this operation a lot of times and each times I would like that each points move à litle bit in a certain range around the diagonal.
I'm trying with raster::select function but I don't understand the way it's work.
If you have any help to give me or just some good R package to do this I woul apreciate a lot !
Thank you,
Antoine

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

How to analyse spatial data using grid codes from a map

I would like to analyse movement data from a semi-captive animal population. We record their location every 5 mins using a location code which corresponds to a map of the reserve we have made ourselves. Each grid square represents 100 square meters, and has a letter and number to correspond with each grid square e.g. H5 or L6 (letters correlate with columns, whereas numbers correlate with rows.I would like to analyse differences in space use between three different periods of time, to answer questions such as do the animals move around more in certain periods, or are more restricted in their space use in other periods. Please can someone give me any indication of how to go about this? I have looked into spatial analysis in rstudio but haven't come across anything that doesn't use official maps or location co-ordinates. I've not done this type of analysis before so any help would be greatly appreciated! Thanks so much.

find out which sampling points are in the same geographical rectangle and extract this information

this is my first time asking a question here. I hope I arrive to formulate it precise enough.
I'm a marine biologist working with biological data sampled at different sites in the North Sea and the English Channel. My data constitute of the longitude and latitude of every sampling site as well a name / number of each sampling site arranged in columns.
The sampling area is devided in statisticle rectangles according to the CRS grid measuring one degree longitude and 0.5 degree latitude. I want to know which sampling sites are in the same statisticle rectangle and to extract this information as additional column in my dataset.
I tried to use the code provided here: https://gis.stackexchange.com/questions/210092/plotting-square-grids-on-a-map-and-extracting-each-grid-information-using-r
and to adapt it to my purpose, but I do not succeed. Basically I am stucked to create a grid that represents the grid of the world map zoomed in to my study region and with the grid cell size described above as a SpatialGrid object.
Can someone help me with this or has a different idea how to approach my objective?
Thank you very much and have a nice day!

A large amount of points to create separate polygons (ArcGIS/QGIS)

Visual example of the data
I used a drone to create a DOF of a small area. During the flight, it takes a photo every 20sh seconds (40sh meters of a flight). I have created a CSV file, which I transferred to a point shapefile. In total, I made with drone 10 so-called "missions", each with 100-200 points which are "shaped" as squares on the map. What I want now is to create a polygon shapefile from the point shapefile.
Because those points sometimes overlap, I cannot use the "Aggregate Points" task, as it's only distance-based. I want to make polygons automatically, using some kind of script. What could help is the fact that a maximum time between two points (AKA photos taken) is 10-20 seconds, so if the time distance is over 3 minutes, it's another "mission". Can you help with such a script, that would quickly and automatically create as many polygons as there are missions?
Okay, I think I understand what you are trying to accomplish. Since no one replied I am going to give it a quick shot, so you have something to try.
I think the best strategy would be to:
Clustering algorithm: Try running a Clustering algorithm such as DBSCAN around the timestamp dimension to classify them based on time groups, instead of the distance (since, as you said, distance based separation is not enough to properly identify and separate the points). After which, you should have all the points classified between different groups with a column group id. Maximum distance parameter in the algorithm should be around 20 seconds steps, or even a minute (since you said each mission was separated at least about 3 minutes apart).
Feature based Polygon to point: At that point, then you run your generic Polygon_from_points(...) function that transforms these clustered points to polygons shapes based on a specific discriminant feature (which in your case is going to be each group id).
How does this work?: This would properly separate the groups first (time-based) and then you should be able to find a generic point to polygon based on a feature (Arcgis should have some).
I dont have an example dataset, nor any code written, but based on what you described I think it would work, hope it helps.

Create stage height raster using least cost path and 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.

Resources