0

I am using Python to work with Google Earth Engine. I would like to extract some data for Paris.

I got the shapefile of Paris and I extracted its boundary as shown below:

import ee
ee.Initialize()
import geopandas as gpd
from shapely.geometry import Polygon
import pylab as plt

gdf = gpd.read_file('drive/MyDrive/Colab Notebooks/shapefiles/France/COMMUNE-shp/')     ## Paris metro area
gdf = gdf.to_crs(epsg=4326)

def returnCityBoundary(gdf):
  ## from shapefile it returns city boundary as a rectangle in different format
  #### polygon_geom: shapely polygon
  #### polygon: geopandas dataframe
  #### geometry: Earth Engine polygon
  bounds = gdf.total_bounds
  lon_point_list = [bounds[0], bounds[0], bounds[2], bounds[2]]
  lat_point_list = [bounds[1], bounds[3], bounds[3], bounds[1]]
  polygon_geom = Polygon(zip(lon_point_list, lat_point_list))
  crs = {'init': 'epsg:4326'}
  polygon = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[polygon_geom]) 
  geometry = ee.Geometry.Polygon(
          [[[bounds[0], bounds[1]],
            [bounds[0], bounds[3]],
            [bounds[2], bounds[3]],
            [bounds[2], bounds[1]]]])
  return polygon_geom, polygon, geometry

polygon, gdf_polygon, geometry = returnCityBoundary(gdf)
fig, ax = plt.subplots()
gdf_polygon.boundary.plot(ax=ax, color='red')
gdf.boundary.plot(ax=ax)

enter image description here

Now I would like to extract some images in this boundary. This is what I am doing but it does not work.

cover = ee.ImageCollection('MODIS/006/MOD11A2').filter(ee.Filter.date('2018-01-01', '2018-05-01'))\
  .select('LST_Day_1km')\
  .filterBounds(geometry)
4
  • what do these multiple small polygons represent? Commented Jan 12, 2021 at 13:22
  • @YogeshChavan this is the shapefile of Paris metropolitan area. I use it to get the bounding box around it (the red rectangle).
    – emax
    Commented Jan 12, 2021 at 13:47
  • can you elaborate, what does not work ? do you get an error ? Commented Jan 12, 2021 at 13:51
  • @PierrickRambaud I do not get an error but I get the data for the entire world
    – emax
    Commented Jan 12, 2021 at 14:32

1 Answer 1

1

According to the comments, the output you are getting is expected. MODIS images on the Google Earth Engine do not come in granules, therefore, your image collection will contain single images of the entire world regardless of filtering by location using .filterBounds. Rather, you will have to .clip each image to geometry to get your desired output:

cover_clipped = cover.map(lambda image : image.clip(geometry))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.