def map_planet_coords(uid,fieldid,coordinates,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 estimate_yield import estimate_yield from merge_planet_img import merge_planet_img # from firebase_admin import messaging cred = credentials.Certificate('servicekey.json') coordinates = collections.OrderedDict(sorted(coordinates.items())) print(coordinates) tci_file_name = uid + '/highres_' +str(fieldid)+'.png' #tci_file_name = uid +'/' + fieldid + '_highres_num.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 = [] print(fieldminlat, fieldmaxlat, fieldminlong, fieldmaxlong, h_tci, w_tci) pixelsperlat = h_tci/abs(float(fieldmaxlong)-float(fieldminlong)) pixelsperlong = w_tci/abs(float(fieldmaxlat)-float(fieldminlat)) print(pixelsperlat, pixelsperlong) pformatflag =0 X = [] Y = [] ploc = 0 for k,v in coordinates.items(): pointKey = "P_" + str(ploc) ploc = ploc + 1 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) poly_m = octave.create_polymask(uid,fieldid,w_tci,h_tci,X,Y) ndvi_value = 0 bsi_value = 0 si_value = 0 vari_value = 0 savi_value = 0 avi_value = 0 evi_value = 0 try: ndvi_value = octave.calc_planet_ndvi(uid,fieldid,'ndvi') #bsi_value = octave.calc_planet_ndvi(uid,fieldid,'bsi') si_value = octave.calc_planet_ndvi(uid,fieldid,'si') vari_value = octave.calc_planet_ndvi(uid,fieldid,'vari') savi_value = octave.calc_planet_ndvi(uid,fieldid,'savi') avi_value = octave.calc_planet_ndvi(uid,fieldid,'avi') evi_value = octave.calc_planet_ndvi(uid,fieldid,'evi') #db.reference('GAVL').child(fieldid).child('ndvi').set(int(field_area)) a1 = merge_planet_img(uid,'ndvi', fieldid) #a2 = merge_planet_img(uid,'bsi', fieldid) a3 = merge_planet_img(uid,'si', fieldid) a4 = merge_planet_img(uid,'vari', fieldid) a5 = merge_planet_img(uid,'savi', fieldid) a6 = merge_planet_img(uid,'avi', fieldid) a7 = merge_planet_img(uid,'evi', fieldid) # a7 = merge_planet_img(uid,'highres', fieldid) a8 = 1 except: ss = 1 a4 = merge_planet_img(uid,'highres',fieldid) return ndvi_value,bsi_value,si_value,vari_value,avi_value,savi_value,evi_value