Module: OGR::Geometry
- Extended by:
- ClassMethods
- Includes:
- EWKBIOExtensions, OGR::GeometryMixins::Extensions
- Included in:
- GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, NoneGeometry, Point, Polygon, UnknownGeometry
- Defined in:
- lib/ogr/geometry.rb,
lib/ogr/extensions/geometry/wkb_record.rb,
lib/ogr/extensions/geometry/ewkb_record.rb,
lib/ogr/extensions/geometry/rttopo_extensions.rb,
lib/ogr/extensions/geometry/ewkb_io_extensions.rb
Defined Under Namespace
Modules: ClassMethods, EWKBIOExtensions, RttopoExtensions
Classes: EWKBRecord, WKBRecord
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#boundary ⇒ OGR::Geometry
-
#buffer(distance, quad_segments = 30) ⇒ OGR::Polygon
Computes the buffer of the geometry by building a new geometry that contains the buffer region around the geometry that this was called on.
-
#centroid ⇒ Integer
-
#clone ⇒ OGR::Geometry
-
#close_rings! ⇒ Object
If this or any contained geometries has polygon rings that aren’t closed, this closes them by adding the starting point at the end.
-
#contains?(geometry) ⇒ Boolean
-
#convex_hull ⇒ OGR::Geometry
-
#coordinate_dimension ⇒ Integer
The dimension of coordinates in this geometry (i.e. 2d vs 3d).
-
#coordinate_dimension=(new_coordinate_dimension) ⇒ Object
-
#crosses?(geometry) ⇒ Boolean
-
#destroy! ⇒ Object
-
#difference(geometry) ⇒ OGR::Geometry
(also: #-)
-
#dimension ⇒ Integer
0 for points, 1 for lines, 2 for surfaces.
-
#disjoint?(geometry) ⇒ Boolean
-
#distance_to(geometry) ⇒ Float
The shortest distance between the two geometries.
-
#dump_readable(file_path = nil, prefix: nil) ⇒ Object
Dump as WKT to the given file_path
; dumps to STDOUT if none is given.
-
#empty! ⇒ Object
Clears all information from the geometry.
-
#empty? ⇒ Boolean
-
#envelope ⇒ OGR::Envelope
-
#equals?(geometry) ⇒ Boolean
(also: #==)
-
#flatten_to_2d! ⇒ Object
Converts this geometry to a 2D geometry.
-
#geometry_count ⇒ Integer
(also: #count)
-
#import_from_wkb(wkb_data) ⇒ Object
-
#import_from_wkt(wkt_data) ⇒ Object
-
#intersection(other_geometry) ⇒ OGR::Geometry
-
#intersects?(geometry) ⇒ Boolean
-
#is_2d? ⇒ Boolean
-
#is_3d? ⇒ Boolean
-
#name ⇒ String
-
#overlaps?(geometry) ⇒ Boolean
-
#point_count ⇒ Integer
-
#point_on_surface ⇒ OGR::Point
Returns a point that’s guaranteed to lie on the surface.
-
#polygonize ⇒ OGR::Geometry
Creates a polygon from a set of sparse edges.
-
#ring? ⇒ Boolean
TRUE if the geometry has no points, otherwise FALSE.
-
#segmentize!(max_length) ⇒ OGR::Geometry
Modify the geometry so that it has no segments longer than max_length
.
-
#simple? ⇒ Boolean
Returns TRUE if the geometry has no anomalous geometric points, such as self intersection or self tangency.
-
#simplify(distance_tolerance, preserve_topology: false) ⇒ OGR::Geometry
Computes and returns a new, simplified geometry.
-
#spatial_reference ⇒ OGR::SpatialReference
NOTE: The returned object may be shared with many geometries, and should thus not be modified.
-
#spatial_reference=(new_spatial_ref) ⇒ Object
Assigns a spatial reference to this geometry.
-
#symmetric_difference(geometry) ⇒ OGR::Geometry
-
#to_geo_json ⇒ String
-
#to_geo_json_ex(**options) ⇒ String
-
#to_gml(**options) ⇒ String
This geometry expressed as GML in GML basic data types.
-
#to_iso_wkt ⇒ String
-
#to_kml(altitude_mode = nil) ⇒ String
-
#to_line_string ⇒ OGR::Geometry
Converts the current geometry to a LineString geometry.
-
#to_linear_ring(close_rings: false) ⇒ OGR::LinearRing
Since GDAL doesn’t provide converting to a LinearRing, this is a hackish method for doing so.
-
#to_multi_line_string ⇒ OGR::Geometry
Converts the current geometry to a MultiLineString geometry.
-
#to_multi_point ⇒ OGR::Geometry
Converts the current geometry to a MultiPoint geometry.
-
#to_multi_polygon ⇒ OGR::MultiPolygon
Converts the current geometry to a MultiPolygon geometry.
-
#to_polygon ⇒ OGR::Geometry
Converts the current geometry to a Polygon geometry.
-
#to_wkb(byte_order = :wkbXDR) ⇒ String
-
#to_wkt ⇒ String
-
#touches?(geometry) ⇒ Boolean
-
#transform!(coordinate_transformation) ⇒ Object
Transforms the coordinates of this geometry in its current spatial reference system to a new spatial reference system.
-
#transform_to!(new_spatial_ref) ⇒ Object
Similar to #transform
, but this only works if the geometry already has an assigned spatial reference system and is transformable to the target coordinate system.
-
#type ⇒ FFI::OGR::API::WKBGeometryType
-
#type_to_name ⇒ String
-
#union(other_geometry) ⇒ OGR::Geometry
-
#valid? ⇒ Boolean
-
#within?(geometry) ⇒ Boolean
-
#wkb_size ⇒ Integer
The exact number of bytes required to hold the WKB of this object.
create, create_from_gml, create_from_json, create_from_wkb, create_from_wkt, factory, merge_geometry_types, release
#to_ewkb
#!=, #collection?, #container?, #curve?, #invalid?, #surface?, #to_vector, #utm_zone
Instance Attribute Details
#c_pointer ⇒ FFI::Pointer
162
163
164
|
# File 'lib/ogr/geometry.rb', line 162
def c_pointer
@c_pointer
end
|
Class Method Details
.included(base) ⇒ Object
152
153
154
155
|
# File 'lib/ogr/geometry.rb', line 152
def self.included(base)
base.send(:include, GDAL::Logger)
base.send(:extend, ClassMethods)
end
|
Instance Method Details
531
532
533
|
# File 'lib/ogr/geometry.rb', line 531
def boundary
build_geometry { FFI::OGR::API.OGR_G_Boundary(@c_pointer) }
end
|
#buffer(distance, quad_segments = 30) ⇒ OGR::Polygon
Computes the buffer of the geometry by building a new geometry that contains the buffer region around the geometry that this was called on.
542
543
544
545
546
|
# File 'lib/ogr/geometry.rb', line 542
def buffer(distance, quad_segments = 30)
build_geometry do
FFI::OGR::API.OGR_G_Buffer(@c_pointer, distance, quad_segments)
end
end
|
257
258
259
260
261
262
263
264
|
# File 'lib/ogr/geometry.rb', line 257
def centroid
point = is_3d? ? OGR::Point25D.new : OGR::Point.new
ogr_err = FFI::OGR::API.OGR_G_Centroid(@c_pointer, point.c_pointer)
return if point.c_pointer.null? || ogr_err.positive?
point
end
|
171
172
173
174
175
|
# File 'lib/ogr/geometry.rb', line 171
def clone
new_geometry_ptr = FFI::OGR::API.OGR_G_Clone(@c_pointer)
OGR::Geometry.factory(new_geometry_ptr)
end
|
#close_rings! ⇒ Object
If this or any contained geometries has polygon rings that aren’t closed, this closes them by adding the starting point at the end.
397
398
399
|
# File 'lib/ogr/geometry.rb', line 397
def close_rings!
FFI::OGR::API.OGR_G_CloseRings(@c_pointer)
end
|
#contains?(geometry) ⇒ Boolean
334
335
336
337
|
# File 'lib/ogr/geometry.rb', line 334
def contains?(geometry)
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
FFI::OGR::API.OGR_G_Contains(@c_pointer, geometry_ptr)
end
|
549
550
551
|
# File 'lib/ogr/geometry.rb', line 549
def convex_hull
build_geometry { FFI::OGR::API.OGR_G_ConvexHull(@c_pointer) }
end
|
#coordinate_dimension ⇒ Integer
The dimension of coordinates in this geometry (i.e. 2d vs 3d).
192
193
194
|
# File 'lib/ogr/geometry.rb', line 192
def coordinate_dimension
FFI::OGR::API.OGR_G_GetCoordinateDimension(@c_pointer)
end
|
#coordinate_dimension=(new_coordinate_dimension) ⇒ Object
197
198
199
200
201
202
203
|
# File 'lib/ogr/geometry.rb', line 197
def coordinate_dimension=(new_coordinate_dimension)
unless [2, 3].include?(new_coordinate_dimension)
raise "Can't set coordinate to #{new_coordinate_dimension}. Must be 2 or 3."
end
FFI::OGR::API.OGR_G_SetCoordinateDimension(@c_pointer, new_coordinate_dimension)
end
|
#crosses?(geometry) ⇒ Boolean
320
321
322
323
|
# File 'lib/ogr/geometry.rb', line 320
def crosses?(geometry)
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
FFI::OGR::API.OGR_G_Crosses(@c_pointer, geometry_ptr)
end
|
#destroy! ⇒ Object
164
165
166
167
168
|
# File 'lib/ogr/geometry.rb', line 164
def destroy!
self.class.release(@c_pointer)
@c_pointer = nil
end
|
#difference(geometry) ⇒ OGR::Geometry
Also known as:
-
413
414
415
416
417
418
|
# File 'lib/ogr/geometry.rb', line 413
def difference(geometry)
new_geometry_ptr = FFI::OGR::API.OGR_G_Difference(@c_pointer, geometry.c_pointer)
return if new_geometry_ptr.null?
self.class.factory(new_geometry_ptr)
end
|
Returns 0 for points, 1 for lines, 2 for surfaces.
185
186
187
|
# File 'lib/ogr/geometry.rb', line 185
def dimension
FFI::OGR::API.OGR_G_GetDimension(@c_pointer)
end
|
#disjoint?(geometry) ⇒ Boolean
307
308
309
310
|
# File 'lib/ogr/geometry.rb', line 307
def disjoint?(geometry)
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
FFI::OGR::API.OGR_G_Disjoint(@c_pointer, geometry_ptr)
end
|
#distance_to(geometry) ⇒ Float
The shortest distance between the two geometries.
434
435
436
|
# File 'lib/ogr/geometry.rb', line 434
def distance_to(geometry)
FFI::OGR::API.OGR_G_Distance(@c_pointer, geometry.c_pointer)
end
|
#dump_readable(file_path = nil, prefix: nil) ⇒ Object
Dump as WKT to the given file_path
; dumps to STDOUT if none is given.
278
279
280
281
282
|
# File 'lib/ogr/geometry.rb', line 278
def dump_readable(file_path = nil, prefix: nil)
file_ptr = file_path ? FFI::CPL::Conv.CPLOpenShared(file_path, "w", false) : nil
FFI::OGR::API.OGR_G_DumpReadable(@c_pointer, file_ptr, prefix)
FFI::CPL::Conv.CPLCloseShared(file_ptr) if file_ptr
end
|
#empty! ⇒ Object
Clears all information from the geometry.
180
181
182
|
# File 'lib/ogr/geometry.rb', line 180
def empty!
FFI::OGR::API.OGR_G_Empty(@c_pointer)
end
|
#empty? ⇒ Boolean
347
348
349
|
# File 'lib/ogr/geometry.rb', line 347
def empty?
FFI::OGR::API.OGR_G_IsEmpty(@c_pointer)
end
|
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/ogr/geometry.rb', line 206
def envelope
case coordinate_dimension
when 2
envelope = FFI::OGR::Envelope.new
FFI::OGR::API.OGR_G_GetEnvelope(@c_pointer, envelope)
when 3
envelope = FFI::OGR::Envelope3D.new
FFI::OGR::API.OGR_G_GetEnvelope3D(@c_pointer, envelope)
when 0 then return nil
else
raise "Unknown envelope dimension."
end
return if envelope.null?
OGR::Envelope.new(envelope)
end
|
#equals?(geometry) ⇒ Boolean
Also known as:
==
298
299
300
301
302
|
# File 'lib/ogr/geometry.rb', line 298
def equals?(geometry)
return false unless geometry.is_a? OGR::Geometry
FFI::OGR::API.OGR_G_Equals(@c_pointer, geometry.c_pointer)
end
|
#flatten_to_2d! ⇒ Object
Converts this geometry to a 2D geometry.
285
286
287
|
# File 'lib/ogr/geometry.rb', line 285
def flatten_to_2d!
FFI::OGR::API.OGR_G_FlattenTo2D(@c_pointer)
end
|
#geometry_count ⇒ Integer
Also known as:
count
244
245
246
|
# File 'lib/ogr/geometry.rb', line 244
def geometry_count
FFI::OGR::API.OGR_G_GetGeometryCount(@c_pointer)
end
|
#import_from_wkb(wkb_data) ⇒ Object
562
563
564
565
566
|
# File 'lib/ogr/geometry.rb', line 562
def import_from_wkb(wkb_data)
OGR::ErrorHandling.handle_ogr_err("Unable to import geometry from WKB") do
FFI::OGR::API.OGR_G_ImportFromWkb(@c_pointer, wkb_data, wkb_data.length)
end
end
|
#import_from_wkt(wkt_data) ⇒ Object
589
590
591
592
593
594
595
596
597
|
# File 'lib/ogr/geometry.rb', line 589
def import_from_wkt(wkt_data)
wkt_data_pointer = FFI::MemoryPointer.from_string(wkt_data)
wkt_pointer_pointer = FFI::MemoryPointer.new(:pointer)
wkt_pointer_pointer.write_pointer(wkt_data_pointer)
OGR::ErrorHandling.handle_ogr_err("Unable to import from WKT: #{wkt_data}") do
FFI::OGR::API.OGR_G_ImportFromWkt(@c_pointer, wkt_pointer_pointer)
end
end
|
#intersection(other_geometry) ⇒ OGR::Geometry
381
382
383
384
385
|
# File 'lib/ogr/geometry.rb', line 381
def intersection(other_geometry)
build_geometry do
FFI::OGR::API.OGR_G_Intersection(@c_pointer, other_geometry.c_pointer)
end
end
|
#intersects?(geometry) ⇒ Boolean
291
292
293
294
|
# File 'lib/ogr/geometry.rb', line 291
def intersects?(geometry)
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
FFI::OGR::API.OGR_G_Intersects(@c_pointer, geometry_ptr)
end
|
#is_2d? ⇒ Boolean
266
267
268
|
# File 'lib/ogr/geometry.rb', line 266
def is_2d?
coordinate_dimension == 2
end
|
#is_3d? ⇒ Boolean
270
271
272
|
# File 'lib/ogr/geometry.rb', line 270
def is_3d?
coordinate_dimension == 3
end
|
235
236
237
238
239
240
241
|
# File 'lib/ogr/geometry.rb', line 235
def name
name, ptr = FFI::OGR::API.OGR_G_GetGeometryName(@c_pointer)
ptr.autorelease = false
name
end
|
#overlaps?(geometry) ⇒ Boolean
341
342
343
344
|
# File 'lib/ogr/geometry.rb', line 341
def overlaps?(geometry)
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
FFI::OGR::API.OGR_G_Overlaps(@c_pointer, geometry_ptr)
end
|
#point_count ⇒ Integer
250
251
252
253
254
|
# File 'lib/ogr/geometry.rb', line 250
def point_count
return 0 if empty?
FFI::OGR::API.OGR_G_GetPointCount(@c_pointer)
end
|
Returns a point that’s guaranteed to lie on the surface.
556
557
558
|
# File 'lib/ogr/geometry.rb', line 556
def point_on_surface
build_geometry { FFI::OGR::API.OGR_G_PointOnSurface(@c_pointer) }
end
|
Creates a polygon from a set of sparse edges. The newly created geometry will contain a collection of reassembled Polygons.
407
408
409
|
# File 'lib/ogr/geometry.rb', line 407
def polygonize
build_geometry { FFI::OGR::API.OGR_G_Polygonize(@c_pointer) }
end
|
#ring? ⇒ Boolean
TRUE if the geometry has no points, otherwise FALSE.
371
372
373
374
375
376
377
|
# File 'lib/ogr/geometry.rb', line 371
def ring?
FFI::OGR::API.OGR_G_IsRing(@c_pointer)
rescue GDAL::Error => e
return false if e.message.include? "IllegalArgumentException"
raise
end
|
#segmentize!(max_length) ⇒ OGR::Geometry
Modify the geometry so that it has no segments longer than max_length
.
524
525
526
527
528
|
# File 'lib/ogr/geometry.rb', line 524
def segmentize!(max_length)
FFI::OGR::API.OGR_G_Segmentize(@c_pointer, max_length)
self
end
|
#simple? ⇒ Boolean
Returns TRUE if the geometry has no anomalous geometric points, such as self intersection or self tangency. The description of each instantiable geometric class will include the specific conditions that cause an instance of that class to be classified as not simple.
364
365
366
|
# File 'lib/ogr/geometry.rb', line 364
def simple?
FFI::OGR::API.OGR_G_IsSimple(@c_pointer)
end
|
#simplify(distance_tolerance, preserve_topology: false) ⇒ OGR::Geometry
Computes and returns a new, simplified geometry.
510
511
512
513
514
515
516
517
518
|
# File 'lib/ogr/geometry.rb', line 510
def simplify(distance_tolerance, preserve_topology: false)
build_geometry do
if preserve_topology
FFI::OGR::API.OGR_G_SimplifyPreserveTopology(@c_pointer, distance_tolerance)
else
FFI::OGR::API.OGR_G_Simplify(@c_pointer, distance_tolerance)
end
end
end
|
NOTE: The returned object may be shared with many geometries, and should thus not be modified.
442
443
444
445
446
447
|
# File 'lib/ogr/geometry.rb', line 442
def spatial_reference
spatial_ref_ptr = FFI::OGR::API.OGR_G_GetSpatialReference(@c_pointer)
return if spatial_ref_ptr.null?
OGR::SpatialReference.new(spatial_ref_ptr)
end
|
#spatial_reference=(new_spatial_ref) ⇒ Object
Assigns a spatial reference to this geometry. Any existing spatial reference is replaced, but this does not reproject the geometry.
453
454
455
456
457
458
459
|
# File 'lib/ogr/geometry.rb', line 453
def spatial_reference=(new_spatial_ref)
new_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, new_spatial_ref, autorelease: false)
FFI::OGR::API.OGR_G_AssignSpatialReference(@c_pointer, new_spatial_ref_ptr)
end
|
#symmetric_difference(geometry) ⇒ OGR::Geometry
423
424
425
426
427
428
|
# File 'lib/ogr/geometry.rb', line 423
def symmetric_difference(geometry)
new_geometry_ptr = FFI::OGR::API.OGR_G_SymDifference(@c_pointer, geometry.c_pointer)
return if new_geometry_ptr.null?
self.class.factory(new_geometry_ptr)
end
|
#to_geo_json ⇒ String
652
653
654
655
656
657
|
# File 'lib/ogr/geometry.rb', line 652
def to_geo_json
json, ptr = FFI::OGR::API.OGR_G_ExportToJson(@c_pointer)
FFI::CPL::VSI.VSIFree(ptr)
json
end
|
#to_geo_json_ex(**options) ⇒ String
665
666
667
668
669
670
671
|
# File 'lib/ogr/geometry.rb', line 665
def to_geo_json_ex(**options)
options_ptr = GDAL::Options.pointer(options)
json, ptr = FFI::OGR::API.OGR_G_ExportToJsonEx(@c_pointer, options_ptr)
FFI::CPL::VSI.VSIFree(ptr)
json
end
|
#to_gml(**options) ⇒ String
This geometry expressed as GML in GML basic data types.
633
634
635
636
637
638
639
|
# File 'lib/ogr/geometry.rb', line 633
def to_gml(**options)
options_ptr = GDAL::Options.pointer(options)
gml, ptr = FFI::OGR::API.OGR_G_ExportToGMLEx(@c_pointer, options_ptr)
FFI::CPL::VSI.VSIFree(ptr)
gml
end
|
#to_iso_wkt ⇒ String
611
612
613
614
615
616
617
|
# File 'lib/ogr/geometry.rb', line 611
def to_iso_wkt
GDAL._cpl_read_and_free_string do |output_ptr|
OGR::ErrorHandling.handle_ogr_err("Unable to export to WKT") do
FFI::OGR::API.OGR_G_ExportToIsoWkt(@c_pointer, output_ptr)
end
end
end
|
#to_kml(altitude_mode = nil) ⇒ String
644
645
646
647
648
649
|
# File 'lib/ogr/geometry.rb', line 644
def to_kml(altitude_mode = nil)
kml, ptr = FFI::OGR::API.OGR_G_ExportToKML(@c_pointer, altitude_mode)
FFI::CPL::VSI.VSIFree(ptr)
kml
end
|
Converts the current geometry to a LineString geometry. The returned object is a new OGR::Geometry instance.
677
678
679
|
# File 'lib/ogr/geometry.rb', line 677
def to_line_string
build_geometry { FFI::OGR::API.OGR_G_ForceToLineString(clone.c_pointer) }
end
|
#to_linear_ring(close_rings: false) ⇒ OGR::LinearRing
Since GDAL doesn’t provide converting to a LinearRing, this is a hackish method for doing so.
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
# File 'lib/ogr/geometry.rb', line 685
def to_linear_ring(close_rings: false)
line_string = to_line_string
return line_string unless line_string.is_a?(OGR::LineString)
linear_ring = OGR::LinearRing.new
linear_ring.spatial_reference = line_string.spatial_reference.clone if line_string.spatial_reference
linear_ring.import_from_wkt(line_string.to_wkt.tr("LINESTRING", "LINEARRING"))
linear_ring.close_rings! if close_rings
linear_ring
end
|
Converts the current geometry to a MultiLineString geometry. The returned object is a new OGR::Geometry instance.
720
721
722
|
# File 'lib/ogr/geometry.rb', line 720
def to_multi_line_string
build_geometry { FFI::OGR::API.OGR_G_ForceToMultiLineString(clone.c_pointer) }
end
|
Converts the current geometry to a MultiPoint geometry. The returned object is a new OGR::Geometry instance.
712
713
714
|
# File 'lib/ogr/geometry.rb', line 712
def to_multi_point
build_geometry { FFI::OGR::API.OGR_G_ForceToMultiPoint(clone.c_pointer) }
end
|
Converts the current geometry to a MultiPolygon geometry. The returned object is a new OGR::Geometry instance.
728
729
730
|
# File 'lib/ogr/geometry.rb', line 728
def to_multi_polygon
build_geometry { FFI::OGR::API.OGR_G_ForceToMultiPolygon(@c_pointer) }
end
|
Converts the current geometry to a Polygon geometry. The returned object is a new OGR::Geometry instance.
704
705
706
|
# File 'lib/ogr/geometry.rb', line 704
def to_polygon
build_geometry { FFI::OGR::API.OGR_G_ForceToPolygon(clone.c_pointer) }
end
|
#to_wkb(byte_order = :wkbXDR) ⇒ String
577
578
579
580
581
582
583
584
585
|
# File 'lib/ogr/geometry.rb', line 577
def to_wkb(byte_order = :wkbXDR)
output = FFI::MemoryPointer.new(:uchar, wkb_size)
OGR::ErrorHandling.handle_ogr_err("Unable to export geometry to WKB (using byte order #{byte_order})") do
FFI::OGR::API.OGR_G_ExportToWkb(@c_pointer, byte_order, output)
end
output.read_bytes(wkb_size)
end
|
601
602
603
604
605
606
607
|
# File 'lib/ogr/geometry.rb', line 601
def to_wkt
GDAL._cpl_read_and_free_string do |output_ptr|
OGR::ErrorHandling.handle_ogr_err("Unable to export to WKT") do
FFI::OGR::API.OGR_G_ExportToWkt(@c_pointer, output_ptr)
end
end
end
|
#touches?(geometry) ⇒ Boolean
314
315
316
|
# File 'lib/ogr/geometry.rb', line 314
def touches?(geometry)
FFI::OGR::API.OGR_G_Touches(@c_pointer, geometry.c_pointer)
end
|
Transforms the coordinates of this geometry in its current spatial reference system to a new spatial reference system. Normally this means reprojecting the vectors, but it could also include datum shifts, and changes of units.
Note that this doesn’t require the geometry to have an existing spatial reference system.
472
473
474
475
476
477
478
479
480
481
|
# File 'lib/ogr/geometry.rb', line 472
def transform!(coordinate_transformation)
coord_trans_ptr = GDAL._pointer(OGR::CoordinateTransformation,
coordinate_transformation)
return if coord_trans_ptr.nil? || coord_trans_ptr.null?
OGR::ErrorHandling.handle_ogr_err("Unable to transform geometry") do
FFI::OGR::API.OGR_G_Transform(@c_pointer, coord_trans_ptr)
end
end
|
Similar to #transform
, but this only works if the geometry already has an assigned spatial reference system and is transformable to the target coordinate system.
Because this function requires internal creation and initialization of an OGRCoordinateTransformation object it is significantly more expensive to use this function to transform many geometries than it is to create the OGRCoordinateTransformation in advance, and call transform() with that transformation. This function exists primarily for convenience when only transforming a single geometry.
496
497
498
499
500
501
502
503
|
# File 'lib/ogr/geometry.rb', line 496
def transform_to!(new_spatial_ref)
new_spatial_ref_ptr = GDAL._pointer(OGR::SpatialReference, new_spatial_ref, autorelease: false)
return if new_spatial_ref_ptr.null?
OGR::ErrorHandling.handle_ogr_err("Unable to transform geometry") do
FFI::OGR::API.OGR_G_TransformTo(@c_pointer, new_spatial_ref_ptr)
end
end
|
#type ⇒ FFI::OGR::API::WKBGeometryType
225
226
227
|
# File 'lib/ogr/geometry.rb', line 225
def type
FFI::OGR::API.OGR_G_GetGeometryType(@c_pointer)
end
|
#type_to_name ⇒ String
230
231
232
|
# File 'lib/ogr/geometry.rb', line 230
def type_to_name
self.class.type_to_name(type)
end
|
389
390
391
392
393
|
# File 'lib/ogr/geometry.rb', line 389
def union(other_geometry)
build_geometry do
FFI::OGR::API.OGR_G_Union(@c_pointer, other_geometry.c_pointer)
end
end
|
#valid? ⇒ Boolean
352
353
354
355
356
|
# File 'lib/ogr/geometry.rb', line 352
def valid?
FFI::OGR::API.OGR_G_IsValid(@c_pointer)
rescue GDAL::Error
false
end
|
#within?(geometry) ⇒ Boolean
327
328
329
330
|
# File 'lib/ogr/geometry.rb', line 327
def within?(geometry)
geometry_ptr = GDAL._pointer(OGR::Geometry, geometry)
FFI::OGR::API.OGR_G_Within(@c_pointer, geometry_ptr)
end
|
The exact number of bytes required to hold the WKB of this object.
571
572
573
|
# File 'lib/ogr/geometry.rb', line 571
def wkb_size
FFI::OGR::API.OGR_G_WkbSize(@c_pointer)
end
|