2

I have a bunch of polygons which I loaded from a shapefile into a fields GeoDataFrame:

   geometry                                           raster_val
0  POLYGON ((8.56799 47.80800, 8.56799 47.77200, ...         1.0
1  POLYGON ((6.73199 47.12400, 6.73199 47.08800, ...         1.0

I plot them using:

fields.plot(color='white', edgecolor='black')
matplotlib.pyplot.show()

I also have a raster layer (ndvi_layer) which is basically a numpy array which I plot using:

fig, ax = matplotlib.pyplot.subplots(figsize=(10, 10))
rasterio.plot.show(ndvi_layer, ax=ax, cmap='RdYlGn')
matplotlib.pyplot.show()

Is there any way to plot the polygons on top of the raster? What if the polygons don't have the same CRS as the raster?

  • 2
    I think, this solve your requirements. gis.stackexchange.com/questions/294072/… – Jhon Galindo Dec 5 '19 at 18:20
  • You're right! Initially, it didn't work because of the difference in CRS of raster and polygons. Once I adjusted CRS of the GeoDataFrame using .to_crs() it all works now! – ksnn Dec 10 '19 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.