geojson-0.0.2: A thin GeoJSON Layer above the json library

Safe HaskellNone

Data.Geospatial

Synopsis

Documentation

type GeoPositionWithoutCRS = [Float]Source

(WithoutCRS 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 eastingnorthing (+- Altitude) or lonlat (+- Altitude)

data GeospatialGeometry Source

See section 2.1 Geometry Objects in the GeoJSON Spec.

Instances

Eq GeospatialGeometry 
Show GeospatialGeometry 
JSON GeospatialGeometry

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

>>> encode NoGeometry
"null"
>>> decode "null" :: Result GeospatialGeometry
Ok NoGeometry
>>> encode lShapedPoly == lShapedPolyJSON
True
>>> decode lShapedPolyJSON == Ok lShapedPoly
True
>>> encode emptyPoly == emptyPolyJSON
True
>>> decode emptyPolyJSON == Ok emptyPoly
True
>>> encode emptyMultiPoly == emptyMultiPolyJSON
True
>>> decode emptyMultiPolyJSON == Ok emptyMultiPoly
True
>>> encode singleLineMultiLine == singleLineMultiLineJSON
True
>>> decode singleLineMultiLineJSON == Ok singleLineMultiLine
True
>>> encode multiLine == multiLineJSON
True
>>> decode multiLineJSON == Ok multiLine
True
>>> encode emptyCollection == emptyCollectionJSON
True
>>> decode emptyCollectionJSON == Ok emptyCollection
True
>>> encode bigassCollection == bigassCollectionJSON
True
>>> decode bigassCollectionJSON == Ok bigassCollection
True

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 
JSON CRSObject

encode and decodes CRS Objects to and from GeoJSON

>>> encode testLinkCRS == testLinkCRSJSON
True
>>> decode testLinkCRSJSON == Ok testLinkCRS
True
>>> encode testNamedCRS == testNamedCRSJSON
True
>>> decode testNamedCRSJSON == Ok testNamedCRS
True
>>> encode testEPSG == testEPSGJSON
True
>>> decode testEPSGJSON == Ok testEPSG
True
>>> encode NoCRS
"null"
>>> decode "null" == Ok NoCRS
True

type GeoPropertyObject = JSValueSource

According to section 2.2 Feature Objects of the GeoJSON spec, the properties object can be any JSON object, or a null value, we may as well just make it a Type Alias for JSValue, even though it has a wider scope (Integer, Rational, String etc...) to take advantage of the solid JSON code out there to handle generic objects and the null value

type BoundingBoxWithoutCRS = [Float]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 Source

See Section 2.2 Feature Objects of the GeoJSON spec.

Instances

Eq GeoFeature 
Show GeoFeature 
JSON GeoFeature

encodes and decodes Feature objects to and from GeoJSON

>>> encode bigFeature == bigFeatureJSON
True
>>> decode bigFeatureJSON == Ok bigFeature
True
>>> encode featureWithNoProperties == featureWithNoPropertiesJSON
True
>>> decode featureWithNoPropertiesJSON == Ok featureWithNoProperties
True
>>> encode featureWithNoId == featureWithNoIdJSON
True
>>> decode featureWithNoIdJSON == Ok featureWithNoId
True
>>> encode featureWithNoBBox == featureWithNoBBoxJSON
True
>>> decode featureWithNoBBoxJSON == Ok featureWithNoBBox
True
>>> encode featureWithNoGeometry == featureWithNoGeometryJSON
True
>>> decode featureWithNoGeometryJSON == Ok featureWithNoGeometry
True

data GeoFeatureCollection Source

See Section 2.3 Feature Collection Objects of the GeoJSON spec

Instances

Eq GeoFeatureCollection 
Show GeoFeatureCollection 
JSON GeoFeatureCollection

Encodes and Decodes FeatureCollection objects to and from GeoJSON

>>> encode bigAssFeatureCollection == bigAssFeatureCollectionJSON
True
>>> decode bigAssFeatureCollectionJSON == Ok bigAssFeatureCollection
True
>>> encode bigAssFeatureCollectionWithNoBBox == bigAssFeatureCollectionWithNoBBoxJSON
True
>>> decode bigAssFeatureCollectionWithNoBBoxJSON == Ok bigAssFeatureCollectionWithNoBBox
True
>>> encode emptyFeatureCollectionWithBBox == emptyFeatureCollectionWithBBoxJSON
True
>>> decode emptyFeatureCollectionWithBBoxJSON == Ok emptyFeatureCollectionWithBBox
True
>>> encode emptyFeatureCollection == emptyFeatureCollectionJSON
True
>>> decode emptyFeatureCollectionJSON == Ok emptyFeatureCollection
True

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 JSON 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.orgrefepsg4326 -> [JSON](http:spatialreference.orgrefepsg4326json/ WGS84 in JSON) is represented thus: