def sites_marker_list(*checkUrl): """ get all the ameriflux sites return MarkerCluster (to be added to a folium map.) Input: checkLnk [0|1] by default (if no argument is provided, we assume the value "False", hence the url provided from ameriflux are considered valid. If checkLnk is "True", ech station url is checked for response "200 OK" """ checkLnk = False if (len(checkUrl)): checkLnk = checkUrl # get the data through the neon api url = 'https://ameriflux-data.lbl.gov/AmeriFlux/SiteSearch.svc/SiteMapData/Fluxnet' r = requests.get(url) fluxnet = r.json() # Now loop throuth the stations and add them to the MarkerCluster mc = MarkerCluster() for station in fluxnet: # extract the location aflocation = station['GRP_LOCATION'] if ('LOCATION_LAT' in aflocation and 'LOCATION_LONG' in aflocation): #print(station['locationName']) # check if lat, lon exist and are numbers, otherwise skip the station if (h.is_number(aflocation['LOCATION_LAT']) and h.is_number(aflocation['LOCATION_LONG'])): #create the markers msg = "<table border=0>" msg += "<tr><td>Network: </td><td>Fluxnet</td></tr>" msg += "<tr><td>Code: </td><td>" + srcLink( station, checkLnk) + "</td></tr>" msg += "<tr><td>Name: </td><td>" + station[ 'SITE_NAME'] + "</td></tr>" msg += "<tr><td>Latitude: </td><td>" + str( aflocation['LOCATION_LAT']) + "</td></tr>" msg += "<tr><td>Longitude: </td><td>" + str( aflocation['LOCATION_LONG']) + "</td></tr>" msg += "</table>" msg = textile.textile(msg) #create a marker and add to cluster m = folium.Marker(location=[ float(aflocation['LOCATION_LAT']), float(aflocation['LOCATION_LONG']) ], popup=msg) m.add_child(h.getIcon('fluxnet')) m.add_to(mc) return mc
def sites_marker_list(*checkUrl): """ get all the lTER sites return MarkerCluster (to be added to a folium map.) Input: checkLnk [0|1] by default (if no argument is provided, we assume the value "False", hence the url provided from ameriflux are considered valid. If checkLnk is "True", ech station url is checked for response "200 OK" """ checkLnk = False if (len(checkUrl)): checkLnk = checkUrl # get the data through the api from DEIMS url = "https://deims.org/geoserver/deims/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=deims:ilter_all_formal&outputFormat=application%2Fjson" #lterAfrica #lterAmericas #lterEurope r = requests.get(url) lter = r.json() # Now loop throuth the stations and add them to the MarkerCluster mc = MarkerCluster() for station in lter['features']: # extract the location lat = station['properties']['field_coordinates_lat'] lon = station['properties']['field_coordinates_lon'] if ('field_coordinates_lat' in station['properties'] and 'field_coordinates_lon' in station['properties']): lat = station['properties']['field_coordinates_lat'] lon = station['properties']['field_coordinates_lon'] # check validity of lat, lon if (h.is_number(lat) and h.is_number(lon)): #create the markers msg = "<table border=0>" msg += "<tr><td>Network: </td><td>" + station['properties'][ 'network'] + "</td></tr>" msg += "<tr><td>Name: </td><td>" + srcLink( station, checkLnk) + "</td></tr>" msg += "<tr><td>Latitude: </td><td>" + str(lat) + "</td></tr>" msg += "<tr><td>Longitude: </td><td>" + str(lon) + "</td></tr>" msg += "</table>" msg = textile.textile(msg) #create a marker and add to cluster m = folium.Marker(location=[float(lat), float(lon)], popup=msg) m.add_child(h.getIcon('lter')) m.add_to(mc) return mc
def sites_marker_list(*checkUrl): """ get all the neon sites and return MarkerCluster (to be added to a folium map.) """ checkLnk = False if (len(checkUrl)): checkLnk = checkUrl # get the data through the neon api url = "http://data.neonscience.org/api/v0/locations/sites" r = requests.get(url) neonsites = r.json() # Now loop throuth the NEON stations and add them to the MarkerCluster mc = MarkerCluster() for station in neonsites['data']: if ('locationDecimalLatitude' in station and 'locationDecimalLongitude' in station): # check if lat, lon exist and are numbers, otherwise skip the station if (h.is_number(station['locationDecimalLatitude']) and h.is_number(station['locationDecimalLongitude'])): #create the markers msg = "<table border=0>" msg += "<tr><td>Network: </td><td>NEON</td></tr>" msg += "<tr><td>Code: </td><td>" + srcLink( station['locationName'], checkLnk) + "</td></tr>" msg += "<tr><td>Name: </td><td>" + station[ 'locationDescription'] + "</td></tr>" msg += "<tr><td>Latitude: </td><td>" + str( station['locationDecimalLatitude']) + "</td></tr>" msg += "<tr><td>Longitude: </td><td>" + str( station['locationDecimalLongitude']) + "</td></tr>" msg += "</table>" msg = textile.textile(msg) #create a marker and add to cluster m = folium.Marker(location=[ float(station['locationDecimalLatitude']), float(station['locationDecimalLongitude']) ], popup=msg) m.add_child(h.getIcon('neon')) m.add_to(mc) return mc
def sites_marker_list(*checkUrl): """ get all the sites return MarkerCluster (to be added to a folium map.) Input: checkLnk [0|1] by default (if no argument is provided, we assume the value "False", hence the url provided from ameriflux are considered valid. If checkLnk is "True", ech station url is checked for response "200 OK" """ checkLnk = False if (len(checkUrl)): checkLnk = checkUrl # Query the ICOS SPARQL endpoint for a station list # output is an object "data" containing the results in JSON # the SPARQL query itself is in the helperFunctions... #------------------------------------------------------------------------ # get ALL icos stations, see documentation in helper_functions url = 'https://meta.icos-cp.eu/sparql' r = requests.get(url, params={ 'format': 'json', 'query': h.icos_stations() }) data = r.json() #------------------------------------------------------------------------ # convert the the result into a table # output is an array, where each row contains # information about the station cols = data['head']['vars'] datatable = [] for row in data['results']['bindings']: item = [] for c in cols: item.append(row.get(c, {}).get('value')) datatable.append(item) # print the table if you want # icosdt = pd.DataFrame(datatable, columns=cols) # icosdt.head(5) # create a MarkerCluster for all the ICOS sites mc = MarkerCluster() # loop through the ICOS datatable and create the markers for station in datatable: # check if lat, lon are numbers, otherwise skip the station if (h.is_number(station[0])) and (h.is_number(station[1])): #create the markers msg = '<table border=0>' msg += '<tr><td>Network: </td><td>ICOS</td></tr>' msg += '<tr><td>Country: </td><td>' + station[3] + '</td></tr>' msg += '<tr><td>Code: </td><td>' + srcLink(station, checkLnk) + '</td></tr>' msg += '<tr><td>Name: </td><td>' + station[5] + '</td></tr>' msg += '<tr><td>Theme: </td><td>' + station[2] + '</td></tr>' msg += '<tr><td>Latitude: </td><td>' + station[0] + '</td></tr>' msg += '<tr><td>Longitude: </td><td>' + station[1] + '</td></tr>' msg += '</table>' msg = textile.textile(msg) #create a marker to display the station on the map marker = folium.Marker( location=[float(station[0]), float(station[1])], popup=msg) # check which icon we should use if (station[2] == "AS"): marker.add_child(h.getIcon('icos', 'AS')) #marker.add_child(folium.Icon(color = 'lightblue', icon='cloud')) elif (station[2] == "ES"): marker.add_child(h.getIcon('icos', 'ES')) #marker.add_child(folium.Icon(color = 'green', icon='leaf')) elif (station[2] == "OS"): marker.add_child(h.getIcon('icos', 'OS')) #marker.add_child(folium.Icon(color = 'blue', icon='tint')) # add the marker to the "marker cluster" mc.add_child(marker) return mc
folium.TileLayer('cartodbpositron').add_to(myMap) folium.TileLayer('cartodbdark_matter').add_to(myMap) folium.TileLayer('stamenwatercolor').add_to(myMap) folium.TileLayer('stamentoner').add_to(myMap) folium.TileLayer('stamenterrain').add_to(myMap) folium.TileLayer('Mapbox Control Room').add_to(myMap) #--------------------------------------------------------------- # create the feature groups and add control # feature groups will be displayed as well in the # top right menu. You can easly switch on/off # the different layers. h.debugPrint(dbg, 'adding feature groups') for i, n in enumerate(networks): n = h.getIcon(n, returnLnk=True) + ' ' + n f = eval('folium.FeatureGroup(name=n)') eval('f.add_child(mcList[i]).add_to(myMap)') folium.LayerControl().add_to(myMap) #--------------------------------------------------------------- # now safe the map to your local computer mapname = 'stations.html' myMap.save(mapname) url = os.path.abspath(mapname) h.debugPrint(dbg, ('map saved to: ' + url)) # the html file is now saved to the directory where your code is # let's try to open your default browser with the map