R-ArcGIS / r-bridge

Bridge library to connect ArcGIS and R, including arcgisbinding R library.
Apache License 2.0
119 stars 26 forks source link

Method to overwrite layers on ArcGIS online? #52

Closed Nova-Scotia closed 3 years ago

Nova-Scotia commented 3 years ago

I regularly update a layer stored in ArcGIS Online (AGOL), every week from my local computer. When I try to overwrite the web layer with a sf data.frame using arc.write I get the following error, e.g.,

arc.write("https://services1.arcgis.com/WERJN54845JDFJg0/arcgis/rest/services/my_AGOL_layer/FeatureServer/0", 
          my_pts,
           overwrite = TRUE)

Error in .call_proxy("arc_write", path, pairlist(data = data, coords = coords,  : 
  Class not registered

Using R v4.0.2. on Windows computer, arcgisbinding v1.0.1.243.

Is there any way to overwrite a web layer from R?

orhuna commented 3 years ago

@Nova-Scotia we do not support direct data write to portal from an R dataframe. I recommend the following workaround using the new scheduler in ArcGIS Pro:

  1. Encapsulate your R script in a script tool that outputs to a feature class
  2. Create a model in ArcGIS Pro that updates the target feature service with the local feature class from R. Here is the link, to a step-by-step guide for doing just that. 3.1 Option 1 In Model-Builder, connect your R script to step 2 above and schedule the model Here is the resource for doing so 3.2 Option 2 From the history pane schedule the R script so that it runs and produces updated output, which will be consumed by step 2 for posting. Almost exactly the same as Option 1 without the need to create a Model.

This will be the most error-prone way of updating the remote data source.

Nova-Scotia commented 3 years ago

Ok, thanks, appreciate the resources. I hope it's considered for a future release. I wrote a number of models in Pro that used R scripts and they worked for a few weeks then just stopped working, no changes on this end, so I went back to working straight from R - it was really disheartening after all that work!

Can you clarify what you mean in your last sentence?

orhuna commented 3 years ago

@Nova-Scotia sorry to hear that you are having issues with script tools. I will try to repro problems with script tools.

As per writing data to portals, that is on our list of things to do or at least look into. Writing to portals opens up many issues related to safety of portals and overall portal management.

As per the last sentence, I mean either Option 1 or Option 2 being stable ways of updating your remote data product. I recommend Option 2 for now as it is simpler. If there is a recurring issue about R script tools that you encounter, please let us know.

suvedimukti commented 3 years ago

@Nova-Scotia did you resolve your issue? I am having the same issue while writing data from R (4.0.3) to geodatabase. The script was working before.
fgdb = TG_Clip_10252020.gdb arc.write(path = paste0(fgdb,"/digitized_Ag_Cliped_noOverlap/TG_classified_0"),data = allData,overwrite = TRUE, validate = TRUE). Thank you!

Nova-Scotia commented 3 years ago

@suvedimukti I don't have any issues writing to regular (local) geodatabases, just to hosted feature classes.

patriciaandolz commented 3 years ago

Hello @suvedimukti,

I have the same problem as you. I have tried to update the Geodatabase of ArcGIS Pro with the data I have loaded in R.

arc.write(path = "C:/Users/Patricia/Documents/ArcGIS/Projects/MyProject/MyProject.gdb/carrers", data = sfInfraestr[sfInfraestr$type!='zones30 poligons',], validate=TRUE, overwrite=TRUE)

And I get the following error: Error in .call_proxy("arc_write", path, pairlist(data = data, coords = coords, : failed to overwrite existing dataset. use arc.delete(path) or add overwrite=TRUE argument

Did you solved it?

Thanks!

Nova-Scotia commented 3 years ago

Hi @patriciaandolz , I've found that sometimes, using "overwrite = TRUE" isn't enough. Try doing what they suggest and including a line of code to delete the old layer (if you've made a backup first!) first.

patriciaandolz commented 3 years ago

Hi @Nova-Scotia , thanks!! I was having troubles becaus I had the ArcGIS Pro opened while I has trying to update the data.

suvedimukti commented 3 years ago

Hi @patriciaandolz ,

In my case, I had opened the exported layer from R in ArcGIS pro, then I removed it from the map, the error was persistent even after removing the layer from the map. I ended up getting arcgisbinding package updated to the latest version and it worked. If it throws the same error even after removing the layer from Map, simply close Arcgis Pro- it should work fine.

orhuna commented 3 years ago

@suvedimukti good to hear this is resolve. @patriciaandolz does the writing issue still persist?

patriciaandolz commented 3 years ago

That solution worked fine for me. So it is solved ;-)

orhuna commented 3 years ago

Issue resolved.