R/GIS: How to subset a shapefile by a lat-long bounding box?

后端 未结 3 1700
广开言路
广开言路 2020-12-17 00:10

I want to subset out a shapefile (the .shp and associated files are here) into another one bounded by a set of coordinates, say between longs [80,90] and lats [20,30], and t

3条回答
  •  有刺的猬
    2020-12-17 00:29

    I know this has been answered, but I think you can do exactly what you want using PBSmapping. PBSmapping has a function to clip Polysets (for polygon and lines data) so you can try:

    df <- importShapefile("/path/asia_rivers.shp")
    df_sub <- clipLines(df, xlim = c(80 , 90) , ylim = c(20 , 30), keepExtra = TRUE )
    dfSL <- PolySet2SpatialLines( df_sub )
    

    The keep extra allows you to keep non-standard columns when you do the clipping (I assume for attribute data).

提交回复
热议问题