Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Geometry

JMap.Geometry

This section contains geometry related methods.

JMap geometry service is based on turfjs implementation.

Index

Functions

bboxIntersect

  • JMap.Geometry.bboxIntersect

    Returns true if the first bbox intersect the second one.

    example
    
    const bbox1 = { sw: { x: 10, 10 }, sw: { x: 20, 20 }}
    const bbox2 = { sw: { x: 12, 12 }, sw: { x: 14, 18 }}
    // The method will return true
    const areIntersecting = JMap.Geometry.bboxIntersect(bbox1, bbox2)

    Parameters

    Returns boolean

checkBbox

  • JMap.Geometry.checkBbox

    Throw an error if the provided parameter is not a valid boundary box.

    example
    
    let bbox = { sw: { x: 10, y: 10 }, ne: { x: 12, y: 12 } }
    // The following instruction will not throw an error
    JMap.Geometry.checkBbox(bbox)
    
    bbox = { sw: { x: 10, y: 10 } } // missing "ne" attribute
    // The following instruction will throw an error
    JMap.Geometry.checkBbox(bbox)

    Parameters

    Returns void

checkCircle

  • checkCircle(circle: JCircle): void
  • JMap.Geometry.checkCircle

    Throw an error if the provided parameter is not a valid circle.

    example
    
    let circle = { center: { x: 10, y: 10 }, radius: 10 }
    // The following instruction will not throw an error
    JMap.Geometry.checkCircle(circle)
    
    circle = { radius: 10 } // missing center
    // The following instruction will throw an error
    JMap.Geometry.checkCircle(circle)

    Parameters

    • circle: JCircle

      The circle object to check

    Returns void

checkLine

  • checkLine(line: JLine): void
  • JMap.Geometry.checkLine

    Throw an error if the provided parameter is not a valid polygon.

    example
    
    let line = [[ 10, 10 ], [ 11, 11 ], [ 12, 12 ]]
    // The following instruction will not throw an error
    JMap.Geometry.checkLine(line)
    
    line = [] // empty line
    // The following instruction will throw an error
    JMap.Geometry.checkLine(line)

    Parameters

    • line: JLine

      The line object to check

    Returns void

checkLocation

  • JMap.Geometry.checkLocation

    Throw an error if the provided parameter is not a valid location.

    example
    
    let location = { x: 10, y: 10 }
    // The following instruction will not throw an error
    JMap.Geometry.checkLocation(location)
    
    location = {} // empty object
    // The following instruction will throw an error
    JMap.Geometry.checkLocation(location)

    Parameters

    • location: JLocation

      The location object to check

    Returns void

checkPolygon

  • JMap.Geometry.checkPolygon

    Throw an error if the provided parameter is not a valid polygon.

    example
    
    let polygon = [[ 10, 10 ], [ 11, 11 ], [ 12, 12 ], [ 10, 10 ]]
    // The following instruction will not throw an error
    JMap.Geometry.checkPolygon(polygon)
    
    polygon = [] // empty array
    // The following instruction will throw an error
    JMap.Geometry.checkPolygon(polygon)

    Parameters

    • polygon: JPolygon

      The polygon array to check

    Returns void

convertArea

  • JMap.Geometry.convertArea

    Converts the distance from a unit to another.

    throws

    if invalid parameters

    example
    
    // returns 2 square kilometers in square miles
    JMap.Geometry.convertArea(2, "miles")
    
    // returns 200 square meters in square yards
    JMap.Geometry.convertArea(200, "yards", "meters")

    Parameters

    Returns number

convertLength

  • JMap.Geometry.convertLength

    Converts the distance from a unit to another.

    throws

    if invalid parameters

    example
    
    // returns 2 kilometers in miles
    JMap.Geometry.convertLength(2, "miles")
    
    // returns 200 meters in yards
    JMap.Geometry.convertLength(200, "yards", "meters")

    Parameters

    Returns number

getArea

  • getArea(feature: Feature): number
  • JMap.Geometry.getArea

    Works for feature having geometry equals to Polygon or a MultiPolygon.

    It returns the area in square meters.

    Throw an error if the provided feature geometry is not a Polygon or a MultiPolygon.

    example
    
    const feature = ...
    // The method will return the area in m2
    JMap.Geometry.getArea(feature)

    Parameters

    • feature: Feature

      The Polygon or MultiPolygon feature

    Returns number

