Turf.jl

A Julia port of Turf.js http://turfjs.org/
Popularity
18 Stars
Updated Last
1 Year Ago
Started In
June 2019

Turf.jl

NOTE: This project is no longer maintained.

Documentation Build Status
Linux/MacOS Windows Coverage Status codecov

A spatial analysis library written in Julia, ported from the great Turf.js.

Turf.jl uses GeoInterface.jl and GeoJSON.jl to create and handle all geographic data.

Installation

Turf.jl can be installed either from the REPL using Pkg mode:

pkg> add Turf

or via Pkg:

julia> import Pkg; Pkg.add("Turf")

Alternatively if you want to use the latest version available, you can do:

pkg> add Turf#master

Example

As an example, let's try to identify which points are within a certain polygon on the map and mark them with a different color. We can do this using Turf.

# Turf already exports all symbols of GeoInterface.jl and GeoJSON.jl, so there's no need to import them
using Turf

# Let's create a basic geojson with a polygon and some points
fc = """
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [5.185547, 47.753949],
            [-0.703125, 39.637989],
            [7.910156, 30.974436],
            [12.568359, 48.107339],
            [5.185547, 47.753949]
          ]
        ]
      }
    },
     {
      "type": "Feature",
      "properties": {},
      "geometry": {"type": "Point", "coordinates": [12.304688, 43.3882]}
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {"type": "Point", "coordinates": [8.964844, 42.031854]}
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {"type": "Point", "coordinates": [2.548828, 41.901134]}
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {"type": "Point", "coordinates": [9.84375, 36.525174]}
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {"type": "Point", "coordinates": [-0.878906, 38.546418]}
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {"type": "Point", "coordinates": [3.47168, 46.407564]}
    }
  ]
}
"""
# convert the geojson into a FeatureCollection object
geo_data = GeoJSON.parse(fc)

# extract the polygon
polygon = geo_data.features[1].geometry

# loop to see which points are inside the polygon
# and add a 'marker-color' property to them
for i in 2:length(geo_data.features)
    feature = geo_data.features[i]
    point = feature.geometry

    if within(point, polygon)
        feature.properties = Dict("marker-color" => "#ff0000")
    end
end

# convert the FeatureCollection back to geojson
result = geojson(geo_data)

If we then plot the results here's what we get:

before:

before (2)

after:

after

For more examples, please take a look at the Examples section of the documentation.

Documentation

  • STABLE: most recent tagged version.
  • DEVEL: development version.

Getting Help

  • Have a bug to report? Open an issue. Include the version of Turf and Julia, a full log, and some code that shows the issue.
  • Have a feature request? Open an issue. Tell us what the feature should do and why you want the feature.

Available Functionality

A list with the currently available features can be found here. Please open an issue if there's a specific Turf.js method that you'd like to have implemented.

Contribute

Contributions are highly welcomed and appreciated. If you want to contribute to this project, feel free to open an issue to discuss your proposal and its implementation. Once it's all good make a pull request and you're done. Thank you for helping out!

Used By Packages

No packages found.