r-bridge-install: arc.write error
I am getting the following error while writing an sf object
dataframe
to a GDB
. The dataframe imported is a feature class from a GDB brought in via the sf
package. After some data manipulation I am trying to write the dataframe
back into the same GDB
as a new
feature class/layer
.
I read in another post that sf
does not support writing a feature class to a gdb
so I had to use arcgisbinding
. However, when I use sf::st_write
to write the df
as a shapefile
, it works just fine.
The arc.write
works on the sample nc
dataset in the sf
package but does not work on my dataset. I don’t know if it matters but my sf object
has more than 700,000
rows and 82
columns.
How can I fix this?
Error
Error in .call_proxy("arc_write", path, pairlist(data = data, coords = coords, :
insert row failed
Code
library(sf)
library(arcgisbinding)
arc.check_product()
product: ArcGIS Pro (12.8.0.29751)
license: Advanced
version: 1.0.1.244
arc.write("path/GDB.gdb/Feature_Class_Name", data = df, overwrite = TRUE)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 20 (1 by maintainers)
Another solution we can try is if you have shapefile you could do the following:
The above should work with the caveat that your data will be at the mercy of what we could write to a shapefile and the checks that went into creating that shapefile to start with, or lack thereof.
@Saadi4469 thank you. As per your question on why shapefile works, shapefiles are not subject to stringent value and geometry checks that feature classes are subject to. This means it is easy to export to a
.shp
but you may end up with problematic geometries in terms of their description (vertices) and/or relationships (such as coincidence, holes, etc.). Also please double check to make sure that the geometries and the values make sense. For shapefiles, if it cannot output a column it silently drops it whereas the arc object throws the error that you saw.Thank you for the column types. I do see some issues in the column types. I do not know details of your dataset but some columns that should be the same type are different for instance
high_chance_00_year00
is a character type whereaslow_chance_15_year00
is a numeric type. Would you spot check some of these columns that are inconsistent? If R converts the whole column to a character that might mean the somewhere there may be an inconsistent row value at that column such as,
insteda of.
or some other character.An easy solution here would be casting. You can set the types of the columns explicitly before writing it out.
@Saadi4469 the data volume is not the issue as the cursor that inserts data from your R dataframe to the feature class in the GDB throws an error and exits.
I think we can debug this further and get you going with your workflow. Below are some checks on the R side, that I recommend you perform on your R data frame:
Steps to Take on the R/R Studio side
Checking for Different Types of missing values
I recommend applying the below separately on the dataset to investigate if there are more than one type of missing data. Where we can handle nas in writint NaN and infinite values need to be represented with a place holder such as
-999
Would you please check for different types of missing/out of bound values with
is.na
,is.infinite
,is.nan
?Note that if you wanted to assign a value for any na, nan or inifinte you can use the following pattern
is.na(x) <- value
Trying to find the problematic row
I suspect that you have one row that causes a problem in writing. After trying the subset you given me, I was able to write it out successfully. Here is what I recommend:
Create a for loop that loops through only up to a row and try to write it.
Note that this takes a minute with the 10 rows you gave me and you may want to search for the row may be first with a jump of 100 and then a jump of 10 etc. Searching every row range one by one may take a while for 800,000 rows.
Steps to Take on the ArcGIS Pro/Desktop side
Creating a New GDB
We see write errors like to one you encountered on corrupt gdbs. One step I recommend is running the
Create File Geodatabase
tool to create a new gdb to write into. There were times where this solved pretty complex problems.Visualizing the feature class that resulted in the error
This step might be a replacement for the for loop I recommended above. Here you can, simply run your code that results in the error. Then in Pro Go to Catalog, right click on the gdb you wrote to and click refresh. If you can see the feature class there add it to your map and look at the Attribute Table. If the Attribute Table is populated the bottom-most row will be the row right before the problematic row that you can either remove or fix in R.
I hope this helps and please reach out if it does not.