Replies: 2 comments 1 reply
-
Something like this will work... training_data = image.sampleRegions(collection=training_points,properties=["Property"],scale=30) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I also encountered this problem, and finally solved it after checking and trying. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Please am trying to playing around with the random forest algorithm which was successful in the code editor, now I try to convert the codes to python and run in colab and having this error which I don't seem to understand.
below is a snapshot of the error and the my script
`
import ee
ee.Initialize()
geometry = ee.Geometry.Polygon([[-2.5130642919845525,9.530810667281315],
[-2.0406521826095525,9.530810667281315],
[-2.0406521826095525,9.958508332761049],
[-2.5130642919845525,9.958508332761049],
[-2.5130642919845525,9.530810667281315]])
# geometry=ee.Feature(ee.Geometry.Rectangle(-2.5130642919845525,9.530810667281315, -2.5130642919845525,9.958508332761049))
# /Loading Sentinel 2 data and filtering by date and bounds
Sentinel2Collection=ee.ImageCollection("COPERNICUS/S2_SR")
.filterDate('2019-01-01','2019-01-28')
.filterBounds(geometry)
.sort('CLOUD_COVER', True)
feat = [
ee.Feature(ee.Geometry.Point(-2.336156720273055,9.617736781866462), {'landcover': 0}),
ee.Feature(ee.Geometry.Point(-2.336156720273055,9.627736781866462), {'landcover': 1}),
ee.Feature(ee.Geometry.Point(-2.4336156720273055,9.627736781866462), {'landcover': 2})
];
Create a FeatureCollection from the list and print it.
forest = ee.FeatureCollection(forest)
urban = ee.FeatureCollection(urban)
vegetation = ee.FeatureCollection(vegetation)
print(fromList)
Filter the collection by the IMAGE_QUALITY property.
filtered = Sentinel2Collection
.filterMetadata('IMAGE_QUALITY', 'equals', 9)
Sentinel_med = Sentinel2Collection.median()
Sentinel_crop = Sentinel_med.clip(geometry)
bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7','B8','B8A']
training = Sentinel_crop.select(bands).sampleRegions({
'collection': feat,
'properties':['landcover'],
'scale': 20
})
print(training, 'training')
Making a Random Forest classifier and training it.
classifier= ee.Classifier.smileRandomForest(4).train({
'features': training,
'classProperty': 'landcover',
'inputProperties': bands
})
print(classifier)
#Classifying the input imagery
classification= Sentinel_crop.select(bands).classify(classifier)
Define a palette for the Land Use classification.
palette = [
'cyan', # forest (0) # red
'red', # urban (1) # green
'green' # agriculture (2) # blue
]
print(classification)`
.
Beta Was this translation helpful? Give feedback.
All reactions