How to segment raster data?

107
1
10-11-2020 08:54 AM
KarenSchulz
New Contributor

I am new to arcgis and appreciate any feedback and help 😃


My aim: I would like to segment a raster image through the python api in the same manner as it is possible with the graphical interface.

My coding approach (using jupyter notebook), that didn't work##:


# import dependencies
import arcgis
from arcgis.gis import GIS
from arcgis.raster import Raster
from arcgis.raster.analytics import *

# set credentials

gis = GIS(<credentials>)

# load raster image, which is a tiff-file

file_path = r"<path>.tif"
raster_img = Raster(file_path)

# use segment function

segment(input_raster=raster_img)

# throws error:

AttributeError: '_ArcpyRaster' object has no attribute '_engine_obj'

Also tried using a different image from the online resources:
items2 = gis.content.search("title: multispectral landsat", item_type="Imagery Layer", outside_org=True)
landsat_layer = items2[0].layers[0]

This lead to a different error:

AttributeError: 'NoneType' object has no attribute 'update'
0 Kudos
1 Reply
KarenSchulz
New Contributor

So, I found a solution for the .tif raster file(1st example) - using arcgis.raster.functions.segment_mean_shift() works properly. The input data type was apparently a reason for the segment() function to not work.
Nevertheless, I still don't see why the example above didn't work for the imagery input type example (2nd one) or how to convert imagery layer data into raster data and vice versa.

0 Kudos