Terraformer

repository·main·Indexed 42 days ago

https://github.com/terraformer-js/terraformer

A geographic toolkit for dealing with geometry, geography, formats, and building geodatabases. A modular ES Module port of the original Esri Terraformer, it includes specialized packages: @terraformer/spatial for spatial predicates and coordinate transformations (Mercator and Geographic), @terraformer/arcgis for converting between ArcGIS JSON and GeoJSON, and @terraformer/wkt for converting between Well-Known Text (WKT) and GeoJSON.

Tokens
11.9K
Snippets
53
Records
63
Agent score
52%

What's inside Terraformer

  1. Overview of @terraformer packages

    main
    @terraformer is a geographic toolkit designed for handling geometry, geography, and various formats, as well as building geodatabases. It is a standalone ES Module port of the original Esri Terraformer, optimized for smaller bundle sizes by allowing you to import only the specific modules you need without requiring the instantiation of 'Primitives'.
  2. Install @terraformer/spatial

    main

    You can use @terraformer/spatial in several environments:

    Browser (via CDN)

    As a UMD module, you can include it via a <script> tag. It will be available under the global Terraformer namespace.

    Node.js

    Install via npm and require the package.

    ES Modules in the Browser

    You can import specific functions directly from a CDN without a build step using the ?module query parameter.

    ### Browser (from CDN)
    ```html
    <script src="https://unpkg.com/@terraformer/spatial"></script>

    Node.js

    const Terraformer = require('@terraformer/spatial');

    ES module in the browser

    <script type='module'>
      import { isConvex } from 'https://unpkg.com/@terraformer/spatial?module';
    
      // look ma, no build step!
      isConvex(/* ... */);
    </script>
  3. Migrate from terraformer-wkt-parser to @terraformer/wkt

    main

    To upgrade from the legacy terraformer-wkt-parser, use the @terraformer/wkt package which provides explicit conversion functions for WKT and GeoJSON.

    # Old way
    npm install terraformer-wkt-parser
    
    # New way
    npm install @terraformer/wkt
    // Old way
    var wkt = require('terraformer-wkt-parser')
    wkt.parse('LINESTRING (30 10, 10 30, 40 40)')
    wkt.convert(/* ... */)
    
    // New way
    import { wktToGeoJSON, geojsonToWkt } from '@terraformer/wkt'
    wktToGeoJSON(/* ... */)
    geojsonToWkt(/* ... */)
  4. Use @terraformer/arcgis in the browser

    main

    You can use @terraformer/arcgis in the browser using several methods:

    Via CDN (UMD/AMD)

    Include the script tag to access the Terraformer global namespace.

    <script src="https://unpkg.com/@terraformer/arcgis"></script>
    <script>
      Terraformer.arcgisToGeoJSON(/* ... */);
    </script>

    Via ES Modules

    You can import specific functions directly from a CDN without a build step.

    <script type='module'>
      import { arcgisToGeoJSON } from 'https://unpkg.com/@terraformer/arcgis?module';
    
      arcgisToGeoJSON(/* ... */);
    </script>
    <script src="https://unpkg.com/@terraformer/arcgis"></script>
  5. Migrate from terraformer to @terraformer/spatial

    main

    If you are upgrading from the legacy terraformer package, you no longer need to instantiate Terraformer.Primitive objects to perform spatial operations. Instead, you work directly with raw GeoJSON objects using functions imported from @terraformer/spatial.

    # Old way
    npm install terraformer
    
    # New way
    npm install @terraformer/spatial
    // Old way
    const Terraformer = require('terraformer')
    const polygon = new Terraformer.Primitive({
      type: "LineString",
      coordinates: [[ 100, 0 ], [ -45, 122 ], [ 80, -60 ]]
    })
    polygon.convexHull()
    
    // New way
    import { convexHull } from '@terraformer/spatial'
    convexHull({
      type: "LineString",
      coordinates: [[ 100, 0 ], [ -45, 122 ], [ 80, -60 ]]
    })
  6. Use @terraformer/wkt in the browser via CDN

    main

    You can use this package directly in the browser using a <script> tag. It is available as a UMD module or as a global Terraformer object.

    Global Namespace Usage:

    <script src="https://unpkg.com/@terraformer/wkt"></script>
    <script>
      Terraformer.wktToGeoJSON("POINT (-122.6764 45.5165)");
    </script>

    ES Module Usage (No build step required):

    <script type='module'>
      import { wktToGeoJSON } from 'https://unpkg.com/@terraformer/wkt?module';
    
      wktToGeoJSON(/* ... */);
    </script>