getBboxFromFeature

  • JMap.Geometry.getBboxFromFeature

    Returns the feature geometry boundary box (JBoundaryBox).

    example
    
    const feature = ...
    // The method will return the feature geometry boundary box
    const bbox = JMap.Geometry.getBboxFromFeature(feature)

    Parameters

    • feature: Feature

      A feature object

    Returns JBoundaryBox

getBboxFromFeatures

  • JMap.Geometry.getBboxFromFeatures

    Returns the boundary box that contains all features

    example
    
    const features = ...
    // returns the features bbox
    const distance = JMap.Geometry.getBboxFromFeatures(features)

    Parameters

    • features: Feature[]

      array of features

    Returns JBoundaryBox

getBboxFromLine

  • JMap.Geometry.getBboxFromLine

    Returns the line boundary box.

    example
    
    const line = [[ 10, 12], [12, 23], [34, 12]]
    // The method will return the line boundary box
    const bbox = JMap.Geometry.getBboxFromLine(line)

    Parameters

    • line: JLine

      A line array

    Returns JBoundaryBox

getBboxFromPolygon

  • JMap.Geometry.getBboxFromPolygon

    Returns the polygon boundary box.

    example
    
    const polygon = [[ 10, 12], [12, 23], [34, 12], [ 10, 12]]
    // The method will return the polygon boundary box
    const bbox = JMap.Geometry.getBboxFromPolygon(feature)

    Parameters

    Returns JBoundaryBox

getCentroid

  • getCentroid(feature: Feature | FeatureCollection): Feature<Point>
  • JMap.Geometry.getCentroid

    Returns a point feature representing the centroid of the provided feature or featureCollection.

    example
    
    const polygonFeature = ...
    // The method will return the centroid of "polygonFeature" as a point feature
    JMap.Geometry.getCentroid(polygonFeature)

    Parameters

    • feature: Feature | FeatureCollection

      a feature or a feature collection

    Returns Feature<Point>

getCircleFeature

  • getCircleFeature(center: JPoint | JLocation, radius: number): Feature<Polygon>
  • JMap.Geometry.getCircleFeature

    Returns a polygon feature equivalent to the circle.

    example
    
    // returns the circle feature
    const circle = JMap.Geometry.getCircleFeature([ 10, 20 ], 1.4)
    
    // returns the circle feature
    const circle = JMap.Geometry.getCircleFeature({ x: 10, y: 20 }, 1.4)

    Parameters

    • center: JPoint | JLocation

      Location of circle's center

    • radius: number

      The radius in KM

    Returns Feature<Polygon>

getDistance

  • JMap.Geometry.getDistance

    Returns the distance in kilometers between 2 points.

    example
    
    // returns the distance between the 2 points
    const distance = JMap.Geometry.getDistance([ 10, 20 ], [ 30, 30 ])
    
    // returns the distance between the 2 points
    const distance = JMap.Geometry.getDistance({ x: 10, y: 20 }, { x: 30, y: 30 })

    Parameters

    Returns number

getFeatureCollection

  • getFeatureCollection(features: Feature[] | JLocation[] | JPoint[]): FeatureCollection
  • JMap.Geometry.getFeatureCollection

    Returns a feature collection.

    example
    
    // returns the feature collection for the 2 points
    const distance = JMap.Geometry.getFeatureCollection([ { x: 10, y: 20 }, { x: 30, y: 30 } ])

    Parameters

    • features: Feature[] | JLocation[] | JPoint[]

      could be a collection of turf features, JMap locations, or JMap points

    Returns FeatureCollection

getFeatureFromLine

  • getFeatureFromLine(line: JLine): Feature<LineString>
  • JMap.Geometry.getFeatureFromLine

    Returns a line feature from a line object (JLine).

    example
    
    const line = [[ 10, 12], [12, 23], [34, 12]]
    // The method will return a line feature
    const feature = JMap.Geometry.getFeatureFromLine(line)

    Parameters

    • line: JLine

      A line array

    Returns Feature<LineString>

getFeatureFromPolygon

  • getFeatureFromPolygon(polygon: JPolygon): Feature<Polygon>
  • JMap.Geometry.getFeatureFromPolygon

    Returns a polygon feature from a polygon array (JPolygon).

    example
    
    const polygon = [[ 10, 12], [12, 23], [34, 12], [ 10, 12]]
    // The method will return a polygon feature
    const feature = JMap.Geometry.getFeatureFromPolygon(line)

    Parameters

    Returns Feature<Polygon>

