Git Product home page Git Product logo

geointerfacerfc.jl's Introduction

Note: this unregistered package served as a draft to redesign Julia's GeoInterface. Follow https://github.com/JuliaGeo/GeoInterface.jl for all current developments.

GeoInterfaceRFC

An interface for geospatial vector data in Julia

This Package describe a set of traits based on the Simple Features standard (SF) for geospatial vector data, including the SQL/MM extension with support for circular geometry.

Packages which support the GeoInterfaceRFC.jl interface can be found in INTEGRATIONS.md.

Changes with respect to SF

While we try to adhere to SF, there are changes and extensions to make it more Julian.

Function names

All function names are without the ST_ prefix and are lowercased. In some cases the names have changed as well, to be inline with common Julia functions. NumX becomes nx and Xn becomes getX:

GeometryType -> geomtype
NumGeometries -> ngeom
GeometryN -> getgeom
NumPatches -> npatch
# etc

We also simplified the dimension functions. From the three original (dimension, coordinateDimension, spatialDimension) there's now only the coordinate dimension, so not to overlap with the Julia ndims.

coordinateDimension -> ncoords

We've generalized the some functions:

SRID -> crs
envelope -> extent

And added a helper method to clarify the naming of coordinates.

coordnames = (:X, :Y, :Z, :M)

Coverage

Not all SF functions are implemented, either as a possibly slower fallback or empty descriptor or not at all. The following SF functions are not (yet) available.

dimension
spatialDimension
asText
asBinary
is3D
isMeasured
boundary

locateAlong
locateBetween

distance
buffer
convexHull

While the following functions have no implementation:

equals
disjoint
touches
within
overlaps
crosses
intersects
contains
relate

intersection
union
difference
symdifference

Implementation

GeoInterface provides a traits interface, not unlike Tables.jl, by

(a) a set of functions:

geomtype(geom)
ncoord(geom)
ngeom(geom)
getgeom(geom::geomtype, i)
...

(b) a set of types for dispatching on said functions. The types tells GeoInterface how to interpret the input object inside a GeoInterface function.

abstract Geometry
Point <: AbstractPoint <: AbstractGeometry
MultiPoint <: AbstractMultiPointGeometry <:AbstractGeometryCollection <: AbstractGeometry
...

For developers looking to implement the interface

GeoInterface requires five functions to be defined for a given geom:

GeoInterface.geomtype(geom::geomtype)::DataType = GeoInterface.X()
GeoInterface.ncoord(geomtype(geom), geom::geomtype)::Integer
GeoInterface.getcoord(geomtype(geom), geom::geomtype, i)::Real  # only for Points
GeoInterface.ngeom(geomtype(geom), geom::geomtype)::Integer
GeoInterface.getgeom(geomtype(geom), geom::geomtype, i)  # geomtype -> GeoInterface.Y

Where the getgeom could be an iterator (without the i) as well. It will return a new geom with the correct geomtype. The ngeom and getgeom are aliases for their geom specific counterparts, such as npoints and getpoint for LineStrings.

There are also optional generic methods that could help or speed up operations:

GeoInterface.crs(geom)::Union{Missing, GeoFormatTypes.CoordinateReferenceSystemFormat}
GeoInterface.extent(geom)  # geomtype -> GeoInterface.Rectangle

And lastly, there are many other optional functions for each specific geometry. GeoInterface provides fallback implementations based on the generic functions above, but these are not optimized. These are detailed in the next chapter.

Examples

A geom::geomtype with "Point"-like traits implements

GeoInterface.geomtype(geom::geomtype)::DataType = GeoInterface.Point()
GeoInterface.ncoord(::GeoInterface.Point, geom::geomtype)::Integer
GeoInterface.getcoord(::GeoInterface.Point, geom::geomtype, i)::Real

# Defaults
GeoInterface.ngeom(::GeoInterface.Point, geom)::Integer = 0
GeoInterface.getgeom(::GeoInterface.Point, geom::geomtype, i) = nothing

A geom::geomtype with "LineString"-like traits implements the following methods:

GeoInterface.geomtype(geom::geomtype)::DataType = GeoInterface.LineString()
GeoInterface.ncoord(::GeoInterface.LineString, geom::geomtype)::Integer

# These alias for npoint and getpoint
GeoInterface.ngeom(::GeoInterface.LineString, geom::geomtype)::Integer
GeoInterface.getgeom(::GeoInterface.LineString, geom::geomtype, i) # of geomtype Point

# Optional
GeoInterface.isclosed(::GeoInterface.LineString, geom::geomtype)::Bool
GeoInterface.issimple(::GeoInterface.LineString, geom::geomtype)::Bool
GeoInterface.length(::GeoInterface.LineString, geom::geomtype)::Real

A geom::geomtype with "Polygon"-like traits can implement the following methods:

GeoInterface.geomtype(geom::geomtype)::DataType = GeoInterface.Polygon()
GeoInterface.ncoord(::GeoInterface.Polygon, geom::geomtype)::Integer

# These alias for nring and getring
GeoInterface.ngeom(::GeoInterface.Polygon, geom::geomtype)::Integer
GeoInterface.getgeom(::GeoInterface.Polygon, geom::geomtype, i)::"LineString"

# Optional
GeoInterface.area(::GeoInterface.Polygon, geom::geomtype)::Real
GeoInterface.centroid(::GeoInterface.Polygon, geom::geomtype)::"Point"
GeoInterface.pointonsurface(::GeoInterface.Polygon, geom::geomtype)::"Point"
GeoInterface.boundary(::GeoInterface.Polygon, geom::geomtype)::"LineString"

