0

I have a bounding box which I have created. I know the lat lon of the four vertices of the box. On these vertices I have created a buffer circle of radius 10m and now I want to calculate a new bounding box which covers these four circles.

I have created four circles where I know the lat,lon of each points which makes the circle. How can I make and find the coordinates of the 4 ends of this new rectangle/bounding box which encloses these four circles in python.

Sample Image

1 Answers1

1

For lat/lon aligned rectangle 10m distance correspond to angular shift

ltdiff = 180 * 10 / 20 000 000  = 0.00009

degrees along latitude

and

lndiff = 180 * 10 / 20 000 000 / cos(lat)  = 0.00009/cos(lat)

degrees along longitude

For example, for latitude 45n:

lndiff = 0.00009/cos(45) = 0.00009/0.7071 = 0.0001273 degrees

So expand you rectangle by these values (for small rectangles top and bottom latitude is nearly the same, so you can use the same value for cosine)

newtopleft.lat = topleft.lat - 0.00009 
newtopleft.lon = topleft.lon - 0.00009/cos(topleft.lat)

newtopright.lat = topright.lat - 0.00009 
newtopright.lon = topright.lon + 0.00009/cos(topright.lat)

similar for bottom left and right
MBo
  • 77,366
  • 5
  • 53
  • 86
  • But how can I find the coordinates of this new rectangle ? – sneha_jerin Jul 06 '23 at 08:52
  • new coordinates added – MBo Jul 06 '23 at 08:55
  • Let's say that the top coord is (74.23,6.45), for the newtop we should negate both Lat and Lon value with 0.0009. Am I right ? – sneha_jerin Jul 06 '23 at 09:01
  • No. If latitude 74.23 contains fractional degrees, then newtop = 74.23-0.00009=74.22991. Lon value will be changed by 0.00009/cos(74.23) = 0.00009/0.27= 0.00033 degrees – MBo Jul 06 '23 at 09:04
  • Could you also explain how I can acheive 4 lat,lon pairs from these. I am not able to understand. Sorry. Let us say this is my lats [54.9, 54.90, 54.913, 54.9138, 54.919] and lon [6.313, 6.311, 6.314, 6.316, 6.313]. – sneha_jerin Jul 06 '23 at 09:30
  • 1
    but why 5 values? – MBo Jul 06 '23 at 09:45
  • The first lat and the last lat was same in the above comment. How can we calculate for lats [54.9, 54.90, 54.913, 54.9138] and lon [6.313, 6.311, 6.314, 6.316] – sneha_jerin Jul 06 '23 at 11:52
  • What is unclear yet? – MBo Jul 06 '23 at 12:25
  • What values would be top,left,bottom,right. Are we using only 2 lat,lon here ? Because we have the 4 lat,lon of the bounding rectangle known. – sneha_jerin Jul 06 '23 at 12:55
  • Take lat and lon of topleft vertice. Subtract 0.00009 from it's lat, subtract 0.00009/cos(topleft.lat) from it's lon. Do similar calculations with other vertices. – MBo Jul 06 '23 at 13:52
  • What can be done if the given shape is not a rectangle but a parallelogram or a simple qaudrilateral ? Could you guide me into some resources. – sneha_jerin Jul 06 '23 at 21:27
  • [For plane geometry](https://stackoverflow.com/a/68109283/844416). For spherical coordinates bisectors should be calculated in more complex way. But your question was about rectangle. If you are using some gis/geo library, it might contain functions for offset polygon calculation. – MBo Jul 07 '23 at 01:24