JS API
Map Object
QueryEngine Object
Layer Object
Feature Object
Query Object
GeoJson Function Library (Experimental)

GeoJson Function Library (Experimental)

The GeoJson function library contains a multitude of functions for creating, manipulating and adapting GeoJSON data.

These functions are used internally by the Mapzania JS API itself, but due to their utility, documentation is provided here for the user to benefit from these functions.

The functions are static and live in the Mapzania.GeoJson namespace (e.g. Mapzania.GeoJson.createPolygon()).

NOTE: The GeoJson function library is a work in progress and currently does not have full coverage of all possible parameters for each function. Where the coverage is an issue, it will be made clear in the documentation below.

Furthermore, there is a possibilty that we may introduce breaking changes to these function (although this is highly unlikely). If so, we will add alerts to the news section and clearly document these changes.

GeoJson Creation

createFeatureCollection

Creates a GeoJSON FeatureCollection object.

Parameters

Name Required Description
source No If source is not set, the FeatureCollection will be empty. Also accepts a FeatureCollection, an array of Features or a single Feature.

createFeature

Creates a GeoJSON Feature object.

Parameters

Name Required Description
geometry Yes The GeoJSON geometry object of the feature.
properties No The properties object of the feature. If not set, the properties object will be an empty object.
id No The id of the feature. Undefined if not set.

createPoint

Creates a GeoJSON Point geometry object.

Parameters

Name Required Description
param1 Yes Either a coordinate array of two values ([x,y]) or a numeric x-value.
param2 No If param1 is a numeric x-value, param2 is a numeric y-value

Example

var gjson = Mapzania.GeoJson.createPoint([20.33, 30.64]);
var gjson = Mapzania.GeoJson.createPoint(20.33, 30.64);

createMultiPoint

Creates a GeoJSON MultiPoint geometry object.

Parameters

Name Required Description
coordinates Yes The GeoJSON coordinates of the MultiPoint.

Example

var gjson = Mapzania.GeoJson.createMultiPoint([[20.33, 30.64],[16.23, 21.59]]);

createLineString

Creates a GeoJSON LineString geometry object.

Parameters

Name Required Description
coordinates Yes The GeoJSON coordinates of the LineString.

Example

var gjson = Mapzania.GeoJson.createLineString([[20.33, 30.64],[16.23, 21.59]]);

createMultiLineString

Creates a GeoJSON MultiLineString geometry object.

Parameters

Name Required Description
coordinates Yes The GeoJSON coordinates of the MultiLineString.

Example

var gjson = Mapzania.GeoJson.createMultiLineString([[[20.33, 30.64],[16.23, 21.59]],[[12.43, 41.22],[19.87, 32.43]]]);

createPolygon

Creates a GeoJSON Polygon geometry object.

Parameters

Name Required Description
coordinates Yes The GeoJSON coordinates of the Polygon or a bounding box coordinate array.

Example

var gjson = Mapzania.GeoJson.createPolygon([[[20.33, 30.64],[16.23, 21.59],[20.33, 30.64]],[[12.43, 41.22],[19.87, 32.43],[12.43, 41.22]]]);
var gjson = Mapzania.GeoJson.createPolygon([12.1, 3.4, 14.3, 4.2]);

createMultiPolygon

Creates a GeoJSON MultiPolygon geometry object.

Parameters

Name Required Description
coordinates Yes The GeoJSON coordinates of the MultiPolygon.

Example

var gjson = Mapzania.GeoJson.createMultiPolygon([[[[20.33, 30.64],[16.23, 21.59],[20.33, 30.64]],[[12.43, 41.22],[19.87, 32.43],[12.43, 41.22]]],[[[20.33, 30.64],[16.23, 21.59],[20.33, 30.64]],[[12.43, 41.22],[19.87, 32.43],[12.43, 41.22]]]]);

GeoJson Editing

appendPointToLineString

Adds the coordinates of a GeoJSON Point object to the end of a GeoJSON LineString object.

Parameters

Name Required Description
line Yes The LineString object to which the Point will be appended.
point Yes The Point object that will be appended to the LineString.

appendPointToPolygon

Adds the coordinates of a GeoJSON Point object to the end of the shell of a GeoJSON Polygon object.

Parameters

Name Required Description
poly Yes The Polygon object to which the Point will be appended.
point Yes The Point object that will be appended to the shell of the Polygon.

merge

Merges either a Feature, an array of Features or a FeatureCollection to an existing FeatureCollection.

Parameters

Name Required Description
source Yes A FeatureCollection, an array of Features or a single Feature.
destination Yes A FeatureCollection.

GeoJson Geospatial Operators

intersection

Finds the GeoJSON geometry that makes up the intersection of two other geometries.

Parameters

Name Required Description
geometry1 Yes Any GeoJSON geometry object.
geometry2 Yes Any GeoJSON geometry object.

