Class: Charta::MultiPolygon

Inherits:
GeometryCollection show all
Defined in:
lib/charta/multi_polygon.rb

Overview

Represent a Geometry with contains only polygons

Instance Attribute Summary

Attributes inherited from Geometry

#ewkt

Instance Method Summary collapse

Methods inherited from GeometryCollection

empty, #homogenize!, #initialize

Methods inherited from Geometry

#!=, #==, #area, #bounding_box, #buffer, #centroid, #circle, #collection?, #convert_to, #difference, #empty?, #find_srid, #flatten, #geom, #initialize, #inspect, #intersection, #merge, #multi_polygon, #point_on_surface, #select_row, #select_value, #select_values, #srid, #srid=, #to_binary, #to_ewkt, #to_geojson, #to_gml, #to_json_object, #to_kml, #to_rgeo, #to_s, #to_svg, #to_svg_path, #to_text, #transform, #type

Constructor Details

This class inherits a constructor from Charta::GeometryCollection

Instance Method Details

#each_polygon(&block) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/charta/multi_polygon.rb', line 4

def each_polygon(&block)
  if block.arity == 1
    polygons.each(&block)
  elsif block.arity == 2
    polygons.each_with_index do |polygon, index|
      yield polygon, index + 1
    end
  else
    raise 'Cannot browse each polygon without parameter'
  end
end

#polygonsObject

Extract polygons ordered by 'PointOnSurface' position


17
18
19
20
21
# File 'lib/charta/multi_polygon.rb', line 17

def polygons
  @polygons ||= select_values("SELECT ST_AsEWKT(geom) FROM (SELECT ST_GeometryN(#{geom}, generate_series(1, ST_NumGeometries(#{geom}))) AS geom) AS polygons ORDER BY ST_X(ST_PointOnSurface(geom)), ST_Y(ST_PointOnSurface(geom))").map do |polygon|
    Polygon.new(polygon)
  end || []
end