[R-sig-Geo] Dimensions problem when extracting latitude and longitude from shapefiles in multipolygon format in lambert 93 format

Aymard Loïc KWEKEU KWEKEU kwekeu@ym@rd|o|c @end|ng |rom gm@||@com
Sat May 11 13:47:30 CEST 2024


I want to extract the latitude and longitude from the shapefile and by
doing this I get a table with more lines than my shapefile.
Below is the corresponding code:
Sincerely :
> library(sf)> geo <-  sf::st_read("IRIS.shp")

Reading layer `IRIS' from data source

  `C:\M2_MAS_True\Stage_EHESP\QGIS\Shapefiles\IRIS.shp' using driver `ESRI
Shapefile'

Simple feature collection with 752 features and 127 fields

Geometry type: MULTIPOLYGON

Dimension:     XY

Bounding box:  xmin: 796251.5 ymin: 6485414 xmax: 868032.2 ymax: 6579885

Projected CRS: RGF93 v1 / Lambert-93

> hos <- geo[!sf::st_is_empty(geo), ]

> santrau <-cbind(hos, st_coordinates(st_centroid(hos$geometry)))

> sontrau <- subset(santrau, select=c(1:40))

> sentrau <- na.omit(sontrau)

sentrau$geometry

Geometry set for 728 features

Geometry type: MULTIPOLYGON

Dimension:     XY

Bounding box:  xmin: 796251.5 ymin: 6485414 xmax: 868032.2 ymax: 6579885

Projected CRS: RGF93 v1 / Lambert-93

First 5 geometries:

MULTIPOLYGON (((843189.6 6521551, 843200.6 6521...

MULTIPOLYGON (((844086.2 6514697, 844097.4 6514...

MULTIPOLYGON (((836376.1 6508104, 836377.4 6508...

MULTIPOLYGON (((847197.7 6510818, 847203.6 6510...

MULTIPOLYGON (((850244.7 6517918, 850248 651792...

> sentrau_wgs84 <- st_transform(sentrau, "+proj=longlat +datum=WGS84")

> coordinates <- st_coordinates(sentrau_wgs84)

> nrow(sentrau)

[1] 728

> nrow(coordinates)

[1] 239649

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list