You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<divclass="alert alert-info"><b>Note:</b> If you are running this guide in an environment <b>without <code>arcpy</code></b>, you can comment out the line that imports it and proceed with the guide. The Python API will look for <code>shapely</code> library and use it for geometry operations.
</div>
Embed Python API map widgets within HBox and VBox
fromipywidgetsimportHBox, VBox, Label, Layout# create 3 map widgetsmap1=gis.map("China", 4)
map2=gis.map("China", 4)
map3=gis.map("China", 4)
# set hbox layout preferenceshbox_layout=Layout()
hbox_layout.justify_content='space-around'# create 2 hbox - one for title, another for mapshb1=HBox([Label('31-Dec-19'),Label('29-Jan-20'), Label('20-Mar-20')])
hb2=HBox([map1, map2, map3])
hb1.layout,hb2.layout=hbox_layout, hbox_layout# sync all mapsmap1.sync_navigation(map2)
map2.sync_navigation(map3)
# each hbox is a row in the vboxVBox([hb1,hb2])
ArcPy snippets I always search for
copy fgdb from samplesdata to home folder
importoshome_dir=os.path.join(os.path.sep, 'arcgis','home')
samples_dir=os.path.join(arcgis_dir, 'samplesdata')
print(f"home dir: {home_dir}")
print(f"samples dir: {samples_dir}")
defcopy_sample_gdb_to_home(gdb_zip_name):
"""Given the full filename (with extensions) of a gdb zip file in /arcgis/samplesdata/, will copy and unzip that gdb to /arcgis/home/ Will return the full path to the unzipped gdb in home"""# Get the full paths of all the source and destination files to copygdb_dir_name=gdb_zip_name.split(".zip")[0]
gdb_zip_path_src=os.path.join(samples_dir, gdb_zip_name)
gdb_dir_path_src=os.path.join(samples_dir, gdb_dir_name)
gdb_zip_path_dst=os.path.join(home_dir, gdb_zip_name)
gdb_dir_path_dst=os.path.join(home_dir, gdb_dir_name)
# If the gdb has been copied/unzipped to home dir before, delete itifos.path.exists(gdb_zip_path_dst):
os.remove(gdb_zip_path_dst)
ifos.path.exists(gdb_dir_path_dst):
shutil.rmtree(gdb_dir_path_dst)
# Copy the zip file to home, unzip itshutil.copy(gdb_zip_path_src, gdb_zip_path_dst)
zip_ref=zipfile.ZipFile(gdb_zip_path_dst, 'r')
zip_ref.extractall(home_dir)
zip_ref.close()
# Return the output full path to /arcgis/home/unzipped_gdbreturngdb_dir_path_dst# call the function to copy data needed for this analysisgdb_path=copy_sample_gdb_to_home('Analyze_Urban_Heat_Using_Kriging.gdb.zip')
print(f"GDB succesfully copied to {gdb_path}")
Read a Python API SeDF into in-memory ArcPy Featureclass
# key here is to specify location as 'memory/dataset-name'fc=boston_sdf.spatial.to_featureclass('memory/boston_fc')
fc>>>'memory/boston_fc'# you can use this in downstream processing and keep chaining results in memoryarcpy.analysis.Buffer(in_features='memory/boston_fc',
out_feature_class='memory/boston_buff_fc',
buffer_distance_or_field=10)
>>><Result'memory/boston_buff_fc'># to see the list of datasets you have in-memory, do thisarcpy.env.workspace='memory'arcpy.ListFeatureClasses()
>>> ['boston_buff_fc', 'boston_fc']