Документация Engee

GeoJSON

Страница в процессе перевода.

Documentation for GeoJSON.

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

GeoJSON

docs stable blue docs dev blue 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)
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.

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.

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.

GeometryCollection{D,T}(geometries::Vector{AbstractGeometry{D,T}})

A GeometryCollection geometry with D dimensions.

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.

LineString{D,T}(coordinates::Union{Nothing,Vector{NTuple{D,T}}})

A LineString geometry with D dimensions.

MultiLineString{D,T}(coordinates::Union{Nothing,Vector{Vector{NTuple{D,T}}}})

A MultiLineString geometry with D dimensions.

MultiPoint{D,T}(coordinates::Union{Nothing,Vector{NTuple{D,T}}})

A MultiPoint geometry with D dimensions.

MultiPolygon{D,T}(coordinates::Union{Nothing,Vector{Vector{Vector{NTuple{D,T}}}}})

A MultiPolygon geometry with D dimensions.

Point{D,T}(coordinates::Union{Nothing,NTuple{D,T}})

A Point geometry with D dimensions.

Polygon{D,T}(coordinates::Union{Nothing,Vector{Vector{NTuple{D,T}}}})

A Polygon geometry with D dimensions.

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.

write([io], geometry)

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

io may be a filename String or IO object.