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

to_featurelayer is not overwriting #1700

Closed SteveScott closed 10 months ago

SteveScott commented 11 months ago

Describe the bug I wish to overwrite the existing feature layer with new data using the to_featurelayer method. I do this by setting the parameters: overwrite=True, service={'featureServiceId': feature_service_id, 'layer': 0}

To Reproduce create a feature layer from a spatially enabled data frame setting overwrite=True and passing in the featureServiceID. results in duplicate feature layers in ArcGIS Enterprise portal.

<insert your code here>

error: no errors.

Code


    def upload_gdf_to_agol(self, gdf : GeoDataFrame, name: str):
        #convert GeoDataFrame to a Spatialy Enabled DataFrame
        sedf = GeoAccessor.from_geodataframe(gdf)

        #get the existing item id
        feature_service_id = self.gis.content.search(query=f"title:{name}", item_type="Feature Service")[0].id
        logging.info(f"feature_service_id: {feature_service_id}")

        #publish as a feature layer 
        hosted_feature_lyr = sedf.spatial.to_featurelayer(title=name, 
                                                          gis=self.gis, 
                                                          tags="tag, here",
                                                          overwrite=True,
                                                          service={'featureServiceId': feature_service_id, 'layer': 0}
                                                         )
        #update the description and tags, or other properties.
        update_dict = {'description': f'''
                       description here
                       ''', 
                       'tags': ['new', 'tag', 'here', f'{datetime.now().year}']
                       }
        hosted_feature_lyr.update(item_properties=update_dict)

        #share the feature layer with the organization
        hosted_feature_lyr.share(everyone=False, org=True)

Expected behavior I expect the feature layer to overwrite the existing feature layer and maintain the same feature service id.

Platform (please complete the following information):

nanaeaubry commented 10 months ago

@SteveScott

Can you please describe a bit better what error you are seeing? Is it not overwriting at all or is there another issue after the overwrite?

SteveScott commented 10 months ago

Yes, when I call to_featurelayer it is creating new layers, not overwriting existing ones. New files are created every time I execute.

nanaeaubry commented 10 months ago

@SteveScott I apologize for all the closing and opening. I realize that what I had posted before is incorrect as it pertains only to tables.

What version of Enterprise are you using?

SteveScott commented 10 months ago

I have administrative access but not enough to access the version on port

  1. But I will ask.

On Mon, Oct 30, 2023 at 8:43 AM Nanae Aubry @.***> wrote:

@SteveScott https://github.com/SteveScott I apologize for all the closing and opening. I realize that what I had posted before is incorrect as it pertains only to tables.

What version of Enterprise are you using?

— Reply to this email directly, view it on GitHub https://github.com/Esri/arcgis-python-api/issues/1700#issuecomment-1785109820, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHLFSKVE6VGAWBH6BM54JLYB6OGFAVCNFSM6AAAAAA6THLYBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBVGEYDSOBSGA . You are receiving this because you were mentioned.Message ID: @.***>

-- From the personal email account of Steve Scott.

nanaeaubry commented 10 months ago

@SteveScott

If you login by creating a gis instance: gis = GIS(<your credentials>) and then do gis.version that should be enough for us

SteveScott commented 10 months ago

The Portal version lists as [2023, 3]

On Wed, Nov 1, 2023 at 4:29 AM Nanae Aubry @.***> wrote:

@SteveScott https://github.com/SteveScott

If you login by creating a gis instance: gis = GIS() and then do gis.version that should be enough for us

— Reply to this email directly, view it on GitHub https://github.com/Esri/arcgis-python-api/issues/1700#issuecomment-1788590947, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHLFSMCPU5XJBDIVTM2CCDYCIB7XAVCNFSM6AAAAAA6THLYBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBYGU4TAOJUG4 . You are receiving this because you were mentioned.Message ID: @.***>

-- From the personal email account of Steve Scott.

nanaeaubry commented 10 months ago

@SteveScott What type of files are created? CSV? Also do you have arcpy or shapely in your environment?

nanaeaubry commented 10 months ago

@SteveScott I was able to find the issue. Normally the feature layer is being overwritten but the intermediary feature layer that was created is not properly cleaned up. We will fix this issue.

Even though a new feature layer does exist can you check and see that the one you are overwriting is being overwritten as well?

SteveScott commented 10 months ago

@nanaeaubry It is hard to tell. I start, I upload one map. I start again, there are two maps, it takes the first map in the list, update that map, now there are three maps. Because it takes the first map in the list, only one map (may) be updated, and you can't tell them apart without looking at the metadata (I put the date created in the description).

nanaeaubry commented 10 months ago

@SteveScott We took care of the issue and it will be backported as a patch to 2.2.0 From what the bug was, the service was in fact being overwritten but it was not properly cleaning up the items being created intermittently