A GeoJsonCodec is responsible for main tasks:

  • Encoding Feature instances into a JavaScript object that adheres to the GeoJSON specification The codec encodes the shape of the feature to GeoJSON geometries as follows:

  • Decoding a GeoJSON JavaScript object into a set of LuciadRIA Feature instances, each containing corresponding LuciadRIA geometries and properties.

    Since there's no direct mapping from a GeoJSON geometry to a LuciadRIA shape, the codec decodes GeoJSON geometries as follows:

    • GeoJSON Points, LineStrings, and single ring Polygons are mapped to LuciadRIA Point, Polyline, and Polygon instances respectively.
    • A GeoJSON single multi ring Polygon is mapped to ComplexPolygon.
    • MultiPoints, MultiLineStrings, MultiPolygons are all mapped to a ShapeList of Point, Polyline, and Polygon instances respectively.
    • GeometryCollections are mapped to ShapeList instances.
    • A null geometry translates into a Feature with a null shape.

    Note: According to the GeoJSON specification, the first and last position of a GeoJSON polygon must be equivalent. The codec removes this duplicate point when decoding the GeoJSON polygon to a LuciadRIA geometry.

Spatial reference

The reference used during the shape decoding process is determined in the following order:

  • The reference supplied to the decode method. This can be used if you need to override the reference for a specific decode request.
  • The reference supplied to the constructor. This can be used to set a consistent reference across all decoding. Note that this can still be overridden on a per-request basis via the decode
  • The reference specified in the data using the legacy crs field. This will be used if no reference is provided in either of the first two steps.
  • If no reference is specified in any of the above methods, the default WGS:84 reference from the GeoJSON specification is used.

Limitations

GeoJSON does not support any other shapes than Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection. Therefore, it cannot support all LuciadRIA shapes. For instance, a Circle cannot be directly represented as a circle in GeoJSON. Handling such shapes requires a custom codec, as demonstrated in the CreateEdit sample.

Type Parameters

  • TFeature extends Feature = Feature

    Represents the type of Feature instances that are handled by the codec. Default type is Feature without restrictions on shape and properties.

Hierarchy

  • Codec<TFeature>
    • GeoJsonCodec

Constructors

Methods

  • Decodes a GeoJSON geometry string to a Shape or null.

    Parameters

    • geometry: string

      The string representation of a GeoJSON geometry.

    • reference: CoordinateReference

      The spatial reference in which the geometry is defined.

    Returns null | Shape

    the corresponding LuciadRIA Shape or null.

    Throws

    ProgrammingError if the input is not a valid GeoJSON geometry.

  • Decodes a GeoJSON geometry object to a Shape or null.

    Parameters

    • geometry: any

      A GeoJSON geometry object, as a JSON object.

    • reference: CoordinateReference

      The spatial reference in which the geometry is defined.

    Returns null | Shape

    the corresponding LuciadRIA Shape or null.

    Throws

    ProgrammingError if the input is not a valid GeoJSON geometry object.

  • Decodes a valid GeoJSON object to a Cursor.

    Parameters

    Returns Cursor<TFeature>

    featureCursor A Feature corresponding to the server response.

  • Encodes a Feature instances into GeoJSON. This method delegates to GeoJsonCodec.encodeShape.

    Parameters

    • featureCursor: Cursor<TFeature>

      a Feature which must be encoded to the arbitrary representation

    Returns EncodeResult

    An object containing two properties:

    • content: the encoded content as a string. This is valid GeoJSON
    • contentType: the mime type as a string. It equals "application/json"
  • Encodes a LuciadRIA Shape to a valid GeoJSON geometry.

    Parameters

    • shape: null | Shape

      A Shape to be encoded to GeoJSON.

    Returns any

    the GeoJSON representation of a shape (as an object, not as a string)