I'm writing a macro in VBA excel. I have two sorts of data types:
WGS84 coordinates
Lambert72 coordinates
The Lambert72 coordinates are more accurate then the WGS84 coordinates. I have to find which WGS84 coordinate is the closest to the lambert72 coordinate (for each lambert72 coordinate) OR which Lambert72 coordinate is the closest to the WGS84 coordinate (for eacht WGS84 coordinate)
So i have to convert the wgs84 to lambert72 format, or vice versa. Someone who has a formula for this? On the internet I found some online converters, but I didn't find any formula.
And then I have to find a method to find the distance between two wgs84 coordinates or two lambert72 coordinates. For lambert72 i know how to do this, these are normally in meter, and is easy to calculate. But wgs84 are in degrees and I am not used to work with these.
Thank you in advance!
The formulas are a bit complicated, but this is what used to construct an excel sheet for those conversions: IGN - Services géodésiques
Exploring these pages you'll find the informations needed (web pages and PDF).
In short, this is the path to follow:
[BD72 datum] Lambert 72 coordinates
-> [BD72 datum] Geographic coordinates (Lat, Lon) (in decimal degrees)
-> [BD72 datum] Geocentric coordinates (X,Y,Z)
-> [WGS84 datum] Geocentric coordinates (X,Y,Z)
-> [WGS84 datum] Geographic coordinates (Lat, Lon) (in decimal degrees)
-> [WGS84 datum] Geographic coordinates (Lat, Lon) (in sexagesimal degrees)
(i.e. "GPS")
(in reverse order to find Lambert 72 coordinates)
Related
I'm trying to associate a set of points (lat, long) to an edge using osmnx library in Python.
I would like to find the nearest points to an edge within a distance x.
I have an edge and I would like to draw a circle and count how many points are into the circle, with a given radius. I have tha lat and long coordinates of each point but I don't know how to calculate the lat, long coordinate of the edge. I also have the coordinates lat, long of the nodes connected by that edge.
Thank you for your help.
import pandas as pd
from shapely.ops import transform
from functools import partial
import pyproj
from shapely.geometry import Point
mid_point = Point(lon,lat) # UNPROJECTED CO-ORDINATES OF MID-POINT OF AN EDGE
node_point = Point(lon_node, lat_node)# UNPROJECTED CO-ORDINATES OF THE NODE
x = 500 #DISTANCE IN METERS
#TRANSFORM INTO PROJECTED CO-ORDINATES
project = partial(pyproj.transform,pyproj.Proj(init='epsg:4326'),pyproj.Proj(init='epsg:3112'))
mid_point_projected = transform(project, mid_point)
node_point_projected = transform(project, node_point)
#CREATE BUFFER CIRCLE WITH DISTANCE X METRES WITH CENTRE AT EDGE MID-POINT
buffer_circle = mid_point_projected.buffer(x)
#PERFORM POINT-IN-POLYGON ANALYSIS TO CHECK WHETHER THE NODE FALLS WITHIN THE BUFFER CIRCLE
print(buffer_circle.contains(node_point_projected))
POINTS TO BE NOTED:
EPSG Geodetic Parameter Dataset is a structured dataset of Coordinate Reference Systems and Coordinate Transformations, accessible through this online registry (www.epsg-registry.org)
EPSG 4326 represents World Geodetic System (WGS84) (https://epsg.io/4326)(points on the Earth's surface represented in terms of latitude and longitude)
I have transformed it into EPSG 3112 representing GDA94 / Geoscience Australia Lambert (https://epsg.io/3112). You should transform it into the corresponding EPSG code for your study area.
I have a set of GPS coordinates 12.9611159,77.6362214. What exactly do these mean? How can I convert them to degrees of longitude and latitude? What formula should I use to get accurate distance between two sets of coordinates when the order of distance is 10km.
Most likely 12.9611159 is the latitude in degrees, 77.6362214 the longitude. In that case, the coordinate is in India. If latitude and longitude are reversed, you end up in the Greenland Sea.
You can easily check this by entering the coordinate pair in the Google maps search box. Google expects latitude first.
For the distance, in python you can easily use the haversine package:
from haversine import haversine
my_coord = (12.9611159,77.6362214)
other_coord = (12.9, 77.6)
distance = haversine(my_coord, other_coord)
This will give you the distance in km.
I create a polygon where each x/y point is WGS84 format
lat/long values.
The polygons are good approximations to circles and sectors of
radius R (each circumference/arc point is a projected lat/long
value of distance R from a centre/apex coordinate - which I have
verified is correct by computing the Haversine distance between
the edge and reference points and getting a value of R back) .
I use GEOSSetSRID(4326) to indicate the coords are WGS84 format.
GEOSGetSRID() confirms the SRID is set.
Use of GEOSArea then gives a value not even remotely close to
the expected value.
I do not see what else I can programmatically do.
If I set the points in cartesian format, and then set the SRID to
4326, will GEOS implicitly convert the polygon points to WGS84 ??
Is the basic GEOS C API incapable of doing the above ??
Dos SRID have no meaning to the API at all ??
Any info/pointers to correct usage/solutions would be much appreciated.
TIA.
The distance that is given is something like degrees between the two points. In actuality, the GEOS API (at least the C++ interface) is units agnostic; the units it gives the distance in is based on whatever you passed in.
In general, multiplying the result you get by 111000 gives you a fairly accurate measurement in meters. For area, you have to do 111000^2.
I am trying to figure out if a latitude/longitude point is contained within a polygon defined by vertexes that represent points on the earth (also lat/lon's, in clockwise order). This is trivial for polygons that can be mapped to the 2D lat/lon space.
Where this becomes increasingly difficult is circle's (now switching back to 3D) that may go from pole to pole covering half the earth. The translation to lat/lon looks like a sine wave. The 2D point in polygon test no longer applies to this case. Is there an algorithm that exists that solves this problem?
================== Clarifications on comments below: ===================
The polygon is defined as (lon, lat) pairs in degrees, i.e., (60, 90), (60, 110), (-30, 110), (-30, 90).
I do have code that implements the ray casting algorithm, and that works. however, certain polygons on the surface of the earth do not translate to closed polygons in the 2D space.
As stated by denniston.t, if you are only interested in circles, and you have a radius, you can simply check if the Great Circle Distance between the center point and the point is less than the radius. To find the great circle distance you typically use the Haversine Formula. The following is my implementation in python:
from math import radians, sin, cos, asin, sqrt
def haversine(point1, point2):
"""Gives the distance between two points on earth.
The haversine formula, given two sets of latitude and longitude,
returns the distance along the surface of the earth in miles,
ignoring potential changes in elevation. The points must be in
decimal degrees.
"""
earth_radius_miles = 3956
lat1, lon1 = (radians(coord) for coord in point1)
lat2, lon2 = (radians(coord) for coord in point2)
dlat, dlon = (lat2 - lat1, lon2 - lon1)
a = sin(dlat/2.0)**2 + cos(lat1) * cos(lat2) * sin(dlon/2.0)**2
great_circle_distance = 2 * asin(min(1,sqrt(a)))
d = earth_radius_miles * great_circle_distance
return d
If you have the center point and radius of your circle drawn on the surface of the sphere, calculate the Great-circle distance between the center point and target point. If it's less than the radius of the circle, the target point lies in the circle.
This will not generalize to arbitrary polygons drawn on your sphere, but you only asked about circles, so I don't know if it matters to you.
containsLocation(point:LatLng, polygon:Polygon)
Greetings,
I have two coordinates:
(52.4412396, -6.563223)
and
(52.8912397, -6.683669)
The delta is:
(-0.4499999, 0.120446)
The distance moved is:
sqrt((-0.4499999)^2+(0.120446)^2)
=.465840261
How do I convert this to meters?!
I hope someone can help.
Many thanks in advance,
You have mistakenly done the sum of squares on spherical coordinates. Each difference has to be converted to its longitudinal and latitudinal distance before getting the hypotenuse. While latitude converts directly to distance, (each degree is equal to 60 nautical miles) the longitude will only do that at the equator) That means that you have to multiply the above by the cosine of the latitude. Then you can move on to a simple hypotenuse calculation before converting to meters.