0.0
No release in over 3 years
Low commit activity in last 3 years
Check if points are inside or outside the region polygons in an imported KML file.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

KmlContains

Parse a KML file and check if geographic points fall inside the polygons it defines. Supports multiple polygons and polygons with holes (inner boundaries).

Usage

Using NSW Local Government Areas from data.gov.au as an example — download the ESRI Shapefile (GDA94) and convert it to KML with GDAL:

ogr2ogr -f KML nsw-lga.kml nsw_lga.shp

Then in Ruby:

region = KmlContains.parse_kml(File.read('nsw-lga.kml'))

sydney = KmlContains::Point.new(151.21, -33.87)
region.contains_point?(sydney)             # => true
region.contains_point?(151.21, -33.87)     # also works

melbourne = KmlContains::Point.new(144.96, -37.81)
region.contains_point?(melbourne)          # => false

# find which polygon contains a point and access its ExtendedData
lga = region.find { |p| p.contains_point?(sydney) }
lga.extended_data['LGA_NAME']              # => "Council of the City of Sydney"

Points are (longitude, latitude). You can pass a KmlContains::Point, a longitude/latitude pair, or any object that responds to x and y.

Dependencies

Credits

Originally created as border_patrol at Square by Zach Brock and Matt Wilson.

Contributors: Scott Gonyea, Rob Olson, Omar Qazi, Denis Haskin, Tamir Duberstein, Erica Kwan.

License

MIT