def merge_sar(uid,fieldid,coordinates,imagedate,fieldmaxlat,fieldminlat,fieldmaxlong,fieldminlong): import math import matplotlib.path from matplotlib.path import Path import numpy as np import cv2 from PIL import Image from merge_contour_images import merge_contour_images from oct2py import octave import collections import firebase_admin from firebase_admin import credentials from firebase_admin import db from create_index_piechart import create_index_piechart from create_soc_piechart import create_soc_piechart from merge_mask_img import merge_mask_img # from firebase_admin import messaging cred = credentials.Certificate('servicekey.json') coordinates = collections.OrderedDict(sorted(coordinates.items())) print(coordinates) tci_file_name = uid + '/' + fieldid + '/TCI.png' tci = cv2.imread(tci_file_name,0) w_tci,h_tci = tci.shape centerx = round(w_tci/2) centery = round(h_tci/2) zero_lat = fieldmaxlat zero_long = fieldminlong print('coords') X = [] Y = [] pixelsperlat = h_tci/abs(float(fieldmaxlong)-float(fieldminlong)) pixelsperlong = w_tci/abs(float(fieldmaxlat)-float(fieldminlat)) pformatflag =0 for k,v in coordinates.items(): if k.find("P_")>=0: pformatflag = 1 break temp_lat = v['Latitude'] temp_long = v['Longitude'] temp_lat = float(temp_lat) temp_long = float(temp_long) x = round((temp_long-zero_long)*pixelsperlat) y = round((zero_lat-temp_lat)*pixelsperlong) print(x) print(y) X.append(x) Y.append(y) if pformatflag == 1: X = [] Y = [] ploc = 1 for k,v in coordinates.items(): pointKey = "P_" + str(ploc) ploc = ploc + 1 try: v = coordinates[pointKey] temp_lat = v['Latitude'] temp_long = v['Longitude'] temp_lat = float(temp_lat) temp_long = float(temp_long) x = round((temp_long-zero_long)*pixelsperlat) y = round((zero_lat-temp_lat)*pixelsperlong) print(x) print(y) X.append(x) Y.append(y) except: v = coordinates["a"] temp_lat = v['Latitude'] temp_long = v['Longitude'] temp_lat = float(temp_lat) temp_long = float(temp_long) x = round((temp_long-zero_long)*pixelsperlat) y = round((zero_lat-temp_lat)*pixelsperlong) print(x) print(y) X.append(x) Y.append(y) poly_m = octave.create_polymask(uid,fieldid,w_tci,h_tci,X,Y) merge_mask_img(uid,'rvi', fieldid) merge_mask_img(uid, 'rsm', fieldid) return 100