Skip to content

Commit

Permalink
Merge pull request #50 from open-AIMS/reefscan-android#37Changes_for_…
Browse files Browse the repository at this point in the history
…Philippines_2024

Reefscan android#37 changes for philippines 2024
  • Loading branch information
gcoleman72 authored Mar 12, 2024
2 parents 55678ae + 9614290 commit 863aa3c
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 191 deletions.
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
psutil
Rust
joblib
pillow
piexif
pyinstaller
PyQt5==5.15.5
shortuuid
PyQtWebEngine
reefscanner @ git+https://github.com/AIMS/reefscan-data-model@v1.1.5
#reefscanner @ file:///C:/aa_git_root/techdev/reef_scanner_data_model/dist/reefscanner-1.1.4.6-py3-none-any.whl
photoenhancer @ git+https://github.com/open-AIMS/photo_enhancer@v1.1.12
#photoenhancer @ file:///C:/aa_git_root/techdev/photo_enhancer/dist/photoenhancer-1.1.9.2-py3-none-any.whl
#reefscanner @ git+https://github.com/AIMS/reefscan-data-model@v1.1.6
reefscanner @ file:///C:/aa_git_root/techdev/reef_scanner_data_model/dist/reefscanner-1.1.6.3-py3-none-any.whl
#photoenhancer @ git+https://github.com/AIMS/photo_enhancer@v1.1.12
photoenhancer @ file:///C:/aa_git_root/techdev/photo_enhancer/dist/photoenhancer-1.1.12-py3-none-any.whl
pandas
smbprotocol
fabric2
psutil;sys_platform == 'linux'
psutil;sys_platform == 'darwin'
Rust;sys_platform == 'darwin'
pywin32;sys_platform == 'windows'
pywin32;sys_platform == 'win32'
tzlocal
Expand Down
11 changes: 7 additions & 4 deletions src/aims/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ def __init__(self):
self.clear_reefcloud = False

self.language = os.getenv("LANG")
if self.language is None:
windll = ctypes.windll.kernel32
windll.GetUserDefaultUILanguage()
self.language = locale.windows_locale[windll.GetUserDefaultUILanguage()]
try:
if self.language is None:
windll = ctypes.windll.kernel32
windll.GetUserDefaultUILanguage()
self.language = locale.windows_locale[windll.GetUserDefaultUILanguage()]
except:
self.language = "eng"

self.vietnemese = self.language == "vi_VN"

Expand Down
16 changes: 13 additions & 3 deletions src/aims/operations/kml_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@
from aims import utils

logger = logging.getLogger("")
def make_kml(survey: Survey, cots_waypoints, minimum_cots_score, output_folder):
def make_kml(survey: Survey, cots_waypoints, minimum_cots_score, output_folder, depth=False):
import alphashape
input_folder = survey.folder
points = track(input_folder, False)
# os.makedirs(output_folder, exist_ok=True)
kml_file_name = f"{output_folder}/{survey.best_name()}.kml"
kml = simplekml.Kml()
for point in points:
kml.newpoint(coords=[(point[1], point[0])])
pnt = kml.newpoint(coords=[(point[1], point[0])])
#TODO Perhaps we need a legend for this
if depth:
# pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'
if point[3] < 8000:
pnt.style.iconstyle.color = simplekml.Color.red
elif point[3] < 12000:
pnt.style.iconstyle.color = simplekml.Color.yellow
else:
pnt.style.iconstyle.color = simplekml.Color.green

kml.save(kml_file_name)

if len(cots_waypoints) > 0:
Expand All @@ -26,7 +36,7 @@ def make_kml(survey: Survey, cots_waypoints, minimum_cots_score, output_folder):
for point in cots_waypoints:
score_ = point[3]
if score_ > minimum_cots_score:
kml.newpoint(coords=[(point[1], point[0])])
pnt = kml.newpoint(coords=[(point[1], point[0])])
kml.save(kml_file_name)

points_for_poly = []
Expand Down
60 changes: 36 additions & 24 deletions src/aims/operations/kml_to_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ def extract_linestrings_from_kml(kml_path):
return linestrings


