Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
geo / geo-wkt-to-geojsonOpenRuns on Liberas

WKT to GeoJSON

A WKT geometry (OGC Simple Features 1.2.1 text, 2D subset) as an RFC 7946 GeoJSON geometry object, serialized in RFC 8785 (JCS) canonical form. Grammar: a type keyword (POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION; ASCII case-insensitive) then EMPTY or a parenthesized list, items separated by commas; whitespace (space, tab, CR, LF) may surround any token. A position is two numbers separated by whitespace (Z, M, ZM or a third number are errors); a number is [+-]? (digits [. digits] | . digits) ([eE] [+-]? digits)?, followed by whitespace, ',' or ')', read as the nearest binary64 (correctly rounded) and an error unless finite. POINT (p); LINESTRING (p, p, …); POLYGON ((ring), …); MULTIPOINT members written p or (p); MULTILINESTRING ((…), …); MULTIPOLYGON (((…)), …); GEOMETRYCOLLECTION (geometry, …), nesting at most 32 collections deep. A line string (alone or in a MultiLineString) has at least 2 positions; a ring has at least 4 and ends at its first position (x = x and y = y numerically); members of a multi-geometry are never empty; else an error. Nothing else is checked (no orientation, self-intersection or coordinate range). Anything else, text after the geometry, or input over 1,048,576 bytes is an error. Output: {"coordinates":…,"type":"Point"} etc. (GeometryCollection: {"geometries":[…],"type":"GeometryCollection"}), positions [x,y] in input order, rings and members as given (no reorientation); EMPTY gives "coordinates":[] (or "geometries":[]). No whitespace; numbers as ECMAScript Number::toString (shortest round-trip digits, exponent from 1e21 and below 1e-6, −0 as 0).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init geo-wkt-to-geojson --lang rust
cd geo-wkt-to-geojson && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
geo-wkt-to-geojson.wit
package root:component;

world root {
  export liberas:geo/wkt-to-geojson@0.1.0;
}
package liberas:geo@0.1.0 {
  interface wkt-to-geojson {
    to-geojson: func(wkt: string) -> result<string, string>;
  }
}
Test vectors27›
geo-wkt-to-geojson.cases.json
[
  {
    "args": {
      "wkt": "POINT (30 10)"
    }
  },
  {
    "args": {
      "wkt": "point(-0.5 1e-7)"
    }
  },
  {
    "args": {
      "wkt": "LINESTRING (30 10, 10 30, 40 40)"
    }
  },
  {
    "args": {
      "wkt": "POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))"
    }
  },
  {
    "args": {
      "wkt": "MULTIPOINT ((10 40), (40 30), (20 20), (30 10))"
    }
  },
  {
    "args": {
      "wkt": "MULTIPOINT (10 40, 40 30)"
    }
  },
  {
    "args": {
      "wkt": "MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))"
    }
  },
  {
    "args": {
      "wkt": "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))"
    }
  },
  {
    "args": {
      "wkt": "GEOMETRYCOLLECTION (POINT (40 10), LINESTRING (10 10, 20 20, 10 40), POLYGON EMPTY)"
    }
  },
  {
    "args": {
      "wkt": "POINT EMPTY"
    }
  },
  {
    "args": {
      "wkt": "GEOMETRYCOLLECTION EMPTY"
    }
  },
  {
    "args": {
      "wkt": "  POINT\t(\n1.5E+21  -0.0000001 )  "
    }
  },
  {
    "args": {
      "wkt": "POINT (123456789012345678901234567890 0.1)"
    }
  },
  {
    "args": {
      "wkt": "POINT (.5 +5.)"
    }
  },
  {
    "args": {
      "wkt": "POINT Z (1 2 3)"
    }
  },
  {
    "args": {
      "wkt": "POINT (1 2 3)"
    }
  },
  {
    "args": {
      "wkt": "POINT (1)"
    }
  },
  {
    "args": {
      "wkt": "POINT (1e400 0)"
    }
  },
  {
    "args": {
      "wkt": "LINESTRING (1 2)"
    }
  },
  {
    "args": {
      "wkt": "POLYGON ((0 0, 1 0, 1 1, 0 1))"
    }
  },
  {
    "args": {
      "wkt": "POLYGON ((0 0, 1 0, 0 0))"
    }
  },
  {
    "args": {
      "wkt": "POINT (1 2) x"
    }
  },
  {
    "args": {
      "wkt": "POINT (1-2)"
    }
  },
  {
    "args": {
      "wkt": "SRID=4326;POINT (1 2)"
    }
  },
  {
    "args": {
      "wkt": "CIRCLE (1 2)"
    }
  },
  {
    "args": {
      "wkt": ""
    }
  },
  {
    "args": {
      "wkt": "GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (1 2))))))))))))))))))))))))))))))))))"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 27 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 4,500,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.