Class: Geos::Polygon

Inherits:
Geometry show all
Defined in:
lib/ffi-geos/polygon.rb

Constant Summary

Constants included from GeomTypes

GeomTypes::GEOS_GEOMETRYCOLLECTION, GeomTypes::GEOS_LINEARRING, GeomTypes::GEOS_LINESTRING, GeomTypes::GEOS_MULTILINESTRING, GeomTypes::GEOS_MULTIPOINT, GeomTypes::GEOS_MULTIPOLYGON, GeomTypes::GEOS_POINT, GeomTypes::GEOS_POLYGON

Instance Attribute Summary

Attributes inherited from Geometry

#ptr

Instance Method Summary collapse

Methods inherited from Geometry

#==, #area, #boundary, #buffer, #build_area, #centroid, #clip_by_rect, #constrained_delaunay_triangulation, #contains?, #convex_hull, #coord_seq, #coverage_union, #covered_by?, #covers?, #crosses?, #delaunay_triangulation, #difference, #dimensions, #disjoint?, #distance, #distance_indexed, #empty?, #end_point, #envelope, #eql?, #eql_almost?, #eql_exact?, #extract_unique_points, #frechet_distance, #geom_type, #has_z?, #hausdorff_distance, #initialize, #initialize_copy, #interpolate, #interpolate_normalized, #intersection, #intersects?, #largest_empty_circle, #length, #line_merge, #make_valid, #maximum_inscribed_circle, #minimum_bounding_circle, #minimum_clearance, #minimum_clearance_line, #minimum_rotated_rectangle, #minimum_width, #nearest_points, #node, #normalize!, #num_coordinates, #num_geometries, #overlaps?, #point_on_surface, #polygonize, #polygonize_cut_edges, #polygonize_full, #polygonize_valid, #precision, #project, #project_normalized, #relate, #relate_boundary_node_rule, #relate_pattern, release, #reverse, #ring?, #shared_paths, #simple?, #simplify, #snap, #srid, #srid=, #start_point, #sym_difference, #to_prepared, #to_s, #topology_preserve_simplify, #touches?, #type_id, #unary_union, #union, #union_cascaded, #valid?, #valid_detail, #valid_reason, #voronoi_diagram, #with_precision, #within?

Methods included from Tools

#bool_result, #bool_to_int, #cast_geometry_ptr, #check_enum_value, #check_geometry, #extract_options!, #pick_srid_according_to_policy, #pick_srid_from_geoms, #symbol_for_enum

Constructor Details

This class inherits a constructor from Geos::Geometry

Instance Method Details

#dump_points(cur_path = []) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/ffi-geos/polygon.rb', line 36

def dump_points(cur_path = [])
  points = [exterior_ring.dump_points]

  interior_rings.each do |ring|
    points.push(ring.dump_points)
  end

  cur_path.concat(points)
end

#exterior_ringObject



21
22
23
24
25
26
27
28
# File 'lib/ffi-geos/polygon.rb', line 21

def exterior_ring
  cast_geometry_ptr(
    FFIGeos.GEOSGetExteriorRing_r(Geos.current_handle_pointer, ptr),
    auto_free: false,
    srid_copy: srid,
    parent: self
  )
end

#interior_ring_n(n) ⇒ Object Also known as: interior_ring



9
10
11
12
13
14
15
16
17
18
# File 'lib/ffi-geos/polygon.rb', line 9

def interior_ring_n(n)
  raise Geos::IndexBoundsError if n.negative? || n >= num_interior_rings

  cast_geometry_ptr(
    FFIGeos.GEOSGetInteriorRingN_r(Geos.current_handle_pointer, ptr, n),
    auto_free: false,
    srid_copy: srid,
    parent: self
  )
end

#interior_ringsObject



30
31
32
33
34
# File 'lib/ffi-geos/polygon.rb', line 30

def interior_rings
  num_interior_rings.times.collect do |n|
    interior_ring_n(n)
  end
end

#num_interior_ringsObject



5
6
7
# File 'lib/ffi-geos/polygon.rb', line 5

def num_interior_rings
  FFIGeos.GEOSGetNumInteriorRings_r(Geos.current_handle_pointer, ptr)
end

#snap_to_grid(*args) ⇒ Object



73
74
75
76
77
# File 'lib/ffi-geos/polygon.rb', line 73

def snap_to_grid(*args)
  ret = dup.snap_to_grid!(*args)
  ret.srid = pick_srid_according_to_policy(srid)
  ret
end

#snap_to_grid!(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ffi-geos/polygon.rb', line 46

def snap_to_grid!(*args)
  unless empty?
    exterior_ring = self.exterior_ring.coord_seq.snap_to_grid!(*args)

    if exterior_ring.empty?
      @ptr = Geos.create_empty_polygon(srid: srid).ptr
    elsif exterior_ring.length < 4
      raise Geos::InvalidGeometryError, "snap_to_grid! produced an invalid number of points in exterior ring - found #{exterior_ring.length} - must be 0 or >= 4"
    else
      interior_rings = []

      num_interior_rings.times do |i|
        interior_ring = interior_ring_n(i).coord_seq.snap_to_grid!(*args)

        interior_rings << interior_ring unless interior_ring.length < 4
      end

      interior_rings.compact!

      polygon = Geos.create_polygon(exterior_ring, interior_rings, srid: srid)
      @ptr = polygon.ptr
    end
  end

  self
end