Is there possible way of obtaining the quaternion from GPS data including latitude, longitude, altitude, and vehicle heading(yaw angle) or Any c++ libs to deal with this task.
Related
I'm new to using spatial data so this probably seems like a very simple question, but something I'm struggling to get my head around.
I have a global dataset of sample sites and corresponding coordinates. I am using st_buffer in the sf package to create buffers of different sizes around these points. However, I need these buffers to be in km, for example 2,10,50 km radius, rather than in the units of the CRS projection (currently in long/lat, WGS84). As I understand it, UTM is the only planar projection, but does this mean I have to split my global dataset into each of the UTM zones before converting to UTM, and then create the buffers for each of these separately?
Is it possible to then convert the buffers back to my previous CRS projection?
Thank you!
It is not necessary to step out of the comfort of WGS84 to do a metric buffer; most of the tools are ready to combine longlat CRS with a metric definition of distance (it is a very common use case).
When buffering in WGS84 I kind of prefer terra::buffer() to sf::st_buffer() as it is likely to produce a smoother shape - the S2 functions that work under the hood of unprojected {sf} do not work smooth enough for me and the outcome is somewhat grainy. But I digress...
Consider this piece of code, what it does is:
looks up the coordinates of a semi random landmark (Greenwich Observatory in London)
buffers it by 25 kilometers
displays the result
Note how the terra documentation states that the buffer is in meters for unprojected coordinates.
library(nominatimlite)
library(sf)
library(terra)
a_point <- geo_lite_sf("Royal Observatory, Greenwich")
st_crs(a_point) # WGS84
terra_buffer <- a_point |>
vect() |>
buffer(width = 25000) %>% # 25 kilometers
st_as_sf()
mapview::mapview(terra_buffer)
I have dowloaded data from the HRRR, similar to the grib2 file from this notebook:
https://nbviewer.org/github/microsoft/AIforEarthDataSets/blob/main/data/noaa-hrrr.ipynb
I now wish to use the data for specific Longitude, Latitude. But I do not know how to convert my (Longitude, Latitude) to the grid coordinates in the matrix data.
The notebook mentions that “the HRRR data comes in the Lambert conformal projection.” (See cell 8).
I have looked at the GMT package, and they seem to handle the Lambert conformal projection: https://docs.juliahub.com/GMT/EoU0j/0.30.1/proj_examples/.
But how can I convert the coordinates?
The following code seems to convert, but I don't think this is for Lambert, and after looking at the GMT documentation, I am not able to adjust the settings in the command.
lat=37.0; lon=-119.0;
gmt("mapproject -J+proj=merc", [lat;lon])
Vector{GMTdataset} with 1 segments
First segment DATA
Global BoundingBox: [-1.3247019404399555e7, 4.118821159351122e6]
First seg BoundingBox: [-1.3247019404399555e7, 4.118821159351122e6]
2×1 Matrix{Float64}:
4.118821159351122e6
-1.3247019404399555e7
I found out that the longitude and latitude were actually in the grib file, so there is no need to convert:
using GRIB
f = GribFile(grb2_filename)
lons, lats, values = data(Message(f))
# lons in range [225.90452026573686, 299.0828072281622] = [-134.09547973426314, -60.91719277183779]
# lats in range [21.138123000000018, 52.61565330680793]
So we can just look for the indexes of the closest longitude and latitude, and read the corresponding value in values.
Since lat and lon degree both approximate to 110 kilometers, I will just minimize the distance as follows:
(min_error, coord) = findmin(abs.(lats .- lat) .+ abs.(lons .- 360 .- lon))
(0.020456228700048484, CartesianIndex(269, 548))
values[coord]
294.8936767578125
While this actually does not answer the title question, it answers my current need and perhaps will be useful for someone else.
I have a set of coordinates that I want to turn into an angle and do some Anova analysis. I used maptools trackAzimuth function to do it, but I keep losing one or two points. I assume it calculates angles between two coordinates. But I want 1 point (angle) on 1 latitude and longitude, for example at [-80.222, 30.555 to 45]. Since my longitude is in North America, it is in a negative value, do we have to convert into positive before converting it into angle? Please enlighten me on this. Following is my data;
Longitude Latitude
-104.952 39.71478
-104.952 39.7149
-104.54 39.7148
-104.955 39.70441
-104.966 39.7175
My codes:
setwd("C:/Users/data")
install.packages("maptools")
library(maptools)
data <- read.table("data.csv", header = T, sep = ",")
dfr<-data.frame(data[3:4])
angle<-data.frame(trackAzimuth(as.matrix(dfr)))
My results is:
Angle
-81.001
-95.57075
-175.254
-32.628
Here, I lost 1 latitude and longitude. And my angles are negative, I want positive angles on this. How do I do it? Please help.
Thanks
I have what may be a very simplistic question on the KEST function in Spatstat.KEST graph output I'm using the KEST function in Spatstat to assess spatial randomness in a dataset. I have uploaded lat and long values spread over London and converted them to a PPP object, using the ripras function to specify the spatial domain. When I run my KEST analysis on my ppp, and plot the graph, I end up with an r value on the x, but although I know this is a distance measurement, I don't know what units it's using. I get this summary output:
Planar point pattern: 113 points
Average intensity 407.9378 points per square unit
Coordinates are given to 9 decimal places
Window: polygonal boundary
single connected closed polygon with 14 vertices
enclosing rectangle: [-0.5532963, 0.3519148] x [51.2901, 51.7022] units
Window area = 0.277003 square units
with the max r on the x axis being 0.1 units, and the K(r) on the y axis being 0.04. How do I figure out what unit of distance these equate to?
Your lat,lon coordinates correspond to points on a sphere (or ellipsoid or whatever) used as a model for planet Earth. Essentially, spatstat assumes you are using coordinates projected on a flat map. This conversion could be done with e.g. the sp package (using Buckingham Palace as an example):
library(sp)
lat = c(51.501476)
lon = c(-0.140634)
xy = data.frame(lon, lat)
coordinates(xy) <- c("lon", "lat")
proj4string(xy) <- CRS("+proj=longlat +datum=WGS84")
NE <- spTransform(xy, CRS("+proj=utm +zone=30 ellps=WGS84"))
NE <- as.data.frame(NE)
The result is a data.frame with projected coordinates in Easting, Northing in metres. Then you can continue your analysis from there. To assign a unit label like "m" for prettier labels in figures use the function unitname on your ppp object (assuming the object is called X): unitname(X) <- "m"
If the function is able to accept geographic coordinates, then it is using a great circle equation to calculate distance. This normally results in units that are in Kilometers.
It is not very good practice to perform PPA on non-projected data. If possible, you should project your data into a coordinate system that is in distance units. I believe that most of the functions in spatstat use Euclidean distance, which is quite inappropriate for projection units in decimal degrees. Since there is not a latlong argument in the Kest function, I do not believe that your results are valid.
The K function itself (i.e. the theoretical K-function, not just the computer code) assumes that the space is flat rather than curved.
This would probably be a reasonable approximation in your case (points scattered over a few dozen kilometres) but not for a point pattern scattered over a continent. That is, in general the planar K-function should not be used for point patterns on a sphere.
The other posts are correct. The Kest function expects the coordinates to be given in an isometric coordinate system. You just need to express the spatial locations in a coordinate system in which the x and y coordinates are measured in the same distance units. Longitude and latitude are not measured in the same distance units because one degree (say) of longitude does not represent the same distance as one degree of latitude. Ege Rubak's example using spTransform is probably the best way to go.
I have mapinfo file and spatial type is point. I want to know longitude and latitude but in this file not include field to specific describe to longitude and latitude.
the CRS is WGS 84/UTM zone 50s (EPSG:32750). I have to export the file (.tab) using ogr but the result is not like a longitude and latitude.
this is the result:
POINT (238339.99924633466 9640080.0006718487)
POINT (238540.00219973351 9640080.0006718487)
POINT (238559.99837215125 9640080.0006718487)
POINT (238580.0027904133 9640080.0006718487)
If I want to get the longitude & latitude from this file is posible?how can?
You will have to run those points through a conversion to get a "normal" (cartesian) latitude and longitude coordinates from them. OSGeo.org has several libraries available to convert these points and translate them to global latitude and longitude points. FreeGIS.org also has a list of tools that you can sort by language. I believe that "Geo" people prefer to use longitude, latitude when describing points.
POINT( longitude latitude )