def create_gpx_file(output_folder, kml_filename, feature_name, many, coordinates):
def create_gpx_file(geojson_folder, gpx_folder, kml_filename, feature_name, coordinates):
gpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
gpx_track = gpxpy.gpx.GPXTrack(name=feature_name)
gpx.tracks.append(gpx_track)
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)
coords_list=[]
for coord in coordinates.split():
coord_list = coord.split(',')
coord_list = [float(coord_list[0]), float(coord_list[1])]
lon = float(coord_list[0])
lat = float(coord_list[1])
coord_list = [lon, lat]
coords_list.append(coord_list)
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude=lat, longitude=lon))

path_feature = {
"type": "Feature",
"properties": {
Expand All @@ -47,30 +51,27 @@ def create_gpx_file(output_folder, kml_filename, feature_name, many, coordinates
features = [path_feature]

# features.append(path_feature)
# lon, lat = coord.split(',')[:2]
# gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude=float(lat), longitude=float(lon)))

geojson_data = {
"type": "FeatureCollection",
"features": features
}
if many:
gpx_filename = f"{output_folder}/{kml_filename}_{feature_name}.geojson"
else:
gpx_filename = f"{output_folder}/{kml_filename}.geojson"
geojson_filename = f"{geojson_folder}/{kml_filename}_{feature_name}.geojson"
gpx_filename = f"{gpx_folder}/{kml_filename}_{feature_name}.gpx"


with open(gpx_filename, 'w') as f:
with open(geojson_filename, 'w') as f:
json.dump(geojson_data, f)

# f.write(gpx.to_xml())
with open(gpx_filename, 'w') as f:
f.write(gpx.to_xml())


def create_start_points_gpx(output_folder, start_points):
# gpx = gpxpy.gpx.GPX()
def create_points_gpx(geojson_folder, gpx_folder, start_points, filename, feature_suffix):
gpx = gpxpy.gpx.GPX()
features = []
for lon, lat, name in start_points:
# gpx.waypoints.append(gpxpy.gpx.GPXWaypoint(latitude=float(lat), longitude=float(lon), name=name))
for lon, lat, name, short_name in start_points:
gpx.waypoints.append(gpxpy.gpx.GPXWaypoint(latitude=float(lat), longitude=float(lon), name=f"{short_name}_{feature_suffix}"))
point_feature = {
"type": "Feature",
"properties": {
Expand All @@ -82,35 +83,46 @@ def create_start_points_gpx(output_folder, start_points):
}
}
features.append(point_feature)
gpx_filename = f"{output_folder}/00__first_points.geojson"
geojson_filename = f"{geojson_folder}/{filename}.geojson"
gpx_filename = f"{gpx_folder}/{filename}.gpx"
geojson_data = {
"type": "FeatureCollection",
"features": features
}
with open(gpx_filename, 'w') as f:
with open(geojson_filename, 'w') as f:
json.dump(geojson_data, f)

with open(gpx_filename, 'w') as f:
f.write(gpx.to_xml())



def make_geojson(kml_folder, output_folder):
def make_geojson(kml_folder, geojson_folder, gpx_folder):
start_points = []
os.makedirs(output_folder, exist_ok=True)
finish_points = []
os.makedirs(geojson_folder, exist_ok=True)
os.makedirs(gpx_folder, exist_ok=True)
for filename in os.listdir(kml_folder):
if filename.endswith('.kml'):
kml_path = os.path.join(kml_folder, filename)
linestrings = extract_linestrings_from_kml(kml_path)

many = len(linestrings) > 1


for feature_name, coordinates in linestrings:
create_gpx_file(output_folder, os.path.splitext(filename)[0], feature_name, many, coordinates)
create_gpx_file(geojson_folder, gpx_folder, os.path.splitext(filename)[0], feature_name, coordinates)

if coordinates:
lon, lat = coordinates.split(' ')[0].split(',')[:2]
start_points.append((lon, lat, f"{os.path.splitext(filename)[0]}_{feature_name}"))
coordinates_list = coordinates.split(' ')
lon, lat = coordinates_list[0].split(',')[:2]
start_points.append((lon, lat, f"{os.path.splitext(filename)[0]}_{feature_name}", feature_name))

lon, lat = coordinates_list[len(coordinates_list)-1].split(',')[:2]
finish_points.append((lon, lat, f"{os.path.splitext(filename)[0]}_{feature_name}", feature_name))

if start_points:
create_start_points_gpx(output_folder, start_points)
create_points_gpx(geojson_folder, gpx_folder, start_points, "00__first_points", "s")
create_points_gpx(geojson_folder, gpx_folder, finish_points, "00__finish_points", "f")



33 changes: 25 additions & 8 deletions src/aims/ui/main_ui_components/data_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ def paste(self):
if self.survey().sea == "" or self.survey().sea is None:
self.survey().sea = self.clipboard.sea

if self.survey().wind == "" or self.survey().wind is None:
self.survey().wind = self.clipboard.wind
if self.survey().wind_speed == "" or self.survey().wind_speed is None:
self.survey().wind_speed = self.clipboard.wind_speed

if self.survey().wind_direction == "" or self.survey().wind_direction is None:
self.survey().wind_direction = self.clipboard.wind_direction

if self.survey().cloud == "" or self.survey().cloud is None:
self.survey().cloud = self.clipboard.cloud
Expand Down Expand Up @@ -352,15 +355,15 @@ def add_new_reefcloud_site(self):
range(self.metadata_widget.cb_reefcloud_site.count())]
logger.info(all_sites)

if site in all_sites:
raise Exception(f"{site} already exists. Choose it from the drop down.")

if project is None or project == "":
raise Exception("Choose a reefcloud project first.")

if site is None or site == "":
raise Exception("Enter a site name in the site field.")

if site in all_sites:
raise Exception(f"{site} already exists. Choose it from the drop down.")

if state.reefcloud_session is None:
raise Exception("Log on to reefcloud first. (See the reefcloud tab)")

Expand All @@ -386,6 +389,7 @@ def disable_save_cancel(self):
self.metadata_widget.ed_vessel.textChanged.connect(self.enable_save_cancel)
self.metadata_widget.cb_sea.currentTextChanged.connect(self.enable_save_cancel)
self.metadata_widget.cb_wind.currentTextChanged.connect(self.enable_save_cancel)
self.metadata_widget.cb_wind_direction.currentTextChanged.connect(self.enable_save_cancel)
self.metadata_widget.cb_cloud.currentTextChanged.connect(self.enable_save_cancel)
self.metadata_widget.cb_vis.currentTextChanged.connect(self.enable_save_cancel)
self.metadata_widget.ed_comments.textChanged.connect(self.enable_save_cancel)
Expand Down Expand Up @@ -555,6 +559,16 @@ def lookups(self):
self.metadata_widget.cb_wind.addItem("25-30")
self.metadata_widget.cb_wind.addItem(">30")

self.metadata_widget.cb_wind_direction.addItem("")
self.metadata_widget.cb_wind_direction.addItem("N")
self.metadata_widget.cb_wind_direction.addItem("NE")
self.metadata_widget.cb_wind_direction.addItem("E")
self.metadata_widget.cb_wind_direction.addItem("SE")
self.metadata_widget.cb_wind_direction.addItem("S")
self.metadata_widget.cb_wind_direction.addItem("SW")
self.metadata_widget.cb_wind_direction.addItem("W")
self.metadata_widget.cb_wind_direction.addItem("NW")

self.metadata_widget.cb_cloud.addItem("")
self.metadata_widget.cb_cloud.addItem("0")
self.metadata_widget.cb_cloud.addItem("1")
Expand Down Expand Up @@ -1144,7 +1158,8 @@ def is_modified(self):
self.xstr(self.survey().observer) != self.metadata_widget.ed_observer.text() or \
self.xstr(self.survey().vessel) != self.metadata_widget.ed_vessel.text() or \
self.xstr(self.survey().sea) != self.metadata_widget.cb_sea.currentData() or \
self.xstr(self.survey().wind) != self.metadata_widget.cb_wind.currentText() or \
self.xstr(self.survey().wind_speed) != self.metadata_widget.cb_wind.currentText() or \
self.xstr(self.survey().wind_direction) != self.metadata_widget.cb_wind_direction.currentText() or \
self.xstr(self.survey().cloud) != self.metadata_widget.cb_cloud.currentText() or \
self.xstr(self.survey().visibility) != self.metadata_widget.cb_vis.currentText() or \
self.xstr(self.survey().comments) != self.metadata_widget.ed_comments.toPlainText() or \
Expand All @@ -1165,7 +1180,8 @@ def ui_to_data(self):
self.survey().observer = self.metadata_widget.ed_observer.text()
self.survey().vessel = self.metadata_widget.ed_vessel.text()
self.survey().sea = self.metadata_widget.cb_sea.currentData()
self.survey().wind = self.metadata_widget.cb_wind.currentText()
self.survey().wind_speed = self.metadata_widget.cb_wind.currentText()
self.survey().wind_direction = self.metadata_widget.cb_wind_direction.currentText()
self.survey().cloud = self.metadata_widget.cb_cloud.currentText()
self.survey().visibility = self.metadata_widget.cb_vis.currentText()
self.survey().comments = self.metadata_widget.ed_comments.toPlainText()
Expand All @@ -1189,7 +1205,8 @@ def data_to_ui(self):
self.metadata_widget.ed_observer.setText(self.xstr(self.survey().observer))
self.metadata_widget.ed_vessel.setText(self.xstr(self.survey().vessel))
self.metadata_widget.cb_sea.setCurrentText(self.xstr(self.survey().sea))
self.metadata_widget.cb_wind.setCurrentText(self.xstr(self.survey().wind))
self.metadata_widget.cb_wind.setCurrentText(self.xstr(self.survey().wind_speed))
self.metadata_widget.cb_wind_direction.setCurrentText(self.xstr(self.survey().wind_direction))
self.metadata_widget.cb_cloud.setCurrentText(self.xstr(self.survey().cloud))
self.metadata_widget.cb_vis.setCurrentText(self.xstr(self.survey().visibility))
self.metadata_widget.cb_tide.setCurrentText(self.xstr(self.survey().tide))
Expand Down
2 changes: 1 addition & 1 deletion src/aims/ui/main_ui_components/map_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,4 @@ def export_kml(self):
output_folder = QFileDialog.getExistingDirectory(self.map_widget, 'Folder to save KML file to?')
if (output_folder is not None and output_folder != ""):
for survey in self.surveys:
make_kml(survey=survey, cots_waypoints=cots_waypoints, minimum_cots_score=minimum_score, output_folder=output_folder)
make_kml(survey=survey, cots_waypoints=cots_waypoints, minimum_cots_score=minimum_score, output_folder=output_folder, depth=True)
10 changes: 7 additions & 3 deletions src/aims/ui/main_ui_components/routes_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ def load_screen(self, aims_status_dialog, parent):

def process(self):
input_folder = self.widget.inputFolderText.text()
output_folder = f"{self.widget.outputFolderText.text()}/geojson"
make_geojson(input_folder, output_folder)
output_folder = self.widget.outputFolderText.text()
geojson_folder = f"{output_folder}/geojson"
gpx_folder = f"{output_folder}/gpx"

make_geojson(input_folder, geojson_folder, gpx_folder)
self.widget.afterProcessWidget.setVisible(True)
self.widget.outputFolderLabel.setText(f" {output_folder}")
self.widget.outputFolderLabel.setText(f" {geojson_folder}")
self.widget.gpx_folder_label.setText(f"And copy the the files from {gpx_folder} to the gps")
self.set_hint()

def openInputFolder(self):
Expand Down
2 changes: 1 addition & 1 deletion src/aims/ui/main_ui_components/upload_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def upload(self):

logger.info(f"Upload Finished in {minutes} minutes")
errorbox = QtWidgets.QMessageBox()
errorbox.setText(self.tr("Upload finished"))
errorbox.setText(self.tr("Upload finished. Your data should be available in ReefCloud within half an hour."))
errorbox.setDetailedText(self.tr("Finished in") + f" {minutes} " + self.tr("minutes"))

self.aims_status_dialog.close()
Expand Down
Loading

0 comments on commit 863aa3c

Please sign in to comment.