class NSWTopo::Shapefile::Layer

def features

def features
  raise "can't specify both SQL and where clause" if @sql && @where
  raise "can't specify both SQL and layer name" if @sql && @layer
  raise "no layer name or SQL specified" unless @layer || @sql
  sql   = ["-sql", sql] if @sql
  where = ["-where", "(" << Array(@where).join(") AND (") << ")"] if @where
  srs   = ["-t_srs", @projection] if @projection
  spat  = ["-spat", *@geometry.bounds.transpose.flatten, "-spat_srs", @geometry.projection] if @geometry
  misc  = %w[-mapFieldType Date=Integer,DateTime=Integer -dim XY]
  json = OS.ogr2ogr *(sql || where), *srs, *spat, *misc, *%w[-f GeoJSON -lco RFC7946=NO /vsistdout/], @source.path, *@layer
  GeoJSON::Collection.load json, **{projection: @projection}.compact
rescue OS::Error => error
  raise unless /Couldn't fetch requested layer (.*)!/ === error.message
  raise "no such layer: #{$1}"
end