I am currently trying to import a batch of kml files in R and to create a single shapefile. Basically, it seems to work fine using st_read and st_write.

But if kml files imported have points lines and polygons together, what's the correct st_write options? I tried to use st_write(a3, "a3.shp",layer_options = c("SHPT=POINT")) (or POLYGON, MULTIPATCH,...), but none of these worked. The error message shows "fail to create feature....".

  • 2
    Use the sf package function st_read, then rbind them all together, and st_write it out.
    – mdsumner
    Mar 22, 2017 at 4:50
  • @mdsumner Please consider adding your comment as an answer so we can consider this question resolved.
    – Aaron
    Apr 5, 2017 at 2:43

1 Answer 1


Use the sf package function st_read, then rbind them all together, and st_write it out.

It's not possible to mix points, lines, polygons in a shapefile - you can have only one type. Shapefiles pre-date the current standards for simple features types (i.e. POLYGON and MULTIPOLYGON are importantly different), they don't have an official mechanism for CRS (.prj is a post-hoc convention not in the standard), and use of dBase is hopelessly limiting for storing data.

Don't create shapefiles. There are good formats that support those things we always need (simple features, projection metadata, reliable data storage and naming, styling and format), the best ones are GeoPackage and MapInfo (MIF).

If you can transfer direct to a database do that instead, if it's over the web consider GeoJSON (but you'll have to be in or transform to long-lat). If it's for other R users create a package and use the package data format, with a data-raw/script to build those from the KML.

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.