class OGR::Geometry
Attributes
ptr[RW]
Public Class Methods
create_empty(geometry_type)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 34 def self.create_empty(geometry_type) OGR::Tools.cast_geometry(FFIOGR.OGR_G_CreateGeometry(geometry_type)) end
from_geojson(geojson)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 17 def self.from_geojson(geojson) if geojson.instance_of? String geojson = MultiJson.load(geojson) end coords = geojson['coordinates'] case geojson['type'] when 'Point' OGR::Point.create coords when 'LineString' OGR::LineString.create coords when 'Polygon' OGR::Polygon.create coords end end
new(ptr)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 5 def initialize(ptr) @ptr = FFI::AutoPointer.new(ptr, self.class.method(:release)) #@ptr = FFI::AutoPointer.new(ptr) @ptr.autorelease = false end
release(ptr)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 11 def self.release(ptr);end
Public Instance Methods
add_geometry(geometry)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 38 def add_geometry(geometry) FFIOGR.OGR_G_AddGeometry(@ptr, geometry.ptr) end
add_geometry_directly(geometry)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 42 def add_geometry_directly(geometry) FFIOGR.OGR_G_AddGeometryDirectly(@ptr, geometry.ptr) end
add_point(coords)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 46 def add_point(coords) raise RuntimeError.new("Invalid coordinate(s) specified") unless coords.size >= 2 x = Float(coords[0]) y = Float(coords[1]) z = Float(coords[2]) if coords.size >= 3 unless z FFIOGR.OGR_G_AddPoint_2D(@ptr, x, y) else FFIOGR.OGR_G_AddPoint(@ptr, x, y, z) end end
flatten()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 76 def flatten FFIOGR.OGR_G_FlattenTo2D(@ptr) end
free()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 13 def free FFIOGR.OGR_G_DestroyGeometry(@ptr) end
get_area()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 99 def get_area FFIOGR.OGR_G_Area(@ptr) end
Also aliased as: area
get_boundary()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 104 def get_boundary FFIOGR.OGR_G_Boundary(@ptr) end
Also aliased as: boundary
get_envelope()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 109 def get_envelope envelope = FFI::MemoryPointer.new :pointer, 4 FFIOGR.OGR_G_GetEnvelope(@ptr, envelope) OGR::Envelope.new(envelope.read_array_of_double(4)) end
Also aliased as: envelope
get_geometry_type()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 80 def get_geometry_type FFIOGR.OGR_G_GetGeometryType(@ptr) end
Also aliased as: geometry_type
get_length()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 94 def get_length FFIOGR.OGR_G_Length(@ptr) end
Also aliased as: length
get_spatial_ref()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 85 def get_spatial_ref OGR::Tools.cast_spatial_reference(FFIOGR.OGR_G_GetSpatialReference(@ptr)) end
Also aliased as: spatial_ref
is_3d?()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 72 def is_3d? !!(geometry_type.to_s =~ /_25d/) end
set_point(coords, idx)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 59 def set_point(coords, idx) raise RuntimeError.new("Invalid coordinate(s) specified") unless coords.size >= 2 x = Float(coords[0]) y = Float(coords[1]) z = Float(coords[2]) if coords.size >= 3 unless z FFIOGR.OGR_G_SetPoint_2D(@ptr, idx, x, y) else FFIOGR.OGR_G_SetPoint(@ptr, idx, x, y, z) end end
to_geojson()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 116 def to_geojson MultiJson.load(FFIOGR.OGR_G_ExportToJson(@ptr)) end
to_gml()
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 125 def to_gml FFIOGR.OGR_G_ExportToGML(@ptr) end
to_kml(elevation=nil)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 120 def to_kml(elevation=nil) elevation = String(elevation) unless elevation.nil? FFIOGR.OGR_G_ExportToKML(@ptr, elevation) end
transform(ct)
click to toggle source
# File lib/ffi-ogr/geometry.rb, line 90 def transform(ct) FFIOGR.OGR_G_Transform(@ptr, ct) end