Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.87k stars 1.1k forks source link

detect_objects() with existing feture service doesn't work #1947

Open amrirasyidi opened 3 weeks ago

amrirasyidi commented 3 weeks ago

Describe the bug A clear and concise description of what the bug is.

In the official documentation, detect_object said to be able to use existing Feature Service for the output_name variable.

output_name Optional. If not provided, a FeatureLayer is created by the method and used as the output . You can pass in an existing Feature Service Item from your GIS to use that instead. Alternatively, you can pass in the name of the output Feature Service that should be created by this method to be used as the output for the tool. A RuntimeError is raised if a service by that name already exists

However, I got an error (provided below) whenever I tried to use a feature service item as the parameter.

To Reproduce Steps to reproduce the behavior:

from arcgis import GIS
from arcgis.learn import Model, detect_objects

gis = GIS(
    url='url', # i filled this with the correct credential of course
    username='username',
    password='username',
)

detect_objects_model_package = gis.content.get('some_id')
raster = gis.content.get('some_other_id')

detect_objects_model = Model(detect_objects_model_package)
detect_objects_model.install(gis=gis)

test_notebook = gis.content.get('another_id') # this is the target feature service

context = {
    'cellSize': 0.1,
    'processorType':'GPU'
}

out_objects = detect_objects(
    input_raster=raster,
    model=detect_objects_model,
    output_name=test_notebook,
    context=context,
    gis=gis
)

error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
In  [30]:
Line 1:     out_objects = detect_objects(

File D:\Program Files\ArcGIS\Pro\bin\Python\envs\arc-big\Lib\site-packages\arcgis\learn\__init__.py, in detect_objects:
Line 347:   return gis._tools.rasteranalysis.detect_objects_using_deep_learning(

File D:\Program Files\ArcGIS\Pro\bin\Python\envs\arc-big\Lib\site-packages\arcgis\_impl\tools.py, in detect_objects_using_deep_learning:
Line 11600: output_service_name = output_objects.replace(" ", "_")

File D:\Program Files\ArcGIS\Pro\bin\Python\envs\arc-big\Lib\site-packages\arcgis\gis\__init__.py, in __getattr__:
Line 13557: raise AttributeError(

AttributeError: 'Item' object has no attribute 'replace'
---------------------------------------------------------------------------

Expected behavior I expect it to either overwrite or append the inferencing result to the existing feature service. I tried to leave the output_name empty and also filled it with string, it works normally.

Platform (please complete the following information):

Additional context My goal is to append the inferencing result to an existing feature service

Given the error, is it correct for me to assume that currently the variable only accepts string as input?

  1. If it is, is it possible to append the inferencing result (assume that I have the item id for the existing feature service I want to append) to the existing feature service using detect_objects only? (I have the work around with .edit_features(), but to me the documentation implies it can use an existing feature service as the output, so I'm curious)
  2. If it is not (i.e. it can actually use another kind of input), what kind of input do I need to put to make it append the result to an existing feature service

Thanks!

nanaeaubry commented 3 weeks ago

@priyankatuteja Can you take a look at this?