Skip to content

Commit

Permalink
Update for julia0.5 (#8)
Browse files Browse the repository at this point in the history
* update for julia0.5

* remove julia 0.4 testing from travis

* x/y/z -> x/y/zcoord

closes #9

* some more x/y/z to xcoord/ycoord/zcoord

and adding Travis testing for 0.6 since nightly is about to diverge
  • Loading branch information
yeesian authored Apr 30, 2017
1 parent 964d7cf commit 5107b71
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ To support operations or visualization of multiple (but similar) implementations
## GEO Interface

### AbstractPosition
A position can be thought of as a tuple of numbers. There must be at least two elements, and may be more. The order of elements must follow `x`, `y`, `z` order (e.g. easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Hence it requires the following methods:
A position can be thought of as a tuple of numbers. There must be at least two elements, and may be more. The order of elements must follow `x`, `y`, `z` order (e.g. easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). It requires the following methods:

- `x(::AbstractPosition)::Float64`
- `y(::AbstractPosition)::Float64`
- `z(::AbstractPosition)::Float64`
- `xcoord(::AbstractPosition)::Float64`
- `ycoord(::AbstractPosition)::Float64`
- `zcoord(::AbstractPosition)::Float64`
- `hasz(::AbstractPosition)::Bool` (`false` by default)

Remark: Although the specification allows the representation of up to 3 dimensions, not all algorithms support require all 3 dimensions. Also, if you are working with an arbitrary `obj::AbstractPosition`, you should call `hasz(obj)` before calling `z(obj)`.
Remark: Although the specification allows the representation of up to 3 dimensions, not all algorithms support require all 3 dimensions. Also, if you are working with an arbitrary `obj::AbstractPosition`, you should call `hasz(obj)` before calling `zcoord(obj)`.

### AbstractGeometry
Represents vector geometry, and encompasses the following abstract types: `AbstractPoint, AbstractMultiPoint, AbstractLineString, AbstractMultiLineString, AbstractMultiPolygon, AbstractPolygon`. It requires the `coordinates` method, where
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia 0.4
Compat 0.8
julia 0.5
16 changes: 7 additions & 9 deletions src/GeoInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ __precompile__()

module GeoInterface

using Compat

export AbstractPosition, Position,
AbstractGeometry, AbstractGeometryCollection, GeometryCollection,
AbstractPoint, Point,
Expand All @@ -16,27 +14,27 @@ module GeoInterface
AbstractFeatureCollection, FeatureCollection,

geotype, # methods
x, y, z, hasz,
xcoord, ycoord, zcoord, hasz,
coordinates,
geometries,
geometry, bbox, crs, properties,
features

abstract AbstractPosition{T <: Real} <: AbstractVector{T}
geotype(::AbstractPosition) = :Position
x(::AbstractPosition) = error("x(::AbstractPosition) not defined.")
y(::AbstractPosition) = error("y(::AbstractPosition) not defined.")
xcoord(::AbstractPosition) = error("xcoord(::AbstractPosition) not defined.")
ycoord(::AbstractPosition) = error("ycoord(::AbstractPosition) not defined.")
# optional
z(::AbstractPosition) = error("z(::AbstractPosition) not defined.")
zcoord(::AbstractPosition) = error("zcoord(::AbstractPosition) not defined.")
hasz(::AbstractPosition) = false
coordinates(p::AbstractPosition) = hasz(p) ? Float64[x(p),y(p),z(p)] : Float64[x(p),y(p)]
coordinates(p::AbstractPosition) = hasz(p) ? Float64[xcoord(p),ycoord(p),zcoord(p)] : Float64[xcoord(p),ycoord(p)]
# (Array-like indexing # http://julia.readthedocs.org/en/latest/manual/arrays/#arrays)
Base.eltype{T <: Real}(p::AbstractPosition{T}) = T
Base.ndims(AbstractPosition) = 1
Base.length(p::AbstractPosition) = hasz(p) ? 3 : 2
Base.size(p::AbstractPosition) = (length(p),)
Base.size(p::AbstractPosition, n::Int) = (n == 1) ? length(p) : 1
Base.getindex(p::AbstractPosition, i::Int) = (i==1) ? x(p) : (i==2) ? y(p) : (i==3) ? z(p) : nothing
Base.getindex(p::AbstractPosition, i::Int) = (i==1) ? xcoord(p) : (i==2) ? ycoord(p) : (i==3) ? zcoord(p) : nothing
Base.convert(::Type{Vector{Float64}}, p::AbstractPosition) = coordinates(p)
# Base.linearindexing{T <: AbstractPosition}(::Type{T}) = LinearFast()

Expand Down Expand Up @@ -69,7 +67,7 @@ module GeoInterface
geotype(::AbstractFeature) = :Feature
geometry(obj::AbstractFeature) = error("geometry(::AbstractFeature) not defined.")
# optional
properties(obj::AbstractFeature) = Dict{AbstractString,Any}()
properties(obj::AbstractFeature) = Dict{String,Any}()
bbox(obj::AbstractFeature) = nothing
crs(obj::AbstractFeature) = nothing

Expand Down
14 changes: 7 additions & 7 deletions src/geotypes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Coordinate Reference System Objects
# (has keys "type" and "properties")
# TODO: Handle full CRS spec
typealias CRS Dict{AbstractString,Any}
typealias CRS Dict{String,Any}

# Bounding Boxes
# The value of the bbox member must be a 2*n array,
Expand All @@ -17,9 +17,9 @@ typealias Position Vector{Float64}
# (x, y, [z, ...]) - meaning of additional elements undefined.
# In an object's contained geometries, Positions must have uniform dimensions.
geotype(::Position) = :Position
x(p::Position) = p[1]
y(p::Position) = p[2]
z(p::Position) = hasz(p) ? p[3] : zero(T)
xcoord(p::Position) = p[1]
ycoord(p::Position) = p[2]
zcoord(p::Position) = hasz(p) ? p[3] : zero(T)
hasz(p::Position) = length(p) >= 3
coordinates(obj::Position) = obj

Expand Down Expand Up @@ -125,10 +125,10 @@ geometries(collection::GeometryCollection) = collection.geometries

type Feature <: AbstractFeature
geometry::Union{Void, AbstractGeometry}
properties::Union{Void, Dict{AbstractString,Any}}
properties::Union{Void, Dict{String,Any}}
end
Feature(geometry::Union{Void,GeoInterface.AbstractGeometry}) = Feature(geometry, Dict{AbstractString,Any}())
Feature(properties::Dict{AbstractString,Any}) = Feature(nothing, properties)
Feature(geometry::Union{Void,GeoInterface.AbstractGeometry}) = Feature(geometry, Dict{String,Any}())
Feature(properties::Dict{String,Any}) = Feature(nothing, properties)
geometry(feature::Feature) = feature.geometry
properties(feature::Feature) = feature.properties
bbox(feature::Feature) = get(feature.properties, "bbox", nothing)
Expand Down

0 comments on commit 5107b71

Please sign in to comment.