3

I have 800+ shapefiles and some of them have different type of attributes. When I use Merge Vector Layers and select all my shapefiles I get "Incorrect parameter value for LAYERS" error.

When I partially select the first 20-30 something shapefiles they merge together but if I select the next 20-30 shapefiles they won't merge. I was able to get the error "has different data type than in other layers (Integer instead of String) Execution failed after 0.12 seconds" by trying to select the last 20-30 shapefiles at a time. So imagine this might be the cause of error when I try to merge them all together at once.

What can I do to merge all these shapefiles, without losing data? I just want to merge everything together, even if there will be duplicate fields in the attribute table. What can I try to merge these files? What could be the culprit here?

2 Answers 2

3

You may want to convert your initial shapefile attributes types to String. The script is unable to work because you have some shapefiles with same column name but with different types (Date, Integer, String,...). The solution on long term would be to modify the script behind "Merge Vector Layers" to add an option to cast all columns to String.

The short term solution could be to convert all your shapefiles with ogr2ogr command line utility by casting all fields to String with

ogr2ogr -f "ESRI Shapefile" -mapFieldType All=String out_file.shp in_shp.shp

To manage multiple shapefiles, you will need to loop. You should look at this question and its answers and make some adaptations for this intent.

Then, open the resulting shapefiles in QGIS and use the same process you already choose but without the issue(s) due to attributes types.

0

You could use sf package in R for that. Like Thomas said you could build a loop through all your files and convert the one column that is wrong to string. Then depending on how you want to merge them, if you want to have the boundaries dissolved or not, you could either use st_union or st_combine on the shapefiles. And finally export the new shapefile.

Just an example (you could also do it in parallel processing to make it faster):

library(sf)

shp_combined <- NULL
files <- list.files("mypath", pattern = ".shp$" , full.names = T)

for (i in 1:length(files)){
  shp <- st_read(files[i])
  shp$tochange <- as.character(shp$tochange)
  if( i == 1){
    shp_combined <- shp
  }
  else{
    shp_combined <- st_union(shp_combined,shp)
  }
}

st_write(shp_combined, "outputpath")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.