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) octave.create_polymask(uid,fieldid,w_tci,h_tci,X,Y)