The result by haversine formula is meter o kmeter? - formula

I use the haversine formula to calculate the distance among the points. The result of this formula is in meter or in kmeter?
http://en.wikipedia.org/wiki/Haversine_formula
Anyone can help me?

Haversine formula is used for finding distance between to points, if latitude and longitude for both points are known.
Formula:
ACOS(SIN(Lat1)*SIN(Lat2) +COS(Lat1)*COS(Lat2)*COS(Lon2-Lon1)) *6371
Excel formula:
=ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371
Note:
Replace 6371 with 3958.756 if you want the answer in miles.
For further detail:
http://bluemm.blogspot.in/2007/01/excel-formula-to-calculate-distance.html

Related

Calculating the cosine of latitude as weights for reanalysis data in r

I am currently trying to calculate "weighted" spatial daily values for pressure using era5 data. This is due to the size of the area being represented differently towards the poles relative to lower-latitude regions. I am a little confused though. Should I multiply each value with the cosine of its latitude? So pressure * (cos(latitude)). The idea is then to apply PCA to the field. Thanks in advance!

How to code great circle distances into glmmtmb mixed effect model?

I am trying to run a mixed effect model using the 'glmmtmb' package with a spatial covariance structure that accounts for distances between points on a sphere. I have dug into the source code and identified where I think they calculate the Euclidean distances for the spatial covariance structure. I know euclidean distances are used based on this website:
https://cran.r-project.org/web/packages/glmmTMB/vignettes/covstruct.html
By bringing up the source code:
trace(getReStruc, edit = T)
Line 44 is where they use the dist(coords) for that distance matrix.
I want to change that = code so that it calculates great circle distances instead of Euclidean ones. However, functions such as distHaversine() from the 'geosphere' packages require 4 arguments (lat of x1, long of x1, lat of x2, long of x2) so I can't just plug in:
geosphere::distHaversine(coords)
Does anyone have a work around for doing this? Any help would be really appreciated!

Variogram in R with distance in km

I'm doing a spatial analysis on my data and I have their localization in terms of longitude and latitude. I calculated the sample variogram in R with geoR and gstat but what I get is the sample variogram with the distance in grades (longitude and latitude). I would like to have the same information but with the distance in km, like what happens when I calculate the spatio-temporal variogram with variogramST (gstat).
Thank you very much for those who are going to answer, it would help me a lot!
You get that with gstat if you specify for your dataset that the coordinates are degrees latitude longitude, e.g. in case you use sp, with proj4string(x) = "+proj=longlat". "distances in degrees" do not exist, they are plane wrong (except on the equator).

r - DBSCAN (Density Based Clustering) describe unit of measure for eps

I was trying to use the dbscan package in R to try to cluster some spatial data. The dbscan::dbscan function takes eps and minpts as input. I have a dataframe with two columns longitude and latitude expressed in degree decimals like in the following:
df <- data.frame(lon = c(seq(1,5,1), seq(1,5,1)),
lat = c(1.1,3.1,1.2,4.1,2.1,2.2,3.2,2.4,1.4,5.1))
and I apply the algorithm:
db <- fpc::dbscan(df, eps = 1, MinPts = 2)
will eps here be defined in degrees or in some other unit ? I'm really trying to understand in which unit this maximum distance eps value is expressed so any help is appreciated
Never use the fpc package, always use dbscan::dbscan instead.
If you have latitude and longitude, you need to choose an appropriate distance function such as Haversine.
The default distance function, Euclidean, ignores the spherical nature of earth. The eps value then is a mixture of degrees latitude and longitude, but these do not correspond to uniform distances! One degree east at the equator is much farther than one degree east in Vancouver.
Even then, you need to pay attention to units. One implementation of Haversine may yield radians, another one meters, and of course someone crazy will work in miles.
Unfortunately, as far as I can tell, none of the R implementations can accelerate Haversine distance. So it may be much faster to cluster the data in ELKI instead (you need to add an index yourself though).
If your data is small enough, you can however use a precomputed distance matrix (dist object) in R. But that will take O(n²) time and memory, so it is not very scalable.

Haversine formula

My question is about Haversine formula as arcsin x = arctan x/(sqrt(1-x^2), therefore the formula should have atan x and not atan2 x when we convert the formula from arcsin to arctan.
θ = 2 arcsin(sqrt(a)) = 2 arctan(sqrt(a)/(sqrt(1-a)))
But in most of the previews answers has an extra 2 after atan.
Can anyone explain it to me please. Thanks
atan(x) is the same as atan2(x,1). atan2(y,x) is the angle of the point (x,y), while atan(y/x) is the angle of the line through the origin and (x,y).
The only inverse trigonometric function present as FPU on x86 CPU/FPUinstruction is FPATAN which implements atan2. Thus also asin(x) is implemented as atan2(x,sqrt(1-x*x)), acos(x) as atan2(sqrt(1-x*x),x).

Resources