Home assignment 5
Contents
Home assignment 5#
Last updated: 2023-02-25 13:41:32
Question 1#
Import the following layers:
data/statisticalareas_demography2019.gdb
—Statistical areas
output/sentinel2.tif
—Sentinel-2 satellite imageRescale the raster values to the 0-1 range (see Rescaling) and calculate NDVI (see Calculating indices)
Calculate the average NDVI per statistical area in Beer-Sheva (
'SHEM_YISHUV'
column =='באר שבע'
), using zonal statistics (see Zonal statistics).Plot the layer of average NDVI in statistical areas of Beer-Sheva. Use the
"Greens"
color map.Note: Do not re-create
sentinel2.tif
in your code. Instead, import it fromoutput/sentinel2.tif
.
Question 2#
Import the following layers:
data/muni_il.shp
—Israel towns
output/sentinel2.tif
—Sentinel-2 satellite imageAggregate the towns layer according to the
'Muni_Heb'
column to dissolve the separate polygons per town (see Aggregation (.dissolve)).Calculate an attribute named
prop
with the proportion of each towns’ polygon area that is within the extent of thesentinel2.tif
image (Stacking raster bands). For example, Beer-Sheva is 100% within the image (prop=1.0
), Meitar is ~60% within the image (prop=0.6
), etc. Hint: calculate the area of the original polygons, then calculate the area of the intersections (see Set-operations (.overlay)) with image extent polygon (see Raster extent), and finally divide the intersection area by the total area.Print the subset of towns layer where the proportion intersecting with the image extent is above
0
, sorted by the proportion.Note: Do not re-create
sentinel2.tif
in your code. Instead, import it fromoutput/sentinel2.tif
.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/tmp/ipykernel_13193/3713045795.py in <module>
12 bbox = bbox.to_crs(towns.crs)
13 # Overlay
---> 14 towns1 = towns.overlay(bbox, how='intersection')
15 # Calculate proportion of overlap
16 towns['area'] = towns.area
~/.local/lib/python3.10/site-packages/geopandas/geodataframe.py in overlay(self, right, how, keep_geom_type, make_valid)
2350 dimension is not taken into account.
2351 """
-> 2352 return geopandas.overlay(
2353 self, right, how=how, keep_geom_type=keep_geom_type, make_valid=make_valid
2354 )
~/.local/lib/python3.10/site-packages/geopandas/tools/overlay.py in overlay(df1, df2, how, keep_geom_type, make_valid)
315 result = _overlay_difference(df1, df2)
316 elif how == "intersection":
--> 317 result = _overlay_intersection(df1, df2)
318 elif how == "symmetric_difference":
319 result = _overlay_symmetric_diff(df1, df2)
~/.local/lib/python3.10/site-packages/geopandas/tools/overlay.py in _overlay_intersection(df1, df2)
28 """
29 # Spatial Index to create intersections
---> 30 idx1, idx2 = df2.sindex.query_bulk(df1.geometry, predicate="intersects", sort=True)
31 # Create pairs of geometries in both dataframes to be intersected
32 if idx1.size > 0 and idx2.size > 0:
~/.local/lib/python3.10/site-packages/geopandas/base.py in sindex(self)
2704 [2]])
2705 """
-> 2706 return self.geometry.values.sindex
2707
2708 @property
~/.local/lib/python3.10/site-packages/geopandas/array.py in sindex(self)
289 def sindex(self):
290 if self._sindex is None:
--> 291 self._sindex = _get_sindex_class()(self.data)
292 return self._sindex
293
~/.local/lib/python3.10/site-packages/geopandas/sindex.py in _get_sindex_class()
19 if compat.HAS_RTREE:
20 return RTreeIndex
---> 21 raise ImportError(
22 "Spatial indexes require either `rtree` or `pygeos`. "
23 "See installation instructions at https://geopandas.org/install.html"
ImportError: Spatial indexes require either `rtree` or `pygeos`. See installation instructions at https://geopandas.org/install.html