Hi,
I have a Hosted Feature Layer in ArcGIS Online, with a point layer and a polygon layer.
I am looking to run an ArcGIS Notebook as a task that will:
I am having difficulty with the buffer() and use_proximity.create_buffers(). No matter what I do the input geometry seems to be recognized as invalid. Typical error messages are invalid geometry or
an error occured with:list indices must be integers or slices, not str
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.geometry import buffer
from arcgis.features import use_proximity
gis = GIS("home")
# Get our layers
layer_item = gis.content.get("xyzxyzxyz")
point_sublayer = layer_item.layers[1]
polygon_sublayer = layer_item.layers[2]
# Query our point layer
# Can set our_sr to 4326 or 3857. WGS84 or projected.
points = point_sublayer.query(where="1=1", out_fields="*", return_geometry=True,out_sr = 4326)
try:
for point in points:
p = point.geometry
print(type(p))
buffers = buffer(geometries=[p], distances=[5], unit='meters',out_sr=4326) # fails
# extra bit would go here to append against polygon
except Exception as e:
print(f"an error occured with:{str(e)}")
I believe it is because the input is a feature, not a featurecollection or other valid type but I'm not sure how to handle it otherwise.
Solved! Go to Solution.
I got the same error from your code above. See code snippet below for using the geometry.buffer to return the geometry for the buffer polygon. Most notably use the LengthUnits enum and the Point geometry.
Let me know if this works on your end.
from arcgis.geometry import LengthUnits
from arcgis.geometry import Point
...
for point in points:
try:
p = Point(point.geometry)
buffers = buffer(geometries=[p], distances=[5], unit=LengthUnits.METER.value, in_sr=4326)
print(buffers)
except Exception as e:
print(f"an error occured with: {str(e)}")
You have inspired this blog post.
All the best,
Glen
I got the same error from your code above. See code snippet below for using the geometry.buffer to return the geometry for the buffer polygon. Most notably use the LengthUnits enum and the Point geometry.
Let me know if this works on your end.
from arcgis.geometry import LengthUnits
from arcgis.geometry import Point
...
for point in points:
try:
p = Point(point.geometry)
buffers = buffer(geometries=[p], distances=[5], unit=LengthUnits.METER.value, in_sr=4326)
print(buffers)
except Exception as e:
print(f"an error occured with: {str(e)}")
You have inspired this blog post.
All the best,
Glen
Thanks @Clubdebambos . The amended geometry / units resolved the issue.
For each point, as we only have one buffer, here's the extra piece to create a polygon feature:
if buffers:
new_polygon= {
"geometry": buffers[0],
"attributes": {
"parentglobalid": point.attributes["globalid"]
# more attributes here
}
}
# Append the new feature to the polygon layer
polygon_layer.edit_features(adds=[new_polygon])