Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Ekstraksi-nilai-raster-di-gee-python-menjadi-GPKG-dan-CSV

Notebook ini mengekstrak nilai band spektral dan indeks vegetasi/lahan dari citra Sentinel-2 pada titik-titik sampel lapangan menggunakan Google Earth Engine (GEE) di lingkungan Google Colab.

Repositori di GitHub

Notebook ini mengekstrak nilai band spektral dan indeks vegetasi/lahan dari citra Sentinel-2 pada titik-titik sampel lapangan menggunakan Google Earth Engine (GEE) di lingkungan Google Colab.

Open In Colab

Deskripsi

Pipeline ini membaca shapefile titik sampel lapangan, membangun composite citra Sentinel-2 SR tahunan (2024), menghitung empat indeks spektral, lalu mengekstrak nilai piksel di setiap titik sampel. Hasil akhir disimpan sebagai CSV dan GeoPackage (.gpkg) di Google Drive.


Alur Kerja

Shapefile Sampel (.shp)
        |
        v
  Google Earth Engine
  FeatureCollection
        |
        v
  Sentinel-2 SR Composite
  (2024, cloud-masked)
        |
        v
  Hitung Indeks Spektral
  NDVI | NDWI | NDMI | NDBI
        |
        v
  sampleRegions() -> DataFrame
        |
        v
  Gabung koordinat (lon/lat)
        |
        v
  Export -> CSV & GPKG

Indeks Spektral

NDVI — Normalized Difference Vegetation Index

Mengukur kerapatan dan kehijauan vegetasi berdasarkan perbedaan reflektansi NIR dan merah (Rouse et al., 1974).

NDVI = (NIR - Red) / (NIR + Red)
     = (B8 - B4) / (B8 + B4)

Rentang nilai: -1 hingga +1. Nilai tinggi (> 0.5) mengindikasikan vegetasi lebat.


NDWI — Normalized Difference Water Index

Mengidentifikasi badan air terbuka dan mengukur kandungan air permukaan (McFeeters, 1996).

NDWI = (Green - NIR) / (Green + NIR)
     = (B3 - B8) / (B3 + B8)

Rentang nilai: -1 hingga +1. Nilai positif (> 0) mengindikasikan keberadaan air.

McFeeters, S. K. (1996). The use of the Normalized Difference Water Index (NDWI) in the delineation of open water features. International Journal of Remote Sensing, 17(7), 1425–1432. McFEETERS (1996)


NDMI — Normalized Difference Moisture Index

Mengukur kelembaban kandungan air pada vegetasi menggunakan band NIR dan SWIR (Gao, 1996).

NDMI = (NIR - SWIR1) / (NIR + SWIR1)
     = (B8 - B11) / (B8 + B11)

Rentang nilai: -1 hingga +1. Nilai tinggi mengindikasikan vegetasi dengan kandungan air tinggi.

Gao, B.-C. (1996). NDWI — A normalized difference water index for remote sensing of vegetation liquid water from space. Remote Sensing of Environment, 58(3), 257–266. Gao (1996)


NDBI — Normalized Difference Built-up Index

Mengidentifikasi dan memetakan kawasan lahan terbangun/impervious menggunakan band SWIR dan NIR (Zha et al., 2003).

NDBI = (SWIR1 - NIR) / (SWIR1 + NIR)
     = (B11 - B8) / (B11 + B8)

Rentang nilai: -1 hingga +1. Nilai positif mengindikasikan dominasi lahan terbangun.

Zha, Y., Gao, J., & Ni, S. (2003). Use of normalized difference built-up index in automatically mapping urban areas from TM imagery. International Journal of Remote Sensing, 24(3), 583–594. Zha et al. (2003)


Data Citra

ParameterNilai
KoleksiCOPERNICUS/S2_SR_HARMONIZED
Periode1 Januari – 31 Desember 2024
Filter cloudCLOUDY_PIXEL_PERCENTAGE < 20
Cloud maskingCloud Score+ (cs_cdf >= 0.60)
KompositMedian, dinormalisasi ke 0–1 (dibagi 10.000)
Skala sampling10 meter

Struktur Output

KolomKeterangan
rand_pointID titik sampel acak
idID tambahan dari atribut shapefile
lon, latKoordinat geografis (EPSG:4326)
B2, B3, B4Band Blue, Green, Red
B8Band NIR (842 nm)
B11, B12Band SWIR1 (1610 nm), SWIR2 (2190 nm)
NDVINormalized Difference Vegetation Index
NDWINormalized Difference Water Index
NDMINormalized Difference Moisture Index
NDBINormalized Difference Built-up Index

