Skip to content

Commit

Permalink
added geohash support
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterprovoost committed May 8, 2024
1 parent f09a97e commit 2a6292d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"leaflet": "^1.9.3",
"leaflet-draw": "^1.0.4",
"leaflet-fullscreen": "^1.0.2",
"ngeohash": "^0.6.3",
"ol": "^6.14.1",
"proj4": "^2.8.0",
"react": "^18.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function App() {

<footer className="footer mt-auto pt-5 pb-4 bg-light">
<Container>
<p className="text-muted">This page parses, visualizes, and shares <a href="https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry" rel="noreferrer" className="text-muted" target="_blank">WKT</a> (ISO 13249) as well as <a href="https://opengeospatial.github.io/ogc-geosparql/geosparql11/spec.html#_rdfs_datatype_geowktliteral" target="blank" rel="noreferrer" className="text-muted">geo:wktLiteral</a> strings in a variety of coordinate reference systems. Built with <a href="https://openlayers.org/" target="blank" rel="noreferrer" className="text-muted">OpenLayers</a>, <a href="https://leafletjs.com/" target="blank" rel="noreferrer" className="text-muted">Leaflet</a>, <a href="https://trac.osgeo.org/proj4js" target="blank" rel="noreferrer" className="text-muted">Proj4js</a>, <a href="https://github.com/terraformer-js/terraformer" target="blank" rel="noreferrer" className="text-muted">terraformer</a>, and <a href="https://epsg.io/" target="blank" rel="noreferrer" className="text-muted">epsg.io</a>. Use the drawing tools to create your own geometries. Copy as Well-known Binary (WKB) or Extended Well-known Binary (EWKB). Also supports the conversion of H3 indices to WKT.</p>
<p className="text-muted">This page parses, visualizes, and shares <a href="https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry" rel="noreferrer" className="text-muted" target="_blank">WKT</a> (ISO 13249) as well as <a href="https://opengeospatial.github.io/ogc-geosparql/geosparql11/spec.html#_rdfs_datatype_geowktliteral" target="blank" rel="noreferrer" className="text-muted">geo:wktLiteral</a> strings in a variety of coordinate reference systems. Built with <a href="https://openlayers.org/" target="blank" rel="noreferrer" className="text-muted">OpenLayers</a>, <a href="https://leafletjs.com/" target="blank" rel="noreferrer" className="text-muted">Leaflet</a>, <a href="https://trac.osgeo.org/proj4js" target="blank" rel="noreferrer" className="text-muted">Proj4js</a>, <a href="https://github.com/terraformer-js/terraformer" target="blank" rel="noreferrer" className="text-muted">terraformer</a>, and <a href="https://epsg.io/" target="blank" rel="noreferrer" className="text-muted">epsg.io</a>. Use the drawing tools to create your own geometries. Copy as Well-known Binary (WKB) or Extended Well-known Binary (EWKB). Also supports <a href="https://h3geo.org/" rel="noreferrer" className="text-muted" target="_blank">H3</a> index and <a href="https://en.wikipedia.org/wiki/Geohash" rel="noreferrer" className="text-muted" target="_blank">Geohash</a> conversion to WKT.</p>
<p className="text-muted">Created by <Twitter className="mb-1"/> <a rel="noreferrer" className="text-muted" href="https://twitter.com/PieterPrvst" target="_blank">PieterPrvst</a></p>
</Container>
</footer>
Expand Down
14 changes: 13 additions & 1 deletion src/wkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import crsList from "./crs";
import { Geometry } from "@pieterprovoost/wkx";
import { Buffer } from "buffer";
import { cellToBoundary } from "h3-js";
import geohash from "ngeohash";

const USE_WKT = false;

Expand Down Expand Up @@ -83,13 +84,24 @@ async function transformInput(input) {
ewkb: null
}

// handle H3
// handle H3 and geohash

if (input.wkt && (input.wkt.length === 15 || input.wkt.length === 16) && input.wkt.match(/^[0-9a-f]+$/i)) {
const boundary = cellToBoundary(input.wkt, true);
const wkt = "POLYGON ((" + boundary.map(x => x[0] + " " + x[1]).join(",") + "))";
input.wkt = wkt;
input.epsg = 4326;
} else if (input.wkt && input.wkt.match(/^[0-9a-z]+$/)) {
const [bottom, left, top, right] = geohash.decode_bbox(input.wkt);
const wkt = "POLYGON((" +
left + " " + top + ", " +
right + " " + top + ", " +
right + " " + bottom + ", " +
left + " " + bottom + ", " +
left + " " + top +
"))";
input.wkt = wkt;
input.epsg = 4326;
}

// split input, parse EPSG if in WKT
Expand Down

0 comments on commit 2a6292d

Please sign in to comment.