Connecting to feature server with arc.open()

1347
2
Jump to solution
11-16-2021 06:31 AM
Labels (2)
cmichaud
New Contributor

Hi everyone, This is my first post here and I'm hoping someone can help me out. I'm working in R (v4.1) with Rstudio (v 1.4) and the arcgisbinding package.  I am hoping to fetch data from the living atlas directly into my R session and have has success with some datasets but not others. 

Workflow: I open ArcPro > Portals > Living atlas > select a dataset and click on the `path` link in the popup.  This opens the dataset's webpage in my browser. Scroll to the bottom of the page and copy the URL from the box in the lower right sidebar.  Then I paste the url into my R script.

huc2 <- arc.open("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/WatershedBoundaryDataset_HUC2/Feat...") 

The above works fine, however, when I attempt to run arc.select on the result : fnl_huc2 <- arc.select(huc2) it fails with the error message: Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘arc.select’ for signature ‘"arc.workspace_impl"’

However...

major_rivers <- arc.open("https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/NHDPlusV21/FeatureServer/2") and then fnl_rvr<- arc.select(major_rivers) works just fine...

Any URL that ends in ".../FeatureServer" elicits an error while those that end with  a backslash and a digit work fine ".../FeatureServer/1"  The only other difference I can see (besides the /digit) is that the HUC2 data is a Feature Layer (Hosted) while the major rivers data is simply a Feature Layer.

Thanks in advance for any thoughts on this

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hello cmichaud,

Welcome to the ESRI community! The issue you are experiencing is due to two reasons:

1. Note that the link to the REST API for the Watershed Boundary Dataset ends with FeatureServer, as opposed to ending with a number (like the Feature Service for major_rivers). This means it is a a data container for a Feature Service but you need to specify which layer in this FeatureServer you actually need. It is similar to trying to bring in a geodatabase as opposed to a feature class inside a geodatabase. In short, the solution to this problem is using the following URL:

https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/WatershedBoundaryDataset_HUC2/FeatureServer/0

 

2. You will realize that arc.open will also not work for the URL above. By the way for the original URL you shared, arc.open will work under normal conditions and it will return it as a data container as opposed to a feature service. How to make this work? The issue is even though this layer is publicly accessible it requires and ArcGIS login because it requires a token. We manage this in the R-ArcGIS Bridge with a two-step process:

1a. In ArcGIS Pro, log in to the portal you need data from, in your case you can just do your regular log in.

1b. Run the function 

arc.check_portal()

 

This will ensure that you can reach any online data that you can reach with the login you provided to ArcGIS pro.

2. Try arc.open as follows:

 

arc.open("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/WatershedBoundaryDataset_HUC2/FeatureServer")

 

You can find this pattern (with how to videos) along other patterns of working with the R-ArcGIS Bridge in this blog.

I hope this solves the problem. If not, please reach out at any time.

Orhun

 

View solution in original post

2 Replies
by Anonymous User
Not applicable

Hello cmichaud,

Welcome to the ESRI community! The issue you are experiencing is due to two reasons:

1. Note that the link to the REST API for the Watershed Boundary Dataset ends with FeatureServer, as opposed to ending with a number (like the Feature Service for major_rivers). This means it is a a data container for a Feature Service but you need to specify which layer in this FeatureServer you actually need. It is similar to trying to bring in a geodatabase as opposed to a feature class inside a geodatabase. In short, the solution to this problem is using the following URL:

https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/WatershedBoundaryDataset_HUC2/FeatureServer/0

 

2. You will realize that arc.open will also not work for the URL above. By the way for the original URL you shared, arc.open will work under normal conditions and it will return it as a data container as opposed to a feature service. How to make this work? The issue is even though this layer is publicly accessible it requires and ArcGIS login because it requires a token. We manage this in the R-ArcGIS Bridge with a two-step process:

1a. In ArcGIS Pro, log in to the portal you need data from, in your case you can just do your regular log in.

1b. Run the function 

arc.check_portal()

 

This will ensure that you can reach any online data that you can reach with the login you provided to ArcGIS pro.

2. Try arc.open as follows:

 

arc.open("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/WatershedBoundaryDataset_HUC2/FeatureServer")

 

You can find this pattern (with how to videos) along other patterns of working with the R-ArcGIS Bridge in this blog.

I hope this solves the problem. If not, please reach out at any time.

Orhun

 

cmichaud
New Contributor

Orhun,

Thanks for the rapid reply.  Your solution worked great.  Interestingly, before I asked my question this morning, I attempted to tag a /1 to the HUC2 URL.  This dataset has only 1 layer so obviously the layer designation would be /0.  Off by 1 error, apparently I was indexing like R!  I really appreciate the help 🙂

0 Kudos