A geom::geomtype with "GeometryCollection"-like traits has to implement the following methods:

GeoInterface.geomtype(geom::geomtype) = GeoInterface.GeometryCollection()
GeoInterface.ncoord(::GeoInterface.GeometryCollection, geom::geomtype)::Integer
GeoInterface.ngeom(::GeoInterface.GeometryCollection, geom::geomtype)::Integer
GeoInterface.getgeom(::GeoInterface.GeometryCollection,geom::geomtypem, i)::"Geometry"

A geom::geomtype with "MultiPoint"-like traits has to implement the following methods:

GeoInterface.geomtype(geom::geomtype) = GeoInterface.MultiPoint()
GeoInterface.ncoord(::GeoInterface.MultiPoint, geom::geomtype)::Integer

# These alias for npoint and getpoint
GeoInterface.ngeom(::GeoInterface.MultiPoint, geom::geomtype)::Integer
GeoInterface.getgeom(::GeoInterface.MultiPoint, geom::geomtype, i)::"Point"

A geom::geomtype with "MultiLineString"-like traits has to implement the following methods:

GeoInterface.geomtype(geom::geomtype) = GeoInterface.MultiLineString()
GeoInterface.ncoord(::GeoInterface.MultiLineString, geom::geomtype)::Integer

# These alias for nlinestring and getlinestring
GeoInterface.ngeom(::GeoInterface.MultiLineString, geom::geomtype)::Integer
GeoInterface.getgeom(::GeoInterface.MultiLineString,geom::geomtypem, i)::"LineString"

A geom::geomtype with "MultiPolygon"-like traits has to implement the following methods:

GeoInterface.geomtype(geom::geomtype) = GeoInterface.MultiPolygon()
GeoInterface.ncoord(::GeoInterface.MultiPolygon, geom::geomtype)::Integer

# These alias for npolygon and getpolygon
GeoInterface.ngeom(::GeoInterface.MultiPolygon, geom::geomtype)::Integer
GeoInterface.getgeom(::GeoInterface.MultiPolygon, geom::geomtype, i)::"Polygon"

Testing the interface

GeoInterface provides a Testsuite for a geom type to check whether all functions that have been implemented also work as expected.

GeoInterface.test_interface_for_geom(geom)

geointerfacerfc.jl's People

Contributors

evetion avatar meggart avatar visr avatar yeesian avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geointerfacerfc.jl's Issues

Review

Still writing things down, this post will be edited/extended!

This is gonna be a long post, not sure about the right format.

Thanks for taking the time to put together an proposal! SF is essential, although like most OGC standards, falls into the rabbit hole of prescriptive standards on top of a descriptive one. The latter is way more developer friendly and is what were doing here now. Therefore I would like to extend and dare I say improve the SF in this package, much like PostGIS has done, for usability. A nice implementation is also over at R.

Functions

I would like to add at least all the functions defined on the abstract geometry type, per SF, although we can play with the names.

  • dimension() : Integer
  • coordinateDimension() : Integer
  • spatialDimension() : Integer
  • geometry Type() : String
  • SRID() : Integer
  • envelope() : Geometry
  • asText() : String
  • asBinary () : Binary
  • isEmpty () : Boolean
  • isSimple() : Boolean
  • is3D() : Boolean
  • isMeasured() : Boolean
  • boundary () : Geometry

Not all of them need to be implemented, but fixing the spatial reference and an easy implementation for the bounding box seem essential to me. Speaking of functions that could use some actual algorithm, where will those be? The whole suite of DE-9IM functions? Pure Julia, or GEOS? Can you choose a backing engine (like a CPU/GPU switch?). Do we provide an area function (defined in SF for Polygons) or length. Where do these implementations belong?

Types

Screenshot 2020-01-14 at 22 00 22

As seen above, there are a lot more types than we now have defined. There are also intermediate types (Curve) or subtypes (Triangle). On top of this, the ISO SQL MM standard extends this, partly implemented and extended by PostGIS.

IO

Parsing WKT/WKB could be in another package that also implements this Interface? Same goes for GeoJSON and many other formats. We probably don't need a function for this.

Nice interface!

I love this well-structured and organized source code ๐Ÿ’ฏ I was able to digest it in a few minutes without going back and forth in different files. Thank you for this amazing effort.

I have a few questions:

  1. What is the pointonsurface trait?
  2. Can we generalize area to volume and reinterpret it as an N-dimensional trait? Like in the volume of a 2D object is its area? Would it make sense to erase area from the traits list and only use volume so that user code is agnostic to dimension?
  3. Similar question for the pointonsurface, is there anything specific to 2D or it could be generalized?
  4. What is the "m" coordinate in the defaults.jl?

Please let me know if you would like help with docstrings, I saw that some functions don't have documentation.

Doc strings?

A problem with GeoInterface.jl is it doesn't really have doc strings describing what the interface does.

The GeoInterface.jl file could have some solid docs describing what the types are for and what the methods do. I would break it up into types.jl for types and interface.jl for the methods, as if they are documented they will get a lot longer.

package implementations

This issue is to track work-in-progress implementations of the GeoInterfaceRFC as proposed in this package. Since this package is of yet only a RFC draft, none of the branches should be merged yet. They can however be useful for testing out the strengths and weaknesses in the proposed RFC.

A list of packages that may implement this interface is also given here: https://github.com/yeesian/GeoInterfaceRFC.jl#affected-packages

Implementations
https://github.com/visr/GeometryBasics.jl/tree/rfc
https://github.com/visr/GeoJSONTables.jl/tree/rfc
https://github.com/JuliaGeo/LibGEOS.jl/tree/rfc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.