12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/nswtopo/gis/shapefile.rb', line 12
def shapefile_layer(shapefile_path, where: nil, sql: nil, layer: nil, margin: {})
raise "#{@source}: can't specify both SQL and where clause" if sql && where
raise "#{@source}: can't specify both SQL and layer name" if sql && layer
sql = ["-sql", sql] if sql
where = ["-where", "(" << Array(where).join(") AND (") << ")"] if where
srs = ["-t_srs", @map.projection]
spat = ["-spat", *@map.bounds(margin: margin).transpose.flatten, "-spat_srs", @map.projection]
misc = %w[-mapFieldType Date=Integer,DateTime=Integer -dim XY]
json = OS.ogr2ogr *(sql || where), *srs, *spat, *misc, "-f", "GeoJSON", "-lco", "RFC7946=NO", "/vsistdout/", shapefile_path, *layer
GeoJSON::Collection.load json, @map.projection
end
|