Commit 6417cae6 authored by izzat's avatar izzat
Browse files

feat: generate four points and planning config input string

parent 1dd5d259
# generate rectangle coordinates # generate rectangle coordinates
Generate four coodinates from a starting waypoint of the left corner of the rectangle (or square), following ecoSUB GUI concepts.
```
usage: generate_rect_coords.py [-h] [-l LENGTH] [-w WIDTH] [-r ROTATION] lat long
positional arguments:
lat Starting WP (bottom left) latitude (decimal degrees)
long Starting WP (bottom left) longitude (decimal degrees)
optional arguments:
-h, --help show this help message and exit
-l LENGTH, --length LENGTH
vertical length (m)
-w WIDTH, --width WIDTH
horizontal length (m)
-r ROTATION, --rotation ROTATION
The bearing or rotation of the rectangle about the starting WP/origin. Defaulted to 0 degrees. (+ clockwise, - anti-clockwise)
```
Example usage:
1. 1000x1000m SOTWB area
`python generate_rect_coords.py 50.322231 -4.158497 -l 1000 -w 1000`
![1000x1000m SOTWB area](image.png)
2. 1000x500m Cawsand Bay area
`python generate_rect_coords.py 50.330505 -4.191456 -l 1000 -w 500 -r 41.81`
![1000x500m Cawsand Bay area](image-1.png)
Verify result with Google Earth:
![Google Earth](image-2.png)
import json
import argparse
from turfpy.measurement import destination
from geojson import Point, Feature
parser = argparse.ArgumentParser()
parser.add_argument("lat",
type=float,
help="Starting WP (bottom left) latitude (decimal degrees)")
parser.add_argument("long",
type=float,
help="Starting WP (bottom left) longitude (decimal degrees)")
parser.add_argument("-l", "--length",
type=int,
help="vertical length (m)")
parser.add_argument("-w", "--width",
type=int,
help="horizontal length (m)")
parser.add_argument("-r", "--rotation",
type=float,
default=0,
help="The bearing or rotation of the rectangle about the starting WP/origin." +
" Defaulted to 0 degrees. (+ clockwise, - anti-clockwise)")
args = parser.parse_args()
origin = Feature(geometry=Point([args.long, args.lat]))
# origin = Feature(geometry=Point([-4.158497, 50.322231]))
distance_horizontal = args.width
distance_vertical = args.length
rotation = args.rotation
options = {'units': 'm'}
dest_bottom_right = destination(origin, distance_horizontal, 90+rotation, options)
dest_top_left = destination(origin, distance_vertical, rotation, options)
dest_top_right = destination(dest_top_left, distance_horizontal, 90+rotation, options)
print("Bottom Left: ", origin.geometry.coordinates[::-1])
print("Bottom Right: ", dest_bottom_right.geometry.coordinates[::-1])
print("Top Left: ", dest_top_left.geometry.coordinates[::-1])
print("Top Right: ", dest_top_right.geometry.coordinates[::-1])
destination_result = [dest_top_left.geometry.coordinates,
dest_top_right.geometry.coordinates,
dest_bottom_right.geometry.coordinates,
origin.geometry.coordinates,
dest_top_left.geometry.coordinates]
print("Planner config input from top left and going clockwise\n" +
" (to be copied and pasted): \n",
json.dumps(destination_result, indent=2))
# print(json.dumps(destination_result, indent=2, sort_keys=True))
image-1.png

712 KB

image-2.png

1.25 MB

image.png

768 KB

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment