You are on page 1of 3

/ / - - - - - - m emanggil SHP DAS

v a r A O I = ee.FeatureCollectio n ( p o l y g o n ) ;
M a p . c e n t erObject(polygon, 10 );
M a p . a d d L ayer(AOI,{}, 'DAS Bog o w o n t o ' ) ;

/ / - - - - - - - masking awan citra l a n d s a t 8


v a r m a s k L8 = function(image) {
v a r q a = image. select ( 'BQA' ) ;
v a r m a s k = qa.bitwiseAnd( 1 < < 4 ) . e q ( 0) ;
r e t u r n image.updateMask(mas k ) ;
} ;

/ / - - - - - - - memanggil data lands a t


v a r c o m p osite = ee.ImageColle c t i o n ( ' L A N D S A T / L C 0 8 / C 0 1 / T 1 _ T O A ' )
. filterDate( '2020 - 01- 0 1 ' , ' 2 0 2 0 - 1 2 - 3 1 ' ) / / P e r i o d e P e r e k a m a n
. map (maskL8)
.median() // reduksi d e n g a n M e d i a n
.clip(polygon);

/ / - - - - - - V isualisasi citra
v a r R G B T rue = composite. selec t ( [ ' B 4 ' , ' B 3 ' , ' B 2 ' ] ) ;
v a r R G B p aram = { min: 0, max: 0 . 3 , } ;
M a p . a d d L ayer(RGBTrue, RGBpara m , ' L a n d s a t 8 R G B 4 3 2 ' ) ;

/ / - - - - - - - -- Tampilan NDVI
v a r t r a i ning_bands = [ 'B2' , ' B 3 ' , ' B 4 ' , ' B 5 ' ] ;
v a r t r a i ning_mosaic = composi t e . s e l e c t ( t r a i n i n g _ b a n d s ) . c l i p ( p o l y g o n );
v a r i m a g e_ndvi = composite.no r m a l i z e d D i f f e r e n c e ( [ ' B 5 ' , ' B 4 ' ] ) ;
v a r v i s P arams_ndvi = {min: 0. 2 , m a x : 1 , p a l e t t e : [ ' r e d ' , ' y e l l o w ' ,
' g r e e n ' ] } ;
M a p . a d d L ayer(image_ndvi,visPa r a m s _ n d v i , ' V i s u a l i s a s i N D V I ' ) ;

/ / - - - - - - - --- Membuat Sampling a r e a u n t u k K l a s i f i k a s i


v a r a o i =
v e g e t a s i _kerapatan_rendah.mer g e ( v e g e t a s i _ k e r a p a t a n _ s e d a n g ) . m e r g e ( v eget
a s i _ k e r a patan_tinggi).me rge(l a h a n _ t e r b a n g u n ) . m e r g e ( l a h a n _ t e r b u k a ) . m erg
e ( t u b u h _ air).merge(tambak);
v a r b a n d s = [ 'B1' , 'B2' ,'B3' ,' B 4 ' , ' B 5 ' , ' B 6 ' , ' B 7 ' ] ;
v a r t r a i ning = composite. sele c t ( b a n d s ) . s a m p l e R e g i o n s ( {
c o l l e c t i on: aoi,
p r o p e r t i es: [ 'kelas' ],
s c a l e : 3 0
} ) ;

/ / - - - - - - - --- Pembagian Trainin g s a m p l i n g u n t u k k l a s i f i k a s i d a n u j i


a k u r a s i
v a r t r a i ningData = training.r a n d o m C o l u m n ( ) ;
v a r t r a i nSet = trainingData.f i l t e r ( e e . F i l t e r . l t ( ' r a n d o m ' , 0 . 8 ) ) ;
v a r t e s t Set = trainingData.fi l t e r ( e e . F i l t e r . g t e ( ' r a n d o m ' , 0 . 8 ) ) ;
/ / - - - - - - ---- Klasifikasi CART
v a r c l a s sifier = ee.Classifie r . s m i l e C a r t ( 1 0 ) . t r a i n ( {
f e a t u r e s : trainSet,
c l a s s P r o perty: 'kelas' ,
i n p u t P r o perties: bands
} ) ;
v a r c l a s sifier1 = ee.Classifi e r . s m i l e C a r t ( 1 0) . t r a i n ( {
f e a t u r e s : testSet,
c l a s s P r o perty: 'kelas' ,
i n p u t P r o perties: bands
} ) ;

