Skip to content

formigarafa/turf-ruby

Repository files navigation

turf-ruby Build Status

Ruby port of Turf.js, an advance geospatial analysis library.

Installation

Add this line to your application's Gemfile:

gem 'turf-ruby'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install turf-ruby

Usage

Example:

# Turf.js uses [GeoJSON](https://en.wikipedia.org/wiki/GeoJSON) is input and output, so does turf-ruby.
from = { type: "Feature", geometry: { type: "Point", coordinates: [-75.343, 39.984] } }
to = { type: "Feature", geometry: { type: "Point", coordinates: [-75.534, 39.123] } }

Turf::distance(from, to, units: 'miles')
# 60.35329997171344

You can view all methods here: https://formigarafa.github.io/turf-ruby/. Most methods have their documentation linked to Turf.js.

Progress

Currently not all functions are available, feel free to fork the repo and port missing functions you need by reading source code of Turf.js. And don't forget to open a pull-request afterward.

This list should be updated from https://github.com/Turfjs/turf/blob/master/documentation.yml.

Measurement

  • along
  • area
  • bbox
  • bboxPolygon
  • bearing
  • center
  • centerOfMass
  • centroid
  • destination
  • distance
  • envelope
  • length
  • midpoint
  • pointOnFeature
  • polygonTangents
  • pointToLineDistance
  • rhumbBearing
  • rhumbDestination
  • rhumbDistance
  • square
  • greatCircle

Coordinate Mutation

  • cleanCoords
  • flip
  • rewind
  • round
  • truncate

Transformation

  • bboxClip
  • bezierSpline
  • buffer
  • circle
  • clone
  • concave
  • convex
  • difference
  • dissolve
  • intersect
  • lineOffset
  • polygonSmooth
  • simplify
  • tesselate
  • transformRotate
  • transformTranslate
  • transformScale
  • union
  • voronoi

Feature Conversion

  • combine
  • explode
  • flatten
  • lineToPolygon
  • polygonize
  • polygonToLine

Misc

  • kinks
  • lineArc
  • lineChunk
  • lineIntersect
  • lineOverlap
  • lineSegment
  • lineSlice
  • lineSliceAlong
  • lineSplit
  • mask
  • nearestPointOnLine
  • sector
  • shortestPath
  • unkinkPolygon

Helper

  • featureCollection
  • feature
  • geometryCollection
  • lineString
  • multiLineString
  • multiPoint
  • multiPolygon
  • point
  • polygon

Random

  • randomPosition
  • randomPoint
  • randomLineString
  • randomPolygon

Data

  • sample

Interpolation

  • interpolate
  • isobands
  • isolines
  • planepoint
  • tin

Joins

  • pointsWithinPolygon
  • tag

Grids

  • hexGrid
  • pointGrid
  • squareGrid
  • triangleGrid

Classification

  • nearestPoint

Aggregation

  • collect
  • clustersDbscan
  • clustersKmeans

Meta

  • coordAll
  • coordEach
  • coordReduce
  • featureEach
  • featureReduce
  • flattenEach
  • flattenReduce
  • getCoord
  • getCoords
  • getGeom
  • getType
  • geomEach
  • geomReduce
  • propEach
  • propReduce
  • segmentEach
  • segmentReduce
  • getCluster
  • clusterEach
  • clusterReduce

Assertions

  • collectionOf
  • containsNumber
  • geojsonType
  • featureOf

Booleans

  • booleanClockwise
  • booleanConcave
  • booleanContains
  • booleanCrosses
  • booleanDisjoint
  • booleanEqual
  • booleanIntersects
  • booleanOverlap
  • booleanParallel
  • booleanPointInPolygon
  • booleanPointOnLine
  • booleanWithin

Unit Conversion

  • bearingToAzimuth
  • convertArea
  • convertLength
  • degreesToRadians
  • lengthToRadians
  • lengthToDegrees
  • radiansToLength
  • radiansToDegrees
  • toMercator
  • toWgs84

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/formigarafa/turf-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Turf Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Great Thanks

Great thanks to people that care to share and helping with the evolution of the community: