Class: GeoScript::Geom::Polygon

Inherits:
JTSPolygon
  • Object
show all
Includes:
GeoScript::Geom
Defined in:
lib/geoscript/geom/polygon.rb

Constant Summary

Constants included from GeoScript::Geom

GEOM_FACTORY, PREP_FACTORY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GeoScript::Geom

buffer, enhance, from_wkt, get_bounds, prepare, simplify, to_wkt

Constructor Details

#initialize(*rings) ⇒ Polygon

Returns a new instance of Polygon.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/geoscript/geom/polygon.rb', line 10

def initialize(*rings)
  if rings.first.kind_of? JTSPolygon
    interior_rings = []
    num_rings = rings.first.num_interior_ring
    for i in (0...num_rings)
      interior_rings << rings.first.get_interior_ring_n(i)
    end
    shell = rings.first.exterior_ring
    holes = interior_rings.to_java(com.vividsolutions.jts.geom.LinearRing)
  else
    linear_rings = []
    rings.each do |ring|
      if ring.kind_of? LinearRing
        linear_rings << ring
      else
        linear_rings << LinearRing.new(*ring)
      end
    end
    
    shell = linear_rings.first
    holes = linear_rings[1..linear_rings.size].to_java(com.vividsolutions.jts.geom.LinearRing)
  end
  super(shell, holes, GEOM_FACTORY)
end

Instance Attribute Details

#boundsObject

Returns the value of attribute bounds.



8
9
10
# File 'lib/geoscript/geom/polygon.rb', line 8

def bounds
  @bounds
end

Instance Method Details

#buffer(dist) ⇒ Object



35
36
37
# File 'lib/geoscript/geom/polygon.rb', line 35

def buffer(dist)
  Polygon.new super
end

#to_jsonObject



47
48
49
# File 'lib/geoscript/geom/polygon.rb', line 47

def to_json
  IO.write_json self
end

#to_wkbObject



43
44
45
# File 'lib/geoscript/geom/polygon.rb', line 43

def to_wkb
  IO.write_wkb self
end

#to_wktObject



39
40
41
# File 'lib/geoscript/geom/polygon.rb', line 39

def to_wkt
  IO.write_wkt self
end