def viewMap(): gis = GIS('home') callback_map = gis.map('San Diego convention center, San Diego, CA', 16) callback_map.on_click(find_addr) callback_map return
def __init__(self): my_gis = GIS() global hello_map hello_map = my_gis.map('Санкт-Петербург', zoomlevel=15) hello_map.basemap = 'osm' # ============ def find_addr(hello_map, g): # try: hello_map.draw(g) global address geocoded = geocoding.reverse_geocode(g) address = geocoded['address']['Match_addr'] # adres_read = Adres_read(address) # print(adres_read.get_points()) try: print('creating') # a = Osm_reader(adres_read.get_points()) # a.create_file() print('file created') except: print("beda") hello_map.on_click(address)
def home(request): gis = GIS() print("Logged in as " + str(gis.properties.user.username)) map_sj = gis.map("San Jose, CA") map_js = 'require(["esri/views/MapView"], function(MapView) {' \ ' });' return_view = '<h1>Home page</h1><br>'+str(map_sj) return HttpResponse(return_view) return render(request, 'deforest/home.html')
def geo_sde(): gis = GIS() map = gis.map("United States") map sde = pd.read_csv("jobs_sde.csv") data3 = pd.DataFrame(columns=('company', 'city', 'state', 'longitude', 'latitude')) for i in range(0, len(sde)): dict = {} if pd.isna(sde.iloc[i]['location']): state == [] else: state = geocode(sde.iloc[i]['location']) if state == []: geo = geocode(sde.iloc[i]['company']) if geo == []: dict['longitude'] = na dict['latitude'] = na dict['city'] = na dict['state'] = na else: dict['longitude'] = geo[0]['location']['x'] dict['latitude'] = geo[0]['location']['y'] dict['city'] = geo[0]['attributes']['City'] dict['state'] = geo[0]['attributes']['RegionAbbr'] else: geo = geocode(sde.iloc[i]['company'], state[0]['extent']) if geo == []: dict['longitude'] = state[0]['location']['x'] dict['latitude'] = state[0]['location']['y'] dict['city'] = state[0]['attributes']['City'] dict['state'] = state[0]['attributes']['RegionAbbr'] else: dict['longitude'] = geo[0]['location']['x'] dict['latitude'] = geo[0]['location']['y'] dict['city'] = geo[0]['attributes']['City'] dict['state'] = geo[0]['attributes']['RegionAbbr'] dict['company'] = sde.iloc[i]['company'] data3.loc[i] = dict data3.to_csv("geo_sde.csv", encoding='utf-8', index=False)
def crawl(file): gis = GIS() map = gis.map("United States") map # read all kinds of job files job_df = pd.read_csv(Point_v1.CONSULTING_FILE).append( pd.read_csv(Point_v1.DS_FILE)).append( pd.read_csv(Point_v1.SDE_FILE)) company_loc_df = pd.DataFrame() company_loc_df["company"] = job_df["company"].unique() geo_info = company_loc_df["company"].apply(lambda company: geocode(company)[0] if geocode(company) else None) company_loc_df['longitude'] = geo_info.apply(lambda info: info["location"]["x"] if info else None) company_loc_df['latitude'] = geo_info.apply(lambda info: info["location"]["y"] if info else None) company_loc_df['city'] = geo_info.apply(lambda info: info['attributes']['City'] if info else None) company_loc_df['state'] = geo_info.apply(lambda info: info['attributes']['RegionAbbr'] if info else None) company_loc_df.to_csv(file, encoding='utf-8', index=False)
import arcgis from arcgis.gis import GIS # In[5]: gis = GIS() # Создание виджета карты # In[8]: map1 = gis.map('Moscow') # In[17]: map1 # Масшатабирование, вращение и центрирование # In[18]: map1.zoom
from arcgis.gis import GIS x = input() gis = GIS() map = gis.map(x) print(map)
from arcgis.gis import GIS while 1: my_gis = GIS() my_gis.map()
import requests import json ONS_QUERY = "https://ons-inspire.esriuk.com/arcgis/rest/services/Administrative_Boundaries/Local_Athority_Districts_December_2018_Boundaries_GB_BFC/MapServer/0/query?where=UPPER(lad18nm)%20like%20'%25NEWCASTLE%20UPON%20TYNE%25'&outFields=*&outSR=4326&f=json" r = requests.get(ONS_QUERY) r_json = json.loads(r.content) from arcgis.gis import GIS print("ArcGIS Online as anonymous user") gis = GIS() print("Logged in as anonymous user to " + gis.properties.portalName) map1 = gis.map("Newcastle, UK") map1
# search and list all items owned by connected user #query=f'owner:{portalDesc["user"]["username"]} AND title:CW BaseMap' #itemType="Feature Layer" #sortField="title" #sortOrder="asc" # default max__items is 10 #maxItems=100 #m = gis.content.search(query,itemType,sortField,sortOrder,maxItems) #%% consumptionLyr = gis.content.import_data(sdf) #%% m = gis.map('Gainesville,FL') #%% m #%% m.add_layer(sdf,options={"renderer":"ClassedSizeRenderer","field_name":"MAXCONSUMPTION"}) #%% m.add_layer(consumptionLyr,options={"renderer":"ClassedSizeRenderer","field_name":"MAXCONSUMPTION"}) #%%
from arcgis.gis import GIS from arcgis import features gis = GIS("home") # Title: shp_trans_state_trails_minnesota | Type: Feature Service | Owner: leex6165_UMN trails = gis.content.get("d1c3c8c8448a4158859a83df2169b028") # buffer state trails by 100 m (50 m on each side) features.use_proximity.create_buffers(trails, distances = [50], units = "Meters", output_name = "MNstate_trails_buff_50m_arconline") # Map buffered state trails # # Title: MNstate_trails_buff_50m_arconline | Type: Feature Service | Owner: leex6165_UMN trails_50m = gis.content.get("bae6c3d7807c4525b713b74c3d504028") trails_50m map1 = gis.map("Minnesota") map1.add_layer(trails_50m) map1.add_layer(item) # View Map map1
#!/usr/bin/env python # coding: utf-8 # ## Welcome to your notebook. # # #### Run this cell to connect to your GIS and get started: # In[1]: from arcgis.gis import GIS gis = GIS("home") # #### Now you are ready to start! # In[7]: map1 = gis.map('Kaneohe, HI') map1 # In[8]: # Item Added From Toolbar # Title: Annual Rainfall (in) | Type: Feature Service | Owner: HawaiiStateGIS item = gis.content.get("f0cadb44d59a495298cebe80247bff80") item # In[9]: map1.add_layer(item)
# #### Run this cell to connect to your GIS and get started: # In[16]: from arcgis.gis import GIS gis = GIS("home") # #### Now you are ready to start! # In[17]: map1 = gis.map("Washington, DC") # In[22]: map1 # In[19]: # Item Added From Toolbar # Title: Points of Interest | Type: Feature Service | Owner: DCGISopendata item = gis.content.get("f323f677b3f34fe08956b8fcce3ace44") item
import arcgis from arcgis.widgets import MapView from arcgis.gis import GIS gis = GIS() hello_map = gis.map("Москва", zoomlevel=15) hello_map.draw(shape='rectangle')
from pathlib import Path from zipfile import ZipFile from IPython.display import display trailheads_id = '883cedb8c9fe4524b64d47666ed234a7' gis = GIS() trailheads_item = gis.content.get(trailheads_id) display(trailheads_item) # In[2]: #Agregar la capa m = gis.map() m.add_layer(trailheads_item) m.center = [34.09042, -118.71511] # `[latitud, longitud]` m.zoom = 11 m # In[ ]:
import geocoder import tweepy from arcgis.gis import GIS gis = GIS() map = gis.map("Redlands, CA") map #Twitter Credentials consumer_key = 'Xsm1PSWiJYFkn0Rmoi53Mm8pU' consumer_secret = 'DzckZZPyAKPQZdCtUWVshUhczjGMOeST53FmR1q41r2oqOWjuL' access_token = '1082567145395937280-10ARA8VBNprf6TzT0o1QDjBojIA9oV' access_token_secret = '0g84r99NYhYY9Pt69OYKrgr5VeBGh2X6nCAt6oHikdSKO' auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth,wait_on_rate_limit=True) # Open/Create a file to append data movieName="Avengers" date="2017-04-03" locations=[] for tweet in tweepy.Cursor(api.search,q="#"+movieName,lang="en",since=date).items(100): gis = GIS() locations.append(tweet.user.location) map = gis.map(locations) print(map)
import arcgis from arcgis.gis import GIS import pyplot as plt my_gis = GIS() hello_map = my_gis.map("Санкт-Петербург", zoomlevel=15) plt.pyplot.show(hello_map)
from arcgis.gis import GIS my_gis = GIS() my_gis.map()
import arcgis from arcgis.gis import GIS import pandas as pd from arcgis.geocoding import Geocoder, get_geocoders, geocode gis = GIS("https://www.arcgis.com", "arcgis_python", "P@ssword123") mymap = gis.map() mymap.basemap = "osm" results = geocode('北京市海淀区莲花池西路国家测绘地理信息局') pd.DataFrame(results) for res in results: popup = { "title": res["attributes"]["Region"], "content": "address:" + res["address"] } mymap.draw(res, popup=popup)
from arcgis.gis import GIS my_gis = GIS() map1 = my_gis.map('United States') map1
polygon = dist7.features[0].geometry #create a geometry object from the geometry property of the json object geomObj = arcgis.geometry.Geometry(polygon) print(geomObj.type) gensD7 = gens.query(geometry_filter=filters.intersects(geomObj)) print(len(gensD7), type(gensD7), type(gens)) print(gensD7.features[0]) gensD7_Layer = arcgis.features.FeatureCollection(gensD7.to_dict()) print(type(gensD7_Layer)) # In[53]: my_gis = GIS() map1 = my_gis.map() map1.center = [34.2, -118.5] map1.zoom = 9 map1.add_layer(gensD7, origRendInfo['renderer']) #map1.add_layer(dist7) map1 # In[17]: print(gensD7.drawing_info) # In[4]: #Make a connection to my portal gis2 = GIS("https://caltrans.maps.arcgis.com", "Saffia.Hossainzadeh")
# In[9]: # publish the new CSV item as a new hosted feature layer new_feature_layer_item = new_csv_item.publish() # In[10]: new_feature_layer_item # just a check, you can remove this # In[11]: # if you want, you can load up a map component # to draw the new hosted feature layer info map1 = gis.map() map1.extent = new_feature_layer_item.extent map1 # In[12]: # don't fret if your layer doesn't appear right away # often takes 10 seconds or so to show up map1.add_layer(new_feature_layer_item) # In[ ]: # test9.csv # ID,GREEK,PHON,LONG,LAT,VAL,NOTES # 0,ALPHA,ALPHA,-74.1,40.4,0,First Letter
from arcgis.gis import GIS import config print("Create GIS Object") gis = GIS("https://www.arcgis.com", config.username, config.password) # Create map object print("Create Map Object") nl_map = gis.map( 'Netherlands', zoomlevel=7) # you can specify the zoom level when creating a map # Look for content created by esri_nl_content print("Search for feature layers") flayer_search_result = gis.content.search("hectometer owner:Esri_NL_Content", "Feature Layer", outside_org=True) # Adding the feature layers to the map object print("Adding feature layers to the map") for featureLayer in flayer_search_result: nl_map.add_layer(featureLayer) # Set item properties item_properties = { 'title': 'Webmap DevDay 2018 via [application]', 'snippet': 'Python generated webmap saved as ArcGIS items', 'tags': ['webmap', 'python generated', 'devday'] } # Save the map object as an ArcGIS item
SentinelHubRequest.input_data( data_source=DataSource.SENTINEL2_L1C, time_interval=('2020-09-08', '2020-09-10'), ) ], responses=[SentinelHubRequest.output_response('default', MimeType.TIFF)], bbox=bbox, size=size, config=config) #true_color_imgs = request_true_color.save_data() #sc_image = true_color_imgs[0] #plt.imshow(sc_image) # In[21]: my_gis = GIS("", "", "") m = my_gis.map() m data_path = (r"./Sentinel/00da87d4e771b8b8b30e2d1ac70e1390") tiff_path = os.path.join(data_path, "response.tiff") tiff_properties = { 'title': 'Sentinel 2 Imagery', 'description': 'true real color imagery September 9 - 10', 'tags': 'arcgis, python, imagery, sentinel2', 'type': 'Image' } #tiff_item = my_gis.content.add(data=tiff_path,item_properties=tiff_properties) #earth = ImageryLayer(img_svc_url) #earth tiff_item
from arcgis.gis import GIS user_name = 'arcgis_python' password = '******' gis = GIS('https://www.arcgis.com', user_name, password) address_1 = input() search_result = gis.content.search("title:" + address_1, item_type="Web Map") if len(search_result) == 0: print("list is empty") else: search_item = search_result[0] search_item map1 = gis.map(address_1) map1
user_name = 'username' password = getpass.getpass("Please enter password: "******"Successfully logged in to {} as {}".format(dev_gis.properties.urlKey + '.' + dev_gis.properties.customBaseUrl, dev_gis.users.me.username)) ago_gis = GIS() gis = GIS("https://www.arcgis.com", "username", "password") from arcgis.gis import GIS user_name = 'username' password = '******' my_gis = GIS('https://www.arcgis.com', user_name, password) map = gis.map("imagery") map from arcgis.gis import GIS gis = GIS() map = gis.map('Streets,SC', 6) map import datetime import arcgis from arcgis.gis import GIS from IPython.display import display import pandas as pd # create a Web GIS object
def display(latitude, longitude, time, param): gis = GIS() map1 = gis.map("US", zoomlevel=8) def genericfun(latitude, longitude, time): try: #print("genericfun\n") string = "https://api.darksky.net/forecast/68d70a9cf38161567cc4aec124be92ed/" + latitude + "," + longitude + "," + time + "?exclude=hourly,currently,minutely,alert,flags" response = requests.get(string) data = response.content if (len(data) < 140): jdf1 = {} #print("genericfun_if\n") return jdf1 else: #print("genericfun_else\n") parsed_data = pd.read_json(data.decode('utf-8')) new = parsed_data['daily'][0] new1 = pd.DataFrame(new) latl = [] longl = [] for i in range(len(new1)): latl.append(latitude) longl.append(longitude) new1['lat'] = latl new1['long'] = longl #map1 = gis.map("US", zoomlevel = 8) df = new1 light = gis.content.import_data(df) light.layer.layers = [dict(light.layer)] map1.add_layer(light) try1 = light.query() dfn = ((try1).df) del dfn['SHAPE'] js = dfn.to_json(orient='index') jdf = json.loads(js) jdf1 = jdf["0"] del (jdf1["lat"]) del (jdf1["long"]) del jdf1["summary"] return jdf1 except: jdf1 = {} return jdf1 #if(param==generic then return jdf1)before it was light...........changed name to generic #air def airfun(latitude, longitude, time): try: #print("airfun\n") response = requests.get( "https://api.openaq.org/v1/measurements?coordinates=" + latitude + "," + longitude + "&radius=28000") variable = str(response.content) #print(variable) if (len(variable) < 140): #print("airfun_if\n") jdf2 = {} return jdf2 else: #print("airfun_else\n") xizz = variable[2:-1].encode('utf-8') xiz = xizz.decode('utf-8') st1 = re.sub('"unit":".*?",', '', xiz) st = re.sub(',"city":".*?"}', '}', st1) data = json.loads(st) df = json_normalize(data, 'results') dict1 = list(df['coordinates']) df2 = pd.DataFrame(dict1) df['lat'] = df2['latitude'] df['long'] = df2['longitude'] del df['coordinates'] dflist = df['date'].tolist() l_data = [] l_local = [] for i in dflist: l_data.append(i['local'][:10]) for i in dflist: l_local.append(i['local'][20:]) del df['date'] del df['location'] df4 = pd.DataFrame() df4['dates'] = l_data df4['local'] = l_local df['date'] = df4['dates'] df['local'] = df4['local'] epoch = [] for i in range(len(df)): date_time = df['date'][i] t = int( tt.mktime(tt.strptime(str(df['date'][i]), "%Y-%m-%d"))) epoch.append(t) df['epocht'] = epoch df.to_csv("final.csv") gis = GIS() #map1 = gis.map("Amsterdam", zoomlevel = 8) df = pd.read_csv('final.csv') airpol = gis.content.import_data(df) airpol.layer.layers = [dict(airpol.layer)] map1.add_layer(airpol) try1 = airpol.query().df del try1['SHAPE'] del try1['Unnamed__0'] time1 = 0 time1 = int(time) min1 = 99999999999 key1 = 0 newset = set(try1['parameter']) newsetl = list(newset) valuesl = [0] * len(newsetl) for i in range(len(try1['epocht'])): for j in range(len(newsetl)): if (newsetl[j] == try1['parameter'][i]): if ((abs(int(try1['epocht'][i]) - time1)) <= min1): min1 = abs(int(try1['epocht'][i]) - time1) valuesl[j] = try1['value'][i] if (min1 == 0): break jdf2 = dict(zip(newsetl, valuesl)) return jdf2 except: jdf2 = {} return jdf2 #if(param==air then return jdf2) #viirs ''' req = Request("https://ngdc.noaa.gov/eog/viirs/download_flare_only_iframe.html") html_page = urlopen(req) soup = BeautifulSoup(html_page, "lxml") links = [] for link in soup.findAll('a'): links.append(link.get('href')) sub = 'd201712' links_dec=[] links_dec=([s for s in links if sub in s]) sub = 'only.csv.gz' links_dec_csv=[] links_dec_csv=([s for s in links_dec if sub in s]) url =links_dec_csv[0] filename = "VNF_npp_d20171205_noaa_v21.flares_only.csv.gz" with open(filename, "wb") as f: r = requests.get(url) f.write(r.content) ''' def lightfun(latitude, longitude, time): try: #print("lightfun\n") with gzip.open('VNF_npp_d20171205_noaa_v21.flares_only.csv.gz', 'rb') as f_in: with open('latest.csv', 'wb') as f_out: shutil.copyfileobj(f_in, f_out) chunksize = 10**6 viirs = pd.DataFrame() for chunk in pd.read_csv("latest.csv", chunksize=chunksize): viirs = viirs.append(chunk) dif = 1000 a = 0 b = 0 k = 999999 for i in range(len(viirs)): R = 6373.0 lat1 = radians(float(viirs['Lat_GMTCO'][i])) lon1 = radians(float(viirs['Lon_GMTCO'][i])) lat2 = radians(float(latitude)) lon2 = radians(float(longitude)) dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2 c = 2 * atan2(sqrt(a), sqrt(1 - a)) distance = R * c #print(str(i)+","+str(a+b)) if (distance <= dif): dif = distance k = i if (k == 999999): #print("lightfun_if\n") jdf3 = {} return jdf3 else: #print("lightfun_else\n") viirsdf = viirs.loc[[k]] viirsdf1 = viirsdf viirsdf1['latitude'] = latitude viirsdf1['longitude'] = longitude virlight = gis.content.import_data(viirsdf1) virlight.layer.layers = [dict(virlight.layer)] map1.add_layer(virlight) virdf = virlight.query() dfn = ((virdf).df.head()) js3 = dfn.to_json(orient='index') jdf = json.loads(js3) jdf3 = {} jdf3["Rad_M07"] = jdf["0"]["Rad_M07"] jdf3["Rad_M08"] = (jdf["0"]["Rad_M08"]) jdf3["Rad_M10"] = (jdf["0"]["Rad_M10"]) jdf3["Rad_M12"] = (jdf["0"]["Rad_M12"]) jdf3["Rad_M13"] = (jdf["0"]["Rad_M13"]) jdf3["Rad_M14"] = (jdf["0"]["Rad_M14"]) jdf3["Rad_M15"] = (jdf["0"]["Rad_M15"]) jdf3["Rad_M16"] = (jdf["0"]["Rad_M16"]) return jdf3 except: jdf3 = {} return jdf3 #if(param==light then return jdf3) def Merge(dict1, dict2): res = {**dict1, **dict2} return res final = {} final["latitude"] = latitude final["longitude"] = longitude final["time"] = time if (param == "generic"): final["values"] = genericfun(latitude, longitude, time) if (param == "air"): final["values"] = airfun(latitude, longitude, time) if (param == "light"): final["values"] = lightfun(latitude, longitude, time) if (param == "all"): jdf1 = genericfun(latitude, longitude, time) jdf2 = airfun(latitude, longitude, time) jdf3 = lightfun(latitude, longitude, time) dic = {} dic = Merge(jdf1, jdf2) fdic = {} fdic = Merge(dic, jdf3) final["values"] = fdic if (param == "airlight" or param == "lightair"): jdf2 = airfun(latitude, longitude, time) jdf3 = lightfun(latitude, longitude, time) dic = {} dic = Merge(jdf2, jdf3) final["values"] = dic if (param == "airgeneric" or param == "genericair"): jdf1 = genericfun(latitude, longitude, time) jdf2 = airfun(latitude, longitude, time) dic = {} dic = Merge(jdf1, jdf2) final["values"] = dic if (param == "genericlight" or param == "lightgeneric"): jdf1 = genericfun(latitude, longitude, time) jdf3 = lightfun(latitude, longitude, time) dic = {} dic = Merge(jdf1, jdf3) final["values"] = dic fin = json.dumps(final) return fin
# -*- coding:utf-8 -*- from arcgis.gis import GIS gis = GIS() map = gis.map("東京都", zoomlevel=13) map.draw(shape=(10, 10)) print(map)
from arcgis.geocoding import geocode, reverse_geocode from arcgis.geometry import Point # Python Standard Library Modules from IPython.display import display gis = GIS() geocode_result = geocode(address="Hollywood sign", as_featureset=True) # A list of features geocode_result.features # In[2]: m = gis.map("Los Angeles, CA", zoomlevel=11) # In[3]: m.draw(geocode_result) m.clear_graphics() location = { 'Y': 34.13419, # `Y` es latitud 'X': -118.29636, # `X` es longitud 'spatialReference': { 'wkid': 4326 } } unknown_pt = Point(location)