from xxlimited import new import fiona import requests import utm from geopy.geocoders import Nominatim import time import json import pandas as pd import xlrd import matplotlib.path as mplPath import numpy as np from statistics import median import math import firebase_admin from firebase_admin import credentials from firebase_admin import db from firebase_admin import messaging import threading from oct2py import octave from io import BytesIO import base64 import os from shapely.geometry import Point from shapely.geometry.polygon import Polygon from numba import jit, cuda cred = credentials.Certificate('servicekey.json') try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') def try_lower(temp_str): try: temp_str = temp_str.lower() except: wew = 1 return temp_str names = ['Bani', 'Beheira', 'Dakhalia', 'Damietta', 'Fayum', 'Gharbia', 'Kafr-el-sheikh', 'Menofia', 'Qina', 'Sharqia'] names = ['Al Minyah'] names = ['Al Ismaillyah'] print(len(names)) # for gov_name in names: # new_ttg_json = 'Egypt geoJsons/' + gov_name + '/' + gov_name + '.geojson' uid = 'wEJQVaxiZZaaId2aJe6lRJ8Zd0S2' farm_num = 0 num = 0 new_ttg_json = 'Downloads/egypt_new.geojson' #dist_names = ['jalgaon', 'aurangabad', 'jalna', 'nanded', 'parbhani', 'amravati', 'buldana', 'chandrapur', 'nagpur', 'wardha', 'yavatmal'] with open(new_ttg_json) as f: data = json.load(f) all_farms_obj = data["features"] for farm_obj in all_farms_obj: farmGeometry = farm_obj["geometry"] gov_name = farm_obj["properties"]["ADM1_REF"] farmName = gov_name farmPoints = farmGeometry["coordinates"] mainFarmPoints = farmPoints farmPoints = farmPoints[0] #farmPointsPath = Polygon(farmPoints) intersection_num = 0 tempObj = {} tempObj["FieldAddress"] = gov_name villageName = farmName allPointsObj = {} allowed = 1 pointNum = 0 mainFarmPoints =mainFarmPoints[0][0] #print(mainFarmPoints) #for i in mainFarmPoints: for k in mainFarmPoints: singlePointobj = k #print(singlePointobj) singlePointLat = singlePointobj[1] singlePointLong = singlePointobj[0] #utmToLatLon = utm.to_latlon(singlePointLong, singlePointLat, 44, 'N') utmToLatLon = [singlePointLat, singlePointLong] tempPoint = {} tempPoint["Latitude"] = utmToLatLon[0] tempPoint["Longitude"] = utmToLatLon[1] if pointNum > 0: allPointsObj[("P_"+str(pointNum))] = tempPoint else: allPointsObj["a"] = tempPoint # geolocator = Nominatim(user_agent ="geoapiExercises") # location = geolocator.reverse(str(utmToLatLon[0])+"," + str(utmToLatLon[1])) # address_obj = location.raw['address'] # state = address_obj.get('state','') # temp_field_address = address_obj.get('suburb','') + ", " + address_obj.get('city','') + ", " + address_obj.get('state','') + ", " + address_obj.get('country','') tempObj["FullAddress"] = villageName tempObj["City"] = villageName pointNum = pointNum + 1 tempObj["Points"] = allPointsObj tempObj["PaymentType"] = 12 tempObj["CropCode"] = 999 tempObj["Village"] = villageName tempObj["UID"] = uid #print(tempObj) r = requests.post('https://us-central1-farmbase-b2f7e.cloudfunctions.net/submitFieldTemp', json = tempObj) #break time.sleep(1)