import json import requests def submit_geojson_to_farmonaut(geojson_data): # Constants UID = "qbnmIkSbAwc8TTR5FPnViu2Rr0A2" CropCode = "1r" PaymentType = 1 API_URL = 'https://us-central1-farmbase-b2f7e.cloudfunctions.net/submitField' # Iterate over each feature in the geojson for feature in geojson_data['features']: # Extract field name field_name = feature['properties']['name'] # Extract polygon coordinates & ensure it is in the correct format if feature['geometry']['type'] == 'Polygon': coordinates = feature['geometry']['coordinates'][0] # Prepare the request body request_body = { "UID": UID, "CropCode": CropCode, "FieldName": field_name, "PaymentType": PaymentType, "Points": coordinates } # Submit the request to the API response = requests.post(API_URL, json=request_body) if response.status_code == 200: print(f"Successfully submitted field: {field_name}") else: print(f"Failed to submit field: {field_name}. Status Code: {response.status_code}, Response: {response.text}") def read_geojson_file(file_path): with open(file_path, 'r') as file: geojson_data = json.load(file) return geojson_data if __name__ == "__main__": # Provide the path to your GeoJSON file geojson_file_path = 'Downloads/SR_Paddy.geojson' geojson_data = read_geojson_file(geojson_file_path) submit_geojson_to_farmonaut(geojson_data)