#Coordinates of point
point = (-122.486, 37.698)

#Set map type and file location
map_type = "visual"
crop_file = "/home/user/FinalAssignment/Downloads/DownloadFile_"+map_type+".tif"

#Download the image
try:
    select_image(url, key, point, map_type, crop_file)
except:
    print "ERROR: No map available"

#Cut to size
cut_size(crop_file, 1500, 1000, 1500, 2000, in_file)

#Creating model to classify trees
create_model(in_file, statistics_file, training_poly, output_model, confusion_matrix)

#Apply model
classify(output_model, in_file, statistics_file, output_map)

#Delete all none trees from dataset
select_trees(output_map, selection_map)

#Calculate percentage green per quadrant (format: nw, sw, ne, se)
print greencalculator(output_map)

##Apply model to other map
#Data source
url = "https://api.planet.com/v0/scenes/ortho/"
key =#Add own key

#Coordinates of point
point_obj = (-118.4, 34.084)

#Set map type and file location
map_type_obj = "visual"
crop_file_obj = "/home/user/FinalAssignment/Downloads/DownloadFileObject_"+map_type_obj+".tif"

#Download the image
try:
    select_image(url, key, point_obj, map_type_obj, crop_file_obj)
except:
    print "ERROR: No map available"

#Cut to size
cut_size(crop_file_obj, 1250, 1500, 750, 750, in_file_obj)

##Use object based selection
min_size = 5 
#Expression to select all dark-green objects
expression = "(p1b2 < 100) and ((p1b2 > p1b1)or(p1b2>p1b3)) and (p1b1 < 90) and (p1b3<90)"
#Select all objects
OBIA_none = ''
select_object(in_file_obj, expression, min_size, OBIA_none, out_file_all)
#Select all round objects
OBIA = "SHAPE_RegionRatio > 0.65"
select_object(in_file_obj, expression, min_size, OBIA, out_file_object)