Add a feature class to a map in Jupyter Notebook

782
2
06-03-2020 07:51 AM
YaoTang
New Contributor

Can I add a field of a feature class to a map using something like map1.add_layer(FeatureClassName, FieldName, SymbologyType, ColorMap)?

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

Notebooks from inside or outside of ArcGIS Pro?

you can use the arcgis and the arcpy modules.

It would be kind of useless to make a map inside a notebook inside of Pro, since you can just look at the map there.

There is webmap stuff and other things in

API Reference for the ArcGIS API for Python — arcgis 1.8.0 documentation 

and the arcpy mapping module

Introduction to arcpy.mp—ArcPy | Documentation 


... sort of retired...
0 Kudos
alex_friant
Occasional Contributor II

Yes you can, sort of. You can't directly view the Feature Class (FC), but if you want to see what the data looks like in a map, you can convert it to a Spatially Enabled DataFrame (SeDF), and then plot that on a map in Jupyter Notebooks. Just keep in mind that your FC and the SeDF are disconnected. If you make changes to your FC then you will need to update the SeDF.

This is one way to do it that I use:

# import modules

import pandas as pd

from arcgis.features import GeoAccessor, GeoSeriesAccessor

from arcgis.gis import GIS

# create map
gis = GIS()

my_map = gis.map(location = 'San Francisco, CA', zoomlevel = 12)

# load your feature class into a spatially enabled dataframe (sedf)

fc = r'c:\gis\my_geodatabase.gdb\firestations'

my_sedf = pd.DataFrame.spatial.from_featureclass(fc)

# plot the sedf on your map

my_sedf.spatial.plot(map_widget = my_map)

# show the map

my_map

example plot