Hello,
I used arc.open() to read a .gdb polygon feature class read into R. I would like to convert the object to a spatialPolygonsDataFrame with the arc.data2sp function. The function fails, however, with the following message:
> nhdSp <- arc.data2sp(nhd)Error: inherits(x, "arc.data") is not TRUE
Turns out the object is of class 'arc.feature_impl',
> class(nhd)[1] "arc.feature_impl" attr(,"package") [1] "arcgisbinding"
whereas arc.data2sp() requires objects of class 'arc.data'. How can I coerce my object to class 'arc.data' for use with the arc.data2sp() function?
Hello Jake,
I can't reproduce this issue with polygon data I have on hand. For the variable that stores the arc.open output, could you paste what it displays when just typing the variable name. For example, here's a simple layer I was using to test:
> d <- arc.open("c:/workspace/basic_catalog.gdb/example_with_nulls_buff_50km")
> d
dataset_type : FeatureClass
path : c:/workspace/basic_catalog.gdb/example_with_nulls_buff_50km
fields : OBJECTID, Shape, ID, Data, BUFF_DIST, ORIG_FID, Shape_Length, Shape_Area
extent : xmin=-85.45471, ymin=-9.452023, xmax=-75.55085, ymax=0.4521846
geometry type : Polygon
WKT : GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984"...
WKID : 4326
What does your data source display? Can you share a sample of the input GDB you're using?
Thanks, Shaun
Hello Shaun,
Thanks for your input. I resolved the problem by using arc.select() to convert the ‘ar.feature_impl’ class object to an ‘arc.data’ class object. Example below:
> # Read in example shapefile from package
> ozone.path <- system.file("extdata", "ca_ozone_pts.shp",
+ package="arcgisbinding")
> ozone.arc.dataset <- arc.open(ozone.path)
>
> class(ozone.arc.dataset) # arc.feature_impl class
[1] "arc.feature_impl"
attr(,"package")
[1] "arcgisbinding"
>
> arc.data2sp(ozone.arc.dataset) # doesn't work
Error: inherits(x, "arc.data") is not TRUE
>
> # convert to class arc.data using arc.select()
> ozone.arc.dataframe <- arc.select(ozone.arc.dataset)
>
> class(ozone.arc.dataframe) # arc.data!
[1] "arc.data" "data.frame"
> ozone.arcdata <- arc.data2sp(ozone.arc.dataframe) # success!
Hello Jake,
Glad you found something that works for you. The other way of doing this is running arc.select on the input after opening it:
> # Read in example shapefile from package
> ozone.path <- system.file("extdata", "ca_ozone_pts.shp",
+ package="arcgisbinding")
> ozone.arc.dataset <- arc.open(ozone.path
> ozone.obs <- arc.select(ozone.arc.dataset)
This two-step process is intentional, to give you a step to filter the data before it is imported during the arc.select step. If you only want certain columns or otherwise to filter the data, you can select just the features you want – minimizing the amount of memory used in R with the resulting dataset.
Cheers,
Shaun