0

I have just started working with GEE in the python environment, so I'm still learning. What I want to do is create a shapefile, outline a specific area, assess which areas are water, mudflats or saltmarshes through the use of NDVI and NDWI.

What I have so far is this:

AOI = "Area"
shp = "/content/drive/MyDrive/shapefile.shp"
roi = emap.shp_to_ee(shp) 

Map = emap.Map()
Map.addLayer(roi, {}, AOI)
Map.centerObject(roi, 10)
Map.addLayerControl()
Map

LT05col = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')

collection = LT05col \
    .filterBounds(roi) \
    .filterDate('1990-01-01', '2011-12-31') \
    .filter('IMAGE_QUALITY >= 7 || IMAGE_QUALITY_OLI >= 7') \
    .filter('CLOUD_COVER < 70') \
    .map(lambda image: image.clip(roi)) \
    .limit(3)

ndwi_threshold = 0
ndvi_threshold = 0.30

Map = emap.Map()
Map.add_basemap('SATELLITE')

def cloudmask(image):
  mask_l5SR_cloud = cloud_mask.landsatSR(['cloud'])
  return mask_l5SR_cloud(image)

# a function for calculating NDVI for Landsat 8 imagery
def calNDVI(image):
    return image.normalizedDifference(['B5', 'B4'])

def calNDWI(image):
    ndwi_image = image.normalizedDifference(['B3', 'B5'])
    #water_image = ndwi_image.gt(ndwi_threshold).selfMask()
    return ndwi_image

vizParams = {
    'bands': ['B5', 'B4', 'B3'],
    'min': 0, 
    'max': 5000
}

cloud_free_images = collection.map(cloudmask)
ndvi_images = cloud_free_images.map(calNDVI)
ndwi_images = cloud_free_images.map(calNDWI)
collection_size = ndvi_images.size().getInfo()
print('Collection size: ', collection_size)

ndwi_min = ndwi_images.reduce(ee.Reducer.min());
water_image = ndwi_min.gt(ndwi_threshold).selfMask()
Map.addLayer(water_image, {'palette': ['lightblue']}, 'Water')

mf_image = ndwi_min.lt(ndwi_threshold).selfMask()
Map.addLayer(mf_image, {'palette': ['sandybrown']}, 'Mud flat')

ndvi_min = ndvi_images.reduce(ee.Reducer.median());
sm_image = ndvi_min.gt(ndvi_threshold).selfMask()
Map.addLayer(sm_image, {'palette': ['darkgreen']}, 'Salt Marsh')

Map.addLayer(roi, {}, AOI)
Map.centerObject(roi, 11)
Map.addLayerControl()
Map

So far so good. However, what I would like to do further, is only extract the map layer 'water' as a new shapefile. I have no clue on how to do this. What I have done so far is to just try and export it as shape file, with the water image as the region, however that doesn't work.:

task_config = {  
     'region': water_image,
     'folder':'Folder_name'
 }
task = ee.batch.Export.image.toDrive(collection, 'Export_test', **task_config)
task.start()
task.status()

Task.status() gives me the error message: "GeometryConstructors.LineString, argument 'coordinates': Invalid type.\nExpected type: List.\nActual type: Image<[nd_min]>."

So my question is, how do I convert a map layer into a seperate shapefile and / or how do I convert my water_image into a file which contains coordinates.

Sorry for the very long question, I'm just struggling with this.

1 Answers1

1

Not all variables are defined so I can't fully reproduce your script, but reduceToVectors should do the trick:

vectorBounds = water_image.reduceToVectors(maxPixels = 1E9, geometry = roi)

task = ee.batch.Export.image.toDrive(collection)
task.start()
hooge048
  • 224
  • 1
  • 4