Skip to content

Commit

Permalink
Feature/wkt support (#86)
Browse files Browse the repository at this point in the history
* Add WKT Support

HitConverter recognizes geometries in WKT format and changes them to GeoJSON.

* Update CHANGELOG.md
  • Loading branch information
dhatcher authored Jun 11, 2024
1 parent 72bfaf8 commit 385f919
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Fixed
* Geometries stored as WKT will now work correctly

## [3.7.0] - 03-27-2024
### Added
* Support for OpenSearch indexes
Expand Down
25 changes: 18 additions & 7 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "standard && tape test/*.js | tap-spec"
},
"keywords": [
"koop"
"koop", "elasticsearch"
],
"author": "Danny Hatcher",
"license": "Apache-2.0",
Expand All @@ -22,11 +22,12 @@
"@mapbox/tilebelt": "^1.0.2",
"flat": "^5.0.0",
"h3-js": "^3.7.2",
"moment": "2.20.1",
"moment": "2.29.4",
"ngeohash": "^0.6.3",
"polygon-splitter": "0.0.8",
"proj4": "2.4.4",
"sqlite-parser": "1.0.1"
"sqlite-parser": "1.0.1",
"@terraformer/wkt": "^2.2.1"
},
"repository": {
"type": "git",
Expand Down
14 changes: 12 additions & 2 deletions src/utils/hitConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const logger = new Logger(config);
const geohash = require('ngeohash');
const flatten = require('flat');
const unflatten = require('flat').unflatten;
const Terraformer = require('@terraformer/wkt');

class HitConverter{

Expand Down Expand Up @@ -100,9 +101,9 @@ class HitConverter{
if(feature.geometry.type === "polygon") {
// Koop expects a capital P and ES has lowercase
feature.geometry.type = "Polygon";
} else if(feature.geometry.type === "multipolygon"){
} else if(feature.geometry.type === "multipolygon") {
feature.geometry.type = "Multipolygon";
} else if (undefined === feature.geometry.type){
} else if (undefined === feature.geometry.type){
// point
var coords = undefined;

Expand Down Expand Up @@ -133,6 +134,15 @@ class HitConverter{
coords = feature.geometry;
}
}
} else if(typeof feature.geometry === 'string'){
// could be WKT
try {
feature.geometry = Terraformer.wktToGeoJSON(feature.geometry);
pointType = feature.geometry.type;
coords = feature.geometry.coordinates;
} catch (e) {
logger.warn(e.message);
}
} else {
pointType = "Point";
if(feature.geometry.hasOwnProperty('lon')){
Expand Down

0 comments on commit 385f919

Please sign in to comment.