Sha256: 7deaf1bcaf8392aea14a5a4a3937e7e67b2c6b9df4a1198326eba49be270c62c

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'bundler/setup'
require 'pry'
require 'ffi-gdal'

include GDAL::Logger
GDAL::Logger.logging_enabled = true

# http://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#create-a-new-layer-from-the-extent-of-an-existing-layer

# Get a Layer's Extent
data_source = OGR::DataSource.open('../spec/support/shapefiles/states_21basic/states.shp', 'r')
layer = data_source.layer(0)
extent = layer.extent

# extent = geometry.envelope.world_to_pixel(floyd.geo_transform)
# x_min = extent[:x_origin]
# x_max = extent[:x_max]
# y_min = extent[:y_origin]
# y_max = extent[:y_max]
# log "x_min: #{x_min}"
# log "y_min: #{y_min}"
# log "y_max: #{y_max}"
# log "x_max: #{x_max}"

# Create a polygon from the extent
ring = OGR::Geometry.create(:wkbLinearRing)
ring.add_point(extent.x_min, extent.y_min)
ring.add_point(extent.x_max, extent.y_min)
ring.add_point(extent.x_max, extent.y_max)
ring.add_point(extent.x_min, extent.y_max)
ring.add_point(extent.x_min, extent.y_min)
poly = OGR::Geometry.create(:wkbPolygon)
poly.add_geometry(ring)

binding.pry

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta3 examples/ogr_layer_to_layer.rb