I have this code:

#init data
xes = c(-122.133533701866, -122.141590665524, -122.382782560179, -122.302227764504, -122.347524548303)
yes = c(47.617342005802, 47.6102707417054, 47.6704037709971, 47.6118279934801, 47.7237286721321)
a = data.frame(id = 1:5, X = xes, Y = yes)

#init sf object
a = st_as_sf(a, coords = c('X','Y'))
st_crs(a) = 4326
st_write(a, "C:/Users/USER/Downloads/aa.shp", delete_dsn=TRUE)
test1 <- st_read("C:/Users/USER/Downloads/aa.shp", stringAsFactors = FALSE)

The final line (test1) returns:

Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) : no simple features geometry column present

Which is odd, because using rgdal and converting to an sf object works just fine:

#Assumes code block above has already been run
a1= as(a, 'Spatial')

writeOGR(a1, 'C:/Users/USER/Downloads/aaa.shp', driver = 'ESRI Shapefile', layer = 'aaa', overwrite_layer = T)

test2 = readOGR('C:/Users/USER/Downloads/aaa.shp')
test3 = readOGR('C:/Users/USER/Downloads/aa.shp') #from the earlier block
identical(test2,test3) #returns TRUE

b = st_as_sf(test2)


[1] TRUE


R version 3.5.1 (2018-07-02) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C
LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils
datasets methods base

other attached packages: [1] rgdal_1.3-6 sp_1.3-1
data.table_1.11.8 openxlsx_4.1.0 sf_0.7-1

loaded via a namespace (and not attached): [1] Rcpp_0.12.19
lattice_0.20-35 class_7.3-14 crayon_1.3.4 grid_3.5.1
spData_0.2.9.4 DBI_1.0.0 magrittr_1.5 e1071_1.7-0 [10] units_0.6-1 pillar_1.3.0 zip_1.0.0 rlang_0.3.0.1
rstudioapi_0.8 tools_3.5.1 yaml_2.2.0 compiler_3.5.1 classInt_0.2-3 [19] tibble_1.4.2

closed as off-topic by Spacedman, BERA, LaughU, nmtoken, Dan C Dec 6 '18 at 16:00

  • This question does not appear to be about geographic information systems (GIS) within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    I'm voting to close this question as off-topic because its a typo. – Spacedman Dec 6 '18 at 8:49

test1 <- st_read("C:/Users/USER/Downloads/aa.shp", stringAsFactors = FALSE)

stringAsFactors is not stringsAsFactors. You've missed an s.

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