lukeroth/gdal

Feature request: clip vector layers using OGR

ljvmiranda921 opened this issue · 4 comments

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:

  1. When will the OGR Clip feature be implemented?
  2. 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!

Hi, were you able to solve this problem?

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. 😄

Reference implementation

Thanks for the solution @ljvmiranda921 ! This helped a lot with my use case.

Closing this issue because resolved