Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Smart_Agro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
28
Issues
28
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-23-236
Smart_Agro
Commits
93e23f12
Commit
93e23f12
authored
May 26, 2023
by
Arachchige P.D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
land cover classification for gis mapping --> Google Earth Engine Code Editor JS API
parent
735c67a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
src/landcover_classification.js
src/landcover_classification.js
+86
-0
No files found.
src/landcover_classification.js
0 → 100644
View file @
93e23f12
var
image
=
L8
.
filterBounds
(
roi
).
filterMetadata
(
'
CLOUD_COVER
'
,
'
less_than
'
,
3
).
filterDate
(
'
2017-01-01
'
,
'
2022-12-31
'
).
map
(
addNDVI
).
median
().
clip
(
roi
);
//var image2 = L7.filterBounds(roi_2).filterMetadata('CLOUD_COVER','less_than',1).filterDate('2019-01-01','2022-12-31')
//var image_3 = S2.filterBounds(roi_2).filterMetadata('CLOUD_COVER','less_than',1).filterDate('2020-01-01','2022-12-31');
//print(image);
Map
.
addLayer
(
image
,
imageVisParam
,
'
True Color Composite
'
);
Map
.
centerObject
(
roi
,
11.5
);
// Collect training samples
// Merge training Samples
var
training
=
Urban
.
merge
(
Forest
).
merge
(
BareLand
).
merge
(
Water
).
merge
(
Agriculture
);
print
(
training
);
var
label
=
'
Class
'
;
//when using external bands
function
addNDVI
(
image
){
var
ndvi
=
image
.
normalizedDifference
([
'
B5
'
,
'
B4
'
]).
rename
(
'
NDVI
'
);
return
image
.
addBands
(
ndvi
);
}
var
bands
=
[
'
B1
'
,
'
B2
'
,
'
B3
'
,
'
B4
'
,
'
B5
'
,
'
B6
'
,
'
B7
'
,
'
NDVI
'
];
var
input
=
image
.
select
(
bands
);
// overlay the points on images to get training
var
train_image
=
input
.
sampleRegions
({
collection
:
training
,
properties
:[
label
],
scale
:
30
});
var
train_data
=
train_image
.
randomColumn
();
var
train_set
=
train_data
.
filter
(
ee
.
Filter
.
lessThan
(
'
random
'
,
0.8
));
var
test_set
=
train_data
.
filter
(
ee
.
Filter
.
greaterThanOrEquals
(
'
random
'
,
0.2
));
// Classification model
var
classifier
=
ee
.
Classifier
.
smileCart
().
train
(
train_set
,
label
,
bands
);
// Classify the image
var
classified
=
input
.
classify
(
classifier
);
// Define a color palette
var
colorPalette
=
[
'
FF3C33
'
,
'
006837
'
,
'
969696
'
,
'
253494
'
,
'
FF8000
'
];
Map
.
addLayer
(
classified
.
clip
(
roi
),
{
palette
:
colorPalette
,
min
:
0
,
max
:
5
},
'
CART Classification
'
);
var
train_accuracy
=
classifier
.
confusionMatrix
();
print
(
train_accuracy
);
// Get information about the trained classifier.
print
(
'
Results of trained classifier
'
,
classifier
.
explain
());
// Get a confusion matrix and overall accuracy for the training sample.
var
train_accuracy
=
classifier
.
confusionMatrix
();
print
(
'
Training error matrix
'
,
train_accuracy
);
print
(
'
Training overall accuracy
'
,
train_accuracy
.
accuracy
());
var
uniqueValues
=
classified
.
reduceRegion
({
reducer
:
ee
.
Reducer
.
frequencyHistogram
(),
geometry
:
roi
,
scale
:
30
});
print
(
'
Unique values:
'
,
uniqueValues
.
get
(
'
classification
'
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment