Class: GeoRuby::SimpleFeatures::LinearRing

Inherits:
LineString show all
Defined in:
lib/geo_ruby/simple_features/linear_ring.rb

Overview

Represents a linear ring, which is a closed line string (see LineString). Currently, no check is performed to verify if the linear ring is really closed.

Instance Attribute Summary

Attributes inherited from LineString

#points

Attributes inherited from Geometry

#srid, #with_m, #with_z

Instance Method Summary collapse

Methods inherited from LineString

#==, #as_json, #binary_geometry_type, #binary_representation, #bounding_box, #clockwise?, #closed?, #do_simplify, #euclidian_distance, from_coordinates, from_points, #georss_gml_representation, #georss_poslist, #georss_simple_representation, #georss_w3cgeo_representation, #intersects?, #kml_poslist, #m_range, #method_missing, #simplify, #spherical_distance, #text_geometry_type, #text_representation, #to_coordinates

Methods inherited from Geometry

#as_ewkb, #as_ewkt, #as_georss, #as_hex_ewkb, #as_hex_wkb, #as_json, #as_kml, #as_wkb, #as_wkt, #bounding_box, #envelope, from_ewkb, from_ewkt, from_geojson, from_georss, from_georss_with_tags, from_hex_ewkb, from_kml, #m_range, #to_json

Constructor Details

#initialize(srid = DEFAULT_SRID, with_z = false, with_m = false) ⇒ LinearRing

Returns a new instance of LinearRing.



8
9
10
# File 'lib/geo_ruby/simple_features/linear_ring.rb', line 8

def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
  super(srid, with_z, with_m)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GeoRuby::SimpleFeatures::LineString

Instance Method Details

#contains_point?(point) ⇒ Boolean

Does this linear string contain the given point? We use the algorithm described here:

www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
# File 'lib/geo_ruby/simple_features/linear_ring.rb', line 22

def contains_point?(point)
  x, y = point.x, point.y
  tuples = @points.zip(@points[1..-1] + [@points[0]])
  crossings =
    tuples.select do |a, b|
      (b.y > y != a.y > y) && (x < (a.x - b.x) * (y - b.y) / (a.y - b.y) + b.x)
    end

  crossings.size % 2 == 1
end

#kml_representation(options = {}) ⇒ Object



14
15
16
# File 'lib/geo_ruby/simple_features/linear_ring.rb', line 14

def kml_representation(options = {})
  orig_kml_representation(options).gsub('LineString', 'LinearRing')
end

#orig_kml_representationObject

fix kml export



13
# File 'lib/geo_ruby/simple_features/linear_ring.rb', line 13

alias_method :orig_kml_representation, :kml_representation