File output:

MyDrive/
├── sampel_indeks.csv    <- tabel hasil sampling
└── sampel_indeks.gpkg   <- geodata untuk QGIS/ArcGIS

Cara Penggunaan

1. Prasyarat

2. Instalasi dependensi

!pip install geemap geopandas

3. Siapkan file input

Letakkan shapefile titik sampel di Google Drive:

MyDrive/sampel_lapangan.shp  (beserta .dbf, .prj, .shx)

Sesuaikan project ID GEE di cell autentikasi:

ee.Initialize(project='ee-<your-project-id>')

4. Jalankan semua cell secara berurutan

CellFungsi
InstallInstall geemap dan geopandas
ImportLoad semua library
Mount Drive & AuthKoneksi Google Drive + autentikasi GEE
Load ShapefileBaca titik sampel, konversi ke EPSG:4326
Convert ke EEUbah GeoDataFrame ke EE FeatureCollection
AOI + S2 CompositeBuat composite Sentinel-2 dengan cloud masking
Hitung IndeksKalkulasi NDVI, NDWI, NDMI, NDBI
SamplingEkstrak nilai piksel di titik sampel
Tambah KoordinatGabung lon/lat dari GeoDataFrame asal
ExportSimpan CSV & GPKG ke Google Drive

Dependensi

LibrarySitasi
geemapWu, Q. (2020). geemap: A Python package for interactive mapping with Google Earth Engine. Journal of Open Source Software, 5(51), 2305. Wu (2020)
geopandasJordahl, K., Van den Bossche, J., Fleischmann, M., et al. (2020). geopandas/geopandas: v0.8.1. Zenodo. Jordahl et al. (2020)
pandasThe Pandas Development Team. (2020). pandas-dev/pandas: Pandas. Zenodo. The pandas development team (2026)
numpyHarris, C. R., et al. (2020). Array programming with NumPy. Nature, 585, 357–362. Harris et al. (2020)
matplotlibHunter, J. D. (2007). Matplotlib: A 2D Graphics Environment. Computing in Science & Engineering, 9(3), 90–95. Hunter (2007)

Referensi

Notebook

Notebook dari repositori ini, tampil lengkap dengan sel kode dan hasilnya:

References
  1. McFEETERS, S. K. (1996). The use of the Normalized Difference Water Index (NDWI) in the delineation of open water features. International Journal of Remote Sensing, 17(7), 1425–1432. 10.1080/01431169608948714
  2. Gao, B. (1996). NDWI—A normalized difference water index for remote sensing of vegetation liquid water from space. Remote Sensing of Environment, 58(3), 257–266. 10.1016/s0034-4257(96)00067-3
  3. Zha, Y., Gao, J., & Ni, S. (2003). Use of normalized difference built-up index in automatically mapping urban areas from TM imagery. International Journal of Remote Sensing, 24(3), 583–594. 10.1080/01431160304987
  4. Wu, Q. (2020). geemap: A Python package for interactive mapping with Google Earth Engine. Journal of Open Source Software, 5(51), 2305. 10.21105/joss.02305
  5. Jordahl, K., Bossche, J. V. D., Fleischmann, M., Wasserman, J., McBride, J., Gerard, J., Tratner, J., Perry, M., Badaracco, A. G., Farmer, C., Hjelle, G. A., Snow, A. D., Cochran, M., Gillies, S., Culbertson, L., Bartos, M., Eubank, N., Maxalbert, Bilogur, A., … Leblanc, F. (2020). geopandas/geopandas: v0.8.1. Zenodo. 10.5281/ZENODO.3946761
  6. The pandas development team. (2026). pandas-dev/pandas: Pandas (v3.1.1) [Computer software]. Zenodo. 10.5281/ZENODO.3509134
  7. Harris, C. R., Millman, K. J., van der Walt, S. J., Gommers, R., Virtanen, P., Cournapeau, D., Wieser, E., Taylor, J., Berg, S., Smith, N. J., Kern, R., Picus, M., Hoyer, S., van Kerkwijk, M. H., Brett, M., Haldane, A., del Río, J. F., Wiebe, M., Peterson, P., … Oliphant, T. E. (2020). Array programming with NumPy. Nature, 585(7825), 357–362. 10.1038/s41586-020-2649-2
  8. Hunter, J. D. (2007). Matplotlib: A 2D Graphics Environment. Computing in Science & Engineering, 9(3), 90–95. 10.1109/mcse.2007.55