Currently Implemented

At present this function is only implemented for the geometry types in the table below.

geometry2
Point MultiPoint LineString MultiLineString Polygon MultiPolygon BoundingBox
geometry1
Point - - - - - - -
MultiPoint - - - - - - -
LineString - - YES - - - -
MultiLineString - - - - - - -
Polygon - - - - - - -
MultiPolygon - - - - - - -
BoundingBox - - - - - - -

intersects

Determines whether two GeoJSON geometries intersect as a boolean.

Parameters

Name Required Description
geometry1 Yes Any GeoJSON geometry object.
geometry2 Yes Any GeoJSON geometry object.

Currently Implemented

At present this function is only implemented for the geometry types in the table below.

geometry2
Point MultiPoint LineString MultiLineString Polygon MultiPolygon BoundingBox
geometry1
Point - - - - - - -
MultiPoint - - - - - - -
LineString - - YES - - - -
MultiLineString - - - - - - -
Polygon - - - - YES - -
MultiPolygon - - - - - - -
BoundingBox - - - - - - YES

isContainedBy

Determines whether a GeoJSON geometry is contained by another GeoJson geometry as a boolean.

Parameters

Name Required Description
geometry Yes Any GeoJSON geometry object.
container Yes Any GeoJSON geometry object.

Currently Implemented

At present this function is only implemented for the geometry types in the table below.

container
Point MultiPoint LineString MultiLineString Polygon MultiPolygon BoundingBox
geometry
Point - - YES(ring) - YES - YES
MultiPoint - - - - - - -
LineString - - YES(ring) - - - -
MultiLineString - - - - - - -
Polygon - - - - YES - -
MultiPolygon - - - - - - -
BoundingBox - - - - - - -

slice

Slices a GeoJSON geometry into multiple geometries based on intersections with other geometries.

NOTE: In the case of the Point geometry, the point will first snap to the other geometry before slicing.

Parameters

Name Required Description
geometry Yes Any GeoJSON geometry object.
sliceBy Yes Any GeoJSON geometry object.

Currently Implemented

At present this function is only implemented for the geometry types in the table below.

sliceBy
Point MultiPoint LineString MultiLineString Polygon MultiPolygon BoundingBox
geometry
Point - - - - - - -
MultiPoint - - - - - - -
LineString YES - - - - - -
MultiLineString - - - - - - -
Polygon - - - - - - -
MultiPolygon - - - - - - -
BoundingBox - - - - - - -

snapTo

Snaps a point onto another geometry.

Parameters

Name Required Description
point Yes Any GeoJSON Point object.
geometry Yes Any GeoJSON geometry object.

Currently Implemented

At present this function is only implemented for the geometry types in the table below.

geometry
Point MultiPoint LineString MultiLineString Polygon MultiPolygon BoundingBox
Point - - YES YES - - -

rotate

returns a rotated GeoJson geometry.

Parameters

Name Required Description
geometry Yes Any GeoJSON geometry object.
origin Yes Any GeoJSON Point object around which to rotate the geometry
angle Yes The andle in radians to rotate the geometry

GeoJson Geometry Functions

getArea

Calculates the area of a GeoJSON geometry object as a numeric value.

Parameters

Name Required Description
geometry Yes Any GeoJSON Point, MultiPoint, LineString, MultiLineString, Polygon or MultiPolygon object.

getCentroid

Calculates the centroid of a GeoJSON geometry object or BoundingBox as a GeoJSON Point.

Parameters

Name Required Description
geometry Yes Any GeoJSON Point, MultiPoint, LineString, MultiLineString, Polygon or MultiPolygon object or a BoundingBox array.

getFeatureAt

Returns a GeoJSON feature at a given distance along a GeoJSON LineString or MultiLineString.

The properties of the feature also include the rotation angle of the LineString/MultiLineString at the given distance.

Parameters

Name Required Description
geometry Yes Any GeoJSON LineString or MultiLineString.
distanceAlong Yes The distance along the GeoJSON LineString or MultiLineString at which to obtain the Feature.

getLength

Calculates the length of a GeoJSON geometry object as a numeric value.

Parameters

Name Required Description
geometry Yes Any GeoJSON Point, MultiPoint, LineString, MultiLineString, Polygon or MultiPolygon object.

getLongest

Returns the longest GeoJSON LineString in a GeoJSON MultiLine.

Parameters

Name Required Description
geometry Yes Any GeoJSON MultiLineString.

getBoundingBox

Calculates the Bounding Box of a GeoJSON geometry object as a Bounding Box array.

Parameters

Name Required Description
geometry Yes Any GeoJSON Point, MultiPoint, LineString, MultiLineString, Polygon or MultiPolygon object.

GeoJson Utility Functions

getType

Determines the type of a GeoJson geometry object as a string.

isBoundingBox

Determines if an object is a bounding box as a boolean.