v a r c l a s sified = composite. se l e c t ( b a n d s ) . c l a s s i f y ( c l a s s i f i e r ) ;
M a p . a d d L ayer(classified,
{ m i n : 0 , max: 6, palette:[
' # 0 0 f f 0 0' ,
' # 0 0 8 0 0 0' ,
' # 0 0 3 3 0 0' ,
' # f f 8 c 6 6' ,
' # f f f f 6 6' ,
' # 6 6 b 3 f f' ,
' # d 9 6 6 f f' ,
] } ,
' K l a s i f i kasi CART' );

/ / E x p o rt the image, specify i n g s c a l e a n d r e g i o n .


E x p o r t . i mage.toDrive({
i m a g e : classified,
d e s c r i p tion: 'Klasifikasi_C A R T ' ,
s c a l e : 30 ,
r e g i o n : polygon
} ) ;

v a r c l a s sifierRF = ee.Classif i e r . s m i l e R a n d o m F o r e s t ( 1 0 ) . t r a i n ( {
f e a t u r e s: trainSet,
c l a s s P r operty: 'kelas' ,
i n p u t P r operties: bands
} ) ;
/ / C l a s s ify the input imagery .
v a r c l a s sifiedRF = composite. s e l e c t ( b a n d s ) . c l a s s i f y ( c l a s s i f i e r R F ) ;
M a p . a d d L ayer(classifiedRF,
{ m i n : 0 , max: 6, palette:
[
' # 0 0 f f 0 0' ,
' # 0 0 8 0 0 0' ,
' # 0 0 3 3 0 0' ,
' # f f 8 c 6 6' ,
' # f f f f 6 6' ,
' # 6 6 b 3 f f' ,
' # d 9 6 6 f f' ,
] } ,
' K l a s i f i kasi Random Forest' );

/ / - - - - - - - ---- Klasifikasi SVM


v a r c l a s sifierSVM = ee.Classi f i e r . l i b s v m ( {
k e r n e l T ype: 'RBF' ,
g a m m a : 0.5 ,
c o s t : 1 0
} ) ;
v a r t r a i ned = classifierSVM.t r a i n ( t r a i n S e t , ' k e l a s ' , b a n d s ) ;
/ / - - - - - K lasifikasi menggunak a n i n p u t c i t r a
v a r c l a s sifiedSVM = composite . s e l e c t ( b a n d s ) . c l a s s i f y ( t r a i n e d ) ;
M a p . a d d L ayer(classifiedSVM,
{ m i n : 0 , max: 6, palette:
[
' # 0 0 f f 0 0' ,
' # 0 0 8 0 0 0' ,
' # 0 0 3 3 0 0' ,
' # f f 8 c 6 6' ,
' # f f f f 6 6' ,
' # 6 6 b 3 f f' ,
' # d 9 6 6 f f' ,
] } ,
' K l a s i f i kasi SVM' );

/ / G e t a confusion matrix rep r e s e n t i n g r e s u b s t i t u t i o n a c c u r a c y .


v a r t r a i nAccuracy = classifie r . c o n f u s i o n M a t r i x ( ) ;
p r i n t ( ' R e substitution error m a t r i x : ' , t r a i n A c c u r a c y ) ;
p r i n t ( ' T r aining overall accur a c y : ' , t r a i n A c c u r a c y . a c c u r a c y ( ) ) ;

/ / S a m p l e the input with a di f f e r e n t r a n d o m s e e d t o g e t v a l i d a t i o n


d a t a .
v a r v a l i dation = composite. se l e c t ( b a n d s ) . s a m p l e R e g i o n s ( {
c o l l e c t i on: aoi,
p r o p e r t i es: [ 'kelas' ],
s c a l e : 3 0
/ / F i l t e r the result to get r i d o f a n y n u l l p i x e l s .
} ) . f i l t e r(ee.Filter.neq( 'B2' , n u l l ) ) ;

/ / - - - - - - - ----- Validasi dari h a s i l k l a s i f i k a s i


v a r v a l i dated = validation.cl a s s i f y ( c l a s s i f i e r 1 ) ;

/ / - - - - - - - ----- Mendapatkan nil a i c o n f u s i o n m a t r i x y a n g


m e r e p r e s entasikan nilai akura s i
v a r t e s t Accuracy = validated. e r r o r M a t r i x ( ' k e l a s ' , ' c l a s s i f i c a t i o n ' );
p r i n t ( ' V a lidation error matri x : ' , t e s t A c c u r a c y ) ;
p r i n t ( ' V a lidation overall acc u r a c y : ' , t e s t A c c u r a c y . a c c u r a c y ( ) ) ;

You might also like