pacman::p_load(sf,dplyr, writexl)

1 Load Data

peta <- sf::st_read("D:\\2. Pengembangan diri\\1 Exercise Bagus\\0 Peta 514 Kako Indonesia OK\\Peta_SHP_514_38Prov\\PetaSHP514_38.shp")
## Reading layer `PetaSHP514_38' from data source 
##   `D:\2. Pengembangan diri\1 Exercise Bagus\0 Peta 514 Kako Indonesia OK\Peta_SHP_514_38Prov\PetaSHP514_38.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 514 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 95.00971 ymin: -11.00766 xmax: 141.02 ymax: 6.076809
## Geodetic CRS:  WGS 84
peta <- st_make_valid(peta)

2 Proyeksi WGS84

Proyeksikan ke WGS84

petaku <- st_transform(peta, crs = 4326)

3 Centroid

Menghitung centroid dan ambil koordinat longitude-latitude.

petaku_coords <- petaku %>%
  mutate(centroid = st_centroid(geometry)) %>%
  mutate(
    lon = st_coordinates(centroid)[, 1],
    lat = st_coordinates(centroid)[, 2]
  )
names(petaku_coords)
##  [1] "fid"      "idkab"    "nmprov"   "nmkab"    "kdprov"   "kdkab"   
##  [7] "sumber"   "periode"  "geometry" "centroid" "lon"      "lat"

4 Hasil

kako_coords_selected <- petaku_coords %>%
  select(id_kab = idkab, nama_kab = nmkab, lon, lat)

Tampilkan hasil

print(kako_coords_selected)
## Simple feature collection with 514 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 95.00971 ymin: -11.00766 xmax: 141.02 ymax: 6.076809
## Geodetic CRS:  WGS 84
## First 10 features:
##    id_kab      nama_kab      lon      lat                       geometry
## 1    1101      SIMEULUE 96.08572 2.613151 MULTIPOLYGON (((95.39075 2....
## 2    1102  ACEH SINGKIL 97.84660 2.348875 MULTIPOLYGON (((97.11587 2....
## 3    1103  ACEH SELATAN 97.43585 3.163234 MULTIPOLYGON (((96.94417 3....
## 4    1104 ACEH TENGGARA 97.69782 3.369073 MULTIPOLYGON (((97.46732 3....
## 5    1105    ACEH TIMUR 97.62814 4.629063 MULTIPOLYGON (((97.61252 4....
## 6    1106   ACEH TENGAH 96.87749 4.518671 MULTIPOLYGON (((96.42585 4....
## 7    1107    ACEH BARAT 96.18391 4.455933 MULTIPOLYGON (((95.88214 4....
## 8    1108    ACEH BESAR 95.51464 5.380229 MULTIPOLYGON (((95.0114 5.7...
## 9    1109         PIDIE 96.02880 5.055939 MULTIPOLYGON (((95.77852 5....
## 10   1110       BIREUEN 96.60667 5.093437 MULTIPOLYGON (((96.32544 4....

5 Export Hasil

Simpan ke Excel

write_xlsx(kako_coords_selected, "Koordinat_Centroid_Kako.xlsx")

Direktorat Statistik Kesejahteraan Rakyat, BPS,