def map(request): """ Controller for the map page """ geoserver_engine = app.get_spatial_dataset_service(name='main_geoserver', as_engine=True) options = [] response = geoserver_engine.list_layers(with_properties=False) if response['success']: for layer in response['result']: options.append((layer.title(), layer)) select_options = SelectInput(display_text='Choose Layer', name='layer', multiple=False, options=options) map_layers = [] if request.POST and 'layer' in request.POST: selected_layer = request.POST['layer'] legend_title = selected_layer.title() geoserver_layer = MVLayer(source='ImageWMS', options={ 'url': 'http://localhost:8181/geoserver/wms', 'params': { 'LAYERS': selected_layer }, 'serverType': 'geoserver' }, legend_title=legend_title, legend_extent=[-114, 36.5, -109, 42.5], legend_classes=[ MVLegendClass('polygon', 'County', fill='#999999'), ]) map_layers.append(geoserver_layer) view_options = MVView(projection='EPSG:4326', center=[-100, 40], zoom=4, maxZoom=18, minZoom=2) map_options = MapView(height='500px', width='100%', layers=map_layers, legend=True, view=view_options) context = {'map_options': map_options, 'select_options': select_options} return render(request, 'cultivar/map.html', context)
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 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) # Define map view options map_view_options = MapView(height='500px', width='100%', controls=['ZoomSlider'], view=view_options, basemap='OpenStreetMap', draw=True, legend=True) # Return map element return [MapView, map_view_options]
def home(request): """ Controller for the app home page. """ # Define view options view_options = MVView(projection='EPSG:4326', center=[-60, 40], zoom=3.5, maxZoom=18, minZoom=2) map_view_options = MapView( height='100%', # height='619px', width='100%', controls=[ 'ZoomSlider', 'Rotate', 'FullScreen', { 'MousePosition': { 'projection': 'EPSG:4326' } }, { 'ZoomToExtent': { 'projection': 'EPSG:4326', 'extent': [-130, 22, -10, 54] } } ], layers=[], view=view_options, basemap='OpenStreetMap', draw=None, legend=True) context = {'map_view_options': map_view_options} return render(request, 'ucar_hydrologic_forecasts/home.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): """ Controller for the app home page. """ # Get list of sensors and create sensors MVLayer: sensors = get_all_sensors() features = [] lat_list = [] lng_list = [] if sensors is not None: for sensor in sensors: lat_list.append(sensor.latitude) lng_list.append(sensor.longitude) sensor_feature = { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [sensor.longitude, sensor.latitude] }, 'properties': { 'id': sensor.id, 'latitude': sensor.latitude, 'longitude': sensor.longitude } } features.append(sensor_feature) # Define GeoJSON FeatureCollection sensors_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } # Create a Map View Layer sensors_layer = MVLayer(source='GeoJSON', options=sensors_feature_collection, legend_title='Sensors', layer_options={ 'style': { 'image': { 'circle': { 'radius': 8, 'fill': { 'color': '#d84e1f' }, 'stroke': { 'color': '#ffffff', 'width': 1 }, } } } }, feature_selection=True) # Define view centered on sensor locations try: view_center = [ sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-98.6, 39.8] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=4.5, maxZoom=18, minZoom=2) sensor_map = MapView(height='100%', width='100%', layers=[sensors_layer], basemap='OpenStreetMap', view=view_options) context = { 'sensor_map': sensor_map, } return render(request, 'open_air/home.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 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 home(request, app_workspace): """ Controller for the app home page. """ # Get list of projects and create projects MVLayer: projects = get_all_projects() ww_features = [] w_features = [] sw_features = [] fac_features = [] golf_features = [] transp_features = [] lat_list = [] lng_list = [] for project in projects: if project.latitude != 0 and project.longitude != 0: lat_list.append(project.latitude) lng_list.append(project.longitude) project_feature = { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [project.longitude, project.latitude], }, 'properties': { 'id': project.id, 'facility_id': project.facility_id, 'project': project.project, 'est_cost': project.est_cost, 'const_year': project.const_year, 'category': project.category, 'description': project.description, 'priority': project.priority, 'est_year': project.est_year, 'const_cost': project.const_cost } } if project.category == "Wastewater": ww_features.append(project_feature) elif project.category == "Stormwater": sw_features.append(project_feature) elif project.category == "Facilities": fac_features.append(project_feature) elif project.category == "Golf": golf_features.append(project_feature) elif project.category == "Transportation": fac_features.append(project_feature) else: w_features.append(project_feature) new_file_path = os.path.join(app_workspace.path, "icon.gif") print(app_workspace.path) # Define GeoJSON FeatureCollections sw_projects_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': sw_features } w_projects_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': w_features } ww_projects_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': ww_features } fac_projects_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': fac_features } golf_projects_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': golf_features } transp_projects_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': transp_features } # sw_style = {'ol.style.Style': { # 'image': {'ol.style.RegularShape': { # 'radius': 10, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 # }} # }} # }} sw_style = { 'ol.style.Style': { 'image': { 'ol.style.Icon': { 'src': '/static/project_inventory/images/Stormwater.png', 'scale': 0.09, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 } }, } } fac_style = { 'ol.style.Style': { 'image': { 'ol.style.Icon': { 'src': '/static/project_inventory/images/facilities.png', 'scale': 0.09, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 } }, } } ww_style = { 'ol.style.Style': { 'image': { 'ol.style.Icon': { 'src': '/static/project_inventory/images/WW.png', 'scale': 0.09, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 } }, } } w_style = { 'ol.style.Style': { 'image': { 'ol.style.Icon': { 'src': '/static/project_inventory/images/Water.png', 'scale': 0.09, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 } }, } } golf_style = { 'ol.style.Style': { 'image': { 'ol.style.Icon': { 'src': '/static/project_inventory/images/Golf.png', 'scale': 0.09, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 } }, } } transp_style = { 'ol.style.Style': { 'image': { 'ol.style.Icon': { 'src': '/static/project_inventory/images/Transportation.png', 'scale': 0.09, # 'points': 4, # 'angle': np.pi / 4, # 'fill': {'ol.style.Fill': { # 'color': '#03fc45' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 } }, } } # w_style = {'ol.style.Style': { # 'image': {'ol.style.Circle': { # 'radius': 10, # 'fill': {'ol.style.Fill': { # 'color': '#d84e1f' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 # }} # }} # }} # ww_style = {'ol.style.Style': { # 'image': {'ol.style.RegularShape': { # 'radius': 10, # 'points': 3, # 'rotation': np.pi / 4, # 'angle': 0, # 'fill': {'ol.style.Fill': { # 'color': '#fc0303' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 # }} # }} # }} # fac_style = {'ol.style.Style': { # 'image': {'ol.style.Circle': { # 'radius': 10, # 'fill': {'ol.style.Fill': { # 'color': '#fcba03' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 # }} # }} # }} # golf_style = {'ol.style.Style': { # 'image': {'ol.style.Circle': { # 'radius': 10, # 'fill': {'ol.style.Fill': { # 'color': '#a6a49f' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 # }} # }} # }} # transp_style = {'ol.style.Style': { # 'image': {'ol.style.Circle': { # 'radius': 10, # 'fill': {'ol.style.Fill': { # 'color': '#c000fa' # }}, # 'stroke': {'ol.style.Stroke': { # 'color': '#ffffff', # 'width': 1 # }} # }} # }} # Create a Map View Layer sw_projects_layer = MVLayer(source='GeoJSON', options=sw_projects_feature_collection, legend_title='Stormwater Projects', layer_options={'style': sw_style}, feature_selection=True) w_projects_layer = MVLayer(source='GeoJSON', options=w_projects_feature_collection, legend_title='Water Projects', layer_options={'style': w_style}, feature_selection=True) ww_projects_layer = MVLayer(source='GeoJSON', options=ww_projects_feature_collection, legend_title='Wastewater Projects', layer_options={'style': ww_style}, feature_selection=True) fac_projects_layer = MVLayer(source='GeoJSON', options=fac_projects_feature_collection, legend_title='Facilities Projects', layer_options={'style': fac_style}, feature_selection=True) golf_projects_layer = MVLayer( source='GeoJSON', options=golf_projects_feature_collection, legend_title='Golf Projects', # legend_classes=[MVLegendClass('point', 'Golf Projects', fill='rgba(0,0,255,0.1)', stroke='blue')], layer_options={'style': golf_style}, feature_selection=True) transp_projects_layer = MVLayer(source='GeoJSON', options=transp_projects_feature_collection, legend_title='Transportation Projects', layer_options={'style': transp_style}, feature_selection=True) # Define view centered on project locations # try: # view_center = [sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list))] # except ZeroDivisionError: view_center = [-103.28, 47.8] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=12.5, maxZoom=18, minZoom=2) project_inventory_map = MapView( height='100%', width='100%', layers=[ sw_projects_layer, w_projects_layer, ww_projects_layer, fac_projects_layer, golf_projects_layer, transp_projects_layer ], basemap=[ 'OpenStreetMap', # 'CartoDB', # {'CartoDB': {'style': 'dark'}}, # 'Stamen', # 'ESRI' ], view=view_options, # legend=True ) add_project_button = Button(display_text='Add Project', name='add-project-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('project_inventory:add_project')) context = { 'project_inventory_map': project_inventory_map, 'add_project_button': add_project_button, # 'can_add_projects': has_permission(request, 'add_projects') } return render(request, 'project_inventory/home.html', context)
def Datamap(request, app_workspace): """ Controller for the background page. """ waters = get_all_water(app_workspace.path) features = [] lat_list = [] lng_list = [] # Define GeoJSON Features for water in waters: water_location = water.pop('location') lat_list.append(water_location['coordinates'][1]) lng_list.append(water_location['coordinates'][0]) water_feature = { 'type': 'Feature', 'geometry': { 'type': water_location['type'], 'coordinates': water_location['coordinates'], } } features.append(water_feature) # Define GeoJSON FeatureCollection water_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } style = { 'ol.style.Style': { 'image': { 'ol.style.Circle': { 'radius': 10, 'fill': { 'ol.style.Fill': { 'color': '#d84e1f' } }, 'stroke': { 'ol.style.Stroke': { 'color': '#ffffff', 'width': 1 } } } } } } # Create a Map View Layer water_layer = MVLayer(source='GeoJSON', options=water_feature_collection, legend_title='Water Samples', layer_options={'style': style}) # Define view centered on dam locations try: view_center = [ sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-159.5, 22.07] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=11, maxZoom=18, minZoom=2) water_sample_map = MapView(height='100%', width='100%', layers=[water_layer], basemap='OpenStreetMap', view=view_options) add_sample_button = Button(display_text='Add Dam', name='add-sample-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('waimea_flux:New_Data')) context = { 'water_sample_map': water_sample_map, 'add_sample_button': add_sample_button } return render(request, 'waimea_flux/Datamap.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 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 home(request): """ Controller for the app home page. """ # Get list of dams and create dams MVLayer: dams = get_all_dams() features = [] lat_list = [] lng_list = [] for dam in dams: lat_list.append(dam.latitude) lng_list.append(dam.longitude) dam_feature = { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [dam.longitude, dam.latitude], }, 'properties': { 'id': dam.id, 'name': dam.name, 'owner': dam.owner, 'river': dam.river, 'date_built': dam.date_built } } features.append(dam_feature) # Define GeoJSON FeatureCollection dams_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } # Create a Map View Layer dams_layer = MVLayer( source='GeoJSON', options=dams_feature_collection, legend_title='Dams', layer_options={ 'style': { 'image': { 'circle': { 'radius': 10, 'fill': {'color': '#d84e1f'}, 'stroke': {'color': '#ffffff', 'width': 1}, } } } } ) # Define view centered on dam locations try: view_center = [sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list))] except ZeroDivisionError: view_center = [-98.6, 39.8] view_options = MVView( projection='EPSG:4326', center=view_center, zoom=4.5, maxZoom=18, minZoom=2 ) dam_inventory_map = MapView( height='100%', width='100%', layers=[dams_layer], basemap='OpenStreetMap', view=view_options ) add_dam_button = Button( display_text='Add Dam', name='add-dam-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('dam_inventory:add_dam') ) context = { 'dam_inventory_map': dam_inventory_map, 'add_dam_button': add_dam_button } return render(request, 'dam_inventory/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 home(request): """ Controller for the app home page. """ # Define view options view_options = MVView(projection='EPSG:4326', center=[-90.856665, 32.309082], zoom=5, maxZoom=18, minZoom=2) esri_layer_names = [ 'NatGeo_World_Map', 'Ocean_Basemap', 'USA_Topo_Maps', 'World_Imagery', 'World_Physical_Map', 'World_Shaded_Relief', 'World_Street_Map', 'World_Terrain_Base', 'World_Topo_Map', ] esri_layers = [{'ESRI': {'layer': l}} for l in esri_layer_names] basemaps = [ 'Stamen', { 'Stamen': { 'layer': 'toner', 'control_label': 'Black and White' } }, { 'Stamen': { 'layer': 'watercolor' } }, 'OpenStreetMap', 'CartoDB', { 'CartoDB': { 'style': 'dark' } }, { 'CartoDB': { 'style': 'light', 'labels': False, 'control_label': 'CartoDB-light-no-labels' } }, 'ESRI', { 'XYZ': { 'url': 'https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png', 'control_label': 'Wikimedia' } } ] basemaps.extend(esri_layers) MapView.ol_version = '5.3.0' map_view_options = MapView(height='100%', width='100%', controls=[ 'ZoomSlider', 'Rotate', 'FullScreen', { 'MousePosition': { 'projection': 'EPSG:4326' } }, { 'ZoomToExtent': { 'projection': 'EPSG:4326', 'extent': [-130, 22, -10, 54] } } ], view=view_options, basemap=basemaps, draw=None, legend=False) collection_select_options = SelectInput( display_text='Select Collection', name='collection', multiple=False, options=[], ) new_collection_name_text_options = TextInput( display_text='New Collection Name', name='new_collection_name', ) new_collection_description_text_options = TextInput( display_text='New Collection Description', name='new_collection_description', ) act_project = quest.api.get_active_project() project_select_options = SelectInput( display_text='Set Active Project', name='project', multiple=False, select2_options={'placeholder': 'Select a Project'}, options=[(v['display_name'], k) for k, v in quest.api.get_projects(expand=True).items() if k != act_project], ) project_delete_select_options = SelectInput( display_text='Project to Delete', name='delete_project', multiple=False, select2_options={'placeholder': 'Select Project to Delete..'}, options=[(v['display_name'], k) for k, v in quest.api.get_projects(expand=True).items() if k != act_project], ) new_project_name_text_options = TextInput( display_text='New Project Name', name='new_project_name', ) parameters_select_options = SelectInput( name='parameter', display_text='', options=[(p, p) for p in quest.api.get_mapped_parameters()], select2_options={'placeholder': 'Select a parameter'}, ) services = json.dumps(list(quest.api.get_services(expand=True).values())) checkbox_tree = utilities.get_hierarchical_provider_list() context = { 'services': services, 'parameters_select_options': parameters_select_options, 'checkbox_tree': checkbox_tree, 'geom_types': [('Points', 'point'), ('Lines', 'line'), ('Polygon', 'polygon'), ('Any', '')], 'map_view_options': map_view_options, 'collection_select_options': collection_select_options, 'new_collection_name_text_options': new_collection_name_text_options, 'new_collection_description_text_options': new_collection_description_text_options, 'project_select_options': project_select_options, 'project_delete_select_options': project_delete_select_options, 'new_project_name_text_options': new_project_name_text_options, 'active_project': quest.api.get_active_project(), } return render(request, 'quest/home.html', context)
def home(request): """ Controller for the app home page. """ data = getAllData(testingHomePage=True) features = [] lat_list = [] long_list = [] for index, row in data.iterrows(): lat_list.append(row['latitude']) long_list.append(row['longitude']) location_feature = { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [row['longitude'], row['latitude']], }, 'properties': { 'location_id': row['location_id'], 'latitude': row['latitude'], 'longitude': row['longitude'], 'county_state': row['county_state'], 'prcp': row['prcp'], 'tave': row['tave'], 'tmin': row['tmin'], 'tmax': row['tmax'] } } features.append(location_feature) locations_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } style = { 'ol.style.Style': { 'image': { 'ol.style.Circle': { 'radius': 1, 'fill': { 'ol.style.Fill': { 'color': 'rgba(255, 255, 0, 0.01)' } }, 'stroke': { 'ol.style.Stroke': { 'color': 'rgba(255, 255, 0, 0.01)', 'width': 1 } } } } } } locations_layer = MVLayer(source='GeoJSON', options=locations_feature_collection, legend_title='Locations', layer_options={'style': style}, feature_selection=True) try: view_center = [ sum(long_list) / float(len(long_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-98.6, 39.8] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=4.5, maxZoom=18, minZoom=2) precip_by_location_map = MapView(height='100%', width='100%', layers=[locations_layer], basemap='OpenStreetMap', view=view_options) context = { 'precip_by_location_map': precip_by_location_map, } return render(request, 'precip_by_location/home.html', context)
def home(request, app_workspace): """ Controller for the app home page. """ # Get list of places and create places MVLayer: places = get_all_places(app_workspace.path) features = [] lat_list = [] lng_list = [] # Define GeoJSON Features for place in places: place_location = place.pop('location') lat_list.append(place_location['coordinates'][1]) lng_list.append(place_location['coordinates'][0]) place_feature = { 'type': 'Feature', 'geometry': { 'type': place_location['type'], 'coordinates': place_location['coordinates'], } } features.append(place_feature) # Define GeoJSON FeatureCollection places_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } style = { 'ol.style.Style': { 'image': { 'ol.style.Circle': { 'radius': 10, 'fill': { 'ol.style.Fill': { 'color': '#d84e1f' } }, 'stroke': { 'ol.style.Stroke': { 'color': '#ffffff', 'width': 1 } } } } } } # Create a Map View Layer places_layer = MVLayer(source='GeoJSON', options=places_feature_collection, legend_title='Places', layer_options={'style': style}) # Define view centered on place locations try: view_center = [ sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-84.079149, 9.933149] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=8.5, maxZoom=18, minZoom=2) vacationeer_map = MapView(height='100%', width='100%', layers=[places_layer], basemap='OpenStreetMap', view=view_options) add_place_button = Button(display_text='Add place', name='add-place-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('vacationeer:add_place')) context = { 'vacationeer_map': vacationeer_map, 'add_place_button': add_place_button } return render(request, 'vacationeer/home.html', context)
def home(request, app_workspace): """ Controller for the app home page. """ # Get list of dams and create dams MVLayer: dams = get_all_dams(app_workspace.path) features = [] lat_list = [] lng_list = [] # Define GeoJSON Features for dam in dams: dam_location = dam.pop('location') lat_list.append(dam_location['coordinates'][1]) lng_list.append(dam_location['coordinates'][0]) dam_feature = { 'type': 'Feature', 'geometry': { 'type': dam_location['type'], 'coordinates': dam_location['coordinates'], } } features.append(dam_feature) # Define GeoJSON FeatureCollection dams_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } style = { 'ol.style.Style': { 'image': { 'ol.style.Circle': { 'radius': 10, 'fill': { 'ol.style.Fill': { 'color': '#d84e1f' } }, 'stroke': { 'ol.style.Stroke': { 'color': '#ffffff', 'width': 1 } } } } } } # Create a Map View Layer dams_layer = MVLayer(source='GeoJSON', options=dams_feature_collection, legend_title='Dams', layer_options={'style': style}) # Define view centered on dam locations try: view_center = [ sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-98.6, 39.8] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=4.5, maxZoom=18, minZoom=2) dam_inventory_map = MapView(height='100%', width='100%', layers=[dams_layer], basemap='OpenStreetMap', view=view_options) add_dam_button = Button(display_text='Add Dam', name='add-dam-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('dam_inventory:add_dam')) save_button = Button(display_text='', name='save-button', icon='glyphicon glyphicon-floppy-disk', style='success', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Save' }) 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' }) context = { 'save_button': save_button, 'edit_button': edit_button, 'remove_button': remove_button, 'previous_button': previous_button, 'next_button': next_button, 'dam_inventory_map': dam_inventory_map, 'add_dam_button': add_dam_button } return render(request, 'dam_inventory/home.html', context)
def map_blooms(request, app_workspace): """ Controller for the background page. """ # Get list of blooms and create blooms MVLayer: blooms = get_all_blooms(app_workspace.path) features = [] lat_list = [] lng_list = [] # Define GeoJSON Features for bloom in blooms: bloom_mapdraw = bloom.pop('mapdraw') lat_list.append(bloom_mapdraw['coordinates'][1]) lng_list.append(bloom_mapdraw['coordinates'][0]) bloom_feature = { 'type': 'Feature', 'geometry': { 'type': bloom_mapdraw['type'], 'coordinates': bloom_mapdraw['coordinates'], } } features.append(bloom_feature) # Define GeoJSON FeatureCollection blooms_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } style = { 'ol.style.Style': { 'image': { 'ol.style.Circle': { 'radius': 10, 'fill': { 'ol.style.Fill': { 'color': '#d84e1f' } }, 'stroke': { 'ol.style.Stroke': { 'color': '#ffffff', 'width': 1 } } } } } } # Create a Map View Layer blooms_layer = MVLayer(source='GeoJSON', options=blooms_feature_collection, legend_title='Blooms', layer_options={'style': style}) # Define view centered on dam locations try: view_center = [ sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-98.6, 39.8] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=7, maxZoom=18, minZoom=2) algal_bloom_map = MapView( height='100%', width='100%', layers=[blooms_layer], basemap='OpenStreetMap', view=view_options, ) new_bloom_button = Button(display_text='New Bloom', name='new_bloom-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('utah_algal_blooms:new_bloom')) context = { 'algal_bloom_map': algal_bloom_map, 'new_bloom_button': new_bloom_button } return render(request, 'utah_algal_blooms/map_blooms.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 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. """ compute_button = Button(display_text='Calcular', name='compute-button', href=reverse('dr_water_allocation:results'), attributes={"onclick": compute_water()}) diversion_points_list = get_all_diversions() dam_list = get_all_dams() features = [] features_dam = [] for item in diversion_points_list: diversion_point_feature = { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [item.latitude, item.longitude], }, 'properties': { 'point_name': item.name, 'demand': item.demand, 'efficiency': item.efficiency, 'priority': item.priority, 'type': 'diversion' } } features.append(diversion_point_feature) for item in dam_list: dam_point_feature = { 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [item.latitude, item.longitude], }, 'properties': { 'point_name': item.name, 'output': item.output, 'type': 'dam' } } features_dam.append(dam_point_feature) diversion_points_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features, } dam_points_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features_dam, } geojson_diversion_point_layer = MVLayer( source='GeoJSON', options=diversion_points_collection, legend_title="Diversion Points", feature_selection=True, layer_options={ 'style': { 'image': { 'circle': { 'radius': 6, 'fill': { 'color': '#d84e1f' }, 'stroke': { 'color': '#ffffff', 'width': 1 }, } } } }) geojson_dam_point_layer = MVLayer(source='GeoJSON', options=dam_points_collection, legend_title="Diversion Points", feature_selection=True, layer_options={ 'style': { 'image': { 'circle': { 'radius': 6, 'fill': { 'color': '#f9f32f' }, 'stroke': { 'color': '#ffffff', 'width': 1 }, } } } }) view_options = MVView(projection='EPSG:4326', center=[-70.8, 18.56], zoom=10, maxZoom=18, minZoom=2) map_view_options = MapView( height='100%', width='100%', controls=[ 'Rotate', 'FullScreen', { 'MousePosition': { 'projection': 'EPSG:4326' } }, { 'ZoomToExtent': { 'projection': 'EPSG:4326', 'extent': [-130, 22, -65, 54] } } ], layers=[geojson_diversion_point_layer, geojson_dam_point_layer], view=view_options, basemap='OpenStreetMap', ) context = { 'compute_button': compute_button, 'map_view_options': map_view_options, } return render(request, 'dr_water_allocation/home.html', context)
def aggregated_risk(request): """ Controller for the app home page. """ add_custom_file_button = Button(display_text='Add File', name='add-custom-file-button', icon='glyphicon glyphicon-plus', style='success', attributes={ 'id': 'add-custom-file-button', 'onclick': 'hideShowCustomCheck()', }) data_submit_button = Button(display_text='Submit', name='data-submit-button', icon='glyphicon glyphicon-upload', style='success', attributes={ 'id': 'data-submit-button', 'onclick': 'executeSpatialJoins()', }) view_center = [-93.3, 44.75] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=12.5, maxZoom=18, minZoom=2) zone_map = MapView( height='150', width='200', # layers=[], basemap=[ 'OpenStreetMap', # 'CartoDB', # {'CartoDB': {'style': 'dark'}}, # 'Stamen', 'ESRI' ], view=view_options, # legend=True ) # initialize session Session = Hpp.get_persistent_store_database('primary_db', as_sessionmaker=True) session = Session() # Query DB for data store types criteria_list = session.query(Criteria) \ .order_by(Criteria.id) \ .all() previous_button = Button(display_text='Previous', name='previous-button', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Previous', 'onclick': 'cyclePagesBackward()' }) next_button = Button(display_text='Next', name='next-button', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Next', 'onclick': 'cyclePagesForward()' }) apply_risk_scores_button = Button(display_text='Apply', name='apply-risk-scores-button', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Previous', 'onclick': 'applyRiskScores()' }) classify_zones_button = Button(display_text='Classify Zones', name='classify_zones-button', attributes={ 'data-toggle': 'tooltip', 'data-placement': 'top', 'title': 'Previous', 'onclick': 'saveZoneClassTableToDB()' }) # datatable_default = DataTableView(column_names=('Name', 'Age', 'Job'), # rows=[('Bill', 30, 'contractor'), # ('Fred', 18, 'programmer'), # ('Bob', 26, 'boss')], # searching=True, # orderClasses=False, # lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]], # ) context = { 'data_submit_button': data_submit_button, # 'datatable_options': datatable_default, 'add_custom_file_button': add_custom_file_button, 'apply_risk_scores_button': apply_risk_scores_button, 'initial_page': 0, 'previous_button': previous_button, 'classify_zones_button': classify_zones_button, 'next_button': next_button, 'zone_map': zone_map, 'criteria_list': criteria_list, } session.close() return render(request, 'hpp/aggregated_risk.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 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. """ 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 home(request): """ Controller for the app home page. """ # Get list of dams and create dams MVLayer: dams = get_all_dams() features = [] lat_list = [] lng_list = [] for dam in dams: dam_location = dam.pop('location') lat_list.append(dam_location['coordinates'][1]) lng_list.append(dam_location['coordinates'][0]) dam_feature = { 'type': 'Feature', 'geometry': { 'type': dam_location['type'], 'coordinates': dam_location['coordinates'], } } features.append(dam_feature) dams_feature_collection = { 'type': 'FeatureCollection', 'crs': { 'type': 'name', 'properties': { 'name': 'EPSG:4326' } }, 'features': features } dams_layer = MVLayer(source='GeoJSON', options=dams_feature_collection, legend_title='Dams') # Define view centered on dam locations try: view_center = [ sum(lng_list) / float(len(lng_list)), sum(lat_list) / float(len(lat_list)) ] except ZeroDivisionError: view_center = [-98.6, 39.8] view_options = MVView(projection='EPSG:4326', center=view_center, zoom=6, maxZoom=18, minZoom=2) dam_inventory_map = MapView(height='100%', width='100%', layers=[dams_layer], basemap='OpenStreetMap', view=view_options) add_dam_button = Button(display_text='Add Dam', name='add-dam-button', icon='glyphicon glyphicon-plus', style='success', href=reverse('dam_inventory:add_dam')) context = { 'dam_inventory_map': dam_inventory_map, 'add_dam_button': add_dam_button } return render(request, 'dam_inventory/home.html', context)
def home(request): """ Controller for the app home page. """ # Retrieve a geoserver engine geoserver_engine = app.get_spatial_dataset_service(name='main_geoserver', as_engine=True) # Check for workspace and create workspace for app if it doesn't exist response = geoserver_engine.list_workspaces() if response['success']: workspaces = response['result'] if WORKSPACE not in workspaces: geoserver_engine.create_workspace(workspace_id=WORKSPACE, uri=GEOSERVER_URI) view_options = MVView(projection='EPSG:4326', center=[-70.16, 18.83], zoom=8, maxZoom=18, minZoom=2) cultivar_map = MapView( height='100%', width='100%', layers=[], view=view_options, basemap=view_options, ) select_district = SelectInput( display_text='Select an Irrigation District:', name='select1', multiple=False, original=True, options=[ ('Yaque Del Sur', '1'), ('Valle de San Juan', '2'), ('Lago Enriquillo', '3'), ('Azua', '4'), ('Laguna de Cabral', '5'), ], initial=['']) select_district_button = Button(display_text='Select', name='select-district-button', icon='glyphicon glyphicon-plus', style='success') add_district_button = Button(display_text='Add District', name='add-district-button', icon='glyphicon glyphicon-plus', style='success') context = { 'cultivar_map': cultivar_map, 'select_district_button': select_district_button, 'add_district_button': add_district_button, 'select_district': select_district } return render(request, 'cultivar/home.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)