from dataclasses import field from tempfile import tempdir import firebase_admin from firebase_admin import credentials from firebase_admin import db from find_s1_image import find_img_value import pandas as pd import statsmodels.api as sm import seaborn as sns sns.set() import json import numpy as np from sklearn.cluster import KMeans from find_study_area_values import find_study_area_values from make_area_estimate_image import make_area_estimate_image #from sentinelhub import WebFeatureService, BBox, CRS, DataSource, MimeType, CRS, BBox, WmsRequest,DataCollection cred = credentials.Certificate('servicekey.json') x = 0.0002 y = 0.0002 fromdate = '20220701' todate = '20220715' s1_images = ['IW-VH-DB'] s2_images = [] # s1_images = ["B02", "B03", "B04", "B05"] #s2_images = ["RVI-NEW"] try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') study_uid = "vPM6EKWHfHRxmRfc0YJ7PZ8J9tR2" gt_uid = ['u5ZgAskSltX7dQdNFUlHsgVhAlf2', 'b2j92LjidjeGt2b60QHhSj4GeS63','0AC0f8JWjUdg9fCm7f8QbXZTOp23'] different_gt_uid = 'hxA3VYEFpaOluurIbHxdzd4gPlw1' study_field_id = '1662365839021' gt_uid = ['D4xU2QGhooXfK6qiEeHdAlp0wk53'] gt_fields = {} for temp_id in gt_uid: temp_gt_fields = db.reference('PaidMonitoredFields').child('PMF').child(temp_id).get() for(p,q) in temp_gt_fields.items(): gt_fields[p] = q json_obj = {} json_obj["type"] = "FeatureCollection" json_obj["features"] = [] for (fieldid, fieldobj) in gt_fields.items(): pointsObj = fieldobj["Coordinates"] single_geometry_obj = {} single_geometry_obj["type"] = "Feature" single_geometry_obj["geometry"] = {} single_geometry_obj["properties"] = {'FieldID': fieldid, 'Area1': fieldobj["Area"]} single_geometry_obj["geometry"]["type"] = "LineString" singleFieldPointsArr = [] p_num = 0 for (pointkey, pointobj) in pointsObj.items(): if p_num == 0: pointArr = [float(pointsObj["a"]["Longitude"]), float(pointsObj["a"]["Latitude"])] else: pointArr = [float(pointsObj[("P_"+ str(p_num))]["Longitude"]), float(pointsObj[("P_"+ str(p_num))]["Latitude"])] p_num = p_num +1 singleFieldPointsArr.append(pointArr) singleFieldPointsArr.append([float(pointsObj["a"]["Longitude"]), float(pointsObj["a"]["Latitude"])]) single_geometry_obj["geometry"]["coordinates"] = singleFieldPointsArr json_obj["features"].append(single_geometry_obj) print(json_obj) json_object = json.dumps(json_obj, indent=4) # Writing to sample.json with open("trst_json_obj.json", "w") as outfile: outfile.write(json_object)