Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot one polygon from a spatial polygon data frame

I'm a bit new to R and so this mights seem an easy command for you. I have a shapefile loaded in R with several polygons in it, and I just would like to plot the first polygon. I tried several commands but it's not working.

My aim is to crop a raster with that first element of my shapefile, again I tried several stuff but it's not working..

I hope I'm clear,

Thanks a lot!

Jude

like image 547
Jude Avatar asked Mar 22 '26 08:03

Jude


1 Answers

Assuming your polygons are called pols, this should work for you:

plot(pols[1,])

A spatial polygon dataframe is just like any other df in this case, with each row corresponding to a feature. So if you want to subset it, you can use ordinary indexing.

like image 125
Val Avatar answered Mar 24 '26 21:03

Val



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!