1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-05 10:16:57 +00:00

Add geonearestpoint operator

This commit is contained in:
jeremy@jermolene.com 2023-04-04 21:49:22 +01:00
parent 28a33df91d
commit 2a19e20307
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,8 @@
title: cities/Winchester
tags: $:/tags/GeoMarker
caption: Winchester
lat: 51.0632
long: -1.308
alt: 0
This is Winchester!

View File

@ -53,6 +53,24 @@ The `geodistance` operator calculates the distance between two points in [[GeoJS
</$let>
```
!! `geonearestpoint` operator
The `geonearestpoint` operator determines the point in a list that is nearest to a target point. Each input list item is interpreted as a [[GeoJSON Point Feature]] comprising the candidate points. The target point is specified as the first operand in [[GeoJSON Point Feature]] format.
```
<$let
oxford={{{ [geopoint[51.751944],[-1.257778]jsonset[id],[Oxford]] }}}
winchester={{{ [geopoint[51.0632],[-1.308]jsonset[id],[Winchester]] }}}
new-york={{{ [geopoint[40.730610],[-73.935242]jsonset[id],[New York]] }}}
>
<$text text={{{ =[<oxford>] =[<winchester>] +[geonearestpoint<new-york>jsonget[id]] }}}/>,
<$text text={{{ =[<oxford>] =[[Not a point]] +[geonearestpoint<new-york>jsonget[id]] }}}/>,
<$text text={{{ =[[Not a point]] +[geonearestpoint<new-york>jsonget[id]] }}}/>
</$let>
```
!! `geounion` operator
The `geounion` operator calculates the union between two or more [[GeoJSON Polygon Features|GeoJSON Polygon Feature]].

View File

@ -28,4 +28,20 @@ exports.geodistance = function(source,operator,options) {
return [JSON.stringify(turf.distance(from,to,{units: units}))];
};
exports.geonearestpoint = function(source,operator,options) {
var target = geotools.parsePoint(operator.operands[0]),
points = [];
source(function(tiddler,title) {
var point = geotools.parsePoint(title);
if(point) {
points.push(point)
}
});
if(points.length > 0) {
return [JSON.stringify(turf.nearestPoint(target,turf.featureCollection(points)))];
} else {
return [];
}
};
})();

View File

@ -0,0 +1,24 @@
title: $:/plugins/tiddlywiki/geospatial/tests/geonearestpoint
description: geonearestpoint operator
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$let
oxford={{{ [geopoint[51.751944],[-1.257778]jsonset[id],[Oxford]] }}}
winchester={{{ [geopoint[51.0632],[-1.308]jsonset[id],[Winchester]] }}}
new-york={{{ [geopoint[40.730610],[-73.935242]jsonset[id],[New York]] }}}
>
<$text text={{{ =[<oxford>] =[<winchester>] +[geonearestpoint<new-york>jsonget[id]] }}}/>,
<$text text={{{ =[<oxford>] =[[Not a point]] +[geonearestpoint<new-york>jsonget[id]] }}}/>,
<$text text={{{ =[[Not a point]] +[geonearestpoint<new-york>jsonget[id]] }}}/>
</$let>
+
title: ExpectedResult
<p>Winchester,Oxford,</p>