JuliaGeo / Shapefile.jl

Parsing .shp files in Julia
http://juliageo.org/Shapefile.jl/
MIT License
82 stars 14 forks source link

subset shp while preserve proj #116

Open kongdd opened 1 week ago

kongdd commented 1 week ago
using Shapefile
import Shapefile: getshp, getdbf
using DataFrames

f = "./test/shapelib_testcases/test.shp"
t = Shapefile.Table(f)
d = DataFrame(t) 

inds = ismissing(d.TestInt)
d2 = d[inds, :] # use DataFrame, proj will be dropped

Shapefile.write(d2, "a.shp")

Any method to subset shp directly via Shapefile?

rafaqz commented 1 week ago

You can use the crs keyword to write

(we do want to retain the crs in DataAPI metadata as a general GeoInterface pattern, but no one has implemented it yet)