getFeatureFromWkt

  • getFeatureFromWkt(wkt: string): Feature
  • JMap.Geometry.getFeatureFromWkt

    Returns a GeoJSON feature from a Well-Known Text geometry representation.

    throws

    if the passed WKT is invalid

    example
    
    const wktPolygon = "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))"
    // The method will return a polygon feature
    const polygonFeature = JMap.Geometry.getFeatureFromWkt(wkt)

    Parameters

    • wkt: string

      a Well-Known Text geometry

    Returns Feature

getLineLength

  • JMap.Geometry.getLineLength

    Works for feature having geometry equals to LineString or a MultiLineString.

    It returns the line length in the desired units (default in kilometers).

    Throw an error if the provided feature geometry is not a LineString or a MultiLineString.

    example
    
    const line = ...
    
    // The method will return the line length in kilometers
    JMap.Geometry.getLineLength(line)
    
    // The method will return the line length in miles
    JMap.Geometry.getLineLength(line, "miles")

    Parameters

    • feature: Feature<LineString> | Feature<MultiLineString>

      The LineString or MultiLineString feature to measure.

    • Optional units: JGEOMETRY_UNITS | JMAP_DISTANCE_UNITS

      Can be "degrees", "radians", "miles", or "kilometers" (default)

    Returns number

getNormalizedBbox

  • JMap.Geometry.getNormalizedBbox

    Returns a normalized bbox that can be used in query string. The input bbox must be expressed in degrees and must also respect the convention of sw longitude being numerically smaller than ne longitude

    A bbox that spans more than 360 degrees will be normalized as [-180, , 180, ]

    A bbox which easting coordinates are not in the range -360<-->+360 will be translated to respect valid coordinates

    The OGC define rules for bboxes that cross the antimeridian, stating that for such a bbox, the westmost coordinate must be expressed as a positive number.

    For instance, this bbox: [-190, 42, -70, 50] would be expressed as [170, 42, -70, 50] in OGC-compliant syntax. Some services require that bboxes respect that syntax, but JS cartographic APIs and frameworks often use the non OGC-compliant format

    The ogcCompliant parameter ensures that the returned bbox will be expressed in the good form.

    example
    
    let bbox = { sw: { x: -190, y: 10 }, ne: { x: -170, y: 12 } }
    // Normalize using OGC syntax
    let normalizedBbox = JMap.Geometry.getNormalizedBbox(bbox, true)
    // { sw: { x: 170, y: 10 }, ne: { x: -170, y: 12 } }

    @param bbox the boundary box to normalize (expressed in degrees) @param ogcCompliant wheter we want an OGC-compliant bbox, or not (default false) @throws if the passed bbox is malformed, or invalid.

    Parameters

    • bbox: JBoundaryBox
    • Optional ogcCompliant: undefined | false | true

    Returns JBoundaryBox

getPolygonFeature

  • getPolygonFeature(coordinates: JPoint[], closeCoordinates?: undefined | false | true): Feature<Polygon>
  • JMap.Geometry.getPolygonFeature

    Returns a polygon feature from coordinates.

    If the coordinates are not closed the method will close it automatically.

    example
    
    // will close the coordinates of the polygon and returns the feature
    const distance = JMap.Geometry.getPolygonFeature([
       [ 10, 20 ],
       [ 30, 30 ],
       [ 10, 60 ]
    ])

    Parameters

    • coordinates: JPoint[]

      the polygon coordinates (closed or not closed)

    • Optional closeCoordinates: undefined | false | true

      if true will close the coordinates (if needed)

    Returns Feature<Polygon>

getPolygonFeatureFromBbox

  • getPolygonFeatureFromBbox(boundaryBox: JBoundaryBox): Feature<Polygon>
  • JMap.Geometry.getPolygonFeatureFromBbox

    Returns a polygon feature corresponding to the boundary box.

    example
    
    const bbox = { sw: { x: 10, y: 10 }, ne: { x: 20, y: 20 }}
    // The method will return the polygon corresponding to the bbox
    const polygonFeature = JMap.Geometry.getPolygonFeatureFromBbox(bbox)

    Parameters

    Returns Feature<Polygon>

