Draw polygons on mapwidget in Python API

855
1
09-10-2018 12:56 PM
NicholasJones2
New Contributor

I'm trying to accomplish a simple task: plot a rectangular bounding box on a map. Here's my code:

from arcgis import GIS

from arcgis.geocoding import geocode

from arcgis.geometry import Polygon

JM_point = geocode("Kingston, Jamaica")[0]['location']
JM_poly = geocode("Jamaica")[0]['extent']

JM_poly2 = Polygon(JM_poly)

m1 = gis.map("Jamaica")
m1

symbol = {"color":[0,0,128,128],"size":18,"angle":0,"xoffset":0,"yoffset":0,"type":"esriSMS","style":"esriSMSSquare","outline":{"color":[0,0,128,255],"width":1,"type":"esriSLS","style":"esriSLSSolid"}}

m1.draw(JM_point)

m1.draw(JM_poly,symbol=symbol)

m1.draw(JM_poly2,symbol=symbol)

The point 'JM_point' plots fine, but I can't get 'JM_poly' to show up. Note that I'm able to plot polygons from a spatial dataframe, but not from a geometry object. My reason for doing this is that I'm cropping population and elevation rasters for a series of countries using bounding boxes. But I want to do visual inspection of the boxes first.

I'm using the API version 1.5 and Python 3.7 in JupyterLab. Can't find guidance or sample notebooks about how to accomplish this simple task. Your advice would really help me out! Thank you.

Tags (2)
0 Kudos
1 Reply
JaySGregory
New Contributor II

Having a similar issue.  Points draw fine but polygons do not.  Did you ever figure this out?

0 Kudos