Bounding Box of vector layer in R

Often we want to find the bounding box of our vector layer. How do we do that in R? We can use the extent function from the raster package, which returns us the boundary coordinates of the layer:

If we want to get a vector layer that contains the extent, we can use the rgeos library we already used. This library contains a tool called gEnvelope, which returns a bounding box of layer that we store in the variable bbox:

Let’s display the result of the function:

Let’s also add the layer from which we created the bounding box:

We have generated the bounding box of the railroad layer. And how do we generate the areas for each line segment in the railroad layer. Nothing difficult, just we add to our gEnvelope function the argument we already used byid:

Let’s display the result of our action:

Remember, you have to load the vector data first! We have used data from previous posts to show you the gEnvelope function.

Leave a Reply

Your email address will not be published.

Translate using Google Translate»
Social media & sharing icons powered by UltimatelySocial

Podoba Ci się nasza strona? Odwiedź nasz profil