def create_map(): """ Function that creates the 'map' element """ # Center and Zoom level center = [-96.5, 38.5] zoom = 4 # Define view options view_options = MVView(projection='EPSG:4326', center=center, zoom=zoom, maxZoom=10, minZoom=1) draw_options = MVDraw( controls=["Pan"], feature_selection=False, point_color='yellow', ) # Define map view options map_view_options = MapView( height='500px', width='100%', controls=['ZoomSlider'], layers=[], view=view_options, basemap='OpenStreetMap', draw=draw_options, legend=True, disable_basemap=False, ) # Return map element return [MapView, map_view_options]
def home(request): """ Controller for the app home page. """ drawing_options = MVDraw( controls=['Modify', 'Delete', 'Move', 'Point', 'LineString', 'Polygon', 'Box'], initial='Point', output_format='WKT' ) view_options = MVView( projection='EPSG:4326', center=[-100, 40], zoom=3.5, maxZoom=18, minZoom=2 ) landchange_map = MapView( height='100%', width='100%', layers=[], basemap='OpenStreetMap', view=view_options, draw=drawing_options ) save_button = Button( display_text='', name='save_button', icon='glyphicon glyphicon-floppy-disk', style='success', attributes={ 'data-toggle':'tooltip', 'data-placement':'top', 'title':'Save' } ) latitude = TextInput( display_text='Latitude', name='Latitude', placeholder='Enter Coordinates' ) longitude = TextInput( display_text='Longitude', name='Longitude', placeholder='Enter Coordinates' ) context = { 'save_button': save_button, 'landchange_map': landchange_map, 'latitude': latitude, 'longitude': longitude, } return render(request, 'landchange_learner/home.html', context)
def home(request): """ Controller for the app home page. """ save_button = Button(display_text='', name='save-button', icon='glyphicon glyphicon-floppy-disk', style='success', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Save' }) drawing_options = MVDraw(controls=['Delete', 'Point', 'Polygon', 'Box'], initial='Point', output_format='WKT') view_options = MVView(projection='EPSG:4326', center=[-100, 40], zoom=3.5, maxZoom=18, minZoom=2) home_map = MapView(height='100%', width='100%', layers=[], basemap='OpenStreetMap', view=view_options, draw=drawing_options) edit_button = Button(display_text='', name='edit-button', icon='glyphicon glyphicon-edit', style='warning', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Edit' }) remove_button = Button(display_text='', name='remove-button', icon='glyphicon glyphicon-remove', style='danger', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Remove' }) previous_button = Button(display_text='Previous', name='previous-button', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Previous' }) next_button = Button(display_text='Next', name='next-button', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Next' }) #rheas_dbs = get_database() # db_schemas = get_schemas() variable_info = get_variables_meta() geoserver_wms_url = cfg.geoserver['wms_url'] geoserver_rest_url = cfg.geoserver['rest_url'] geoserver_workspace = cfg.geoserver['workspace'] context = { 'save_button': save_button, 'edit_button': edit_button, 'remove_button': remove_button, 'previous_button': previous_button, 'next_button': next_button, 'home_map': home_map, #"rheas_dbs":rheas_dbs, # "db_schemas":db_schemas, "variable_info": json.dumps(variable_info), "geoserver_wms_url": geoserver_wms_url, "geoserver_rest_url": geoserver_rest_url, "geoserver_workspace": geoserver_workspace } return render(request, 'rheas_viewerv2/home.html', context)
def Data_Input(request): """ Geoprocessing page """ # Default Values LowValue1 = '' HighValue1 = '' river = '' date_built = '' location = '' # Errors LowValue1_error = '' HighValue1_error = '' river_error = '' date_error = '' location_error = '' # Handle form submission if request.POST and 'add-button' in request.POST: # Get values has_errors = False LowValue1 = request.POST.get('LowValue1', None) HighValue1 = request.POST.get('HighValue1', None) river = request.POST.get('river', None) date_built = request.POST.get('date-built', None) location = request.POST.get('geometry', None) # Validate if not LowValue1: has_errors = True LowValue1_error = 'LowValue1 is required.' if not HighValue1: has_errors = True HighValue1_error = 'HighValue1 is required.' if not river: has_errors = True river_error = 'River is required.' if not date_built: has_errors = True date_error = 'Date Built is required.' if not location: has_errors = True location_error = 'Location is required.' # if not has_errors: # Data_input(db_directory=app_workspace.path, location=location, LowValue1=LowValue1, HighValue1=HighValue1, river=river, date_built=date_built) # return redirect(reverse('lil_people_elcpa:home')) messages.error(request, "Please fix errors.") # Define form gizmos LowValue1 = TextInput( display_text='LowValue1', name='LowValue1', initial=LowValue1, error=LowValue1_error, ) HighValue1_input = TextInput( display_text='HighValue1', name='HighValue1', initial=HighValue1, error=HighValue1_error ) river_input = TextInput( display_text='Weight', name='river', placeholder='new value', initial=river, error=river_error ) date_built = TextInput( display_text='Low Value 2', name='date-built', error=date_error ) initial_view = MVView( projection='EPSG:4326', center=[-98.6, 39.8], zoom=3.5 ) drawing_options = MVDraw( controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000' ) location_input = MapView( height='500px', width='100%', basemap='OpenStreetMap', draw=drawing_options, view=initial_view, ) add_button = Button( display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'Weight-form'}, submit=True ) cancel_button = Button( display_text='Cancel', name='cancel-button', href=reverse('lil_people_elcpa:home') ) context = { 'LowValue1': LowValue1, 'HighValue1_input': HighValue1_input, 'river_input': river_input, 'date_built_input': date_built, 'location_input': location_input, 'location_error': location_error, 'add_button': add_button, 'cancel_button': cancel_button, } # context = {} return render(request, 'lil_people_elcpa/Data_Input.html', context)
def add_facility(request): """ Controller for the Add Facility page. """ print("In the controller") # Default Values facility_id = '' project = '' est_cost = '' const_year = '' location = '' category = '' description = '' priority = '' est_year = '' const_cost = '' debt_checked = False recur_checked = False # Errors facility_id_error = '' project_error = '' est_cost_error = '' const_year_error = '' location_error = '' category_error = '' description_error = '' priority_error = '' est_year_error = '' const_cost_error = '' # Handle form submission if request.POST and 'add-button' in request.POST: print("In the first if") # Get values has_errors = False facility_id = request.POST.get('facility_id', None) location = request.POST.get('geometry', None) # project = (request.POST.get(str(i) + '_add_project_project_name', None)) # est_cost = (request.POST.get(str(i) + '_add_project_project_estcost', None)) # est_year = (request.POST.get(str(i) + '_add_project_project_estyear', None)) # const_cost = (request.POST.get(str(i) + '_add_project_project_constcost', None)) # const_year =(request.POST.get(str(i) + '_add_project_project_constyear', None)) # category = (request.POST.get(str(i) + '_add_project_project_category', None)) # priority = (request.POST.get(str(i) + '_add_project_project_priority', None)) # description = (request.POST.get(str(i) + '_add_project_project_description', None)) # debt_checked = (request.POST.get(str(i) + '_add_project_debt_checkbox', None)) # recur_checked = (request.POST.get(str(i) + '_add_project_recur_checkbox', None)) project = (request.POST.get('project', None)) est_cost = (request.POST.get('est_cost', None)) est_year = (request.POST.get('est_year', None)) const_cost = (request.POST.get('const_cost', None)) const_year = (request.POST.get('const_year', None)) category = (request.POST.get('category', None)) priority = (request.POST.get('priority', None)) description = (request.POST.get('description', None)) debt_checked = (request.POST.get('debt_checkbox', None)) recur_checked = (request.POST.get('recur_checkbox', None)) # Validate if not facility_id: has_errors = True facility_id_error = 'Facility ID is required.' if not project: has_errors = True project_error = 'Project Name is required.' if not est_cost: has_errors = True est_cost_error = 'Cost is required.' if not const_year: has_errors = True const_year_error = 'Planned Year is required.' if not category: has_errors = True category_error = 'Category is required.' if not description: has_errors = True description_error = 'Description is required.' if not priority: has_errors = True priority_error = 'Priority is required.' if not est_year: has_errors = True est_year_error = 'Estimate Year is required.' if not const_cost: has_errors = True const_cost_error = 'Construction Cost is required.' if not location: has_errors = True location_error = 'Location is required.' if not has_errors: print("No Errors") # Get value of max_projects custom setting max_projects = app.get_custom_setting('max_projects') # Query database for count of projects Session = app.get_persistent_store_database('primary_db', as_sessionmaker=True) session = Session() num_projects = session.query(Project).count() # Only add the project if custom setting doesn't exist or we have not exceed max_projects if not max_projects or num_projects < max_projects: add_new_project(row_id=(num_projects + 1), location=location, facility_id=facility_id, project=project, est_cost=est_cost, const_year=const_year, category=category, description=description, priority=priority, est_year=est_year, const_cost=const_cost, debt_checkbox_val=debt_checked, recur_checkbox_val=recur_checked) print("Project Added") else: messages.warning( request, 'Unable to add project "{0}", because the inventory is full.' .format(facility_id)) else: messages.error(request, "Please fix errors.") return redirect(reverse('project_inventory:home')) # Define form gizmos facility_id_input = TextInput(display_text='Facility ID', name='facility_id', initial=facility_id, error=facility_id_error) project_input = TextInput(display_text='Project Name', name='project', initial=project, error=project_error) est_cost_input = TextInput(display_text='Estimated Cost', name='est_cost', attributes={ 'id': 'est_cost', 'type': 'number' }, initial=est_cost, error=est_cost_error) description_input = TextInput(display_text='Description', name='description', initial=description, error=description_error) const_cost_input = TextInput(display_text='Construction Cost', name='const_cost', attributes={ 'id': 'const_cost', 'type': 'number' }, initial=const_cost, error=const_cost_error) est_year_input = TextInput(display_text='Estimate Year', name='est_year', attributes={ 'id': 'est_year', 'type': 'number' }, initial=est_year, error=est_year_error) const_year_input = TextInput(name='const_year', display_text='Construction Year', attributes={ 'id': 'const_year', 'type': 'number' }, initial=const_year, error=const_year_error) category_input = SelectInput(display_text='Category', name='category', multiple=False, options=[('Water', 'Water'), ('Wastewater', 'Wastewater'), ('Stormwater', 'Stormwater'), ('Facilities', 'Facilities'), ('Golf', 'Golf'), ('Transportation', 'Transportation') ], initial=['Water'], error=category_error) priority_input = SelectInput(display_text='Priority', name='priority', multiple=False, options=[('One', '1'), ('Two', '2'), ('Three', '3'), ('Four', '4'), ('Five', '5')], initial=['One'], error=priority_error) view_center = [-103.28, 47.8] initial_view = MVView(projection='EPSG:4326', center=view_center, zoom=12.5) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') location_input = MapView( height='300px', width='100%', basemap=[ 'OpenStreetMap' # 'CartoDB', # {'CartoDB': {'style': 'dark'}}, # 'Stamen', # 'ESRI' ], draw=drawing_options, view=initial_view) add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-project-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('project_inventory:home')) context = { 'facility_id_input': facility_id_input, 'project_input': project_input, 'est_cost_input': est_cost_input, 'const_year_input': const_year_input, 'est_year_input': est_year_input, 'category_input': category_input, 'description_input': description_input, 'priority_input': priority_input, 'const_cost_input': const_cost_input, 'location_input': location_input, 'location_error': location_error, 'add_button': add_button, 'cancel_button': cancel_button, 'can_add_projects': has_permission(request, 'add_projects') } return render(request, 'project_inventory/add_facility.html', context)
def New_Data(request, app_workspace): """ Controller for New Data page. """ # Default Values sampleid = '' river = '' datecol = '' timecol = '' note = '' pH = '' temper = '' cond = '' ca = '' mg = '' na = '' k = '' hco = '' cl = '' so = '' sio = '' loaction = '' # Errors sampleid_error = '' datecol_error = '' location_error = '' # Handle form submission if request.POST and 'add-button' in request.POST: # Get values has_errors = False sampleid = request.POST.get('sampleid', None) river = request.POST.get('river', None) datecol = request.POST.get('datecol', None) timecol = request.POST.get('timecol', None) note = request.POST.get('note', None) pH = request.POST.get('pH', None) temper = request.POST.get('temper', None) cond = request.POST.get('cond', None) ca = request.POST.get('ca', None) mg = request.POST.get('mg', None) na = request.POST.get('na', None) k = request.POST.get('k', None) hco = request.POST.get('hco', None) cl = request.POST.get('cl', None) so = request.POST.get('so', None) sio = request.POST.get('sio', None) location = request.POST.get('geometry', None) #validate if not sampleid: has_errors = True sampleid_error = 'Sample ID is required' if not datecol: has_errors = True datecol_error = 'Date Collected is Required' if not location: has_errors = True location_error = 'Location is required' if not has_errors: #Do Stuff here add_new_data(db_directory=app_workspace.path, location=location, sampleid=sampleid, river=river, datecol=datecol, timecol=timecol, note=note, pH=pH, temper=temper, cond=cond, ca=ca, mg=mg, na=na, k=k, hco=hco, cl=cl, so=so, sio=sio) return redirect(reverse('waimea_flux:home')) messages.error(request, "Please fix errors.") # Define form gizmos sampleid_input = TextInput(display_text='Sample ID', name='sampleid', initial=sampleid, error=sampleid_error) river_input = TextInput(display_text='River', name='river', placeholder='e.g.: Waimea River') datecol_input = DatePicker(name='datecol', display_text='Date Collected', autoclose=True, format='MM d, yyyy', start_view='decade', today_button=True, initial=datecol, error=datecol_error) timecol_input = TextInput(display_text='Time of Sample Collection', name='timecol') note_input = TextInput(display_text='Any Notes?', name='note') pH_input = TextInput(display_text='pH', name='pH') temper_input = TextInput(display_text='Temperature (C)', name='temper') cond_input = TextInput(display_text='Conductivity (microsiemens/cm)', name='cond') ca_input = TextInput(display_text='Ca2+ (mg/L)', name='ca') mg_input = TextInput(display_text='Mg2+ (mg/L)', name='mg') na_input = TextInput(display_text='Na+ (mg/L)', name='na') k_input = TextInput(display_text='K+ (mg/L)', name='k') hco_input = TextInput(display_text='HCO3- (mg/L)', name='hco') cl_input = TextInput(display_text='Cl- (mg/L)', name='cl') so_input = TextInput(display_text='SO42- (mg/L)', name='so') sio_input = TextInput(display_text='SiO2 (mg/L)', name='sio') initial_view = MVView(projection='EPSG:4326', center=[-159.5, 22.07], zoom=10) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') location_input = MapView(height='300px', width='100%', basemap='OpenStreetMap', draw=drawing_options, view=initial_view) add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-sample-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('waimea_flux:home')) context = { 'sampleid_input': sampleid_input, 'river_input': river_input, 'datecol_input': datecol_input, 'timecol_input': timecol_input, 'note_input': note_input, 'pH_input': pH_input, 'temper_input': temper_input, 'cond_input': cond_input, 'ca_input': ca_input, 'mg_input': mg_input, 'na_input': na_input, 'k_input': k_input, 'hco_input': hco_input, 'cl_input': cl_input, 'so_input': so_input, 'sio_input': sio_input, 'location_input': location_input, 'location_error': location_error, 'add_button': add_button, 'cancel_button': cancel_button, } return render(request, 'waimea_flux/New_Data.html', context)
def add_dam(request, app_workspace): """ Controller for the Add Dam page. """ # Default values name = '' owner = 'Reclamation' river = '' date_built = '' location = '' # Errors name_error = '' owner_error = '' river_error = '' date_error = '' location_error = '' # Handle form submission if request.POST and 'add-button' in request.POST: # Get values has_errors = False name = request.POST.get('name', None) owner = request.POST.get('owner', None) river = request.POST.get('river', None) date_built = request.POST.get('date-built', None) location = request.POST.get('geometry', None) # Validate if not name: has_errors = True name_error = 'Name is required.' if not owner: has_errors = True owner_error = 'Owner is required.' if not river: has_errors = True river_error = 'River is required.' if not date_built: has_errors = True date_error = 'Date Built is required.' if not location: has_errors = True location_error = 'Location is required.' if not has_errors: add_new_dam(db_directory=app_workspace.path, name=name, owner=owner, river=river, date_built=date_built, location=location) return redirect(reverse('dam_inventory:home')) messages.error(request, "Please fix errors.") # Define form gizmos name_input = TextInput(display_text='Name', name='name', initial=name, error=name_error) owner_input = SelectInput(display_text='Owner', name='owner', multiple=False, options=[('Reclamation', 'Reclamation'), ('Army Corp', 'Army Corp'), ('Other', 'Other')], initial=owner, error=owner_error) river_input = TextInput(display_text='River', name='river', placeholder='e.g.: Mississippi River', initial=river, error=river_error) date_built = DatePicker(display_text='Date Built', name='date-built', autoclose=True, format='MM d, yyyy', start_view='decade', today_button=True, initial=date_built, error=date_error) initial_view = MVView(projection='EPSG:4326', center=[-98.6, 39.8], zoom=3.5) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') location_input = MapView(height='300px', width='100%', basemap='OpenStreetMap', draw=drawing_options, view=initial_view) add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-dam-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('dam_inventory:home')) context = { 'name_input': name_input, 'owner_input': owner_input, 'river_input': river_input, 'date_built_input': date_built, 'location_input': location_input, 'location_error': location_error, 'add_button': add_button, 'cancel_button': cancel_button, } return render(request, 'dam_inventory/add_dam.html', context)
def add_place(request, app_workspace): """ Controller for the Add place page. """ # Default Values name = '' type = '' description = '' location = '' # Errors name_error = '' type_error = '' location_error = '' description_error = '' # Handle form submission if request.POST and 'add-button' in request.POST: # Get values has_errors = False name = request.POST.get('name', None) type = request.POST.get('type', None) description = request.POST.get('description', None) location = request.POST.get('geometry', None) # Validate if not name: has_errors = True name_error = 'Name is required.' if not type: has_errors = True type_error = 'type is required.' if not description: has_errors = True date_error = 'Date Built is required.' if not location: has_errors = True location_error = 'Location is required.' if not has_errors: add_new_place(db_directory=app_workspace.path, location=location, name=name, type=type, description=description) return redirect(reverse('vacationeer:home')) messages.error(request, "Please fix errors.") # Define form gizmos name_input = TextInput(display_text='Name', name='name', initial=name, error=name_error) type_input = SelectInput(display_text='Type of Activity', name='type', multiple=False, options=[('Adventure', 'Adventure'), ('Relax', 'Relax'), ('Sightseeing', 'Sightseeing')], initial=['Adventure'], error=type_error) description = TextInput(name='description', display_text='Description of Activity', initial=description, error=description_error) initial_view = MVView(projection='EPSG:4326', center=[-84.079149, 9.933149], zoom=7.5) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') location_input = MapView(height='500px', width='100%', basemap='OpenStreetMap', draw=drawing_options, view=initial_view) add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-place-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('vacationeer:home')) context = { 'name_input': name_input, 'type_input': type_input, 'description_input': description, 'location_input': location_input, 'location_error': location_error, 'add_button': add_button, 'cancel_button': cancel_button, } return render(request, 'vacationeer/add_place.html', context)
def home(request, user_workspace): """ Controller for the app home page. """ # Get bounding box from user boundary if it exists boundary_props = get_boundary_fc_props_for_user(request.user) map_view = MapView( height='100%', width='100%', controls=[{ 'Zoom': { 'projection': 'EPSG:4326', 'extent': boundary_props.get('bbox', [-180, -90, 180, 90]) # Default to World } }], basemap=[ 'OpenStreetMap', 'Stamen', { 'ESRI': { 'layer': 'World_Imagery' } }, { 'ESRI': { 'layer': 'World_Street_Map' } }, ], view=MVView( projection='EPSG:4326', center=boundary_props.get('centroid', [0, 0]), # Default to World zoom=boundary_props.get('zoom', 3), # Default to World maxZoom=18, minZoom=2), draw=MVDraw(controls=[ 'Pan', 'Modify', 'Delete', 'Move', 'Point', 'Polygon', 'Box' ], initial='Pan', output_format='GeoJSON')) default_platform = 'modis' default_sensors = EE_PRODUCTS[default_platform] first_sensor_key = next(iter(default_sensors.keys())) default_products = default_sensors[first_sensor_key] first_product_key = next(iter(default_products.keys())) first_product = default_products[first_product_key] # Build initial platform control platform_select = SelectInput( name='platform', display_text='Satellite Platform or model', options=( ('MODIS', 'modis'), ('Sentinel', 'sentinel'), ('Landsat', 'landsat'), ('GLDAS', 'gldas'), ('WAPOR', 'wapor'), ('GPWV411', 'gpwv411'), ('GRACE', 'grace'), ('CHIRPS', 'chirps'), ('TERRACLIMATE', 'terraclimate'), # ('OpenLandMap', 'openlandmap'),terraclimate # ('GHSL', 'ghsl') )) # Build initial sensor control sensor_options = [] for sensor in default_sensors: sensor_options.append((sensor.upper(), sensor)) sensor_select = SelectInput( name='sensor', display_text='Sensor', options=sensor_options, ) # Build initial product control product_options = [] for product, info in default_products.items(): product_options.append((info['display'], product)) product_select = SelectInput(name='product', display_text='Product', options=product_options) # Hardcode initial end date to today (since all of our datasets extend to present) today = dt.datetime.today() initial_end_date = today.strftime('%Y-%m-%d') # Initial start date will a set number of days before the end date # NOTE: This assumes the start date of the dataset is at least 30+ days prior to today initial_end_date_dt = dt.datetime.strptime(initial_end_date, '%Y-%m-%d') initial_start_date_dt = initial_end_date_dt - dt.timedelta(days=30) initial_start_date = initial_start_date_dt.strftime('%Y-%m-%d') # Build date controls first_product_start_date = first_product.get('start_date', None) first_product_end_date = first_product.get('end_date', None) or initial_end_date start_date = DatePicker(name='start_date', display_text='Start Date', format='yyyy-mm-dd', start_view='decade', today_button=True, today_highlight=True, start_date=first_product_start_date, end_date=first_product_end_date, initial=initial_start_date, autoclose=True) end_date = DatePicker(name='end_date', display_text='End Date', format='yyyy-mm-dd', start_view='decade', today_button=True, today_highlight=True, start_date=first_product_start_date, end_date=first_product_end_date, initial=initial_end_date, autoclose=True) # Build reducer method control reducer_select = SelectInput(name='reducer', display_text='Reduction Method', options=( ('Median', 'median'), ('Mosaic', 'mosaic'), ('Mode', 'mode'), ('Mean', 'mean'), ('Minimum', 'min'), ('Maximum', 'max'), ('Sum', 'sum'), ('Count', 'count'), ('Product', 'product'), )) # Build Buttons load_button = Button(name='load_map', display_text='Load', style='default', attributes={'id': 'load_map'}) clear_button = Button(name='clear_map', display_text='Clear', style='default', attributes={'id': 'clear_map'}) plot_button = Button(name='load_plot', display_text='Plot Time Series', style='default', attributes={'id': 'load_plot'}) # Boundary Upload Form set_boundary_button = Button( name='set_boundary', display_text='Set Boundary', style='default', attributes={ 'id': 'set_boundary', 'data-toggle': 'modal', 'data-target': '#set-boundary-modal' # ID of the Set Boundary Modal }) # Handle Set Boundary Form # Handle Set Boundary Form set_boundary_error = '' if request.POST and request.FILES: set_boundary_error = handle_shapefile_upload(request, user_workspace) if not set_boundary_error: # Redirect back to this page to clear form return HttpResponseRedirect(request.path) context = { 'platform_select': platform_select, 'sensor_select': sensor_select, 'product_select': product_select, 'start_date': start_date, 'end_date': end_date, 'reducer_select': reducer_select, 'ee_products': EE_PRODUCTS, 'load_button': load_button, 'clear_button': clear_button, 'plot_button': plot_button, 'set_boundary_button': set_boundary_button, 'set_boundary_error': set_boundary_error, 'map_view': map_view } return render(request, 'earth_engine2/home.html', context)
def new_bloom(request, app_workspace): """ Controller for the background page. """ #Default Values location = '' type = 'Lake' severity = '' date = '' mapdraw = '' #Errors location_error = '' type_error = '' severity_error = '' date_error = '' mapdraw_error = '' #Handle form submission if request.POST and 'add-button' in request.POST: #Get values has_errors = False location = request.POST.get('location', None) type = request.POST.get('type', None) severity = request.POST.get('severity', None) date = request.POST.get('date', None) mapdraw = request.POST.get('geometry', None) #validate if not location: has_errors = True location_error = 'Location is required.' if not type: has_errors = True type_error = 'Type is required.' if not severity: has_errors = True severity_error = 'Severity is required.' if not date: has_errors = True date_error = 'Date is required.' if not mapdraw: has_errors = True mapdraw_error = 'Must draw location on map.' if not has_errors: add_new_bloom(db_directory=app_workspace.path, mapdraw=mapdraw, location=location, type=type, severity=severity, date=date) return redirect(reverse('utah_algal_blooms:home')) messages.error(request, "Please fix errors.") # Define form gizmos location_input = TextInput(display_text='Location', name='location', placeholder='e.g.: Utah Lake', initial=location, error=location_error) type_input = SelectInput(display_text='Water Body Type', name='type', multiple=False, options=[('Lake', 'Lake'), ('Reservoir', 'Reservoir'), ('Other', 'Other')], initial=type, error=type_error) severity_input = SelectInput(display_text='Severity', name='severity', multiple=False, options=[('Low', 'Low'), ('Moderate', 'Moderate'), ('High', 'High'), ('Extreme', 'Extreme')], initial=severity, error=severity_error) date = DatePicker(name='date', display_text='Date of Appearance', autoclose=True, format='MM d, yyyy', start_view='decade', today_button=True, initial=date, error=date_error) initial_view = MVView(projection='EPSG:4326', center=[-110, 39.8], zoom=5) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') mapdraw_input = MapView(height='300px', width='100%', basemap='OpenStreetMap', draw=drawing_options, view=initial_view) add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-bloom-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('utah_algal_blooms:home')) context = { 'location_input': location_input, 'type_input': type_input, 'severity_input': severity_input, 'date_input': date, 'mapdraw_input': mapdraw_input, 'mapdraw_error': mapdraw_error, 'add_button': add_button, 'cancel_button': cancel_button, } return render(request, 'utah_algal_blooms/new_bloom.html', context)
def home(request): """ Controller for the app home page. """ default_platform = 'modis' default_sensors = EE_PRODUCTS[default_platform] first_sensor_key = next(iter(default_sensors.keys())) default_products = default_sensors[first_sensor_key] first_product_key = next(iter(default_products.keys())) first_product = default_products[first_product_key] # Build initial platform control platform_select = SelectInput(name='platform', display_text='Satellite Platform', options=(('MODIS', 'modis'), ('Sentinel', 'sentinel'), ('Landsat', 'landsat'))) # Build initial sensor control sensor_options = [] for sensor in default_sensors: sensor_options.append((sensor.upper(), sensor)) sensor_select = SelectInput(name='sensor', display_text='Sensor', options=sensor_options) # Build initial product control product_options = [] for product, info in default_products.items(): product_options.append((info['display'], product)) product_select = SelectInput(name='product', display_text='Product', options=product_options) # Hardcode initial end date to today (since all of our datasets extend to present) today = dt.datetime.today() initial_end_date = today.strftime('%Y-%m-%d') # Initial start date will a set number of days before the end date # NOTE: This assumes the start date of the dataset is at least 30+ days prior to today initial_end_date_dt = dt.datetime.strptime(initial_end_date, '%Y-%m-%d') initial_start_date_dt = initial_end_date_dt - dt.timedelta(days=30) initial_start_date = initial_start_date_dt.strftime('%Y-%m-%d') # Build date controls first_product_start_date = first_product.get('start_date', None) first_product_end_date = first_product.get('end_date', None) or initial_end_date start_date = DatePicker(name='start_date', display_text='Start Date', format='yyyy-mm-dd', start_view='decade', today_button=True, today_highlight=True, start_date=first_product_start_date, end_date=first_product_end_date, initial=initial_start_date, autoclose=True) end_date = DatePicker(name='end_date', display_text='End Date', format='yyyy-mm-dd', start_view='decade', today_button=True, today_highlight=True, start_date=first_product_start_date, end_date=first_product_end_date, initial=initial_end_date, autoclose=True) # Build reducer method control reducer_select = SelectInput(name='reducer', display_text='Reduction Method', options=( ('Median', 'median'), ('Mosaic', 'mosaic'), ('Mode', 'mode'), ('Mean', 'mean'), ('Minimum', 'min'), ('Maximum', 'max'), ('Sum', 'sum'), ('Count', 'count'), ('Product', 'product'), )) # Build Buttons load_button = Button(name='load_map', display_text='Load', style='default', attributes={'id': 'load_map'}) clear_button = Button(name='clear_map', display_text='Clear', style='default', attributes={'id': 'clear_map'}) plot_button = Button(name='load_plot', display_text='Plot AOI', style='default', attributes={'id': 'load_plot'}) map_view = MapView(height='100%', width='100%', controls=[ 'ZoomSlider', 'Rotate', 'FullScreen', { 'ZoomToExtent': { 'projection': 'EPSG:4326', 'extent': [29.25, -4.75, 46.25, 5.2] } } ], basemap=[ 'CartoDB', { 'CartoDB': { 'style': 'dark' } }, 'OpenStreetMap', 'Stamen', 'ESRI' ], view=MVView(projection='EPSG:4326', center=[37.880859, 0.219726], zoom=7, maxZoom=18, minZoom=2), draw=MVDraw(controls=[ 'Pan', 'Modify', 'Delete', 'Move', 'Point', 'Polygon', 'Box' ], initial='Pan', output_format='GeoJSON')) context = { 'platform_select': platform_select, 'sensor_select': sensor_select, 'product_select': product_select, 'start_date': start_date, 'end_date': end_date, 'reducer_select': reducer_select, 'load_button': load_button, 'clear_button': clear_button, 'plot_button': plot_button, 'ee_products': EE_PRODUCTS, 'map_view': map_view } return render(request, 'earth_engine/home.html', context)
def add_dam(request): """ Controller for the Add Dam page. """ # Default Values name = '' owner = 'Reclamation' river = '' date_built = '' location = '' # Errors name_error = '' owner_error = '' river_error = '' date_error = '' location_error = '' # Handle form submission if request.POST and 'add-button' in request.POST: # Get values has_errors = False name = request.POST.get('name', None) owner = request.POST.get('owner', None) river = request.POST.get('river', None) date_built = request.POST.get('date-built', None) location = request.POST.get('geometry', None) # Validate if not name: has_errors = True name_error = 'Name is required.' if not owner: has_errors = True owner_error = 'Owner is required.' if not river: has_errors = True river_error = 'River is required.' if not date_built: has_errors = True date_error = 'Date Built is required.' if not location: has_errors = True location_error = 'Location is required.' if not has_errors: # Get value of max_dams custom setting max_dams = app.get_custom_setting('max_dams') # Query database for count of dams Session = app.get_persistent_store_database('primary_db', as_sessionmaker=True) session = Session() num_dams = session.query(Dam).count() user_id = request.user.id # Only add the dam if custom setting doesn't exist or we have not exceed max_dams if not max_dams or num_dams < max_dams: add_new_dam(location=location, name=name, owner=owner, river=river, date_built=date_built, user_id=user_id) else: messages.warning( request, 'Unable to add dam "{0}", because the inventory is full.'. format(name)) new_num_dams = session.query(Dam).count() if new_num_dams > num_dams: channel_layer = get_channel_layer() async_to_sync(channel_layer.group_send)("notifications", { "type": "dam_notifications", "message": "New Dam" }) return redirect(reverse('dam_inventory:home')) messages.error(request, "Please fix errors.") # Define form gizmos name_input = TextInput(display_text='Name', name='name', initial=name, error=name_error) owner_input = SelectInput(display_text='Owner', name='owner', multiple=False, options=[('Reclamation', 'Reclamation'), ('Army Corp', 'Army Corp'), ('Other', 'Other')], initial=owner, error=owner_error) river_input = TextInput(display_text='River', name='river', placeholder='e.g.: Mississippi River', initial=river, error=river_error) date_built = DatePicker(name='date-built', display_text='Date Built', autoclose=True, format='MM d, yyyy', start_view='decade', today_button=True, initial=date_built, error=date_error) initial_view = MVView(projection='EPSG:4326', center=[-98.6, 39.8], zoom=3.5) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') location_input = MapView(height='300px', width='100%', basemap='OpenStreetMap', draw=drawing_options, view=initial_view) add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-dam-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('dam_inventory:home')) context = { 'name_input': name_input, 'owner_input': owner_input, 'river_input': river_input, 'date_built_input': date_built, 'location_input': location_input, 'location_error': location_error, 'add_button': add_button, 'cancel_button': cancel_button, 'can_add_dams': has_permission(request, 'add_dams') } return render(request, 'dam_inventory/add_dam.html', context)
def addloc(request, app_workspace): """ Controller for the Add Site page. """ country = '' city = '' lat = '' date_eq = '' long = '' country_error = '' city_error = '' lat_error = '' date_error = '' long_error = '' if request.POST and 'add-button' in request.POST: has_errors = False country = request.POST.get('country', None) city = request.POST.get('city', None) lat = request.POST.get('lat', None) date_eq = request.POST.get('date-eq', None) long = request.POST.get('long', None) if not country: has_errors = True country_error = 'Country is required.' if not city: has_errors = True city_error = 'City is required.' if not lat: has_errors = True lat_error = 'Lattitude is required.' if not date_eq: has_errors = True date_error = 'Date of earthquake is required.' if not long: has_errors = True long_error = 'Longitude is required.' if not has_errors: add_new_site(db_directory=app_workspace.path, long=long, country=country, city=city, lat=lat, date_eq=date_eq) return redirect(reverse('liq_inventory:home')) messages.error(request, "Please fix errors.") country_input = TextInput(display_text='Country', name='country', initial=country, error=country_error) city_input = TextInput(display_text='City', name='city', initial=city, error=city_error) lat_input = TextInput(display_text='Lattitude', name='lat', initial=lat, error=lat_error) long_input = TextInput(display_text='Longitude', name='long', initial=long, error=long_error) date_eq = DatePicker(name='date-eq', display_text='Date of Earthquake', autoclose=True, format='MM d, yyyy', start_view='decade', today_button=True, initial=date_eq, error=date_error) initial_view = MVView(projection='EPSG:4326', center=[-98.6, 39.8], zoom=3.5) drawing_options = MVDraw(controls=['Modify', 'Delete', 'Move', 'Point'], initial='Point', output_format='GeoJSON', point_color='#FF0000') add_button = Button(display_text='Add', name='add-button', icon='glyphicon glyphicon-plus', style='success', attributes={'form': 'add-site-form'}, submit=True) cancel_button = Button(display_text='Cancel', name='cancel-button', href=reverse('liq_inventory:home')) context = { 'country_input': country_input, 'city_input': city_input, 'lat_input': lat_input, 'date_eq_input': date_eq, 'long_input': long_input, 'add_button': add_button, 'cancel_button': cancel_button, } return render(request, 'liq_inventory/addloc.html', context)
def viewer(request, user_workspace): """ Controller for the app viewer page. """ default_platform = 'modis' default_sensors = EE_PRODUCTS[default_platform] first_sensor_key = next(iter(default_sensors.keys())) default_products = default_sensors[first_sensor_key] first_product_key = next(iter(default_products.keys())) first_product = default_products[first_product_key] # Build initial platform control platform_select = SelectInput(name='platform', display_text='Satellite Platform', options=(('MODIS', 'modis'), ('Sentinel', 'sentinel'), ('Landsat', 'landsat'))) # Build initial sensor control sensor_options = [] for sensor in default_sensors: sensor_options.append((sensor.upper(), sensor)) sensor_select = SelectInput(name='sensor', display_text='Sensor', options=sensor_options) # Build initial product control product_options = [] for product, info in default_products.items(): product_options.append((info['display'], product)) product_select = SelectInput(name='product', display_text='Product', options=product_options) # Get initial default dates and date ranges for date picker controls first_product_dates = compute_dates_for_product(first_product) start_date = DatePicker( name='start_date', display_text='Start Date', format='yyyy-mm-dd', start_view='decade', today_button=True, today_highlight=True, start_date=first_product_dates['beg_valid_date_range'], end_date=first_product_dates['end_valid_date_range'], initial=first_product_dates['default_start_date'], autoclose=True) end_date = DatePicker( name='end_date', display_text='End Date', format='yyyy-mm-dd', start_view='decade', today_button=True, today_highlight=True, start_date=first_product_dates['beg_valid_date_range'], end_date=first_product_dates['end_valid_date_range'], initial=first_product_dates['default_end_date'], autoclose=True) # Build reducer method control reducer_select = SelectInput(name='reducer', display_text='Reduction Method', options=( ('Median', 'median'), ('Mosaic', 'mosaic'), ('Mode', 'mode'), ('Mean', 'mean'), ('Minimum', 'min'), ('Maximum', 'max'), ('Sum', 'sum'), ('Count', 'count'), ('Product', 'product'), )) # Build Buttons load_button = Button(name='load_map', display_text='Load', style='default', attributes={'id': 'load_map'}) clear_button = Button(name='clear_map', display_text='Clear', style='default', attributes={'id': 'clear_map'}) plot_button = Button(name='load_plot', display_text='Plot AOI', style='default', attributes={'id': 'load_plot'}) # Get bounding box from user boundary if it exists boundary_props = get_boundary_fc_props_for_user(request.user) map_view = MapView( height='100%', width='100%', controls=[ 'ZoomSlider', 'Rotate', 'FullScreen', { 'ZoomToExtent': { 'projection': 'EPSG:4326', 'extent': boundary_props.get( 'bbox', [-180, -90, 180, 90]) # Default to World } } ], basemap=[ 'CartoDB', { 'CartoDB': { 'style': 'dark' } }, 'OpenStreetMap', 'Stamen', 'ESRI' ], view=MVView( projection='EPSG:4326', center=boundary_props.get('centroid', [0, 0]), # Default to World zoom=boundary_props.get('zoom', 3), # Default to World maxZoom=18, minZoom=2), draw=MVDraw(controls=[ 'Pan', 'Modify', 'Delete', 'Move', 'Point', 'Polygon', 'Box' ], initial='Pan', output_format='GeoJSON')) # Boundary Upload Form set_boundary_button = Button( name='set_boundary', display_text='Set Boundary', style='default', attributes={ 'id': 'set_boundary', 'data-toggle': 'modal', 'data-target': '#set-boundary-modal' # ID of the Set Boundary Modal }) # Handle Set Boundary Form set_boundary_error = '' if request.POST and request.FILES: set_boundary_error = handle_shapefile_upload(request, user_workspace) if not set_boundary_error: # Redirect back to this page to clear form return HttpResponseRedirect(request.path) context = { 'platform_select': platform_select, 'sensor_select': sensor_select, 'product_select': product_select, 'start_date': start_date, 'end_date': end_date, 'reducer_select': reducer_select, 'load_button': load_button, 'clear_button': clear_button, 'plot_button': plot_button, 'set_boundary_button': set_boundary_button, 'set_boundary_error': set_boundary_error, 'ee_products': EE_PRODUCTS, 'map_view': map_view } return render(request, 'earth_engine/viewer.html', context)
def home(request): """ Controller for the app home page. """ drawing_options = MVDraw( controls=[ 'Delete', 'Point', 'Polygon', 'Box'], initial='Point', output_format='WKT' ) view_options = MVView( projection='EPSG:4326', center=[-100, 40], zoom=3.5, maxZoom=18, minZoom=2 ) landchange_map = MapView( height='100%', width='100%', layers=[], basemap='OpenStreetMap', view=view_options, draw=drawing_options ) get_ndvi_button = Button( display_text='Load NDVI', name='get_ndvi', attributes={ 'data-toggle':'tooltip', 'data-placement':'top', 'title':'Load NDVI' } ) latitude = TextInput( display_text='Latitude', name='Latitude', placeholder='Enter Coordinates' ) longitude = TextInput( display_text='Longitude', name='Longitude', placeholder='Enter Coordinates' ) startdatepicker = DatePicker(name='startdate', display_text='Start Date', autoclose=True, format='yyyy-mm-dd', start_date='2014-02-01', start_view='decade', today_button=True, initial='2014-02-01') enddatepicker = DatePicker(name='enddate', display_text='End Date', autoclose=True, format='yyyy-mm-dd', start_date='2015-02-01', start_view='decade', today_button=True, initial='2015-02-01') context = { 'get_ndvi_button': get_ndvi_button, 'landchange_map': landchange_map, 'latitude': latitude, 'longitude': longitude, 'startdatepicker': startdatepicker, 'enddatepicker': enddatepicker } return render(request, 'landchange_learner/home.html', context)