4.3 Data searching and visualization¶
In this lesson another Python package developed by Esri will demostrated.
The ArcGIS Python package (arcgis) is a library for working with geographic data, maps, and spatial analysis in Python. It is primarily used with ArcGIS Online and ArcGIS Enterprise but can also work with local GIS data.
Let's import arcgis
module and show the map. See documentation.
In [46]:
Copied!
import arcgis
gis = arcgis.GIS()
map1 = gis.map()
map1
import arcgis
gis = arcgis.GIS()
map1 = gis.map()
map1
Out[46]:
Map(extent={'xmin': 1346302, 'ymin': 6199274, 'xmax': 2099198, 'ymax': 6631578, 'spatialReference': {'wkid': 1…
New interactive map will be zoomed to Prague, Czech Republic (which default settings for CTU organization).
Let's create a new interactive window with area of interest and zoom level specified.
In [58]:
Copied!
map2 = gis.map('Prague, Czech Republic')
map2.zoom = 12
map2
map2 = gis.map('Prague, Czech Republic')
map2.zoom = 12
map2
Out[58]:
Map(center=[6458611.195920989, 1608669.9159487225], extent={'xmin': 1588743.7270967264, 'ymin': 6427623.310685…
The module allows to search in ArcGIS Hub.
In [51]:
Copied!
from IPython.display import display
items = gis.content.search('Prague', item_type="Feature Layer", outside_org=True)
print(f"Number of layers: len(items)")
for item in items[:3]:
print(item.title, item.owner)
display(item)
from IPython.display import display
items = gis.content.search('Prague', item_type="Feature Layer", outside_org=True)
print(f"Number of layers: len(items)")
for item in items[:3]:
print(item.title, item.owner)
display(item)
Number of layers: len(items) Prague_Restaurants Rachel_K
přírodní památky Editor_4ct
Trajet_PRAGUEE CLHOR7@ulaval.ca_ulaval
Let's add selected layer into interactive map.
In [60]:
Copied!
layer = items[0].layers[0]
map2.content.add(layer)
map2.zoom_to_layer(layer)
map2
layer = items[0].layers[0]
map2.content.add(layer)
map2.zoom_to_layer(layer)
map2
Out[60]:
Map(center=[14.450927726000034, 50.07150885421764], extent={'xmin': 1595641.1192472717, 'ymin': 6452664.683106…
Local data may be added into interactive map using Pandas library.
In [61]:
Copied!
import pandas
nuts_path = r"S:\K155\Public\155ISDP\01\NUTS_RG_20M_2021_3035.shp"
arcpy.workspace = r"C:\Users\martin\Downloads" # change path here
code = "CZ"
arcpy.analysis.Select(nuts_path, f"nuts_{code}.shp", f"CNTR_CODE = '{code}' AND LEVL_CODE = 2")
okresy = pandas.DataFrame.spatial.from_featureclass(f"nuts_{code}.shp")
map3 = gis.map(location='Czech Republic')
map3.zoom = 7
okresy.spatial.plot(map_widget=map3)
map3
import pandas
nuts_path = r"S:\K155\Public\155ISDP\01\NUTS_RG_20M_2021_3035.shp"
arcpy.workspace = r"C:\Users\martin\Downloads" # change path here
code = "CZ"
arcpy.analysis.Select(nuts_path, f"nuts_{code}.shp", f"CNTR_CODE = '{code}' AND LEVL_CODE = 2")
okresy = pandas.DataFrame.spatial.from_featureclass(f"nuts_{code}.shp")
map3 = gis.map(location='Czech Republic')
map3.zoom = 7
okresy.spatial.plot(map_widget=map3)
map3
Out[61]:
Map(center=[6401172.192090536, 1706724.8605290516], extent={'xmin': 1448463.6418886571, 'ymin': 6010711.717534…