library(jsonlite)
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(sf)
## Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE
library(geojsonio)
## Registered S3 method overwritten by 'geojsonsf':
## method from
## print.geojson geojson
##
## Attaching package: 'geojsonio'
## The following object is masked from 'package:base':
##
## pretty
library(writexl)
# Baca file JSON
data_json = fromJSON("C:\\Users\\MUTHI'AH IFFA\\Downloads\\projek visdat\\Jabar_By_Kab.geojson")
# Baca file Excel (default: sheet pertama)
data_excel = read_excel("C:\\Users\\MUTHI'AH IFFA\\Downloads\\projek visdat\\SUSENAS2023.xlsx")
class(data_json)
## [1] "list"
class(data_excel)
## [1] "tbl_df" "tbl" "data.frame"
data_json = st_read("C:\\Users\\MUTHI'AH IFFA\\Downloads\\projek visdat\\Jabar_By_Kab.geojson")
## Reading layer `Jabar_By_Kab' from data source
## `C:\Users\MUTHI'AH IFFA\Downloads\projek visdat\Jabar_By_Kab.geojson'
## using driver `GeoJSON'
## Simple feature collection with 27 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 106.3705 ymin: -7.823398 xmax: 108.8338 ymax: -5.91377
## Geodetic CRS: WGS 84
df = as.data.frame(data_json)
View(df)
str(data_json)
## Classes 'sf' and 'data.frame': 27 obs. of 9 variables:
## $ OBJECTID : int 1 2 3 4 5 6 7 8 9 10 ...
## $ PROVINSI : chr "JAWA BARAT" "JAWA BARAT" "JAWA BARAT" "JAWA BARAT" ...
## $ PROVNO : chr "32" "32" "32" "32" ...
## $ KABKOTNO : chr "01" "02" "03" "04" ...
## $ KABKOT : chr "BOGOR" "SUKABUMI" "CIANJUR" "BANDUNG" ...
## $ ID_KAB : num 3201 3202 3203 3204 3205 ...
## $ Shape_Leng: num 4.45 4.05 4.89 3.09 3.48 ...
## $ Shape_Area: num 0.245 0.34 0.294 0.144 0.253 ...
## $ geometry :sfc_MULTIPOLYGON of length 27; first list element: List of 1
## ..$ :List of 3
## .. ..$ : num [1:10876, 1:2] 107 107 107 107 107 ...
## .. ..$ : num [1:4, 1:2] 107.13 107.13 107.13 107.13 -6.47 ...
## .. ..$ : num [1:3501, 1:2] 107 107 107 107 107 ...
## ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA
## ..- attr(*, "names")= chr [1:8] "OBJECTID" "PROVINSI" "PROVNO" "KABKOTNO" ...
df = df %>% mutate(KABKOTNO = as.numeric(KABKOTNO))
View(df)
data_merged = left_join(df, data_excel, by = "KABKOTNO")
## Warning in left_join(df, data_excel, by = "KABKOTNO"): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 1 of `x` matches multiple rows in `y`.
## ℹ Row 32859 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
View(data_merged)
st_write(data_merged, “C:\Users\MUTHI’AH IFFA\Downloads\Jabar_By_Kab_baru.geojson”)
data = st_read(“C:\Users\MUTHI’AH IFFA\Downloads\Jabar_By_Kab_baru.geojson”)
#konversi ke dalam .shp st_write(data, “C:\Users\MUTHI’AH IFFA\Downloads\Jabar_By_Kab_baru.geojson”)