geojson-1.1.0: A thin GeoJSON Layer above the aeson library

MaintainerDom De Re
Safe HaskellNone

Data.Geospatial

Contents

Description

Refer to the GeoJSON Spec http:www.geojson.org/geojson-spec.html

Synopsis

Types

type GeoPositionWithoutCRS = [Double]Source

(GeoPositionWithoutCRS is a catch all for indeterminate CRSs and for expression of positions before a CRS has been determined

data GeoPosition Source

see Section 2.1.1 Position in the GeoJSON Spec, I make the assumption here that the only position types we will use will involve easting or northing (+ve or -ve Altitude) or lon or lat (+ve or -ve Altitude)

data GeospatialGeometry Source

See section 2.1 Geometry Objects in the GeoJSON Spec.

Instances

Eq GeospatialGeometry 
Show GeospatialGeometry 
ToJSON GeospatialGeometry

encodes and Geometry Objects to GeoJSON (refer to source to see the values for the test values)

>>> A.encode NoGeometry
"null"
>>> (A.decode . A.encode) lShapedPoly == Just lShapedPoly
True
>>> (A.decode . A.encode) emptyPoly == Just emptyPoly
True
>>> (A.decode . A.encode) emptyMultiPoly == Just emptyMultiPoly
True
>>> (A.decode . A.encode) singleLineMultiLine == Just singleLineMultiLine
True
>>> (A.decode . A.encode) multiLine == Just multiLine
True
>>> (A.decode . A.encode) emptyCollection == Just emptyCollection
True
>>> (A.decode . A.encode) bigassCollection == Just bigassCollection
True
FromJSON GeospatialGeometry

encodes and decodes Geometry Objects to and from GeoJSON (refer to source to see the values for the test values)

>>> decode' lShapedPolyJSON == Just lShapedPoly
True
>>> decode' emptyPolyJSON == Just emptyPoly
True
>>> decode' emptyMultiPolyJSON == Just emptyMultiPoly
True
>>> decode' singleLineMultiLineJSON == Just singleLineMultiLine
True
>>> decode' multiLineJSON == Just multiLine
True
>>> decode' emptyCollectionJSON == Just emptyCollection
True
>>> decode' bigassCollectionJSON == Just bigassCollection
True

Aeson doesnt decode null into Null unfortunately

decode' null :: Maybe GeospatialGeometry Just NoGeometry

data CRSObject Source

See Section 3 Coordinate Reference System Objects in the GeoJSON Spec NoCRS is required because no crs attribute in a GeoJSON feature is NOT the same thing as a null crs attribute. no crs value implies the default CRS, while a null CRS means you cannot assume a CRS, null will mapped to NoCRS while a non-existent attribute will be mapped to a Nothing Maybe value

Instances

Eq CRSObject 
Show CRSObject 
ToJSON CRSObject

encode CRS Objects to GeoJSON

>>> (A.decode . A.encode) testLinkCRS == Just testLinkCRS
True
>>> (A.decode . A.encode) testNamedCRS == Just testNamedCRS
True
>>> (A.decode . A.encode) testEPSG == Just testEPSG
True
>>> A.encode NoCRS
"null"
FromJSON CRSObject

encode and decodes CRS Objects to and from GeoJSON

>>> (A.decode . BS.pack) testLinkCRSJSON == Just testLinkCRS
True
>>> (A.decode . BS.pack) testNamedCRSJSON == Just testNamedCRS
True
>>> (A.decode . BS.pack) testEPSGJSON == Just testEPSG
True

Aeson doesnt decode null to Null unfortunately

(A.decode . BS.pack) null == Just NoCRS True

type BoundingBoxWithoutCRS = [Double]Source

See Section 4 Bounding Boxes of the GeoJSON spec, The length of the list/array must be 2*n where n is the dimensionality of the position type for the CRS with min values first followed by the max values, wich both the min/max sets following the same axis order as the CRS, e.g for WGS84: minLongitude, minLatitude, maxLongitude, maxLatitude The spec mentions that it can be part of a geometry object too but doesnt give an example, This implementation will ignore bboxes on Geometry objects, they can be added if required.

data GeoFeature a Source

See Section 2.2 Feature Objects of the GeoJSON spec. Parameterised on the property type

Instances

Eq a => Eq (GeoFeature a) 
Show a => Show (GeoFeature a) 
ToJSON a => ToJSON (GeoFeature a)

encodes Feature objects to and from GeoJSON

>>> (A.decode . A.encode) bigFeature == Just bigFeature
True
>>> (A.decode . A.encode) featureWithNoProperties == Just featureWithNoProperties
True
>>> (A.decode . A.encode) featureWithNoId == Just featureWithNoId
True
>>> (A.decode . A.encode) featureWithNoBBox == Just featureWithNoBBox
True
>>> (A.decode . A.encode) featureWithNoGeometry == Just featureWithNoGeometry
True
FromJSON a => FromJSON (GeoFeature a)

decodes Feature objects to and from GeoJSON

>>> decode' bigFeatureJSON == Just bigFeature
True
>>> decode' featureWithNoPropertiesJSON == Just featureWithNoProperties
True
>>> decode' featureWithNoIdJSON == Just featureWithNoId
True
>>> decode' featureWithNoBBoxJSON == Just featureWithNoBBox
True
>>> decode' featureWithNoGeometryJSON == Just featureWithNoGeometry
True

data GeoFeatureCollection a Source

See Section 2.3 Feature Collection Objects of the GeoJSON spec

Instances

Eq a => Eq (GeoFeatureCollection a) 
Show a => Show (GeoFeatureCollection a) 
ToJSON a => ToJSON (GeoFeatureCollection a)

Encodes FeatureCollection objects to and from GeoJSON

>>> (A.decode . A.encode) bigAssFeatureCollection == Just bigAssFeatureCollection
True
>>> (A.decode . A.encode) bigAssFeatureCollectionWithNoBBox == Just bigAssFeatureCollectionWithNoBBox
True
>>> (A.decode . A.encode) emptyFeatureCollectionWithBBox == Just emptyFeatureCollectionWithBBox
True
>>> (A.decode . A.encode) emptyFeatureCollection == Just emptyFeatureCollection
True
FromJSON a => FromJSON (GeoFeatureCollection a)

Decodes FeatureCollection objects to and from GeoJSON

>>> decode' bigAssFeatureCollectionJSON == Just bigAssFeatureCollection
True
>>> decode' bigAssFeatureCollectionWithNoBBoxJSON == Just bigAssFeatureCollectionWithNoBBox
True
>>> decode' emptyFeatureCollectionWithBBoxJSON == Just emptyFeatureCollectionWithBBox
True
>>> decode' emptyFeatureCollectionJSON == Just emptyFeatureCollection
True

Functions

stripCRSFromPosition :: GeoPosition -> GeoPositionWithoutCRSSource

the GeoPosition is a bit special in that when you convert it to GeoJSON, it will lose the CRS info attached to it and cannot be read back in from the GeoJSON. Hence it is ineligible for the FromJSON type class, so this function will strip it down to a GeoPositionWithoutCRS, which is eligible

defaultCRS :: CRSObjectSource

The default CRS according to Section 3 Coordinate Reference System Objects is WGS84 which I believe, from http://spatialreference.org/ref/epsg/4326/ which translates to this in JSON: http://spatialreference.org/ref/epsg/4326/json/) is represented thus:

Lenses

Geometry Lenses

Feature Lenses

properties :: forall a a. Lens (GeoFeature a) (GeoFeature a) a aSource

Prisms

Geometry

CRS