GeoJSON

Documentation for GeoJSON.

See the GeoInterfaces.jl and Tables.jl documentation for most applicable methods.

GeoJSON.GeoJSONModule

GeoJSON

CI codecov

Read GeoJSON files using JSON3.jl, and provide the Tables.jl interface.

This package is heavily inspired by, and borrows code from, JSONTables.jl, which does the same thing for the general JSON format. GeoJSON puts the geometry in a geometry column, and adds all properties in the columns individually.

Usage

GeoJSON only provides simple read and write methods. GeoJSON.read takes a file path, string, IO, or bytes.

julia> using GeoJSON, DataFrames

julia> fc = GeoJSON.read("path/to/a.geojson")
FeatureCollection with 171 Features

julia> first(fc)
Feature with geometry type Polygon and properties Symbol[:geometry, :timestamp, :version, :changeset, :user, :uid, :area, :highway, :type, :id]

# use the Tables interface to convert the format, extract data, or iterate over the rows
julia> df = DataFrame(fc)

# write to string
julia> write(fc)
"{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-69.99693762899992...

HTTP access

To read JSON from a URL, use HTTP.jl


julia> using GeoJSON, HTTP

julia> resp = HTTP.get("https://path/to/file.json")

julia> fc = GeoJSON.read(resp.body)
source
GeoJSON.CRSType
CRS(type::String, properties::Dict{String,Any})

A Coordinate Reference System for compatibility. Should not be used, as it is not part of the GeoJSON specification. The CRS of a GeoJSON object is always WGS84.

source
GeoJSON.FeatureType
Feature{D,T}(id::Union{String,Nothing}, bbox::Union{Nothing,Vector{T}}, geometry::Union{Nothing,AbstractGeometry{D,T}}, properties::Union{Nothing,Dict{String,Any}})

A Feature with D dimensional geometry.

source
GeoJSON.FeatureCollectionType
FeatureCollection{D,T}(bbox::Union{Nothing,Vector{T}}, features::Vector{Feature{D,T}}, crs::Union{Nothing,CRS})

A FeatureCollection with D dimensional geometry in its features.

source
GeoJSON.LazyFeatureCollectionType
LazyFeatureCollection{D,T}(bbox::Union{Nothing,Vector{T}}, features::Vector{LazyFeature{D,T}}, crs::Union{Nothing,String})

A FeatureCollection with D dimensional geometry in its features, but its features are lazily parsed from the GeoJSON string. Indexing into the collection will parse the feature. This can be more efficient when interested in only a few features from a large collection, or parsing a very large collection iteratively without loading it all into memory.

source
GeoJSON.LineStringType
LineString{D,T}(coordinates::Union{Nothing,Vector{NTuple{D,T}}})

A LineString geometry with D dimensions.

source
GeoJSON.MultiLineStringType
MultiLineString{D,T}(coordinates::Union{Nothing,Vector{Vector{NTuple{D,T}}}})

A MultiLineString geometry with D dimensions.

source
GeoJSON.MultiPointType
MultiPoint{D,T}(coordinates::Union{Nothing,Vector{NTuple{D,T}}})

A MultiPoint geometry with D dimensions.

source
GeoJSON.MultiPolygonType
MultiPolygon{D,T}(coordinates::Union{Nothing,Vector{Vector{Vector{NTuple{D,T}}}}})

A MultiPolygon geometry with D dimensions.

source
GeoJSON.PointType
Point{D,T}(coordinates::Union{Nothing,NTuple{D,T}})

A Point geometry with D dimensions.

source
GeoJSON.PolygonType
Polygon{D,T}(coordinates::Union{Nothing,Vector{Vector{NTuple{D,T}}}})

A Polygon geometry with D dimensions.

source
GeoJSON.readMethod
GeoJSON.read(json; lazyfc=false, ndim=2, numbertype=Float32)

Read GeoJSON to a GeoInterface.jl compatible object.

Arguments

  • json: A file path, string, IO, or bytes (AbstractVector{UInt8) containing JSON to read.
  • lazyfc::Bool=false: When reading in huge featurecollections (1M features), set lazyfc=true to only parse them into memory when accessed.
  • ndim::Int=2: Use 3 for 3D geometries, which is also used when 2D parsing fails.
  • numbertype::DataType=Float32: Use Float64 when the precision is required.
source
GeoJSON.writeMethod
write([io], geometry)

Write a GeoInterface.jl compatible feature or geometry to a GeoJSON String.

io may be a filename String or IO object.

source