Using arc.open function to import a feature class from SQL (ArcGIS for Server)?

1808
1
Jump to solution
10-05-2017 06:41 AM
EQRGIS
by
New Contributor

Hello - 

I can use the arc.open function to successfully import a local .shp file into R.  I can also successfully import regular old SQL tables into R using the sqlQuery function in the RODBC package and an ODBC connection.

But I cannot figure out how to import a feature class from SQL (Running ArcGIS for Server) into R directly?  I'd like to be able to import files directly so that I'm working with a live dataset, rather than pulling from a static dataset within a a .gdb file.

1 Solution

Accepted Solutions
ShaunWalbridge
Esri Regular Contributor

Brian,

Thanks for the question, this is something that I'll add a note for me to document in the package documentation. To reference a database, there are a couple of approaches:

  1. If you only need access to one layer: you'll need to create a layer file which references the data. You should be able to do this from within ArcMap or Pro by right clicking on the layer > Save as Layer File, if it's in your current map, or right click the layer in the Catalog pane and select "Create Layer". Once you've created that layer file, you can reference it directly with arc.open(), and it'll work like any other data source.
  2. If you want to access arbitrary layers in your database: instead of creating an intermediary layer file, you can directly reference things from the .sde file. This file is created when you add a database connection, by default it'll end up in your user profile. You can find it from ArcMap for example by right clicking on the database, selecting Properties, the 'Name' field contains the full path to the sde file. You can copy this elsewhere, or reference it directly, using the syntax:

    r <- arc.open('c:/path/to/my.sde/dbname.layername')

The bridge doesn't currently have the underpinnings to figure out the necessary information directly, but either of the above approaches will give you direct access. Let us know if you need anything else.

Cheers,

Shaun

View solution in original post

1 Reply
ShaunWalbridge
Esri Regular Contributor

Brian,

Thanks for the question, this is something that I'll add a note for me to document in the package documentation. To reference a database, there are a couple of approaches:

  1. If you only need access to one layer: you'll need to create a layer file which references the data. You should be able to do this from within ArcMap or Pro by right clicking on the layer > Save as Layer File, if it's in your current map, or right click the layer in the Catalog pane and select "Create Layer". Once you've created that layer file, you can reference it directly with arc.open(), and it'll work like any other data source.
  2. If you want to access arbitrary layers in your database: instead of creating an intermediary layer file, you can directly reference things from the .sde file. This file is created when you add a database connection, by default it'll end up in your user profile. You can find it from ArcMap for example by right clicking on the database, selecting Properties, the 'Name' field contains the full path to the sde file. You can copy this elsewhere, or reference it directly, using the syntax:

    r <- arc.open('c:/path/to/my.sde/dbname.layername')

The bridge doesn't currently have the underpinnings to figure out the necessary information directly, but either of the above approaches will give you direct access. Let us know if you need anything else.

Cheers,

Shaun