r-spatial / sf

Simple Features for R
https://r-spatial.github.io/sf/
Other
1.34k stars 298 forks source link

Geometric problem #1854

Closed Ysuerte closed 2 years ago

Ysuerte commented 2 years ago

Hello. I receive always the error : "Error in s2_geography_from_wkb(x, oriented = oriented, check = check) : Loop 0 is not valid: Edge 7 has duplicate vertex with edge 19". I found this error on same topics here, but i didn't solve the problem using the solutions found here. I'm using the release 3.6.1 of R software

Librerie

library("sp") library("rgdal") library("stringr") library("plyr") library("dplyr") library("sf") library("foreign")

setwd("N:\CONSEGNA 2018") fgdb <-"N:\CONSEGNA 2018\CATASTO_2018.gdb"

subset(ogrDrivers(), grepl("GDB", name)) fc_list <- ogrListLayers(fgdb) layer<-sort(print(fc_list)) filtro <- substring(layer,1,2) %in% c("BZ","TN") layer <- layer[filtro==F] filtro <- grep("_old$",layer) layer<-layer[-filtro] filtro <- grep("_butta$",layer) layer<-layer[-filtro] filtro <- grep("_errato7",layer) layer<-layer[-filtro] table(substring(layer,1,2))

tipo_file=c("_FAB","_PART", "_FID", "_FOG", "_ACQ", "_STRA")

layer<-c("MT_FAB", "MT_PART", "MT_FID", "MT_FOG", "MT_ACQ", "MT_STRA")

stati_tot<-as.data.frame(matrix(NA,ncol=3,nrow=0)) colnames(stati_tot)=c("Feature","Nomefile","Freq") for(i in 1:length(tipo_file)){ layer_da_girare<-layer[substring(layer, 3)==tipo_file[i]] for(j in 1:length(layer_da_girare)){ catasto<-st_read(dsn=fgdb,layer=layer_da_girare[j], stringsAsFactors = F)

, sf_column_name = if (is.character(nomefile)) nomefile else nm[codice_comune],)

#st_geometry(catasto) = "nomefile"
    a=count(catasto, Nomefile)
if(nrow(a)==0){a=count(catasto$nomefile)}
stati<-cbind(layer_da_girare[j],a)
colnames(stati)=c("Feature","Nomefile","Freq")
stati_tot<-rbind(stati_tot,stati)

}

stati_tot<-rbind(stati_tot,stati)

}

Sorry but certainly I have made many mistakes by posting incorrectly (in addition to those in R)

edzer commented 2 years ago

You can try st_make_valid() on the invalid object, or else switch using s2 off with sf_use_s2(FALSE).

Ysuerte commented 2 years ago

Thanks for the valuable advice. Unfortunately in both cases it gives me an error: Error in st_sf (x, ..., agr = agr, sf_column_name = sf_column_name): no simple features geometry column present

edzer commented 2 years ago

We can't do anything without a reproducible example.

Ysuerte commented 2 years ago

library("sp") library("rgdal") library("stringr") library("plyr") library("dplyr") library("sf") setwd("N:\CONSEGNA 2018") fgdb <-"N:\CONSEGNA 2018\CATASTO_2018.gdb" subset(ogrDrivers(), grepl("GDB", name)) fc_list <- ogrListLayers(fgdb) layer<-sort(print(fc_list)) filtro <- substring(layer,1,2) %in% c("BZ","TN") layer <- layer[filtro==F] filtro <- grep("_old$",layer) layer<-layer[-filtro] filtro <- grep("_butta$",layer) layer<-layer[-filtro] filtro <- grep("_errato7",layer) layer<-layer[-filtro] table(substring(layer,1,2)) tipo_file=c("_FAB","_PART", "_FID", "_FOG", "_ACQ", "_STRA") layer<-c("MT_FAB", "MT_PART", "MT_FID", "MT_FOG", "MT_ACQ", "MT_STRA") stati_tot<-as.data.frame(matrix(NA,ncol=3,nrow=0)) colnames(stati_tot)=c("Feature","Nomefile","Freq") for(i in 1:length(tipo_file)){ layer_da_girare<-layer[substring(layer, 3)==tipo_file[i]]

layer[str_detect(layer, tipo_file[i])]

for(j in 1:length(layer_da_girare)){ st_make_valid(catasto<-st_read(dsn=fgdb,layer=layer_da_girare[j], stringsAsFactors = F, is.numeric("Nomefile") )) a=count(catasto, Nomefile) if(nrow(a)==0){a=count(catasto$nomefile)} stati<-cbind(layer_da_girare[j],a) colnames(stati)=c("Feature","Nomefile","Freq") stati_tot<-rbind(stati_tot,stati) } }

Unfortunately I cannot put the structure of the "Catasto" file because it is precisely that which creates problems.

edzer commented 2 years ago

How then do you envisage someone can help you?

Ysuerte commented 2 years ago

You are right, Sorry. I was able to investigate the structure of the file

str(catasto) Classes ‘sf’ and 'data.frame': 475082 obs. of 20 variables: $ OBJECTID : int 1 2 3 4 5 6 7 8 9 10 ... $ Sez : chr "" "" "" "" ... $ Fg : chr "0001" "0001" "0001" "0001" ... $ Mappale : chr "1" "10" "100" "101" ... $ Denom : chr " " " " " " " " ... $ Allegato : chr "0" "0" "0" "0" ... $ Svi : chr "0" "0" "0" "0" ... $ Nomefile : chr "D547_000100" "D547_000100" "D547_000100" "D547_000100" ... $ Ext : chr " " " " " " " " ... $ Htxt : num 18 18 12 12 12 18 18 12 12 18 ... $ Rtxt : num 0 0 0 0 0 0 0 0 0 0 ... $ Xtxt : num 18.3 18.3 18.3 18.3 18.3 ... $ Ytxt : num 40.5 40.5 40.5 40.5 40.5 ... $ supcat : num 48189 34225 151 963 21 ... $ geom_Lengt : num 0.013181 0.049893 0.00105 0.001595 0.000328 ... $ geom_Area : num -5.14e-06 -3.65e-06 -1.61e-08 -1.03e-07 -2.27e-09 ... $ Codice_comune: chr "D547" "D547" "D547" "D547" ... $ Shape_Length : num 0.01317 0.049816 0.001049 0.001593 0.000327 ... $ Shape_Area : num 5.13e-06 3.64e-06 1.60e-08 1.02e-07 2.27e-09 ... $ Shape :sfc_MULTIPOLYGON of length 475082; first list element: List of 1 ..$ :List of 1 .. ..$ : num [1:46, 1:2] 16.4 16.4 16.4 16.4 16.4 ... ..- attr(*, "class")= chr "XY" "MULTIPOLYGON" "sfg"

edzer commented 2 years ago

This is not going anywhere and I'm closing here. Please return when you have figured out how to share a reproducible example.