Feature request: clip vector layers using OGR
ljvmiranda921 opened this issue · 4 comments
ljvmiranda921 commented
Hello everyone,
I'm planning to clip a vector layer using a raster extent using this library. However, I noticed in this line that it is currently unimplemented.
This is my original command when using ogr2ogr
$ ogr2ogr out.shp in.shp -clipsrc <extent>
I would like to ask:
- When will the OGR Clip feature be implemented?
- Is it possible to achieve the task above with the current feature set?
Thank you very much @lukeroth and I appreciate your effort for this library!
magtanggol03 commented
Hi, were you able to solve this problem?
ljvmiranda921 commented
Hi @magtanggol03 , 😆
I solved it by using the SetSpatialFilter
method!
var shpFile gdal.Layer
var extent gdal.Geometry
shpFile.SetSpatialFilter(extent)
shpFile.ResetReading()
outDriver := gdal.OGRDriverByName("GeoJSON")
outDataSource, _ := outDriver.Create(outpath, []string{})
outDataSource.CopyLayer(shpFile, "Labels", []string{})
outDataSource.Destroy()
It does not necessarily cut the shapes, but is workable for my use-case. 😄
ardieorden commented
Thanks for the solution @ljvmiranda921 ! This helped a lot with my use case.
ljvmiranda921 commented
Closing this issue because resolved