Determining the middle of a line using latitude and longitude - r

I have a large set of data with 7 stations along a river. During the collection of the data, samples were taken up and down a range of the river to get a representative idea of the environment. These aren't insignificant distances, the reaches can be over 50 miles over a curvy river. However, for the purposes of analysis, I've been asked to compress this data to a representative site in the middle of this reach using the latitude and longitude. This would be easy to do in GIS, but working with R I haven't been able to find a good method. I've tried taking the median of both the latitude and longitude and comparing them, but there's no overlap and I don't think that's a justifiable method. Is there a good package in R or a mathematical trick that I'm missing to find a median latitude, longitude pair?

Related

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!

Sampling points on raster layer with specific patterns

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

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.

Approaches for spatial geodesic latitude longitude clustering in R -- Follow-Up

Mine are follow-ups to the question & answer in Approaches for spatial geodesic latitude longitude clustering in R with geodesic or great circle distances.
I would like to better understand:
Question #1: If all the lat / long values are within the same city, is it necessary to use either fossil or distHaversine(...) to first calculate great circle distances ?
or, within a single city, is it OK to run clustering on the lat/long values themselves ?
Question #2: jlhoward suggests that :
It's worth noting that these methods require that all points must go into some cluster. If you just ask which points are close together, and allow that some cities don't go into any cluster, you get very different results.
In my case I would like to ask just ask "which points are close together", without forcing every point into a cluster. How can I do this ?
Question #3: To include one or two factor variables into the clustering (in addition to lat/long), is it as easy as including those factor variables in the df upon which the clustering is run ?
Please confirm.
Thanks!
"within a single city, is it OK to run clustering on the lat/long values themselves ?"
Yes, as long as your city is on the equator, where a degree of longitude is the same distance as a degree of latitude.
I'm standing very close to the north pole. One degree of longitude is 1/360 of the circumference of the circle round the pole from me. Someone ten degrees east of me might only be ten feet away. Someone one degree south of me is miles away. A clustering algorithm based on lat-long would think that guy miles away was closer to me than the guy I can wave to ten degrees east of me.
The solution for small areas to save having to compute great-circle ellipsoid distances is to project to a coordinate system that is near-enough cartesian so that you can use pythagoras' theorem for distance without too much error. Typically you would use a UTM zone transform, which is essentially a coordinate system that puts its equator through your study area.
The spTransform function in sp and rgdal will sort this out for you.

Calculating elevation using mathematical formula

Does anyone know how to calculate elevation using lattitude and longitude. By calculation I mean formula to calculate it manually. Other than using lattitude and longitude is there any other way to find elevation from any other parameters ?
EDIT 1
To be more specific regarding my above question other than using Elevation API provided by Google is there any way we could calculate elevation using any data from GPS of device.
Also Is it possible to calculate elevation from altitude..?
No, it is not possible to derive elevation from altitude or longitude or latitude or any combination of those things.
There are different ways to look at this problem, and I wouldn't say it is impossible.
If the surface elevation model is represented by an equation, such as with spherical harmonics, you could compute the elevation from this model, given a tuple of latitude and longitude.
You could also precompute the elevations on an appropriately sized grid and look up the values as is done in this answer.

Resources