getPolygonFeatureFromCircle

  • JMap.Geometry.getPolygonFeatureFromCircle

    Returns a polygon feature from a circle object (JCircle).

    example
    
    const circle = [[ 10, 12], [12, 23], [34, 12], [ 10, 12]]
    // The method will return a polygon feature
    const feature = JMap.Geometry.getPolygonFeatureFromCircle(circle)

    Parameters

    Returns Feature<Polygon>

getRotatedFeature

  • getRotatedFeature(feature: Feature, angleInDegrees: number): Feature
  • JMap.Geometry.getRotatedFeature

    Returns the feature with geometry rotated from the centroid.

    throws

    if layer not found or layer is a layer group

    example
    
    // 37 degrees rotation of the polygon
    const polygon = ...
    const rotatedPolygon = JMap.Geometry.getRotatedFeature(polygon, 37)

    Parameters

    • feature: Feature

      the feature

    • angleInDegrees: number

      from -360 to 360 degrees

    Returns Feature

isGeometryTypeValidForLayer

  • isGeometryTypeValidForLayer(layerId: JId, geometryType: GeoJSON.GeoJsonGeometryTypes): boolean
  • JMap.Geometry.getPolygonFeature

    Returns true if the geometry type match the Layer geometry type, else false.

    throws

    if layer not found or layer is a layer group

    example
    
    // returns true if the layer id=3 has "Polygon" features, else false
    const distance = JMap.Geometry.isGeometryTypeValidForLayer(3, "Polygon")

    Parameters

    • layerId: JId

      the JMap layer id

    • geometryType: GeoJSON.GeoJsonGeometryTypes

    Returns boolean

isValidBbox

  • JMap.Geometry.isValidBbox

    Returns false if the provided parameter is not a valid boundary box.

    example
    
    let bbox = { sw: { x: 10, y: 10 }, ne: { x: 12, y: 12 } }
    // The following instruction will return true
    JMap.Geometry.isValidBbox(bbox)
    
    bbox = { sw: { x: 10, y: 10 } } // missing "ne" attribute
    // The following instruction will return false
    JMap.Geometry.isValidBbox(bbox)

    Parameters

    Returns boolean

isValidGeometry

  • isValidGeometry(geometry: any): boolean
  • JMap.Geometry.isValidGeometry

    Returns true if the provided geometry is valid.

    example
    
    // returns true
    JMap.Geometry.isValidGeometry({
      "type": "Point",
      "coordinates": [43.6, 10.1]
    })
    
    // returns false
    JMap.Geometry.isValidGeometry({
     "coordinates": [43.6, 10.1]
    })

    Parameters

    • geometry: any

      The given geometry object to test

    Returns boolean

isValidLocation

  • isValidLocation(location: JLocation | undefined): boolean
  • JMap.Geometry.isValidLocation

    Returns false if the provided parameter is not a valid location.

    example
    
    let location = { x: 10, y: 10 }
    // The following instruction will return true
    JMap.Geometry.isValidLocation(location)
    
    location = {} // empty object
    // The following instruction will return false
    JMap.Geometry.isValidLocation(location)

    Parameters

    • location: JLocation | undefined

      The location object to check

    Returns boolean

lineIntersect

  • lineIntersect(lineFeature: Feature<LineString>, otherFeature: Feature): boolean
  • JMap.Geometry.lineIntersect

    Returns true if the line feature geometry intersects the other feature geometry.

    example
    
    const lineFeature = ...
    const otherFeature = ...
    // The method will return true if otherFeature intersect the lineFeature
    const areIntersecting = JMap.Geometry.lineIntersect(lineFeature, otherFeature)

    Parameters

    • lineFeature: Feature<LineString>

      A line feature

    • otherFeature: Feature

      A feature (can be not a line)

    Returns boolean

polygonIntersect

  • polygonIntersect(polygonFeature: Feature<Polygon>, otherFeature: Feature): boolean
  • JMap.Geometry.polygonIntersect

    Returns true if the polygon feature geometry intersects the other feature geometry.

    example
    
    const polygonFeature = ...
    const otherFeature = ...
    // The method will return true if otherFeature intersect the polygonFeature
    const areIntersecting = JMap.Geometry.polygonIntersect(polygonFeature, otherFeature)

    Parameters

    • polygonFeature: Feature<Polygon>

      A polygon feature

    • otherFeature: Feature

      A feature (can be not a polygon)

    Returns boolean