GeoJSON
Documentation for GeoJSON.
See the GeoInterfaces.jl and Tables.jl documentation for most applicable methods.
GeoJSON.GeoJSON
— ModuleGeoJSON
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)
GeoJSON.CRS
— TypeCRS(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.
GeoJSON.Feature
— TypeFeature{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.
GeoJSON.FeatureCollection
— TypeFeatureCollection{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.
GeoJSON.GeometryCollection
— TypeGeometryCollection{D,T}(geometries::Vector{AbstractGeometry{D,T}})
A GeometryCollection geometry with D
dimensions.
GeoJSON.LazyFeatureCollection
— TypeLazyFeatureCollection{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.
GeoJSON.LineString
— TypeLineString{D,T}(coordinates::Union{Nothing,Vector{NTuple{D,T}}})
A LineString geometry with D
dimensions.
GeoJSON.MultiLineString
— TypeMultiLineString{D,T}(coordinates::Union{Nothing,Vector{Vector{NTuple{D,T}}}})
A MultiLineString geometry with D
dimensions.
GeoJSON.MultiPoint
— TypeMultiPoint{D,T}(coordinates::Union{Nothing,Vector{NTuple{D,T}}})
A MultiPoint geometry with D
dimensions.
GeoJSON.MultiPolygon
— TypeMultiPolygon{D,T}(coordinates::Union{Nothing,Vector{Vector{Vector{NTuple{D,T}}}}})
A MultiPolygon geometry with D
dimensions.
GeoJSON.Point
— TypePoint{D,T}(coordinates::Union{Nothing,NTuple{D,T}})
A Point geometry with D
dimensions.
GeoJSON.Polygon
— TypePolygon{D,T}(coordinates::Union{Nothing,Vector{Vector{NTuple{D,T}}}})
A Polygon geometry with D
dimensions.
GeoJSON.read
— MethodGeoJSON.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), setlazyfc=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.
GeoJSON.write
— Methodwrite([io], geometry)
Write a GeoInterface.jl compatible feature or geometry to a GeoJSON String
.
io
may be a filename String
or IO
object.