Skip to content

sterblue/geospatial

Repository files navigation

Sterblue Geospatial

Geospatial monorepo for geospatial related packages

See @lcalisto's presentation about it at FOSS4G 2021 here https://www.youtube.com/watch?v=l6B5MyILMpM

Packages

Auxiliary packages

Packages used for compiling and other auxiliary tasks.

Get started

Just add the required package to your dependencies e.g. yarn add @geospatial/geometry-referential or add it directly editing your package.json enjoy! More info can be found inside the package folder.

The example below show how to use both Geometry Referential and Coordinates altitude

import { addAltitudeToGeojson } from "@geospatial/geometry-coordinates-altitude";
import { convert, convertAsync } from "@geospatial/geometry-referential";



    const geojson = {
        "type": "FeatureCollection",
        "crs": {
          "type": "name",
          "properties": {
            "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
          }
        },
        "features": [
              {
                "type": "Feature",
                "properties": {
                  "name": "Bourgogne"
                },
                "geometry": { "type": "Point", "coordinates": [3.461807, 46.880655] }
              },
              {
                "type": "Feature",
                "properties": {
                  "name": "Cote d'ivoire"
                },
                "geometry": { "type": "Point", "coordinates": [-4.395542, 5.332077] }
              }
            ]
      };
    async function asyncFunction() {

        /*************************
         * Add altitude to coordinate 
         * using @geospatial/geometry-coordinates-altitude
        **************************/
        var result = await addAltitudeToGeojson(geojson);
        console.log(result.features[0].geometry.coordinates);

        /*************************
         * Transform from EPSG:4326 to EPSG:3857 
         * and convert from arrayXYZ into objectXYZ
         * Using @geospatial/geometry-referential
        **************************/
        const myConversion = await convertAsync(
            {
                system: {
                  type: "reference",
                  definition: "EPSG:4326",
                  altitudeReference: "default"
                },
                format: {
                  type: "arrayXYZ"
                }
              },
              {
                system: {
                  type: "reference",
                  definition: "EPSG:3857",
                  altitudeReference: "default"
                },
                format: {
                  type: "objectXYZ"
                }
              }
          );
        result = await myConversion(result.features[0].geometry.coordinates);
        console.log(result);
      }
      asyncFunction();