Skip to contents

Save spatial data.frame as shapefile.zip

Usage

shape2zip(shp, file = "shapefile.zip")

Arguments

shp

a spatial data.frame as from shapefile_from_any() or sf::st_read()

file

full path to and name of the .zip file to create

Value

normalized path of the cleaned up file param (path and name of .zip)

Examples

# shp <- shapes_from_fips(fips = name2fips(c('tucson,az', 'tempe, AZ')))
shp <- testshapes_2
# \donttest{
fname <- file.path(tempdir(), "myfile.zip")
fpath <- shape2zip(shp = shp, file = fname)
#> Writing layer `myfile' to data source 
#>   `/tmp/RtmpuU15oN/myfile.shp' using driver `ESRI Shapefile'
#> Writing 2 features with 16 fields and geometry type Multi Polygon.
#> saved /tmp/RtmpuU15oN/myfile.zip 
file.exists(fpath)
#> [1] TRUE
zip::zip_list(fpath)
#> # A data frame: 4 × 8
#>   filename   compressed_size uncompressed_size timestamp           permissions
#>   <chr>                <dbl>             <dbl> <dttm>              <octmode>  
#> 1 myfile.shp            5416              7492 2025-05-23 20:36:46 644        
#> 2 myfile.dbf             321              2884 2025-05-23 20:36:46 644        
#> 3 myfile.prj             135               167 2025-05-23 20:36:46 644        
#> 4 myfile.shx              65               116 2025-05-23 20:36:46 644        
#> # ℹ 3 more variables: crc32 <hexmode>, offset <dbl>, type <chr>
# read it back in
shp2 <- shapefile_from_any(fpath)
#> /tmp/RtmpuU15oN/myfile.zip appears to be .zip containing files 
#> Reading layer `myfile' from data source `/tmp/RtmpuU15oN/tempsubdir/myfile.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 2 features and 16 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -75.57634 ymin: 39.01019 xmax: -75.48002 ymax: 39.04598
#> Geodetic CRS:  NAD83
# }