I am interested in finding Lat/Long coordinates of two points (A and B). If I have one GeoJSON reference point A (e.g., x,y) and B is a defined distance d (e.g., 10 meters) away from A, is it possible to determine the GeoJSON (Lat/Long) coordinates for B, such that B = (x,y)+d?
Check here to see example image
Related
I have a collection of Points (lat, long for a collection of buildings) and I want to group them based on whether they are within x meters of each other. I know that I could do this pairwise by first using Geopandas buffer() function (with x/2 meter radius) and then using sjoin(). However, I don't want to just do this pairwise. I want to group all buildings whose buffer region (the lat, long as the center and the buffer being a circle of radius x/2 meters) overlaps with ANY OTHER buffer region.
For example, if I have three buildings (denoted A, B and C), with each building 25 meters from its neighbor and I use a 25 meter buffer, then A and B can be grouped with sjoin() and B and C can be grouped, but I would want all THREE to be grouped.
That's in contrast to the case where A and B are 25 meters apart and C is 50 meters from B. In that case, I would want to be able to group A and B together and C in its own group.
In reality, I have potentially 100 or more buildings, so it isn't possible to run all permutations pairwise. I would need a function that groups multiple buildings whenever the building's buffer circle intersects with any other buffer circle.
Is there a simple way to do this with Geopandas?
Thank you for your responses. I wound up doing the following:
buffered each building's lat/long Point by a set distance, in meters (** see note below **)
determined the geopandas.unary_union of all of the buffers to get a multi-polygon (list of polygons)
wrote a custom function to identify which polygon in the list intersects with a specific buildings Point (using geopandas's .intersection), and called that list index the "location group"
used panda's apply with the above function to get the "location group" that each building belonged to
used panda's groupby to sum the values based on the "location group"
For the above, I had to be a bit careful about edge cases where the intersection was not a multipolygon but rather a polygon (or even a Point, in cases where the buffer was zero).
A bigger issue I ran into was enormous trouble getting geopanda's buffer function to work properly. I know that this has to do with the crs/projections and tried all sorts of variations, but could never get the buffer function to work properly with the buffer distance in meters. I found a nice custom function here (Is there an easy way to create square buffers around point and if they intersect, merge them?) that did work, but then realized that my Postgres setup has the PostGIS functions and used ST_Buffer to get the buffer polygons at the same time I am querying the database for the building lat/long data.
Hopefully the above will be helpful to others.
I am attempting to calculate the bearing from an object with geodesic coords given by latitude/longitude and a heading to another object at different latitude/longitude coordinates.
A rough sketch of the problem is
where the triangle represents object one, the arrow represents object one's heading, and the square represents object two.
I am aware this can be done using the haversine formula, as in , but how would one do this while simultaneously taking spheroid earth into consideration.
We have:
Moving camera C
Static object O
I1 , I2 are images taken by Camera C at time points t1,t2
x1,y1 are center coordinates of the object O in I1
x2,y2 are center coordinates of the object O in I2
P1 , P2 are the 3d positions of the camera C in the real world at time points t1,t2
Given x1,x2,y1,y2,P1,P2 how to calculate the the position of the object in the real world (P_obj)
This is epipolar geometry (https://docs.opencv.org/master/da/de9/tutorial_py_epipolar_geometry.html) and stereo triangulation (https://docs.opencv.org/master/dd/d53/tutorial_py_depthmap.html). You'll need to know camera parameters (focal length, resolution, etc.).
After long search I found a video which can be useful, especially starting from minute 19:00:
Epipolar Geometry III
I'd like to calculate the topological distance instead of Euclidean distance between two polygons. The distance between two neighboring polygons is 1, between two polygons connecting through a common neighbor is 2 and so on.
Is there any easy method to calculate the topological distance? I searched this question but found no solution.
Thank you.
Basically you want to search the distance between Polygon A & B
Here are the steps that I will took:
Distance = 1;
Check whether Polygon B is the neighbor of Polygon A, If it is=Finish, If not go to point 2.
Calculate the coordinate centroid (the middle point) of all neighbouring Polygons, and Polygon B
Count the distance between the neighbouring centroid to Polygon B centroid, select the polygon with the closest distance (Polygon C)
Distance = Distance + 1, Check whether Polygon B is the neighbor of Polygon C, If it is=Finish, If not, Polygon A = Polygon C, go to Point 2
At the end you'll get the distance.
I find a way to implement this calculation using existing software.
First, import the shp file to PostgreSQL using the PostGIS plugin.
Second, use the ST_Touches function to calculate each polygon's neighboring polygons.
Third, take each polygon as a point, and construct a new network.
Finally, calculate the shortest path between each two points using the Dijkstra algorithm.
In my project my users can choose to be put in a random position inside a given, circular area.
I have the latitude and longitude of the center and the radius: how can I calculate the latitude and longitude of a random point inside the given area?
(I use PHP but examples in any language will fit anyway)
You need two randomly generated numbers.
Thinking about this using rectangular (Cartesian) (x,y) coordinates is somewhat unnatural for the problem space. Given a radius, it's somewhat difficult to think about how to directly compute an (Δx,Δy) delta that falls within the circle defined by the center and radius.
Better to use polar coordinates to analyze the problem - in which the dimensions are (r1, Θ). Compute one random distance, bounded by the radius. Compute a random angle, from 0 to 360 degrees. Then convert the (r,Θ) to Cartesian (Δx,Δy), where the Cartesian quantities are simply offsets from your circle center, using the simple trigonometry relations.
Δx = r * cos(Θ)
Δy = r * sin(Θ)
Then your new point is simply
xnew = x + Δx
ynew = y + Δy
This works for small r, in which case the geometry of the earth can be approximated by Euclidean (flat plane) geometry.
As r becomes larger, the curvature of the earth means that the Euclidean approximation does not match the reality of the situation. In that case you will need to use the formulas for geodesic distance, which take into account the 3d curvature of the earth. This begins to make sense, let's say, above distances of 100 km. Of course it depends on the degree of accuracy you need, but I'm assuming you have quite a bit of wiggle room.
In 3d-geometry, you once again need to compute 2 quantities - the angle and the distance. The distance is again bound by your r radius, except in this case the distance is measured on the surface of the earth, and is known as a "great circle distance". Randomly generate a number less than or equal to your r, for the first quantity.
The great-circle geometry relation
d = R Δσ
...states that d, a great-circle distance, is proportional to the radius of the sphere and the central angle subtended by two points on the surface of the sphere. "central angle" refers to an angle described by three points, with the center of the sphere at the vertex, and the other two points on the surface of the sphere.
In your problem, this d must be a random quantity bound by your original 'r'. Calculating a d then gives you the central angle, in other words Δσ , since the R for the earth is known (about 6371.01 km).
That gives you the absolute (random) distance along the great circle, away from your original lat/long. Now you need the direction, quantified by an angle, describing the N/S/E/W direction of travel from your original point. Again, use a 0-360 degree random number, where zero represents due east, if you like.
The change in latitude can be calculated by d sin(Θ) , the change in longitude by d cos(Θ). That gives the great-circle distance in the same dimensions as r (presumably km), but you want lat/long degrees, so you'll need to convert. To get from latitudinal distance to degrees is easy: it's about 111.32 km per degree regardless of latitude. The conversion from longitudinal distance to longitudinal degrees is more complicated, because the longitudinal lines are closer to each other nearer the poles. So you need to use some more complex formulae to compute the change in longitude corresponding to the selected d (great distance) and angle. Remember you may need to hop over the +/- 180° barrier. (The designers of the F22 Raptor warplane forgot this, and their airplanes nearly crashed when attempting to cross the 180th meridian.)
Because of the error that may accumulate in successive approximations, you will want to check that the new point fits your constraints. Use the formula
Δσ = arccos( cos(Δlat) - cos(lat1)*cos(lat2)*(1 - cos(Δlong) ) .
where Δlat is the change in latitude, etc.
This gives you Δσ , the central angle between the new and old lat/long points. Verify that the central angle you've calcuated here is the same as the central angle you randomly selected previously. In other words verify that the computed d (great-circle-distance) between the calculated points is the same as the great circle distance you randomly selected. If the computed d varies from your selected d, you can use numerical approximation to improve the accuracy, altering the latitude or longitude slightly until it meets your criterion.
This can simply be done by calculating a random bearing (between 0 and 2*pi) and a random distance between 0 and your desired maximum radius. Then compute the new (random) lat/lon using the random bearing/range from your given lat/lon center point. See the section 'Destination point given distance and bearing from start point' at this web site: http://www.movable-type.co.uk/scripts/latlong.html
Note: the formula given expects all angles as radians (including lat/lon). The resulting lat/lon with be in radians also so you will need to convert to degrees.