lib/turf/boolean_point_in_polygon.rb
def boolean_point_in_polygon(point, polygon, ignore_boundary: false)
    polygon = deep_symbolize_keys(polygon)
    pt = get_coord(point)
    geom = get_geom(polygon)
    type = geom.fetch(:type)
    bbox = polygon[:bbox]
    polys = geom.fetch(:coordinates)

    # Quick elimination if point is not inside bbox
    return false if bbox && !in_bbox(pt, bbox)

    # normalize to multipolygon
    polys = [polys] if type == "Polygon"

    inside_poly = false
    polys.each do |poly|
      # check if it is in the outer ring first
      next unless in_ring(pt, poly[0], ignore_boundary)

      in_hole = false

      # check for the point in any of the holes
      poly.slice(1, poly.size - 1).each do |hole|
        if in_ring(pt, hole, !ignore_boundary)
          in_hole = true
        end
      end
      if !in_hole
        inside_poly = true
      end
    end
    inside_poly
  end
# Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon
# can be convex or concave. The function accounts for holes.
# @see http://turfjs.org/docs/#booleanPointInPolygon
# @param point [Coord] input point
# @param polygon [Feature<(Polygon | MultiPolygon)>] input polygon or multipolygon
# @param ignore_boundary [boolean] True if polygon boundary should be ignored when determining if the point is
# inside
# the polygon otherwise false.
# @return [boolean] true if the Point is inside the Polygon; false if the Point is not inside the Polygon
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon
can be convex or concave. The function accounts for holes.
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon . The polygon can be convex or concave . The function accounts for holes .
def boolean_point_in_polygon(point, polygon, ignore_boundary: false)
    polygon = deep_symbolize_keys(polygon)
    pt = get_coord(point)
    geom = get_geom(polygon)
    type = geom.fetch(:type)
    bbox = polygon[:bbox]
    polys = geom.fetch(:coordinates)
    return false if bbox && !in_bbox(pt, bbox)
    polys = [polys] if type == "Polygon"
    inside_poly = false
    polys.each do |poly|
      next unless in_ring(pt, poly[0], ignore_boundary)
      in_hole = false
      poly.slice(1, poly.size - 1).each do |hole|
        if in_ring(pt, hole, !ignore_boundary)
          in_hole = true
        end
      end
      if !in_hole
        inside_poly = true
      end
    end
    inside_poly
  end
def boolean_point_in_polygon ( point , polygon , ignore_boundary : false ) polygon = deep_symbolize_keys ( polygon ) pt = get_coord ( point ) geom = get_geom ( polygon ) type = geom . fetch ( :type ) bbox = polygon [ :bbox ] polys = geom . fetch ( :coordinates ) return false if bbox && ! in_bbox ( pt , bbox ) polys = [ polys ] if type == "Polygon" inside_poly = false polys . each do | poly | next unless in_ring ( pt , poly [ 0 ] , ignore_boundary ) in_hole = false poly . slice ( 1 , poly . size - 1 ) . each do | hole | if in_ring ( pt , hole , ! ignore_boundary ) in_hole = true end end if ! in_hole inside_poly = true end end inside_poly end
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon.
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon .
# Quick elimination if point is not inside bbox # normalize to multipolygon # check if it is in the outer ring first # check for the point in any of the holes
true if the Point is inside the Polygon; false if the Point is not inside the Polygon
true if the Point is inside the Polygon ; false if the Point is not inside the Polygon
boolean
point
None
polygon
input polygon or multipolygon
input polygon or multipolygon
ignore_boundary
True if polygon boundary should be ignored when determining if the point is inside the polygon otherwise false.
True if polygon boundary should be ignored when determining if the point is inside the polygon otherwise false .
see
None