import rasterio import numpy from xml.dom import minidom from socket import * from oct2py import octave from io import BytesIO import base64 from google.cloud import storage from oauth2client.service_account import ServiceAccountCredentials import os import firebase_admin from firebase_admin import credentials from firebase_admin import db from PIL import Image, ImageFilter from send_notification import send_notification from sendemail import sendemail from sen_start_noti import sen_start_noti from send_sar_email import send_sar_email import json import scipy import random import time import datetime from merge_sar import merge_sar from find_sar import find_sar from merge_dem import merge_dem from find_dem import find_dem from scipy import ndimage from make_bigquery import make_bigquery from send_moni_noti import send_moni_noti from send_error_noti import send_error_noti from gmap_image import gmap_image from gmap_image_large import gmap_image_large from datetime import date from find_img import find_img from find_img_large import find_img_large from merge_img import merge_img from all_proc import all_proc from contour_images import contour_images from send_expiring_noti import send_expiring_noti from send_expired_noti import send_expired_noti from make_trial_bigquery import make_trial_bigquery from gen_geotiff import gen_geotiff from sendgeotifs import sendgeotifs from gen_report import gen_report from get_weather_data import get_weather_data from sendonlyreport import sendonlyreport from gen_failed_report import gen_failed_report from sendfailedreport import sendfailedreport #from search_sentinel import search_sentinel from map_coords import map_coords from search_new_sentinel import search_new_sentinel from convert_to_pdf import convert_to_pdf from latlon_jp2_to_pixel import latlon_jp2_to_pixel from gen_geotiff2 import gen_geotiff2 from search_sentinel_again import search_sentinel_again from get_prev_date import get_prev_date from make_bigquery_again import make_bigquery_again import requests import pdftotree from convert_to_html import convert_to_html from map_planet_coords import map_planet_coords from latlon_tif_to_pixel import latlon_tif_to_pixel import cv2 as cv from merge_planet_img import merge_planet_img import csv import math import urllib.parse import urllib.request from io import StringIO from PIL import Image from math import log, exp, tan, atan, pi, ceil from latlontopixels import latlontopixels from pixelstolatlon import pixelstolatlon import io import math import os from getmapstaticcoords import getmapstaticcoords from get_highres_img import get_highres_img from find_palms import find_palms from find_palms2 import find_palms2 from find_palms3 import find_palms3 import xlrd import time uid = 'gavl' polygon_points = polygon_data["Coordinates"] coordinates = polygon_points polygon_max_lat = -180 polygon_min_lat = 180 polygon_max_long = -180 polygon_min_long = 180 for(pointKey, pointData) in polygon_points.items(): print('Point data') print(pointKey) print(pointData) pointLat = pointData["Latitude"] pointLong = pointData["Longitude"] if pointLat > polygon_max_lat: polygon_max_lat = pointLat if pointLat < polygon_min_lat: polygon_min_lat = pointLat if pointLong > polygon_max_long: polygon_max_long = pointLong if pointLong < polygon_min_long: polygon_min_long = pointLong fieldminlat = polygon_min_lat fieldmaxlat = polygon_max_lat fieldminlong = polygon_min_long fieldmaxlong = polygon_max_long print(polygon_id) templateName = get_highres_img(uid,polygon_id,fieldmaxlat,fieldminlat, fieldmaxlong, fieldminlong) new_string_json = {} new_string_json["StartPixelLat"] = fieldminlat new_string_json["EndPixelLat"] = fieldmaxlat new_string_json["StartPixelLong"] = fieldminlong new_string_json["EndPixelLong"] = fieldmaxlong fieldid = polygon_id new_string_json["UID"] = uid new_string_json["FieldID"] = polygon_id i = i+1 try: ndvi_value,bsi_value,si_value,vari_value,avi_value,savi_value,evi_value = map_planet_coords(uid,fieldid,coordinates,fieldmaxlat,fieldminlat,fieldmaxlong,fieldminlong) n_trees = find_palms3(uid,fieldid, templateName) #time.sleep(10) avg_per_ha = 143 #avg_per_ha = round(n_trees/(field_area/10000)) row = [polygon_id, farmer_name, phone_number, field_area, n_trees, avg_per_ha] writer.writerow(row) org = (0,20) font =cv.FONT_HERSHEY_SIMPLEX fontScale = 0.25 color = (255,0,0) thickness = 1 fileName = polygon_id + '_highres_side_by_side.png' destination = uid+'/'+fileName img = cv.imread(destination) text = 'Trees: ' + str(row[4]) + ', ' + 'Area: ' + str(row[3]) + ', ' + 'Avg. Per. Ha.: ' + str(row[5]) cv.putText(img,text,org,font,fontScale,color,thickness,cv.LINE_AA) cv.imwrite(destination,img) except: print('finding error..')