w-gis

w-gis

new w-gis()

Source:

Members

(static) turf

Description:
  • 取得引用turf物件

    Unit Test: Github

Source:

取得引用turf物件

Unit Test: Github

Example
let r = importTurf
console.log(r)
// => [Module: null prototype] {
//   along: [Function: along],
//   angle: [Function: angle],
//   applyFilter: [Function: applyFilter],
//   area: [Function: area],
//   ...

Methods

(static) Build() → {Object}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於某一特徵(Feature)內之字典物件,若有則回傳該特徵之鍵名,若無則回傳def值

    Unit Test: Github

Source:
Example
let geojson
let p
let r

geojson = `
{
    'type': 'FeatureCollection',
    'name': 'pgs',
    'features': [
        {
            'type': 'Feature',
            'properties': {
                'name': 'pgs1',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [0, 0],
                            [0, 1],
                            [1, 1],
                            [1, 0],
                            [0, 0],
                        ]
                    ]
                ]
            }
        },
        {
            'type': 'Feature',
            'properties': {
                'name': 'pgs2',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [1, 1],
                            [1, 2],
                            [2, 2],
                            [2, 1],
                            [1, 1],
                        ]
                    ]
                ]
            }
        },
    ]
}
`
let BD = buildFindPointInGeojson
let bd = new BD()
await bd.init(geojson, { keysPick: 'properties.name' })

p = [0.5, 0.5]
r = await bd.getPoint(p)
console.log(r)
// => 'pgs1'

p = [1.5, 1.5]
r = await bd.getPoint(p)
console.log(r)
// => 'pgs2'

p = [1.5, 0.5]
r = await bd.getPoint(p)
console.log(r)
// => 'unknow'

p = [1.5, 0.5]
r = await bd.getPoint(p, { def: '未知' })
console.log(r)
// => '未知'
Returns:

回傳函數物件,包含init、isInit、getPoint函數。init為初始化,輸入geojson與opt,無輸出,功能詳見getKpFeatureFromGeojson。isInit為回傳是否初始化布林值,無輸入。getPoint為查詢點位於哪個特徵並回傳該鍵名,輸入p與opt,功能詳見findPointInKpFeature。

Type
Object

(static) Build() → {Object}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於某一多邊形與其邊界內之字典物件,若有則回傳該特徵之鍵名,若無則回傳def值

    Unit Test: Github

Source:
Example
let kpPgs = {
    'pgs1': [
        [0, 0],
        [0, 1],
        [1, 1],
        [1, 0],
        [0, 0],
    ],
    'pgs2': [
        [1, 1],
        [1, 2],
        [2, 2],
        [2, 1],
        [1, 1],
    ],
}
let p
let r

let BD = buildFindPointInKpBoxPolygons
let bd = new BD()
await bd.add('pgs1', kpPgs['pgs1'])
await bd.add('pgs2', kpPgs['pgs2'])

p = [0.5, 0.5]
r = await bd.getPoint(p)
console.log(r)
// => 'pgs1'

p = [1.5, 1.5]
r = await bd.getPoint(p)
console.log(r)
// => 'pgs2'

p = [1.5, 0.5]
r = await bd.getPoint(p)
console.log(r)
// => 'unknow'

p = [1.5, 0.5]
r = await bd.getPoint(p, { def: '未知' })
console.log(r)
// => '未知'
Returns:

回傳函數物件,包含add、getPoint函數。add為新增,輸入name、pgs與opt,無輸出。getPoint為查詢點位於哪個多邊形並回傳該鍵名,輸入p與opt,功能詳見findPointInKpBoxPolygons。

Type
Object

(static) Build() → {Object}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於某一多邊形內之字典物件,若有則回傳該多邊形之鍵名,若無則回傳def值

    Unit Test: Github

Source:
Example
let kpPgs = {
    'pgs1': [
        [0, 0],
        [0, 1],
        [1, 1],
        [1, 0],
        [0, 0],
    ],
    'pgs2': [
        [1, 1],
        [1, 2],
        [2, 2],
        [2, 1],
        [1, 1],
    ],
}
let p
let r

let BD = buildFindPointInKpPolygons
let bd = new BD()
await bd.init(kpPgs)

p = [0.5, 0.5]
r = await bd.getPoint(p)
console.log(r)
// => 'pgs1'

p = [1.5, 1.5]
r = await bd.getPoint(p)
console.log(r)
// => 'pgs2'

p = [1.5, 0.5]
r = await bd.getPoint(p)
console.log(r)
// => 'unknow'

p = [1.5, 0.5]
r = await bd.getPoint(p, { def: '未知' })
console.log(r)
// => '未知'
Returns:

回傳函數物件,包含init、isInit、getPoint函數。init為初始化,輸入kpPgs,無輸出,isInit為回傳是否初始化布林值,無輸入。getPoint為查詢點位於哪個多邊形並回傳該鍵名,輸入p與opt,功能詳見findPointInKpPolygons。

Type
Object

(static) Build() → {Object}

Description:
  • 查詢點陣列[x,y]或點物件{x,y}於指定Tiff點陣圖內數值,若無則回傳def值

    Unit Test: Github

Source:
Example
import b642u8arr from 'wsemi/src/b642u8arr.mjs'
import buildFindPointInTiff from 'wsemi/src/buildFindPointInTiff.mjs'

let p
let r

let b64Tif = `SUkqAA4HAAAQAAABAwABAAAAFAAAAAEBAwABAAAAEgAAAAIBAwABAAAAIAAAAAMBAwABAAAAAQAAAAYBAwABAAAAAQAAABEBBAABAAAAAAAAABUBAwABAAAAAQAAABYBAwABAAAAEgAAABcBBAABAAAAAAAAABwBAwABAAAAAQAAAFMBAwABAAAAAwAAAA6DDAADAAAAzgAAAIKEDAAGAAAA5gAAAK+HAwAgAAAAFgEAALCHDAACAAAAVgEAALGHAgAIAAAAZgEAAAAAAADNzEQtza0wP+Q4kVqKIC0/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADpmsk322BeQM3MzMzMDDlAAAAAAAAAAAABAAEAAAAHAAAEAAABAAIAAQQAAAEAAQAACAAAAQDmEAEIsYcHAAAABggAAAEAjiMJCLCHAQABAAsIsIcBAAAAiG10lh2kckAAAABAplRYQVdHUyA4NHwAoJ1LQDTzSkATGUpA/4JIQHenR0BuskZAX6NFQF+jRUDJjERAKEpCQLseQUBftT5ALXg9QPIDPEATTjpAE046QBNOOkATTjpAdWI4QAGfNkCgnUtANPNKQBMZSkD/gkhAd6dHQG6yRkBfo0VAX6NFQMmMREAoSkJAux5BQF+1PkAteD1A8gM8QBNOOkATTjpAE046QBNOOkB1YjhAAZ82QCLTS0B+FktA7kJKQDm0SEC5ykdAHsdGQJi7RUCYu0VAaahEQD1sQkDlQ0FAeuA+QHF/PUDO7jtA/RM6QP0TOkD9EzpA/RM6QD9WOEDv6zZATwZMQFY3S0ALdkpA0dRIQJvhR0C94UZAyNlFQMjZRUADykRAPJRCQOZuQUCW7D5Acmg9QGOzO0CtAzpArQM6QK0DOkCtAzpAmXI4QJlnN0COEExAsl9LQHmXSkAQ5UhAGfpHQJQCR0A2/kVANv5FQNjxREBdwkJA9J9BQJLcPkAJNj1AG6k7QGAjOkCtAzpArQM6QK0DOkCZcjhAmWc3QI4QTECyX0tAeZdKQBDlSEAZ+kdAlAJHQDb+RUA2/kVA2PFEQF3CQkD0n0FAktw+QAk2PUAbqTtAYCM6QGAjOkBgIzpAYCM6QL+9OEBg5jdA/BBMQJRvS0DAsUpAE/dIQFoUSEAlJUdALSlGQC0pRkAwIEVA4fZCQE62QUAUsz5AjjI9QM3MO0DtbzpA7W86QO1vOkDtbzpA1jo5QBhjOEBd/ktA5mxLQEm+SkBuFElAjTBIQJlJR0DzVUZA81VGQFtVRUCiEkNAbrRBQJa2PkA0Wz1ALCA8QNnROkDZ0TpA2dE6QNnROkA30zlAzf04QGf1S0CsWUtAJ8JKQLM9SUDDWEhAJHBHQLSERkC0hEZAX4xFQHEgQ0BuqUFAq/E+QKa6PUA+gjxAmT07QJk9O0CZPTtAmT07QGVvOkDymzlAH1ZMQCCtS0A4CktAin1JQJGNSEBXo0dAqLVGQKi1RkDdrEVACh5DQD/IQUACVT9AcCA+QFnqPECC0ztAgtM7QILTO0CC0ztAFwc7QDQ1OkBAVk1A5qBMQGHmS0ANNEpAuDdJQHcqSEDqCkdA6gpHQMrXRUBpiENACm9CQMQjQEAL8z5A47s9QLrpPEC66TxAuuk8QLrpPEAaFTxA7T47QNeRTUAW4kxA8CpMQK+VSkDfmElANHRIQOc8R0DnPEdALxRGQBDuQ0AP10JA0KZAQKWNP0AwbT5AOpY9QDqWPUA6lj1AOpY9QIy8PEAe4TtA0cZNQDQsTUBteExAoedKQPLqSUAXw0hAIKxHQCCsR0BYo0ZAVpxEQMGEQ0DuXEFAr0dAQP4lP0CyST5Askk+QLJJPkCyST5AZmo9QByJPECx9U1AeHBNQEPPTEDRKEtA3yxKQKgkSUCYKkhAmCpIQGFBR0C/VEVAe1lEQGhRQkB7IkFArwRAQIMiP0CyST5Askk+QLJJPkBmaj1AHIk8QLH1TUB4cE1AQ89MQNEoS0DfLEpAqCRJQJgqSECYKkhAYUFHQL9URUB7WURAaFFCQHsiQUCvBEBAgyI/QIMiP0CDIj9AgyI/QAE9PkAwNz1AEx9OQHmvTUDzFE1AZGhLQByASkCNl0lANrpIQDa6SEBi3UdAPAtGQOg3RUATT0NAdfBBQBvAQEASwj9AEsI/QBLCP0ASwj9AOdg+QIqwPUCsYU5AwdxNQFRJTUDXv0tAFetKQBMYSkD+M0lA/jNJQM1NSEB5nEZAs/JFQJwpREBzxkJAPppBQH+AQEB/gEBAf4BAQH+AQEAWej9A5DA+QBqrTkAHF05ATW5NQN4lTEAlcktAmqNKQLfFSUAY1khAGNZIQKNBR0Bvo0ZAtNZEQM+LQ0BjdEJAFz9BQBc/QUAXP0FAFz9BQDUcQEDduD5AEQAAAQMAAQAAABQAAAABAQMAAQAAABIAAAACAQMAAQAAACAAAAADAQMAAQAAAAEAAAAGAQMAAQAAAAEAAAARAQQAAQAAAG4BAAAVAQMAAQAAAAEAAAAWAQMAAQAAABIAAAAXAQQAAQAAAKAFAAAcAQMAAQAAAAEAAABTAQMAAQAAAAMAAAAOgwwAAwAAAOAHAACChAwABgAAAPgHAACvhwMAIAAAACgIAACwhwwAAgAAAGgIAACxhwIACAAAAHgIAACBpAIAGQAAAIAIAAAAAAAAzcxELc2tMD/kOJFaiiAtPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6ZrJN9tgXkDNzMzMzAw5QAAAAAAAAAAAAQABAAAABwAABAAAAQACAAEEAAABAAEAAAgAAAEA5hABCLGHBwAAAAYIAAABAI4jCQiwhwEAAQALCLCHAQAAAIhtdJYdpHJAAAAAQKZUWEFXR1MgODR8AC0zLjQwMjgyMzA2MDczNzA5NjUzZSszOAA=`
let u8a = b642u8arr(b64Tif)
// lon 121.51338 121.51847
// lat 25.046 25.05

let BD = buildFindPointInTiff
let bd = new BD()
await bd.init(u8a)

p = [121.51353, 25.04987]
r = await bd.getPoint(p)
console.log(r)
// => 3.1814956665039062

p = [121.51835, 25.04608]
r = await bd.getPoint(p)
console.log(r)
// => 2.9800331592559814

p = [121.51353, 25.05016]
r = await bd.getPoint(p)
console.log(r)
// => 'unknow'

p = [121.51353, 25.05016]
r = await bd.getPoint(p, { def: '未知' })
console.log(r)
// => '未知'
Returns:

回傳函數物件,包含init、isInit、getPoint函數。init為初始化,輸入inp與opt,無輸出,isInit為回傳是否初始化布林值,無輸入。getPoint為查詢點位於點陣圖內數值,輸入p與opt。

Type
Object

(static) aggregatePoints(ops, xmin, dx, ymin, dy, optopt) → {Array}

Description:
  • 依照規則網格提取點數據

    Unit Test: Github

Source:
Example
let ops
let r

ops = 'not array'
try {
  r = aggregatePoints(ops, 0, 10, 0, 10)
}
catch (err) {
 r = err.message
}
console.log(r)
// => 'no ops'

ops = [{ x: 1, y: 1, z: 10, id: 'a' }] // cell 0:0
r = aggregatePoints(ops, 0, 10, 0, 10, { modePick: 'min' })
console.log(r)
// => [ { x: 1, y: 1, z: 10, id: 'a' } ]

ops = [
    { x: 1, y: 1, z: 10, id: 'a' }, // cell 0:0
    { x: 2, y: 2, z: 5, id: 'b' }, // cell 0:0 (same cell, smaller z)
    { x: 15, y: 1, z: 7, id: 'c' }, // cell 1:0
]
r = aggregatePoints(ops, 0, 10, 0, 10, { modePick: 'min' })
console.log(r)
// => [ { x: 2, y: 2, z: 5, id: 'b' }, { x: 15, y: 1, z: 7, id: 'c' } ]

ops = [
    { x: 1, y: 1, z: 10, id: 'a' }, // cell 0:0 (bigger z)
    { x: 2, y: 2, z: 5, id: 'b' }, // cell 0:0
    { x: 15, y: 1, z: 7, id: 'c' }, // cell 1:0
]
r = aggregatePoints(ops, 0, 10, 0, 10, { modePick: 'max' })
console.log(r)
// => [ { x: 1, y: 1, z: 10, id: 'a' }, { x: 15, y: 1, z: 7, id: 'c' } ]

ops = [
    { lon: 121.50, lat: 25.00, val: 3, id: 'p1' }, // cell 5:5  (xmin=121, dx=0.1; ymin=24.5, dy=0.1)
    { lon: 121.59, lat: 25.00, val: 9, id: 'p2' }, // same cell 5:5 (val bigger)
    { lon: 121.61, lat: 25.00, val: 1, id: 'p3' }, // cell 6:5
]
r = aggregatePoints(ops, 121.0, 0.1, 24.5, 0.1, {
    keyX: 'lon',
    keyY: 'lat',
    keyZ: 'val',
    modePick: 'max',
})
console.log(r)
// => [ { lon: 121.59, lat: 25, val: 9, id: 'p2' }, { lon: 121.61, lat: 25, val: 1, id: 'p3' } ]

ops = [
    { x: -1, y: -1, z: 9, id: 'n1' }, // cell -1:-1
    { x: -2, y: -2, z: 1, id: 'n2' }, // cell -1:-1 (min z)
    { x: 1, y: 1, z: 5, id: 'p1' }, // cell 0:0
]
r = aggregatePoints(ops, 0, 10, 0, 10, { modePick: 'min' })
console.log(r)
// => [ { x: -2, y: -2, z: 1, id: 'n2' }, { x: 1, y: 1, z: 5, id: 'p1' } ]
Parameters:
Name Type Attributes Default Description
ops Array

輸入點物件陣列

xmin Number

輸入網格x向最小座標數字

dx Number

輸入網格x向間距數字

ymin Number

輸入網格y向最小座標數字

dy Number

輸入網格y向間距數字

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x座標欄位字串,預設'x'

keyY String <optional>
'y'

輸入點物件之y座標欄位字串,預設'y'

keyZ String <optional>
'z'

輸入點物件之z座標或值欄位字串,預設'z'

modePick String <optional>
'min'

輸入挑選方式字串,可選'min'、'max',預設'min'

Returns:

回傳點物件陣列

Type
Array

(static) bufferMultiPolygon(pgs, w, optopt) → {Array}

Description:
  • 針對MultiPolygon進行Buffer處理

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-0.999972965374907, 0.0016734646215225838], [-0.9816999365134195, -0.16952408506808617], [-0.9256550485311431, -0.33424464732165526], [-0.8339576843969376, -0.48618630154023834], [-0.7100824785045414, -0.6195134735411201], [-0.5587377945819172, -0.7290740927297131], [-0.3856985719274389, -0.8105963097699821], [-0.19759749454066486, -0.8608576036547885], [-0.0016801581736105632, -0.8778191418707327], [100.0016801581736, -0.8778191418707327], [100.19759749454067, -0.8608576036547885], [100.38569857192745, -0.8105963097699821], [100.55873779458192, -0.7290740927297131], [100.71008247850455, -0.6195134735411201], [100.83395768439694, -0.48618630154023795], [100.92565504853114, -0.33424464732165526], [100.98169993651341, -0.16952408506808608], [100.99997296537491, 0.0016734646215225838], [101.0001378195948, 0.9962737353793626], [100.98227733151975, 1.1658759961268101], [100.92734305241007, 1.329269548373683], [100.83736709792183, 1.480321394964545], [100.71568951389246, 1.6133389494598158], [100.5668443075726, 1.7232781856005774], [100.39640190540993, 1.8059329159519186], [100.21077163081944, 1.8580983786377043], [100.01696944720078, 1.8777023240108164], [-0.016969447200789016, 1.8777023240108164], [-0.21077163081944233, 1.8580983786377043], [-0.3964019054099387, 1.8059329159519186], [-0.5668443075725933, 1.7232781856005777], [-0.7156895138924567, 1.613338949459816], [-0.8373670979218306, 1.480321394964545], [-0.9273430524100664, 1.3292695483736832], [-0.9822773315197597, 1.1658759961268104], [-1.0001378195948039, 0.9962737353793626], [-0.999972965374907, 0.0016734646215225838]]]]

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-0.999972965374907, 0.0016734646215225838], [-0.9816999365134195, -0.16952408506808617], [-0.9256550485311431, -0.33424464732165526], [-0.8339576843969376, -0.48618630154023834], [-0.7100824785045414, -0.6195134735411201], [-0.5587377945819172, -0.7290740927297131], [-0.3856985719274389, -0.8105963097699821], [-0.19759749454066486, -0.8608576036547885], [-0.0016801581736105632, -0.8778191418707327], [100.0016801581736, -0.8778191418707327], [100.19759749454067, -0.8608576036547885], [100.38569857192745, -0.8105963097699821], [100.55873779458192, -0.7290740927297131], [100.71008247850455, -0.6195134735411201], [100.83395768439694, -0.48618630154023795], [100.92565504853114, -0.33424464732165526], [100.98169993651341, -0.16952408506808608], [100.99997296537491, 0.0016734646215225838], [101.0001378195948, 0.9962737353793626], [100.98227733151975, 1.1658759961268101], [100.92734305241007, 1.329269548373683], [100.83736709792183, 1.480321394964545], [100.71568951389246, 1.6133389494598158], [100.5668443075726, 1.7232781856005774], [100.39640190540993, 1.8059329159519186], [100.21077163081944, 1.8580983786377043], [100.01696944720078, 1.8777023240108164], [-0.016969447200789016, 1.8777023240108164], [-0.21077163081944233, 1.8580983786377043], [-0.3964019054099387, 1.8059329159519186], [-0.5668443075725933, 1.7232781856005777], [-0.7156895138924567, 1.613338949459816], [-0.8373670979218306, 1.480321394964545], [-0.9273430524100664, 1.3292695483736832], [-0.9822773315197597, 1.1658759961268104], [-1.0001378195948039, 0.9962737353793626], [-0.999972965374907, 0.0016734646215225838]]]]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-0.999972965374907, 0.0016734646215225838], [-0.9816999365134195, -0.16952408506808617], [-0.9256550485311431, -0.33424464732165526], [-0.8339576843969376, -0.48618630154023834], [-0.7100824785045414, -0.6195134735411201], [-0.5587377945819172, -0.7290740927297131], [-0.3856985719274389, -0.8105963097699821], [-0.19759749454066486, -0.8608576036547885], [-0.0016801581736105632, -0.8778191418707327], [100.0016801581736, -0.8778191418707327], [100.19759749454067, -0.8608576036547885], [100.38569857192745, -0.8105963097699821], [100.55873779458192, -0.7290740927297131], [100.71008247850455, -0.6195134735411201], [100.83395768439694, -0.48618630154023795], [100.92565504853114, -0.33424464732165526], [100.98169993651341, -0.16952408506808608], [100.99997296537491, 0.0016734646215225838], [101.0001378195948, 0.9962737353793626], [100.98227733151975, 1.1658759961268101], [100.92734305241007, 1.329269548373683], [100.83736709792183, 1.480321394964545], [100.71568951389246, 1.6133389494598158], [100.5668443075726, 1.7232781856005774], [100.39640190540993, 1.8059329159519186], [100.21077163081944, 1.8580983786377043], [100.01696944720078, 1.8777023240108164], [-0.016969447200789016, 1.8777023240108164], [-0.21077163081944233, 1.8580983786377043], [-0.3964019054099387, 1.8059329159519186], [-0.5668443075725933, 1.7232781856005777], [-0.7156895138924567, 1.613338949459816], [-0.8373670979218306, 1.480321394964545], [-0.9273430524100664, 1.3292695483736832], [-0.9822773315197597, 1.1658759961268104], [-1.0001378195948039, 0.9962737353793626], [-0.999972965374907, 0.0016734646215225838]]]]

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-0.9999871734419754, 0.00020200853748591523], [-0.9808664898611782, -0.1946303469545636], [-0.9240590295626437, -0.3819873726126987], [-0.8317412783820994, -0.5546734807953713], [-0.7074512829437212, -0.7060534506846929], [-0.5559553546711901, -0.8303064908026484], [-0.38306768046047435, -0.9226499871568967], [-0.195429088113392, -0.9795242908122764], [-0.00025297819980798976, -0.9987311926308354], [10.000252978199807, -0.9987311926308354], [10.195429088113391, -0.9795242908122764], [10.383067680460474, -0.9226499871568967], [10.55595535467119, -0.8303064908026482], [10.70745128294372, -0.7060534506846932], [10.831741278382099, -0.5546734807953713], [10.924059029562644, -0.38198737261269833], [10.980866489861178, -0.19463034695456283], [10.999987173441975, 0.00020200853748591523], [11.000139599094679, 0.9996433568427817], [10.981111268878019, 1.194295116728359], [10.924452966177004, 1.3815039238779527], [10.832325648018566, 1.5540919010292005], [10.70824947011501, 1.7054376090190566], [10.5569720003843, 1.8297295150398156], [10.384289098273342, 1.9221894529124708], [10.196824616632652, 1.9792573819173556], [10.001776914642905, 1.998730032258952], [-0.0017769146429057866, 1.998730032258952], [-0.1968246166326525, 1.9792573819173556], [-0.38428909827334173, 1.9221894529124712], [-0.5569720003843, 1.8297295150398156], [-0.7082494701150103, 1.7054376090190564], [-0.832325648018567, 1.5540919010292005], [-0.9244529661770031, 1.3815039238779527], [-0.9811112688780195, 1.1942951167283595], [-1.0001395990946789, 0.9996433568427817], [-0.9999871734419754, 0.00020200853748591523]]]]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-0.999972965374907, 0.0016734646215225838], [-0.9818179034627895, -0.16898994746760032], [-0.9817286766212256, -0.1692522720975529], [-0.9816999365134195, -0.16952408506808617], [-0.9631011593561465, -0.22407383768307954], [-0.9261241214554894, -0.3332373958589337], [-0.9258324936825051, -0.33372149935647244], [-0.9256550485311431, -0.33424464732165526], [-0.8892908142480597, -0.39442877141272903], [-0.8349844591540967, -0.4848246738151669], [-0.8343937467699749, -0.4854623435574076], [-0.8339576843969376, -0.48618630154023834], [-0.7815123236794599, -0.5425846069291526], [-0.7118306192672567, -0.617966664323285], [-0.7108683890212548, -0.6186663371142785], [-0.7100824785045414, -0.6195134735411201], [-0.6438607603336002, -0.6674180415864824], [-0.5613139162097582, -0.7275512283974191], [-0.5599384315738856, -0.7282038378223106], [-0.5587377945819172, -0.7290740927297131], [-0.4815608678259665, -0.7654105089476456], [-0.38914121973710103, -0.8093331046820568], [-0.38734618924505493, -0.8098192008360738], [-0.3856985719274389, -0.8105963097699821], [-0.300793362822793, -0.8332697929762293], [-0.20186994365286973, -0.8601008071059514], [-0.19968724762839168, -0.8602986156555108], [-0.19759749454066486, -0.8608576036547885], [-0.10847270367557475, -0.868569161366415], [-0.006667604417683045, -0.8778095371878784], [9.993428809235239, -0.9207122196111148], [10.188576797568265, -0.9039018060848659], [10.295049619580887, -0.8747058746123754], [100.0016801581736, -0.8778191418707327], [100.19759749454067, -0.8608576036547885], [100.38569857192745, -0.8105963097699821], [100.55873779458192, -0.7290740927297131], [100.71008247850455, -0.6195134735411201], [100.83395768439694, -0.48618630154023795], [100.92565504853114, -0.33424464732165526], [100.98169993651341, -0.16952408506808608], [100.99997296537491, 0.0016734646215225838], [101.0001378195948, 0.9962737353793626], [100.98227733151975, 1.1658759961268101], [100.92734305241007, 1.329269548373683], [100.83736709792183, 1.480321394964545], [100.71568951389246, 1.6133389494598158], [100.5668443075726, 1.7232781856005774], [100.39640190540993, 1.8059329159519186], [100.21077163081944, 1.8580983786377043], [100.01696944720078, 1.8777023240108164], [-0.016969447200789016, 1.8777023240108164], [-0.11558040549931292, 1.8677241551728063], [-0.20196072981722304, 1.8597293891562097], [-0.20626195777391565, 1.858554257348017], [-0.21077163081944233, 1.8580983786377043], [-0.3067863154675664, 1.8311044071431357], [-0.3893099761639009, 1.8085904175573915], [-0.3926991135614241, 1.806972518540605], [-0.3964019054099387, 1.8059329159519186], [-0.4863105507139498, 1.7623108430118768], [-0.5615422029114501, 1.7264550095794515], [-0.5640106294673816, 1.7246509402885304], [-0.5668443075725933, 1.7232781856005777], [-0.6473490514031758, 1.663783711980742], [-0.7120942637611076, 1.6165517199956638], [-0.7137092988448768, 1.6147998465280684], [-0.7156895138924567, 1.613338949459816], [-0.7838266159960944, 1.5388048864692472], [-0.8352568321155254, 1.4831421001822067], [-0.8361525232284192, 1.4816472873608162], [-0.8373670979218306, 1.480321394964545], [-0.8906132011432863, 1.3908626928796188], [-0.9263796499859861, 1.3313525673628122], [-0.9267439007849886, 1.330273516904206], [-0.9273430524100664, 1.3292695483736832], [-0.9636915808353507, 1.221044761788726], [-0.9820353170742947, 1.1669793617516468], [-0.9820941733833396, 1.1664191164939568], [-0.9822773315197597, 1.1658759961268104], [-1.0001378195948039, 0.9962737353793626], [-0.999972965374907, 0.0016734646215225838]]]]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = bufferMultiPolygon(pgs, 1, { supposeType: 'ringStrings' })
console.log(JSON.stringify(r))
// => [[[[-0.999972965374907, 0.0016734646215225838], [-0.9816999365134195, -0.16952408506808617], [-0.9256550485311431, -0.33424464732165526], [-0.8339576843969376, -0.48618630154023834], [-0.7100824785045414, -0.6195134735411201], [-0.5587377945819172, -0.7290740927297131], [-0.3856985719274389, -0.8105963097699821], [-0.19759749454066486, -0.8608576036547885], [-0.0016801581736105632, -0.8778191418707327], [100.0016801581736, -0.8778191418707327], [100.19759749454067, -0.8608576036547885], [100.38569857192745, -0.8105963097699821], [100.55873779458192, -0.7290740927297131], [100.71008247850455, -0.6195134735411201], [100.83395768439694, -0.48618630154023795], [100.92565504853114, -0.33424464732165526], [100.98169993651341, -0.16952408506808608], [100.99997296537491, 0.0016734646215225838], [101.0001378195948, 0.9962737353793626], [100.98227733151975, 1.1658759961268101], [100.92734305241007, 1.329269548373683], [100.83736709792183, 1.480321394964545], [100.71568951389246, 1.6133389494598158], [100.5668443075726, 1.7232781856005774], [100.39640190540993, 1.8059329159519186], [100.21077163081944, 1.8580983786377043], [100.01696944720078, 1.8777023240108164], [-0.016969447200789016, 1.8777023240108164], [-0.21077163081944233, 1.8580983786377043], [-0.3964019054099387, 1.8059329159519186], [-0.5668443075725933, 1.7232781856005777], [-0.7156895138924567, 1.613338949459816], [-0.8373670979218306, 1.480321394964545], [-0.9273430524100664, 1.3292695483736832], [-0.9822773315197597, 1.1658759961268104], [-1.0001378195948039, 0.9962737353793626], [-0.999972965374907, 0.0016734646215225838]]]]

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [-10, 0],
            [-10, 123],
            [0, 1],
        ]
    ]
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-0.8003200115692618, -0.17319483904229072], [-0.7836767917581119, -0.36185129662050025], [-0.7353492500966056, -0.5356205533066913], [-0.6573598915218491, -0.6875171220741705], [-0.5528860710099704, -0.8114615637915055], [-0.42613263014680774, -0.9025083033202159], [-0.2821710575596541, -0.9570287022736291], [-0.12674982173334867, -0.9728448294506357], [0.03391918073616935, -0.9493106435389045], [0.19339258801976364, -0.8873384160857741], [0.3452397121045475, -0.7893692808009591], [1.5369003654533981, 0.1356647138214438], [9.191588198819693, 0.06826918146634159], [9.192307047783357, -0.13578991039784927], [9.202271009169792, -0.13405428491048416], [10.158804482559859, 0.9689919195461543], [10.16077733912813, 0.9811061542316537], [2.863436899967487, 1.136386159346504], [99.68496688680972, -0.7769642896931913], [99.83421179074095, -0.8734562808152566], [99.98972082173093, -0.9357358967318228], [100.14543660096865, -0.9614370794615064], [100.29533052474301, -0.9495976354600516], [100.43362308806415, -0.9006892544922344], [100.55499140621131, -0.8165981549358158], [100.65475869385061, -0.7005572523974315], [100.72906125012604, -0.5570315931071955], [100.77498905365053, -0.3915596835725485], [100.79069637974868, -0.21055438124997924], [100.7957087779399, 0.7861023638526387], [100.7827532046974, 0.9688299225352316], [100.74119174958985, 1.1529088665478575], [100.67241992924023, 1.3315795752497988], [100.57883417333557, 1.4982369383506398], [100.46376327137136, 1.6466785725630189], [100.33136278849213, 1.7713440655763257], [-0.3606934449687615, 1.7836997442899267], [-0.48814185554933515, 1.6628590462504012], [-0.5984756368305508, 1.5191268524795047], [-0.6879472419221372, 1.357557344702564], [-0.7535627612906908, 1.1837977633730536], [-0.7816588585154715, 1.0561406499162043], [-0.7838663526582138, 1.0453979454196165], [-0.7840227537259681, 1.0454085103112076], [-0.7931718682275202, 1.0038836582061355], [-0.7935555351828718, 0.9982639340509075], [-0.7947986623768644, 0.9922187506328833], [-0.8055260197997868, 0.8240253238448642], [-0.8003200115692618, -0.17319483904229072]]]]
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

w Number

輸入Buffer寬度數字

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

units String <optional>
'degrees'

輸入Buffer寬度單位,可選'degrees'、'radians'、'meters'、'kilometers'、'feet'、'miles',預設'degrees'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) calcContours(points) → {Array|Object}

Description:
  • 不規則點基於三角化網格計算等值線圖

    Unit Test: Github

Source:
Example
let opt
let pgs

let points = [
    [24.325, 120.786, 0], [23.944, 120.968, 10], [24.884, 121.234, 20], [24.579, 121.345, 80], [24.664, 121.761, 40], [23.803, 121.397, 30],
    [23.727, 120.772, 0], [23.539, 120.975, 0], [23.612, 121.434, 0],
    [23.193, 120.355, 22], [23.456, 120.890, 42], [23.280, 120.551, 25], [23.162, 121.247, 5],
]

let containInner = [ //此結構代表1個polygon, leaflet可支援顯示, 但turf做intersect不支援, 故l-contour會通過toMultiPolygon轉換才能支援
    [
        [24.28, 120.842], [24.494, 121.203], [24.314, 121.190], [24.232, 121.109], [24.249, 120.910],
    ],
    [
        [24.217, 120.851], [24.172, 121.242], [24.059, 121.333], [24.001, 121.055],
    ],
]

let clipInner = [ //此結構代表1個polygon, leaflet可支援顯示, 但turf做difference不支援, 故l-contour會通過toMultiPolygon轉換才能支援
    [
        [24.28, 120.842], [24.494, 121.203], [24.314, 121.190], [24.232, 121.109], [24.249, 120.910],
    ],
    [
        [24.217, 120.851], [24.172, 121.242], [24.059, 121.333], [24.001, 121.055],
    ],
]

let clipOuter = [
    [24.585, 120.79], [24.9, 121.620], [23.984, 121.6], [23.941, 121.196], [24.585, 120.79]
]

let thresholds = [0, 5, 10, 20, 30, 40, 55, 70, 85]

opt = {
    containInner,
    // clipInner,
    // clipOuter,
    // thresholds,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours1.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => [
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 8816415983.520641,
//     effectAreaCentroid: [ 23.973333333333333, 121.13616666666665 ],
//     range: { text: '0 - 10', low: 0, up: 10 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array], [Array] ],
//     effectArea: 6313849792.51668,
//     effectAreaCentroid: [ 23.80531082115246, 121.00212446033244 ],
//     range: { text: '10 - 20', low: 10, up: 20 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 4644527033.145393,
//     effectAreaCentroid: [ 23.791076270349798, 120.96719391394832 ],
//     range: { text: '20 - 30', low: 20, up: 30 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 3211476473.817216,
//     effectAreaCentroid: [ 24.025569342289934, 121.2215115677248 ],
//     range: { text: '30 - 40', low: 30, up: 40 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 2077979122.6009896,
//     effectAreaCentroid: [ 24.155744629924033, 121.28620957869633 ],
//     range: { text: '40 - 50', low: 40, up: 50 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 1165016840.7246127,
//     effectAreaCentroid: [ 24.45565142857143, 121.3283007142857 ],
//     range: { text: '50 - 60', low: 50, up: 60 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   }
// ]

opt = {
    // containInner,
    clipInner,
    // clipOuter,
    // thresholds,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours2.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => [
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 8816415983.520641,
//     effectAreaCentroid: [ 23.973333333333333, 121.13616666666665 ],
//     range: { text: '0 - 10', low: 0, up: 10 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array], [Array], [Array] ],
//     effectArea: 6313849792.51668,
//     effectAreaCentroid: [ 23.80531082115246, 121.00212446033244 ],
//     range: { text: '10 - 20', low: 10, up: 20 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array], [Array], [Array], [Array] ],
//     effectArea: 4644527033.145393,
//     effectAreaCentroid: [ 23.791076270349798, 120.96719391394832 ],
//     range: { text: '20 - 30', low: 20, up: 30 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array], [Array], [Array] ],
//     effectArea: 3211476473.817216,
//     effectAreaCentroid: [ 24.025569342289934, 121.2215115677248 ],
//     range: { text: '30 - 40', low: 30, up: 40 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 2077979122.6009896,
//     effectAreaCentroid: [ 24.155744629924033, 121.28620957869633 ],
//     range: { text: '40 - 50', low: 40, up: 50 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 1165016840.7246127,
//     effectAreaCentroid: [ 24.45565142857143, 121.3283007142857 ],
//     range: { text: '50 - 60', low: 50, up: 60 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 517569529.67260885,
//     effectAreaCentroid: [ 24.49676761904762, 121.33386714285714 ],
//     range: { text: '60 - 70', low: 60, up: 70 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: 'top',
//     latLngs: [ [Array] ],
//     effectArea: 129338350.80859056,
//     effectAreaCentroid: [ 24.537883809523812, 121.33943357142857 ],
//     range: { text: '70 - 80', low: 70, up: 80 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   }
// ]

opt = {
    // containInner,
    // clipInner,
    clipOuter,
    // thresholds,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours3.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => [
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 8816415983.520641,
//     effectAreaCentroid: [ 23.973333333333333, 121.13616666666665 ],
//     range: { text: '0 - 10', low: 0, up: 10 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 6313849792.51668,
//     effectAreaCentroid: [ 23.80531082115246, 121.00212446033244 ],
//     range: { text: '10 - 20', low: 10, up: 20 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array], [Array], [Array] ],
//     effectArea: 4644527033.145393,
//     effectAreaCentroid: [ 23.791076270349798, 120.96719391394832 ],
//     range: { text: '20 - 30', low: 20, up: 30 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array], [Array] ],
//     effectArea: 3211476473.817216,
//     effectAreaCentroid: [ 24.025569342289934, 121.2215115677248 ],
//     range: { text: '30 - 40', low: 30, up: 40 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 2077979122.6009896,
//     effectAreaCentroid: [ 24.155744629924033, 121.28620957869633 ],
//     range: { text: '40 - 50', low: 40, up: 50 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 1165016840.7246127,
//     effectAreaCentroid: [ 24.45565142857143, 121.3283007142857 ],
//     range: { text: '50 - 60', low: 50, up: 60 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 517569529.67260885,
//     effectAreaCentroid: [ 24.49676761904762, 121.33386714285714 ],
//     range: { text: '60 - 70', low: 60, up: 70 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: 'top',
//     latLngs: [ [Array] ],
//     effectArea: 129338350.80859056,
//     effectAreaCentroid: [ 24.537883809523812, 121.33943357142857 ],
//     range: { text: '70 - 80', low: 70, up: 80 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   }
// ]

opt = {
    // containInner,
    // clipInner,
    // clipOuter,
    thresholds,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours4.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => [
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 8816415983.520641,
//     effectAreaCentroid: [ 23.973333333333333, 121.13616666666665 ],
//     range: { text: '0 - 5', low: 0, up: 5 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 7186533231.875366,
//     effectAreaCentroid: [ 23.802593637502845, 121.01686739291412 ],
//     range: { text: '5 - 10', low: 5, up: 10 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 6313849792.51668,
//     effectAreaCentroid: [ 23.80531082115246, 121.00212446033244 ],
//     range: { text: '10 - 20', low: 10, up: 20 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 4644527033.145393,
//     effectAreaCentroid: [ 23.791076270349798, 120.96719391394832 ],
//     range: { text: '20 - 30', low: 20, up: 30 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 3211476473.817216,
//     effectAreaCentroid: [ 24.025569342289934, 121.2215115677248 ],
//     range: { text: '30 - 40', low: 30, up: 40 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 2077979122.6009896,
//     effectAreaCentroid: [ 24.155744629924033, 121.28620957869633 ],
//     range: { text: '40 - 55', low: 40, up: 55 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 808871008.3417139,
//     effectAreaCentroid: [ 24.476209523809523, 121.33108392857142 ],
//     range: { text: '55 - 70', low: 55, up: 70 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   },
//   {
//     sepZone: 'top',
//     latLngs: [ [Array] ],
//     effectArea: 129338350.80859056,
//     effectAreaCentroid: [ 24.537883809523812, 121.33943357142857 ],
//     range: { text: '70 - 85', low: 70, up: 85 },
//     center: [ 23.973333333333333, 121.13616666666665 ]
//   }
// ]

opt = {
    withStyle: true,
    // returnGeojson: true,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours5.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => [
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 8816415983.520641,
//     effectAreaCentroid: [ 23.973333333333333, 121.13616666666665 ],
//     range: { text: '0 - 10', low: 0, up: 10 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(255, 255, 255, 1)',
//       weight: 1,
//       fillColor: 'rgba(255, 255, 255, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(255, 255, 255, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(255, 255, 255, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 6313849792.51668,
//     effectAreaCentroid: [ 23.80531082115246, 121.00212446033244 ],
//     range: { text: '10 - 20', low: 10, up: 20 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(254, 200, 127, 1)',
//       weight: 1,
//       fillColor: 'rgba(254, 200, 127, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(254, 200, 127, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(254, 200, 127, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 4644527033.145393,
//     effectAreaCentroid: [ 23.791076270349798, 120.96719391394832 ],
//     range: { text: '20 - 30', low: 20, up: 30 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(253, 135, 61, 1)',
//       weight: 1,
//       fillColor: 'rgba(253, 135, 61, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(253, 135, 61, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(253, 135, 61, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 3211476473.817216,
//     effectAreaCentroid: [ 24.025569342289934, 121.2215115677248 ],
//     range: { text: '30 - 40', low: 30, up: 40 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(247, 75, 41, 1)',
//       weight: 1,
//       fillColor: 'rgba(247, 75, 41, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(247, 75, 41, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(247, 75, 41, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array], [Array] ],
//     effectArea: 2077979122.6009896,
//     effectAreaCentroid: [ 24.155744629924033, 121.28620957869633 ],
//     range: { text: '40 - 50', low: 40, up: 50 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(225, 61, 39, 1)',
//       weight: 1,
//       fillColor: 'rgba(225, 61, 39, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(225, 61, 39, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(225, 61, 39, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 1165016840.7246127,
//     effectAreaCentroid: [ 24.45565142857143, 121.3283007142857 ],
//     range: { text: '50 - 60', low: 50, up: 60 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(209, 48, 29, 1)',
//       weight: 1,
//       fillColor: 'rgba(209, 48, 29, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(209, 48, 29, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(209, 48, 29, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: '',
//     latLngs: [ [Array] ],
//     effectArea: 517569529.67260885,
//     effectAreaCentroid: [ 24.49676761904762, 121.33386714285714 ],
//     range: { text: '60 - 70', low: 60, up: 70 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(194, 37, 34, 1)',
//       weight: 1,
//       fillColor: 'rgba(194, 37, 34, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(194, 37, 34, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(194, 37, 34, 1)',
//       'fill-opacity': 0.2
//     }
//   },
//   {
//     sepZone: 'top',
//     latLngs: [ [Array] ],
//     effectArea: 129338350.80859056,
//     effectAreaCentroid: [ 24.537883809523812, 121.33943357142857 ],
//     range: { text: '70 - 80', low: 70, up: 80 },
//     center: [ 23.973333333333333, 121.13616666666665 ],
//     style: {
//       color: 'rgba(180, 30, 60, 1)',
//       weight: 1,
//       fillColor: 'rgba(180, 30, 60, 1)',
//       fillOpacity: 0.2,
//       stroke: 'rgba(180, 30, 60, 1)',
//       'stroke-width': 1,
//       'stroke-opacity': 1,
//       fill: 'rgba(180, 30, 60, 1)',
//       'fill-opacity': 0.2
//     }
//   }
// ]

opt = {
    withStyle: true,
    returnGeojson: true,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours6.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => {
//   type: 'FeatureCollection',
//   features: [
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] }
//   ]
// }

opt = {
    withStyle: true,
    returnGeojson: true,
    inverseCoordinate: true,
}
pgs = calcContours(points, opt)
fs.writeFileSync('./calcContours7.json', JSON.stringify(pgs), 'utf8')
console.log(pgs)
// => {
//   type: 'FeatureCollection',
//   features: [
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] },
//     { type: 'Feature', properties: [Object], geometry: [Object] }
//   ]
// }
Parameters:
Name Type Attributes Default Description
points Array

輸入點陣列,各點可為[{x:x1,y:y1},{x:x2,y:y2},...]物件型態,或可為[[x1,y1],[x2,y2],...]陣列型態

opt.keyX String <optional>
'x'

輸入點物件之x座標欄位字串,預設'x'

opt.keyY String <optional>
'y'

輸入點物件之y座標欄位字串,預設'y'

opt.keyZ String <optional>
'z'

輸入點物件之z座標或值欄位字串,預設'z'

opt.containInner Array <optional>
null

輸入等值線圖須保留之MultiPolygon陣列,也就是等值線圖取交集,預設null

opt.clipInner Array <optional>
null

輸入等值線圖須剔除以內之MultiPolygon陣列,也就是等值線圖取差集,預設null

opt.clipOuter Array <optional>
null

輸入等值線圖須剔除以外之MultiPolygon陣列,效果同containInner是等值線圖取交集,預設null

opt.thresholds Array <optional>
null

輸入指定等值線切分值陣列,預設null

opt.withStyle Boolean <optional>
false

輸入是否給予樣式布林值,若returnGeojson給予true也會強制給予樣式,預設false

opt.kpGradientColor function <optional>
{0: 'rgb(255, 255, 255)',0.2: 'rgb(254, 178, 76)',0.4: 'rgb(252, 78, 42)',0.6: 'rgb(220, 58, 38)',0.8: 'rgb(200, 40, 23)',1: 'rgb(180, 30, 60)'}

輸入內插顏色用梯度物件,預設{0: 'rgb(255, 255, 255)',0.2: 'rgb(254, 178, 76)',0.4: 'rgb(252, 78, 42)',0.6: 'rgb(220, 58, 38)',0.8: 'rgb(200, 40, 23)',1: 'rgb(180, 30, 60)'}

opt.funGetFillColor function <optional>
null

輸入內插面顏色用函數,輸入為(k,n),分別代表當前等值線指標與最大指標(也就是等值線數-1),不提供函數時使用預設kpGradientColor進行內插,預設null

opt.fillOpacity Number <optional>
0.2

輸入面顏色透明度數字,預設0.2

opt.lineColor Number <optional>
''

輸入線顏色字串,若有funGetLineColor則優先使用,若無則預設使用面顏色,預設''

opt.funGetLineColor function <optional>
null

輸入內插線顏色用函數,若有給予則覆蓋lineColor,輸入為(k,n),分別代表當前等值線指標與最大指標(也就是等值線數-1),不提供函數時使用預設為面顏色,預設null

opt.lineOpacity Number <optional>
1

輸入線顏色透明度數字,預設1

opt.lineWidth Number <optional>
1

輸入線寬度數字,預設1

opt.returnGeojson Boolean <optional>
false

輸入是否回傳GeoJSON布林值,若為true會強制withStyle給予true,預設false

opt.inverseCoordinate Boolean <optional>
false

輸入是否交換經緯度布林值,因GeoJSON之各點為經緯度,而Leaflet為緯經度,若座標來源與輸出須交換經緯度則使用此設定。預設false

Returns:

回傳點物件陣列或點物件,若使用returnWithVariogram=true則回傳物件資訊,若發生錯誤則回傳錯誤訊息物件

Type
Array | Object

(static) calcDelaunay(points, optopt) → {Object}

Description:
  • 計算Delaunay三角網格

    Unit Test: Github

Source:
Example
let ps
let o
let r

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 283 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371, ext: 'abc' }, { x: 814, y: 252 }]
r = calcDelaunay(ps)
console.log(r)
// => {
//   triangles: [
//     { n0: 5, n1: 7, n2: 9 },
//     { n0: 7, n1: 3, n2: 9 },
//     { n0: 9, n1: 3, n2: 5 },
//     { n0: 8, n1: 4, n2: 3 },
//     { n0: 3, n1: 4, n2: 5 },
//     { n0: 7, n1: 8, n2: 3 },
//     { n0: 5, n1: 0, n2: 7 },
//     { n0: 0, n1: 1, n2: 7 },
//     { n0: 5, n1: 6, n2: 0 },
//     { n0: 0, n1: 6, n2: 1 }
//   ]
// }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 283 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371, ext: 'abc' }, { x: 814, y: 252 }]
o = calcDelaunay(ps, { withFinder: true })

r = o.funFindIn({ x: 1151, y: 371 })
console.log(r)
// => 8

r = o.funFindIn({ x: 1071, y: 371 }, { returnPoint: true })
console.log(r)
// => { x: 1151, y: 371, ext: 'abc' }

r = o.funFindIn({ x: 1061, y: 371 })
console.log(r)
// => 4
Parameters:
Name Type Attributes Default Description
points Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x欄位字串,為座標,預設'x'

keyY String <optional>
'y'

輸入點物件之y欄位字串,為座標,預設'y'

withFinder Boolean <optional>
false

輸入是否多回傳查詢x,y座標所在網格函數布林值,預設false

withInst Boolean <optional>
false

輸入是否多回傳D3的Delaunay建構物件布林值,預設false

Returns:

回傳三角網格資訊物件,triangles為三角網格之節點指標,若發生錯誤則回傳錯誤訊息物件

Type
Object

(static) calcVoronoi(points, optopt) → {Object}

Description:
  • 計算Voronoi多邊形網格

    Unit Test: Github

Source:
Example
let ps
let o
let r

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 283 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371, ext: 'abc' }, { x: 814, y: 252 }]
r = calcVoronoi(ps)
console.log(r)
// => {
//   nodes: [
//     { x: 492.2829390058606, y: 101.37540698936401 },
//     { x: 386.3692756036636, y: 293.58909242298085 },
//     { x: 98.28090392098173, y: 141.96363364262197 },
//     { x: 491.16970240018804, y: 8.420150415699624 },
//     { x: 341.3003289473684, y: 389.4 },
//     { x: 180.96226415094338, y: 389.4 },
//     { x: 68.03825239785515, y: 150.0010950834529 },
//     { x: -35.5, y: 389.4 },
//     { x: -35.5, y: 100.80434782608694 },
//     { x: 856.3136690647482, y: 389.4 },
//     { x: 941.5591142744167, y: 7.170423092131273 },
//     { x: 950.5224880382775, y: -15.400000000000006 },
//     { x: 1037.7035971223022, y: -15.400000000000006 },
//     { x: 1017.3179856115107, y: 389.4 },
//     { x: 1207.5, y: 267.85802469135797 },
//     { x: 1040.6372881355933, y: 389.4 },
//     { x: 1207.5, y: -15.400000000000006 },
//     { x: 690.3167288225892, y: 345.381326584976 },
//     { x: 499.40228070175453, y: -15.400000000000006 },
//     { x: -35.5, y: -15.400000000000006 },
//     { x: 708.7505415162454, y: 389.4 },
//     { x: 1207.5, y: 389.4 }
//   ],
//   polygons: [
//     [ 0, 1, 2, 3, 0 ],
//     [ 1, 4, 5, 6, 2, 1 ],
//     [ 7, 8, 6, 5, 7 ],
//     [ 9, 10, 11, 12, 13, 9 ],
//     [ 14, 15, 13, 12, 16, 14 ],
//     [
//       17,  0,  3, 18,
//       11, 10, 17
//     ],
//     [
//       19, 18,  3, 2,
//        6,  8, 19
//     ],
//     [ 4, 1, 0, 17, 20, 4 ],
//     [ 15, 14, 21, 15 ],
//     [ 20, 17, 10, 9, 20 ]
//   ]
// }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 283 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371, ext: 'abc' }, { x: 814, y: 252 }]
r = calcVoronoi(ps, {
    box: {
        xb0: -100,
        yb0: -50,
        xb1: 1300,
        yb1: 400,
    }
})
console.log(r)
// => {
//   nodes: [
//     { x: 492.2829390058606, y: 101.37540698936401 },
//     { x: 386.3692756036636, y: 293.58909242298085 },
//     { x: 98.28090392098173, y: 141.96363364262197 },
//     { x: 491.16970240018804, y: 8.420150415699624 },
//     { x: 336.3141447368421, y: 400 },
//     { x: 185.96226415094338, y: 400 },
//     { x: 68.03825239785515, y: 150.0010950834529 },
//     { x: -100, y: 400 },
//     { x: -100, y: 70.15683229813664 },
//     { x: 853.9496402877697, y: 400 },
//     { x: 941.5591142744167, y: 7.170423092131273 },
//     { x: 964.2631578947369, y: -50 },
//     { x: 1039.4460431654677, y: -50 },
//     { x: 1016.7841726618705, y: 400 },
//     { x: 1300, y: 200.48148148148147 },
//     { x: 1026.084745762712, y: 400 },
//     { x: 1300, y: -50 },
//     { x: 690.3167288225892, y: 345.381326584976 },
//     { x: 511.3605263157897, y: -50 },
//     { x: -100, y: -50 },
//     { x: 713.1895306859205, y: 400 },
//     { x: 1300, y: 400 }
//   ],
//   polygons: [
//     [ 0, 1, 2, 3, 0 ],
//     [ 1, 4, 5, 6, 2, 1 ],
//     [ 7, 8, 6, 5, 7 ],
//     [ 9, 10, 11, 12, 13, 9 ],
//     [ 14, 15, 13, 12, 16, 14 ],
//     [
//       17,  0,  3, 18,
//       11, 10, 17
//     ],
//     [
//       19, 18,  3, 2,
//        6,  8, 19
//     ],
//     [ 4, 1, 0, 17, 20, 4 ],
//     [ 15, 14, 21, 15 ],
//     [ 20, 17, 10, 9, 20 ]
//   ]
// }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 283 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371, ext: 'abc' }, { x: 814, y: 252 }]
o = calcVoronoi(ps, { withFinder: true })

r = o.funFindIn({ x: 1151, y: 371, ext: 'abc' })
console.log(r)
// => 8

r = o.funFindIn({ x: 1071, y: 371 }, { returnPoint: true })
console.log(r)
// => { x: 1151, y: 371, ext:'abc' }

r = o.funFindIn({ x: 1061, y: 371 })
console.log(r)
// => 4
Parameters:
Name Type Attributes Default Description
points Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x欄位字串,為座標,預設'x'

keyY String <optional>
'y'

輸入點物件之y欄位字串,為座標,預設'y'

scaleBox Number <optional>
1.1

輸入自動計算外框邊界的x,y上下限放大比例,預設1.1

box Array <optional>
[]

輸入外框邊界,為左上右下的2點座標,若有輸入則強制取消scaleBox,預設[]

withFinder Boolean <optional>
false

輸入是否多回傳查詢x,y座標所在網格函數布林值,預設false

withInst Boolean <optional>
false

輸入是否多回傳D3的Voronoi建構物件布林值,預設false

Returns:

回傳多邊形網格資訊物件,nodes為多邊形網格之節點,polygons為多邊形網格之節點指標,其位置係基於points產生,故順序亦對應points,若發生錯誤則回傳錯誤訊息物件

Type
Object

(static) clipMultiPolygon(pgs1, pgs2, optopt) → {Array}

Description:
  • 針對MultiPolygon進行差集(clip)處理,代表pgs1減去pgs2

    Unit Test: Github

Source:
Example
let pgs1
let pgs2
let r

pgs1 = 'not array'
pgs2 = [[[[2, 0], [4, 0], [4, 4], [2, 4]]]] //multiPolygon
try {
    r = clipMultiPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs1

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = 'not array'
try {
    r = clipMultiPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid pgs2

pgs1 = [[[[0, 0], [1, 0], [1, 1], [0, 1]]]] //multiPolygon
pgs2 = []
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[1,0],[1,1],[0,1],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[2,0],[2,4],[0,4],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 0], [2, 2], [0, 2]]] //polygon
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,2],[2,2],[2,0],[4,0],[4,4],[0,4],[0,2]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 2], [0, 4]]] //polygon
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[2,2],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[2, 0], [4, 0], [4, 4], [2, 4]]]] //multiPolygon
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[2,0],[2,4],[0,4],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[0, 0], [2, 0], [2, 2], [0, 2]]]] //multiPolygon
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,2],[2,2],[2,0],[4,0],[4,4],[0,4],[0,2]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[0, 0], [2, 2], [0, 4]]]] //multiPolygon
r = clipMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[2,2],[0,0]]]]
Parameters:
Name Type Attributes Default Description
pgs1 Array

輸入被裁切之MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

pgs2 Array

輸入裁切用之MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) clipPolygon(pgs1, pgs2, optopt) → {Array}

Description:
  • 針對Polygon進行差集(clip)處理,代表pgs1減去pgs2

    Unit Test: Github

Source:
Example
let pgs1
let pgs2
let r

pgs1 = 'not array'
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
try {
    r = clipPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs1

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = 'not array'
try {
    r = clipPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid pgs2

pgs1 = [[[0, 0], [1, 0], [1, 1], [0, 1]]] //polygon
pgs2 = []
r = clipPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[0,0],[1,0],[1,1],[0,1],[0,0]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
r = clipPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[2,4],[2,0],[0,0],[0,4],[2,4]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 0], [2, 2], [0, 2]]] //polygon
r = clipPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[2,0],[2,2],[0,2],[0,4],[4,4]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 2], [0, 4]]] //polygon
r = clipPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[0,0],[2,2],[0,4],[4,4]]]
Parameters:
Name Type Attributes Default Description
pgs1 Array

輸入第1個Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

pgs2 Array

輸入第2個Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
epsilon Number <optional>
0.000000000001

輸入 polybooljs 計算容許誤差

Returns:

回傳Polygon陣列

Type
Array

(static) convertCoordinate(cdFrom, cdTo, ps) → {Array}

Description:
Source:
Example
let ps
let r

//from WGS84
ps = [121, 24]
r = convertCoordinate('WGS84', 'TWD97', ps)
console.log('WGS84', 'to', 'TWD97', r)
// => WGS84 to TWD97 [ 121, 24.000000000000004 ]

ps = [121, 24]
r = convertCoordinate('WGS84', 'TWD67', ps)
console.log('WGS84', 'to', 'TWD67', r)
// => WGS84 to TWD67 [ 120.99185287062672, 24.001775588106096 ]

ps = [121, 24]
r = convertCoordinate('WGS84', 'TWD97TM2', ps)
console.log('WGS84', 'to', 'TWD97TM2', r)
// => WGS84 to TWD97TM2 [ 250000, 2655023.124957118 ]

ps = [121, 24]
r = convertCoordinate('WGS84', 'TWD67TM2', ps)
console.log('WGS84', 'to', 'TWD67TM2', r)
// => WGS84 to TWD67TM2 [ 249171.1063953548, 2655228.969012536 ]

ps = [121, 24]
r = convertCoordinate('WGS84', 'UTMTM6', ps)
console.log('WGS84', 'to', 'UTMTM6', r)
// => WGS84 to UTMTM6 [ 295715.5173190569, 2655913.497631182 ]

//from TWD97
ps = [121, 24.000000000000004]
r = convertCoordinate('TWD97', 'WGS84', ps)
console.log('TWD97', 'to', 'WGS84', r)
// => TWD97 to WGS84 [ 121, 24.000000000000004 ]

ps = [121, 24.000000000000004]
r = convertCoordinate('TWD97', 'TWD67', ps)
console.log('TWD97', 'to', 'TWD67', r)
// => TWD97 to TWD67 [ 120.99185287062672, 24.001775588106103 ]

ps = [121, 24.000000000000004]
r = convertCoordinate('TWD97', 'TWD97TM2', ps)
console.log('TWD97', 'to', 'TWD97TM2', r)
// => TWD97 to TWD97TM2 [ 250000, 2655023.124957118 ]

ps = [121, 24.000000000000004]
r = convertCoordinate('TWD97', 'TWD67TM2', ps)
console.log('TWD97', 'to', 'TWD67TM2', r)
// => TWD97 to TWD67TM2 [ 249171.1063953548, 2655228.9690125366 ]

ps = [121, 24.000000000000004]
r = convertCoordinate('TWD97', 'UTMTM6', ps)
console.log('TWD97', 'to', 'UTMTM6', r)
// => TWD97 to UTMTM6 [ 295715.5173190569, 2655913.4976311824 ]

//from TWD67
ps = [120.99185287062672, 24.001775588106103]
r = convertCoordinate('TWD67', 'WGS84', ps)
console.log('TWD67', 'to', 'WGS84', r)
// => TWD67 to WGS84 [ 120.99999996996448, 24.000000006583658 ]

ps = [120.99185287062672, 24.001775588106103]
r = convertCoordinate('TWD67', 'TWD97', ps)
console.log('TWD67', 'to', 'TWD97', r)
// => TWD67 to TWD97 [ 120.99999996996448, 24.000000006583658 ]

ps = [120.99185287062672, 24.001775588106103]
r = convertCoordinate('TWD67', 'TWD97TM2', ps)
console.log('TWD67', 'to', 'TWD97TM2', r)
// => TWD67 to TWD97TM2 [ 249999.99694413712, 2655023.125686239 ]

ps = [120.99185287062672, 24.001775588106103]
r = convertCoordinate('TWD67', 'TWD67TM2', ps)
console.log('TWD67', 'to', 'TWD67TM2', r)
// => TWD67 to TWD67TM2 [ 249171.1063953548, 2655228.969012536 ]

ps = [120.99185287062672, 24.001775588106103]
r = convertCoordinate('TWD67', 'UTMTM6', ps)
console.log('TWD67', 'to', 'UTMTM6', r)
// => TWD67 to UTMTM6 [ 295715.51731826895, 2655913.4976365822 ]

//from TWD97TM2
ps = [250000, 2655023.124957118]
r = convertCoordinate('TWD97TM2', 'WGS84', ps)
console.log('TWD97TM2', 'to', 'WGS84', r)
// => TWD97TM2 to WGS84 [ 121, 24.000000000000004 ]

ps = [250000, 2655023.124957118]
r = convertCoordinate('TWD97TM2', 'TWD97', ps)
console.log('TWD97TM2', 'to', 'TWD97', r)
// => TWD97TM2 to TWD97 [ 121, 24.000000000000004 ]

ps = [250000, 2655023.124957118]
r = convertCoordinate('TWD97TM2', 'TWD67', ps)
console.log('TWD97TM2', 'to', 'TWD67', r)
// => TWD97TM2 to TWD67 [ 120.99185287062672, 24.001775588106103 ]

ps = [250000, 2655023.124957118]
r = convertCoordinate('TWD97TM2', 'TWD67TM2', ps)
console.log('TWD97TM2', 'to', 'TWD67TM2', r)
// => TWD97TM2 to TWD67TM2 [ 249171.1063953548, 2655228.9690125366 ]

ps = [250000, 2655023.124957118]
r = convertCoordinate('TWD97TM2', 'UTMTM6', ps)
console.log('TWD97TM2', 'to', 'UTMTM6', r)
// => TWD97TM2 to UTMTM6 [ 295715.5173190569, 2655913.4976311824 ]

//from TWD67TM2
ps = [249171.1063953548, 2655228.969012536]
r = convertCoordinate('TWD67TM2', 'WGS84', ps)
console.log('TWD67TM2', 'to', 'WGS84', r)
// => TWD67TM2 to WGS84 [ 120.99999996996448, 24.000000006583658 ]

ps = [249171.1063953548, 2655228.969012536]
r = convertCoordinate('TWD67TM2', 'TWD97', ps)
console.log('TWD67TM2', 'to', 'TWD97', r)
// => TWD67TM2 to TWD97 [ 120.99999996996448, 24.000000006583658 ]

ps = [249171.1063953548, 2655228.969012536]
r = convertCoordinate('TWD67TM2', 'TWD67', ps)
console.log('TWD67TM2', 'to', 'TWD67', r)
// => TWD67TM2 to TWD67 [ 120.99185287062672, 24.001775588106096 ]

ps = [249171.1063953548, 2655228.969012536]
r = convertCoordinate('TWD67TM2', 'TWD97TM2', ps)
console.log('TWD67TM2', 'to', 'TWD97TM2', r)
// => TWD67TM2 to TWD97TM2 [ 249999.99694413712, 2655023.125686239 ]

ps = [249171.1063953548, 2655228.969012536]
r = convertCoordinate('TWD67TM2', 'UTMTM6', ps)
console.log('TWD67TM2', 'to', 'UTMTM6', r)
// => TWD67TM2 to UTMTM6 [ 295715.51731826895, 2655913.4976365822 ]

//from UTMTM6
ps = [295715.5173190569, 2655913.497631182]
r = convertCoordinate('UTMTM6', 'WGS84', ps)
console.log('UTMTM6', 'to', 'WGS84', r)
// => UTMTM6 to WGS84 [ 120.99999997049657, 24.000000006421075 ]

ps = [295715.5173190569, 2655913.497631182]
r = convertCoordinate('UTMTM6', 'TWD97', ps)
console.log('UTMTM6', 'to', 'TWD97', r)
// => UTMTM6 to TWD97 [ 120.99999997049657, 24.000000006421075 ]

ps = [295715.5173190569, 2655913.497631182]
r = convertCoordinate('UTMTM6', 'TWD67', ps)
console.log('UTMTM6', 'to', 'TWD67', r)
// => UTMTM6 to TWD67 [ 120.99185287063509, 24.00177558805831 ]

ps = [295715.5173190569, 2655913.497631182]
r = convertCoordinate('UTMTM6', 'TWD97TM2', ps)
console.log('UTMTM6', 'to', 'TWD97TM2', r)
// =>UTMTM6 to TWD97TM2 [ 249999.99699827324, 2655023.1256682333 ]

ps = [295715.5173190569, 2655913.497631182]
r = convertCoordinate('UTMTM6', 'TWD67TM2', ps)
console.log('UTMTM6', 'to', 'TWD67TM2', r)
// => UTMTM6 to TWD67TM2 [ 249171.10639620616, 2655228.9690072443 ]
Parameters:
Name Type Description
cdFrom String

輸入來源座標系統字串

cdTo String

輸入轉出座標系統字串

ps Array

輸入座標(x,y)陣列

Returns:

回傳轉換之座標陣列

Type
Array

(static) distilMultiPolygon(r) → {Array}

Description:
  • 萃取為MultiPolygon座標陣列

    因turf計算後可能產生多種幾何類型,例如Polygon、MultiPolygon、LineString、GeometryCollection等,故將全部轉成MultiPolygon後回傳

    Unit Test: Github

Source:
Example
let data
let r

data = null
r = distilMultiPolygon(data)
console.log(r)
// => []

data = {
    geometry: {
        type: 'Polygon',
        coordinates: [
            [[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]],
        ],
    },
}
r = distilMultiPolygon(data)
console.log(JSON.stringify(r))
// => [[[[0,0],[1,0],[1,1],[0,1],[0,0]]]]

data = {
    geometry: {
        type: 'MultiPolygon',
        coordinates: [
            [
                [[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]],
            ],
            [
                [[2, 0], [3, 0], [3, 1], [2, 1], [2, 0]],
            ],
        ],
    },
}
r = distilMultiPolygon(data)
console.log(JSON.stringify(r))
// => [[[[0,0],[1,0],[1,1],[0,1],[0,0]]],[[[2,0],[3,0],[3,1],[2,1],[2,0]]]]

data = {
    geometry: {
        type: 'GeometryCollection',
        geometries: [
            { type: 'LineString', coordinates: [[0, 0], [1, 1]] },
            { type: 'Polygon', coordinates: [[[0, 0], [2, 0], [2, 2], [0, 2], [0, 0]]] },
            { type: 'MultiPolygon', coordinates: [[[[10, 0], [11, 0], [11, 1], [10, 1], [10, 0]]]] },
        ],
    },
}
r = distilMultiPolygon(data)
console.log(JSON.stringify(r))
// => [[[[0,0],[2,0],[2,2],[0,2],[0,0]]],[[[10,0],[11,0],[11,1],[10,1],[10,0]]]]

data = {
    geometry: {
        type: 'LineString',
        coordinates: [[0, 0], [1, 1]],
    },
}
r = distilMultiPolygon(data)
console.log(r)
// => []
Parameters:
Name Type Description
r Object

輸入turf幾何運算回傳之Feature物件

Returns:

回傳MultiPolygon陣列

Type
Array

(static) findPointInKpBoxPolygons(p, kpPgs, optopt) → {String}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於某一多邊形與範圍之字典物件,若有則回傳該物件之鍵名,若無則回傳def值

    Unit Test: Github

Source:
Example
let p
let kpPgs = {
    'pgs1': {
        box: { xmin: 0, ymin: 0, xmax: 1, ymax: 1 },
        pgs: [
            [0, 0],
            [0, 1],
            [1, 1],
            [1, 0],
            [0, 0],
        ],
    }
}
let b

p = [0.5, 0.5]
b = findPointInKpBoxPolygons(p, kpPgs)
console.log(b)
// => 'pgs1'

p = [1.5, 0.5]
b = findPointInKpBoxPolygons(p, kpPgs)
console.log(b)
// => 'unknow'

p = [1.5, 0.5]
b = findPointInKpBoxPolygons(p, kpPgs, { def: '未知' })
console.log(b)
// => '未知'
Parameters:
Name Type Attributes Default Description
p Array | Object

輸入點陣列或點物件,為[x,y]或{x,y}

kpPgs Object

輸入多邊形與範圍字典物件,為{key1:{box:{xmin:xmin1,ymin:ymin1,xmax:xmax1,ymax:ymax1},pgs:pgs1},key2:{box:{xmin:xmin2,ymin:ymin2,xmax:xmax2,ymax:ymax2},pgs:pgs2},...keyn:{box:{xmin:xminn,ymin:yminn,xmax:xmaxn,ymax:ymaxn},pgs:pgsn}}

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

toTurfMultiPolygon Boolean <optional>
true

輸入是否轉換多邊形為Turf的MultiPolygon,若須加速可於外部先轉好就不用於函數內再轉,預設true

def String <optional>
'unknow'

輸入若點未位於任一多邊形時,回傳指定名稱字串,預設'unknow'

Returns:

回傳名稱字串

Type
String

(static) findPointInKpFeature(p, kpFt, optopt) → {String}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於某一特徵(Feature)內之字典物件,若有則回傳該特徵之鍵名,若無則回傳def值

    Unit Test: Github

Source:
Example
let p
let b

let kpFt = {
    ft1: {
        'type': 'Feature',
        'properties': {
            'name': 'pgs1',
        },
        'geometry': {
            'type': 'MultiPolygon',
            'coordinates': [
                [
                    [
                        [0, 0],
                        [0, 1],
                        [1, 1],
                        [1, 0],
                        [0, 0],
                    ]
                ]
            ]
        }
    },
    ft2: {
        'type': 'Feature',
        'properties': {
            'name': 'pgs2',
        },
        'geometry': {
            'type': 'MultiPolygon',
            'coordinates': [
                [
                    [
                        [1, 1],
                        [1, 2],
                        [2, 2],
                        [2, 1],
                        [1, 1],
                    ]
                ]
            ]
        }
    },
}

p = [0.5, 0.5]
b = findPointInKpFeature(p, kpFt)
console.log(b)
// => 'ft1'

p = [1.5, 1.5]
b = findPointInKpFeature(p, kpFt)
console.log(b)
// => 'ft2'

p = [2.5, 2.5]
b = findPointInKpFeature(p, kpFt)
console.log(b)
// => 'unknow'

p = [0.5, 0.5]
kpFt = {
    'ft1': [
        [0, 0],
        [0, 1],
        [1, 1],
        [1, 0],
        [0, 0],
    ],
}
b = findPointInKpFeature(p, kpFt)
console.log(b)
// => 'unknow'

p = [0.5, 0.5]
kpFt = {
    'ft1': [
        [0, 0],
        [0, 1],
        [1, 1],
        [1, 0],
        [0, 0],
    ],
}
b = findPointInKpFeature(p, kpFt, { def: '未知' })
console.log(b)
// => '未知'
Parameters:
Name Type Attributes Default Description
p Array | Object

輸入點陣列或點物件,為[x,y]或{x,y}

kpFt Object

輸入字典物件,為{key1:ft1,key2:ft2,...keyn:ftn}

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

def String <optional>
'unknow'

輸入若點未位於任一多邊形時,回傳指定名稱字串,預設'unknow'

Returns:

回傳名稱字串

Type
String

(static) findPointInKpPolygons(p, kpPgs, optopt) → {String}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於某一多邊形內之字典物件,若有則回傳該物件之鍵名,若無則回傳def值

    Unit Test: Github

Source:
Example
let p
let kpPgs = {
    'pgs1': [
        [0, 0],
        [0, 1],
        [1, 1],
        [1, 0],
        [0, 0],
    ],
}
let b

p = [0.5, 0.5]
b = findPointInKpPolygons(p, kpPgs)
console.log(b)
// => 'pgs1'

p = [1.5, 0.5]
b = findPointInKpPolygons(p, kpPgs)
console.log(b)
// => 'unknow'

p = [1.5, 0.5]
b = findPointInKpPolygons(p, kpPgs, { def: '未知' })
console.log(b)
// => '未知'
Parameters:
Name Type Attributes Default Description
p Array | Object

輸入點陣列或點物件,為[x,y]或{x,y}

kpPgs Object

輸入多邊形字典物件,為{key1:pgs1,key2:pgs2,...keyn:pgsn}

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

toTurfMultiPolygon Boolean <optional>
true

輸入是否轉換多邊形為Turf的MultiPolygon,若須加速可於外部先轉好就不用於函數內再轉,預設true

def String <optional>
'unknow'

輸入若點未位於任一多邊形時,回傳指定名稱字串,預設'unknow'

Returns:

回傳名稱字串

Type
String

(static) fixCloseMultiPolygon(pgs, optopt) → {Array}

Description:
  • 修復MultiPolygon內各RingString為閉合

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = fixCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]]]]

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = fixCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = fixCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = fixCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[10,0],[10,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = fixCloseMultiPolygon(pgs) //預設polygon轉multiPolygon使用視為polygons, 故其內會是2個polygons
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]]],[[[0,0],[10,0],[10,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = fixCloseMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]],[[0,0],[10,0],[10,1],[0,1],[0,0]]]]

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = fixCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]],[[0,0],[10,0],[10,1],[0,1],[0,0]]]]
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) fixClosePolygon(pgs, optopt) → {Array}

Description:
  • 修復Polygon內各RingString為閉合

    Unit Test: Github

Source:
Example
Parameters:
Name Type Attributes Default Description
pgs Array

輸入Polygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Returns:

回傳Polygon陣列

Type
Array

(static) fixGeometryMultiPolygon(pgs, optopt) → {Array}

Description:
  • 針對MultiPolygon基於buffer技術進行修復交疊處理

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 1],
        [100, 1],
        [100, 2],
        [0, 2],
    ],
]
r = fixGeometryMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[2.4543004643887743e-8,0.000004341000778110449],[4.478253942047132e-7,3.9563737264184023e-7],[0.000004944644202122001,4.909272681804741e-8],[99.9999950553558,4.909272681804741e-8],[99.99999955217461,3.956373738345482e-7],[99.9999999754572,0.000004341002588442417],[99.99999999348924,0.9999988486143221],[99.99999995344626,0.999999568870442],[99.99999997591864,1.999995742997783],[99.99999956723738,1.9999996309608217],[99.99999514934096,2.000000100059736],[0.000004850659040284691,2.000000100059736],[4.327626116498794e-7,1.9999996309608212],[2.4081188104139243e-8,1.9999957429959938],[6.485176439941562e-9,1.0000011469494172],[4.65536071226287e-8,1.0000004402548102],[2.4543004643887743e-8,0.000004341000778110449]]]]

pgs = [ //polygon
    [
        [0, 0],
        [30, 0],
        [30, 2],
        [0, 2],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = fixGeometryMultiPolygon(pgs, { supposeType: 'ringStrings' }) //polygon內為聯集與剔除的ringStrings
console.log(JSON.stringify(r))
// => [[[[0.0015371637167360477, 1.000002364293075], [9.999900189704238, 1.0000001535413956], [9.999919673591801, 0.9999982095214766], [9.999938404758197, 0.9999925119288909], [9.999955665246668, 0.9999832791495612], [9.999970793470819, 0.9999708650714649], [9.999983209572939, 0.9999557455202851], [9.999992437649679, 0.9999385000212361], [9.999998123993217, 0.9999197895861321], [10.000000050648726, 0.9999003313771063], [10.000010148025869, 0.020386546319412994], [29.99999507326125, 1.497440845759323e-8], [29.999999555920844, 4.3906304398087087e-7], [29.99999998502795, 0.000004870917164687769], [29.999999985105863, 1.9999951573833497], [29.999999560229313, 1.999999569456975], [29.999995099003108, 2.000000029875097], [0.000004900996893631207, 2.000000029875097], [4.397706744600083e-7, 1.999999569456975], [1.489414954562251e-8, 1.9999951573833894], [0.0015371637167360477, 1.000002364293075]]], [[[1.4972047690880916e-8, 0.000004870917155344889], [4.4407915560926857e-7, 4.390630445772249e-7], [0.0000049267387479317335, 1.497440845759323e-8], [0.00009806485682730713, 2.9805899505592034e-7], [0.00008057633554534632, 0.0000019843341333453064], [0.00006180997515592718, 0.000007598079494486938], [0.0000445187648792545, 0.000016727463821629017], [0.000029368046749337576, 0.000029021200606014553], [0.000016940799547362766, 0.00004400624346903811], [0.000007715206588066703, 0.00006110598835085726], [0.00000204625592147356, 0.00007966246044143109], [2.995522223425946e-7, 0.00009745909243872494], [1.4972047690880916e-8, 0.000004870917155344889]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [30, 0],
        [30, 2],
        [0, 2],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]]
r = fixGeometryMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0.0015371637167360477, 1.000002364293075], [9.999900189704238, 1.0000001535413956], [9.999919673591801, 0.9999982095214766], [9.999938404758197, 0.9999925119288909], [9.999955665246668, 0.9999832791495612], [9.999970793470819, 0.9999708650714649], [9.999983209572939, 0.9999557455202851], [9.999992437649679, 0.9999385000212361], [9.999998123993217, 0.9999197895861321], [10.000000050648726, 0.9999003313771063], [10.000010148025869, 0.020386546319412994], [29.99999507326125, 1.497440845759323e-8], [29.999999555920844, 4.3906304398087087e-7], [29.99999998502795, 0.000004870917164687769], [29.999999985105863, 1.9999951573833497], [29.999999560229313, 1.999999569456975], [29.999995099003108, 2.000000029875097], [0.000004900996893631207, 2.000000029875097], [4.397706744600083e-7, 1.999999569456975], [1.489414954562251e-8, 1.9999951573833894], [0.0015371637167360477, 1.000002364293075]]], [[[1.4972047690880916e-8, 0.000004870917155344889], [4.4407915560926857e-7, 4.390630445772249e-7], [0.0000049267387479317335, 1.497440845759323e-8], [0.00009806485682730713, 2.9805899505592034e-7], [0.00008057633554534632, 0.0000019843341333453064], [0.00006180997515592718, 0.000007598079494486938], [0.0000445187648792545, 0.000016727463821629017], [0.000029368046749337576, 0.000029021200606014553], [0.000016940799547362766, 0.00004400624346903811], [0.000007715206588066703, 0.00006110598835085726], [0.00000204625592147356, 0.00007966246044143109], [2.995522223425946e-7, 0.00009745909243872494], [1.4972047690880916e-8, 0.000004870917155344889]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [30, 0],
        [30, 2],
        [0, 2],
    ],
    [
        [1, 0],
        [10, 0],
        [10, 1],
        [1, 1],
    ]
]]
r = fixGeometryMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[1.4972047690880916e-8, 0.000004870917155344889], [4.4407915560926857e-7, 4.390630445772249e-7], [0.0000049267387479317335, 1.497440845759323e-8], [1.000004200923848, 0.002940711771548052], [1.0000001418723181, 0.999900985569779], [1.000002036116173, 0.9999203046467752], [1.0000077013962363, 0.9999388868022], [1.0000169199814777, 0.9999560178763972], [1.0000293375783202, 0.9999710394783875], [1.0000444769469907, 0.9999833742895019], [1.0000617562430016, 0.9999925482512149], [1.0000805113789035, 0.9999982087844425], [1.0001000215468387, 1.0000001383400934], [9.999900174166491, 1.0000001380711014], [9.999919660261853, 0.9999981966946103], [9.999938393998693, 0.9999925009017745], [9.999955657179884, 0.999983269052659], [9.999970787985113, 0.9999708550694856], [9.999983206343181, 0.99995573486829], [9.999992436170238, 0.9999384881136842], [9.999998123621497, 0.9999197759961898], [10.000000050656604, 0.9999003158841037], [10.000010148025869, 0.020386546319412994], [29.99999507326125, 1.497440845759323e-8], [29.999999555920844, 4.3906304398087087e-7], [29.99999998502795, 0.000004870917164687769], [29.999999985105863, 1.9999951573833497], [29.999999560229313, 1.999999569456975], [29.999995099003108, 2.000000029875097], [0.000004900996893631207, 2.000000029875097], [4.397706744600083e-7, 1.999999569456975], [1.489414954562251e-8, 1.9999951573833894], [1.4972047690880916e-8, 0.000004870917155344889]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [30, 0],
        [30, 2],
        [0, 2],
    ],
    [
        [0, 0.5],
        [10, 0.5],
        [10, 1.5],
        [0, 1.5],
    ]
]]
r = fixGeometryMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[1.4972047690880916e-8, 0.000004870917155344889], [4.4407915560926857e-7, 4.390630445772249e-7], [0.0000049267387479317335, 1.497440845759323e-8], [29.99999507326125, 1.497440845759323e-8], [29.999999555920844, 4.3906304398087087e-7], [29.99999998502795, 0.000004870917164687769], [29.999999985105863, 1.9999951573833497], [29.999999560229313, 1.999999569456975], [29.999995099003108, 2.000000029875097], [0.000004900996893631207, 2.000000029875097], [4.397706744600083e-7, 1.999999569456975], [1.489414954562251e-8, 1.9999951573833894], [0.0011530813901156408, 1.5000020713424091], [9.999900172402961, 1.5000001792447202], [9.999919659692646, 1.4999982302186918], [9.999938394116294, 1.4999925278358137], [9.99995565759653, 1.499983290664326], [9.999970788436201, 1.4999708727584635], [9.999983206680765, 1.4999557500878122], [9.999992436347585, 1.4999385022937257], [9.99999812367, 1.4999197904720754], [10.00000005065697, 1.4999003318338948], [10.000000050797992, 0.5000999761110504], [9.99999811685868, 0.5000804796940861], [9.999992409269023, 0.5000617344631452], [9.999983147655499, 0.5000444617292844], [9.999970688402396, 0.5000293261422671], [9.999955510938227, 0.5000169101150291], [9.999938199287458, 0.5000076914126002], [9.999919419597397, 0.5000020247678552], [9.999899894505019, 0.5000001282315094], [0.0011527347727830106, 0.5000014752481151], [1.4972047690880916e-8, 0.000004870917155344889]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [30, 0],
        [30, 2],
        [0, 2],
    ],
    [
        [0, 0.1],
        [10, 1],
        [0, 1.9],
    ]
]]
r = fixGeometryMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[1.4972047690880916e-8, 0.000004870917155344889], [4.4407915560926857e-7, 4.390630445772249e-7], [0.0000049267387479317335, 1.497440845759323e-8], [29.99999507326125, 1.497440845759323e-8], [29.999999555920844, 4.3906304398087087e-7], [29.99999998502795, 0.000004870917164687769], [29.999999985105863, 1.9999951573833497], [29.999999560229313, 1.999999569456975], [29.999995099003108, 2.000000029875097], [0.000004900996893631207, 2.000000029875097], [4.397706744600083e-7, 1.999999569456975], [1.489414954562251e-8, 1.9999951573833894], [0.0002922411406645481, 1.8999745622923148], [9.998906350816243, 1.0001011572306464], [9.998925696522443, 1.0000974213416731], [9.998943933308668, 1.0000899705538862], [9.998960353341364, 1.0000790940583504], [9.998974319301526, 1.000065214009869], [9.998985289121299, 1.0000488691416811], [9.998992837023545, 1.0000306938553383], [9.998996670047767, 1.0000113935973485], [9.998996639420906, 0.9999917174783173], [9.998992746331771, 0.9999724291973252], [9.998985141884864, 0.9999542774000806], [9.998974121235493, 0.9999379666213498], [9.998960112133709, 0.9999241299394874], [9.998943658321851, 0.9999133044044544], [9.99892539842995, 0.9999059101930335], [9.998906041188281, 0.9999022343003149], [0.00029208302913059816, 0.10002633650646778], [1.4972047690880916e-8, 0.000004870917155344889]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [30, 0],
        [30, 2],
        [0, 2],
    ],
    [
        [0, 0],
        [10, 1],
        [0, 2],
    ]
]]
r = fixGeometryMultiPolygon(pgs, { w: 0.1 })
console.log(JSON.stringify(r))
// => [[[[0.00001493562676801525, 0.004870917159739751], [0.00044407887408247094, 0.00043906331038822934], [0.0049267387507242605, 0.000014972007631596088], [29.995073261249274, 0.000014972007631596088], [29.99955592112591, 0.00043906331038842813], [29.999985064373227, 0.004870917159736172], [29.9999851419269, 1.9951573831632807], [29.999560229699426, 1.9995694566349922], [29.99509900303653, 2.0000298703100317], [0.004900996963469827, 2.0000298703100317], [0.00043977030057626383, 1.9995694566349926], [0.000014858073099092731, 1.9951573831632807], [0.0015348884924635973, 1.0386277975367435], [0.0003175207251453951, 1.8907939069468858], [0.001984832322072281, 1.9090372392814843], [0.007029565194554841, 1.9266592551841506], [0.015278720084231411, 1.9430550680328056], [0.02644931845677425, 1.957661815388661], [0.04015808041696531, 1.9699779675362736], [0.05593454467525001, 1.9795805438228191], [0.07323718582519159, 1.9861396463070775], [0.09147198071214062, 1.9894298103275292], [0.11001279027535979, 1.989337779082996], [9.016671974453434, 1.1006903809241837], [9.035853602287938, 1.0968092006025036], [9.05391072984683, 1.0892740950662076], [9.070151787761773, 1.07837352261084], [9.083954741413793, 1.064524859541747], [9.094790931645358, 1.048258420646872], [9.102245336883204, 1.03019714718097], [9.106032478086824, 1.0110327410947344], [9.106007355743246, 0.991499161311665], [9.102170999500421, 0.9723444995519088], [9.094670418473028, 0.9543023155537147], [9.083792955680968, 0.9380635321364007], [9.069955265138775, 0.9242499686190593], [9.053687336499435, 0.9133905275635273], [9.035612181926473, 0.9059009471844243], [9.016421965741754, 0.9020678941227268], [0.11024304431593406, 0.011026429282299877], [0.09168084895552824, 0.010881848524895], [0.07341663848111533, 0.014132082279345088], [0.05607968722019283, 0.02066486665262698], [0.04026722958033469, 0.030254879844295875], [0.02652390664930831, 0.0425715343608882], [0.015323033525298983, 0.05719038479346033], [0.007050327996649368, 0.07360775581914084], [0.0019906558094120565, 0.09125808606905769], [0.00031824404173219384, 0.1095333917675677], [0.00001493562676801525, 0.004870917159739751]]]]
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

w Number <optional>
0.0001

輸入Buffer寬度數字,預設0.0001

units String <optional>
'degrees'

輸入Buffer寬度單位,可選'degrees'、'radians'、'meters'、'kilometers'、'feet'、'miles',預設'degrees'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) flattenMultiPolygon(pgs, optopt) → {Array}

Description:
  • 針對MultiPolygon進行扁平化處理,適配GeoJSON規範要求

    GeoJSON 規格(RFC 7946)對Polygon的定義是第1個LinearRing是exterior ring,後面的則是interior rings(holes),把多層ring都塞在同一個Polygon內時,對於GeoJSON就變成除了第一個以外,其他ring都會被當成洞(interior rings)

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = 'not array'
try {
    r = flattenMultiPolygon(pgs, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs

pgs = [ //polygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[2, 0], [4, 0], [4, 4], [2, 4]],
]
r = flattenMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [[[[0,4],[0,0],[2,0],[2,4],[0,4]]]]

pgs = [ //polygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[0, 0], [2, 0], [2, 2], [0, 2]],
]
r = flattenMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [[[[0,4],[0,2],[2,2],[2,0],[4,0],[4,4],[0,4]]]]

pgs = [ //polygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[0, 0], [2, 2], [0, 4]],
]
r = flattenMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [[[[0,4],[2,2],[0,0],[4,0],[4,4],[0,4]]]]

pgs = [[ //multiPolygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[2, 0], [4, 0], [4, 4], [2, 4]],
]]
r = flattenMultiPolygon(pgs, {})
console.log(JSON.stringify(r))
// => [[[[0,4],[0,0],[2,0],[2,4],[0,4]]]]

pgs = [[ //multiPolygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[0, 0], [2, 0], [2, 2], [0, 2]],
]]
r = flattenMultiPolygon(pgs, {})
console.log(JSON.stringify(r))
// => [[[[0,4],[0,2],[2,2],[2,0],[4,0],[4,4],[0,4]]]]

pgs = [[ //multiPolygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[0, 0], [2, 2], [0, 4]],
]]
r = flattenMultiPolygon(pgs, {})
console.log(JSON.stringify(r))
// => [[[[0,4],[2,2],[0,0],[4,0],[4,4],[0,4]]]]

pgs = [[ //multiPolygon
    [[0, 0], [4, 0], [4, 4], [0, 4]],
    [[10, 0], [12, 2], [10, 4]],
]]
r = flattenMultiPolygon(pgs, {})
console.log(JSON.stringify(r))
// => [[[[0,4],[0,0],[4,0],[4,4],[0,4]]],[[[10,4],[10,0],[12,2],[10,4]]]]
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) getAreaMultiPolygon(pgs, optopt) → {Number}

Description:
  • 計算MultiPolygon面積 得要考慮多區域、剔除區域之組合: http://esri.github.io/geometry-api-java/doc/Polygon.html

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getAreaMultiPolygon(pgs)
console.log(r)
// => 100

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getAreaMultiPolygon(pgs)
console.log(r)
// => 100

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getAreaMultiPolygon(pgs)
console.log(r)
// => 100

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getAreaMultiPolygon(pgs)
console.log(r)
// => 10

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getAreaMultiPolygon(pgs) //預設polygon轉multiPolygon使用視為polygons, 故其內會是2個polygons故面積直接加總
console.log(r)
// => 110

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getAreaMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(r)
// => 90

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = getAreaMultiPolygon(pgs)
console.log(r)
// => 90
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳面積數字

Type
Number

(static) getAreaMultiPolygonSm(pgs, optopt) → {Number}

Description:
  • 計算MultiPolygon面積,輸入各點為經緯度座標,輸出為平方公尺面積

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [121, 23],
    [122, 23],
    [122, 24],
    [121, 24],
    [121, 23], //閉合
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 11338704025.00093

pgs = [ //ringString
    [121, 23],
    [122, 23],
    [122, 24],
    [121, 24],
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 11338704025.00093

pgs = [ //polygon
    [
        [121, 23],
        [122, 23],
        [122, 24],
        [121, 24],
    ]
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 11338704025.00093

pgs = [ //polygon
    [
        [121, 23],
        [121.5, 23],
        [121.5, 24],
        [121, 24],
    ]
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 5669352012.500465

pgs = [ //polygon
    [
        [121, 23],
        [122, 23],
        [122, 24],
        [121, 24],
    ],
    [
        [121, 23],
        [121.5, 23],
        [121.5, 24],
        [121, 24],
    ]
]
r = getAreaMultiPolygonSm(pgs) //預設polygon轉multiPolygon使用視為polygons, 故其內會是2個polygons故面積直接加總
console.log(r)
// => 17008056037.501396

pgs = [ //polygon
    [
        [121, 23],
        [122, 23],
        [122, 24],
        [121, 24],
    ],
    [
        [121, 23],
        [121.5, 23],
        [121.5, 24],
        [121, 24],
    ]
]
r = getAreaMultiPolygonSm(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings, 但turf計算時只取最後ringString計算面積
console.log(r)
// => 5669352012.500465

pgs = [ //multiPolygon
    [
        [
            [121, 23],
            [122, 23],
            [122, 24],
            [121, 24],
        ],
        [
            [121, 23],
            [121.5, 23],
            [121.5, 24],
            [121, 24],
        ]
    ]
]
r = getAreaMultiPolygonSm(pgs) //turf計算時只取最後ringString計算面積
console.log(r)
// => 5669352012.500465
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳面積數字,單位為m2

Type
Number

(static) getAreaPolygon(pg) → {Number}

Description:
  • 計算Polygon面積 得要考慮多區域、剔除區域之組合: http://esri.github.io/geometry-api-java/doc/Polygon.html

    Unit Test: Github

Source:
Example
let pg
let r

pg = [
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getAreaPolygon(pg)
console.log(r)
// => 100

pg = [
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getAreaPolygon(pg)
console.log(r)
// => 100

pg = [
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getAreaPolygon(pg)
console.log(r)
// => 100

pg = [
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getAreaPolygon(pg)
console.log(r)
// => 10

pg = [
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getAreaPolygon(pg)
console.log(r)
// => 90

pg = [
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [ //第 2 RingString 與第 1 RingString 不重疊, 但polygon第1個為主要區, 其後為剔除區, 此為有問題多邊形
        [200, 0],
        [210, 0],
        [210, 1],
        [200, 1],
    ]
]
r = getAreaPolygon(pg)
console.log(r)
// => 90, 實際為110
Parameters:
Name Type Description
pg Array

輸入Polygon資料陣列,為[[[x1,y1],[x2,y2],...]]構成之陣列

Returns:

回傳面積數字

Type
Number

(static) getAreaRingString(rs, optopt) → {Number}

Description:
  • 計算RingString面積

    Unit Test: Github

Source:
Example
let rs
let r

rs = [
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getAreaRingString(rs)
console.log(r)
// => 100

rs = [
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getAreaRingString(rs)
console.log(r)
// => 100

rs = [
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getAreaRingString(rs)
console.log(r)
// => 0
Parameters:
Name Type Attributes Default Description
rs Array

輸入RingString資料陣列,為[[x1,y1],[x2,y2],...]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
useAbs Boolean <optional>
true

輸入面積是否取絕對值,預設true

Returns:

回傳面積數字

Type
Number

(static) getBox(fts) → {Object}

Description:
  • 計算點、線、面陣列之外接矩形範圍

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getBox(pgs)
console.log(JSON.stringify(r))
// => {"xmin":0,"ymin":0,"xmax":100,"ymax":1}

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getBox(pgs)
console.log(JSON.stringify(r))
// => {"xmin":0,"ymin":0,"xmax":100,"ymax":1}

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getBox(pgs)
console.log(JSON.stringify(r))
// => {"xmin":0,"ymin":0,"xmax":100,"ymax":1}

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getBox(pgs)
console.log(JSON.stringify(r))
// => {"xmin":0,"ymin":0,"xmax":10,"ymax":1}

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getBox(pgs)
console.log(JSON.stringify(r))
// => {"xmin":0,"ymin":0,"xmax":100,"ymax":1}

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [-10, 0],
            [-10, 123],
            [0, 1],
        ]
    ]
]
r = getBox(pgs)
console.log(JSON.stringify(r))
// => {"xmin":-10,"ymin":0,"xmax":100,"ymax":123}
Parameters:
Name Type Description
fts Array

輸入資料陣列,為多點(multiPoint)、線(line)、多線(multiLine)、面(polygon)、多面(multiPolygon)數據陣列

Returns:

回傳外接矩形範圍物件

Type
Object

(static) getBoxFromGeojson(geojson, optopt) → {Object}

Description:
  • 計算Geojson的點、線、面陣列之外接矩形範圍

    Unit Test: Github

Source:
Example
let geojson
let r

geojson = {
    'type': 'FeatureCollection',
    'name': 'pgs',
    'features': [
        {
            'type': 'Feature',
            'properties': {
                'name': 'pgs1',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [0, 0],
                            [0, 1],
                            [1, 1],
                            [1, 0],
                            [0, 0],
                        ]
                    ]
                ]
            }
        },
        {
            'type': 'Feature',
            'properties': {
                'name': 'pgs2',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [1, 1],
                            [1, 2],
                            [2, 2],
                            [2, 1],
                            [1, 1],
                        ]
                    ]
                ]
            }
        },
    ]
}
r = getBoxFromGeojson(geojson)
console.log(r)
// => { xmin: 0, xmax: 2, ymin: 0, ymax: 2 }

geojson = {
    'type': 'Feature',
    'properties': {},
    'geometry': {
        'type': 'MultiPolygon',
        'coordinates': {
            'type': 'Feature',
            'properties': {
                'name': 'pgs',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [0, 0],
                            [-0.2, 1],
                            [1, 1.1],
                            [1, 0],
                            [0, 0],
                        ]
                    ]
                ]
            }
        }
    }
}
r = getBoxFromGeojson(geojson)
console.log(r)
// => { xmin: -0.2, xmax: 1, ymin: 0, ymax: 1.1 }
Parameters:
Name Type Attributes Default Description
geojson Array

輸入資料陣列,為多點(multiPoint)、線(line)、多線(multiLine)、面(polygon)、多面(multiPolygon)數據陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
toTurfMultiPolygon Boolean <optional>
true

輸入是否轉換多邊形為Turf的MultiPolygon,若須加速可於外部先轉好就不用於函數內再轉,預設true

Returns:

回傳外接矩形範圍物件

Type
Object

(static) getBoxPolygon(fts) → {Array}

Description:
  • 計算點、線、面陣列之外接矩形並轉出polygon陣列

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getBoxPolygon(pgs)
console.log(r)
// => [ [ 0, 0 ], [ 100, 0 ], [ 100, 1 ], [ 0, 1 ], [ 0, 0 ] ]

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getBoxPolygon(pgs)
console.log(r)
// => [ [ 0, 0 ], [ 100, 0 ], [ 100, 1 ], [ 0, 1 ], [ 0, 0 ] ]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getBoxPolygon(pgs)
console.log(r)
// => [ [ 0, 0 ], [ 100, 0 ], [ 100, 1 ], [ 0, 1 ], [ 0, 0 ] ]

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getBoxPolygon(pgs)
console.log(r)
// => [ [ 0, 0 ], [ 10, 0 ], [ 10, 1 ], [ 0, 1 ], [ 0, 0 ] ]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getBoxPolygon(pgs)
console.log(r)
// => [ [ 0, 0 ], [ 100, 0 ], [ 100, 1 ], [ 0, 1 ], [ 0, 0 ] ]

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [-10, 0],
            [-10, 123],
            [0, 1],
        ]
    ]
]
r = getBoxPolygon(pgs)
console.log(r)
// => [ [ -10, 0 ], [ 100, 0 ], [ 100, 123 ], [ -10, 123 ], [ -10, 0 ] ]
Parameters:
Name Type Description
fts Array

輸入資料陣列,為多點(multiPoint)、線(line)、多線(multiLine)、面(polygon)、多面(multiPolygon)數據陣列

Returns:

回傳polygon陣列

Type
Array

(static) getCenterOfMassMultiPolygon(pgs, optopt) → {Number}

Description:
  • 計算MultiPolygon質心座標

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getCenterOfMassMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5]

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getCenterOfMassMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getCenterOfMassMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5]

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getCenterOfMassMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [5,0.5]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getCenterOfMassMultiPolygon(pgs) //預設polygon轉multiPolygon使用視為polygons, 故其內會是2個polygons
console.log(JSON.stringify(r))
// => [50,0.5] //非2個ringString共構的polygon質心, 僅計算第1個

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getCenterOfMassMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [50,0.5] //非第1個ringString剔除第2個ringString的質心, 僅計算第1個

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = getCenterOfMassMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5] //非第1個ringString剔除第2個ringString的質心, 僅計算第1個
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳質心座標

Type
Number

(static) getCentroidMultiPolygon(pgs, optopt) → {Array}

Description:
  • 計算MultiPolygon形心座標

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = getCentroidMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5]

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = getCentroidMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = getCentroidMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [50,0.5]

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getCentroidMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [5,0.5]

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getCentroidMultiPolygon(pgs) //預設polygon轉multiPolygon使用視為polygons, 故其內會是2個polygons
console.log(JSON.stringify(r))
// => [27.5,0.5] //非2個ringString共構的polygon形心
console.log('(50*10+5*1)/11', (50 * 10 + 5 * 1) / 11)
// => (50*10+5*1)/11 45.90909090909091

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = getCentroidMultiPolygon(pgs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [27.5,0.5] //非第1個ringString剔除第2個ringString的形心

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = getCentroidMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [27.5,0.5] //非第1個ringString剔除第2個ringString的形心
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳形心座標陣列

Type
Array

(static) getKpFeatureFromGeojson(geojson, optopt) → {Object}

Description:
  • 由geojson內features提取指定key做鍵之字典物件

    Unit Test: Github

Source:
Example
let geojson
let kp

geojson = `
{
    'type': 'FeatureCollection',
    'name': 'pgs',
    'features': [
        {
            'type': 'Feature',
            'properties': {
                'name': 'pgs1',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [0, 0],
                            [0, 1],
                            [1, 1],
                            [1, 0],
                            [0, 0],
                        ]
                    ]
                ]
            }
        },
        {
            'type': 'Feature',
            'properties': {
                'name': 'pgs2',
            },
            'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                    [
                        [
                            [1, 1],
                            [1, 2],
                            [2, 2],
                            [2, 1],
                            [1, 1],
                        ]
                    ]
                ]
            }
        },
    ]
}
`

kp = getKpFeatureFromGeojson(geojson, { keysPick: 'properties.name' })
console.log(kp)
// => {
//   pgs1: {
//     type: 'Feature',
//     properties: { name: 'pgs1' },
//     geometry: { type: 'MultiPolygon', coordinates: [Array] }
//   },
//   pgs2: {
//     type: 'Feature',
//     properties: { name: 'pgs2' },
//     geometry: { type: 'MultiPolygon', coordinates: [Array] }
//   }
// }
Parameters:
Name Type Attributes Default Description
geojson String | Object

輸入geojson字串或物件

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyFeatures String <optional>
'geometry.coordinates.features'

輸入geojson轉換至Turf的MultiPolygon物件時,取得Features數據之鍵名路徑字串,預設'geometry.coordinates.features'

keysPick Array | String <optional>
[]

輸入由特徵取得做為鍵名之路徑字串,預設[]

sepKeysPick String <optional>
'|'

輸入由keysPick取得多鍵名之組裝用分隔字串,預設'|'

def String <optional>
'unknow'

輸入回傳預設鍵名字串,代表features內找不到opt.key則使用opt.def做鍵名,而若有多個找不到情形則複寫處理,也就是取最末者。預設'unknow'

Returns:

回傳字典物件

Type
Object

(static) getPointDepth(p) → {Integer}

Description:
  • 計算數據內點物件深度

    Unit Test: Github

Source:
Example
let p
let r

try {
    p = [[[[[1, 2.5], [1.1, 2.3]]]]]
    r = getPointDepth(p)
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid p[[[[[[1,2.5],[1.1,2.3]]]]]]

p = [[[[1, 2.5], [1.1, 2.3]]]]
r = getPointDepth(p)
console.log(r)
// => 3

p = [[[[1, 2.5]]]]
r = getPointDepth(p)
console.log(r)
// => 3

p = [[[1, 2.5]]]
r = getPointDepth(p)
console.log(r)
// => 2

p = [[1, 2.5]]
r = getPointDepth(p)
console.log(r)
// => 1

try {
    p = [{ x: 1, y: 2.5 }]
    r = getPointDepth(p)
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid p[[{"x":1,"y":2.5}]]
Parameters:
Name Type Description
p Object

輸入點座標物件

Returns:

回傳深度整數

Type
Integer

(static) interp1(ps, x, optopt) → {Number|Object}

Description:
  • 針對不規則一維數據進行指定內插點數值

Source:
Example
let ps
let p
let r

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 28 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371 }, { x: 814, y: 252 }]
p = {
    x: 243,
}
r = await interp1(ps, p)
console.log(r)
// => { x: 243, y: 206 }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 28 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371 }, { x: 814, y: 252 }]
p = {
    x: 283,
}
r = await interp1(ps, p)
console.log(r)
// => { x: 283, y: 228.0408163265306 }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 28 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371 }, { x: 814, y: 252 }]
p = {
    x: 1160,
}
r = await interp1(ps, p)
console.log(r)
// => { x: 1160, y: null }

ps = [{ a: 243, b: 206 }, { a: 233, b: 225 }, { a: 21, b: 325 }, { a: 953, b: 28 }, { a: 1092, b: 290 }, { a: 744, b: 200 }, { a: 174, b: 3 }, { a: 537, b: 368 }, { a: 1151, b: 371 }, { a: 814, b: 252 }]
p = {
    a: 243,
}
r = await interp1(ps, p, { keyX: 'a', keyY: 'b' })
console.log(r)
// => { a: 243, b: 206 }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 28 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371 }, { x: 814, y: 252 }]
p = [
    {
        x: 243,
    },
    {
        x: 283,
    },
]
r = await interp1(ps, p)
console.log(r)
// => [ { x: 243, y: 206 }, { x: 283, y: 228.0408163265306 } ]

ps = [{ x: 0.000243, y: 0.000206 }, { x: 0.000233, y: 0.000225 }, { x: 0.000021, y: 0.000325 }, { x: 0.000953, y: 0.000028 }, { x: 0.001092, y: 0.00029 }, { x: 0.000744, y: 0.000200 }, { x: 0.000174, y: 0.000003 }, { x: 0.000537, y: 0.000368 }, { x: 0.001151, y: 0.000371 }, { x: 0.000814, y: 0.000252 }]
p = {
    x: 0.000243,
}
r = await interp1(ps, p)
console.log(r)
// => { x: 0.000243, y: 0.00020600000000000002 }

ps = [{ x: 243, y: 206 }, { x: 233, y: 225 }, { x: 21, y: 325 }, { x: 953, y: 28 }, { x: 1092, y: 290 }, { x: 744, y: 200 }, { x: 174, y: 3 }, { x: 537, y: 368 }, { x: 1151, y: 371 }, { x: 814, y: 252 }]
p = {
    x: 243,
}
r = interp1(ps, p, { useSync: true }) //使用interp2.wk.umd.js則不支援sync模式
console.log(r)
// => { x: 243, y: 206 }
Parameters:
Name Type Attributes Default Description
ps Array

輸入一維數據,格式可支援兩種,第一種各點為陣列[[x1,y1],[x2,y2],...],例如[[0.1,5],[0.2,12],...],第二種各點為物件,屬性至少要有x與y,格式為[{x:x1,y:y1},{x:x2,y:y2},...],例如[{x:0.1,y:5},{x:0.2,y:12},...],key值x與y可由opt更換

x Number

輸入要內插點的x值

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
method String <optional>
''

輸入內插方法,可選'linear'、'stairs'、'blocks',預設'linear'

keyX String <optional>
'x'

輸入若數據為物件陣列,取物件x值時的key字串,預設為'x'

keyY String <optional>
'y'

輸入若數據為物件陣列,取物件y值時的key字串,預設為'y'

xMin Number <optional>

輸入若mode='stairs',更改x範圍下限值,預設為undefined

xMax Number <optional>

輸入若mode='stairs',更改x範圍上限值,預設為undefined

Returns:

回傳內插結果數值,或是無法內插時之錯誤訊息物件

Type
Number | Object

(static) interp2(psSrc, psTar, optopt) → {Promise|Array|Object}

Description:
  • 針對不規則二維數據進行指定內插點數值

    Unit Test: Github

Source:
Example
let ps
let p
let r

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
r = await interp2(ps, p)
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486813 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 283,
    y: 207,
}
r = await interp2(ps, p)
console.log(r)
// => { x: 283, y: 207, z: 114.43040421951908 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 1160,
    y: 380,
}
r = await interp2(ps, p)
console.log(r)
// => { x: 1160, y: 380, z: null }

ps = [{ a: 243, b: 206, c: 95 }, { a: 233, b: 225, c: 146 }, { a: 21, b: 325, c: 22 }, { a: 953, b: 28, c: 223 }, { a: 1092, b: 290, c: 39 }, { a: 744, b: 200, c: 191 }, { a: 174, b: 3, c: 22 }, { a: 537, b: 368, c: 249 }, { a: 1151, b: 371, c: 86 }, { a: 814, b: 252, c: 125 }]
p = {
    a: 243,
    b: 207,
}
r = await interp2(ps, p, { keyX: 'a', keyY: 'b', keyZ: 'c' })
console.log(r)
// => { a: 243, b: 207, c: 97.29447682486813 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = [
    {
        x: 243,
        y: 207,
    },
    {
        x: 283,
        y: 207,
    },
]
r = await interp2(ps, p)
console.log(r)
// => [
//   { x: 243, y: 207, z: 97.29447682486813 },
//   { x: 283, y: 207, z: 114.43040421951908 }
// ]

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
r = await interp2(ps, p, { method: 'kriging' })
console.log(r)
// => { x: 243, y: 207, z: 97.4283695751981 }

ps = [{ x: 0.000243, y: 0.000206, z: 95 }, { x: 0.000233, y: 0.000225, z: 146 }, { x: 0.000021, y: 0.000325, z: 22 }, { x: 0.000953, y: 0.000028, z: 223 }, { x: 0.001092, y: 0.00029, z: 39 }, { x: 0.000744, y: 0.000200, z: 191 }, { x: 0.000174, y: 0.000003, z: 22 }, { x: 0.000537, y: 0.000368, z: 249 }, { x: 0.001151, y: 0.000371, z: 86 }, { x: 0.000814, y: 0.000252, z: 125 }]
p = {
    x: 0.000243,
    y: 0.000207,
}
r = await interp2(ps, p)
console.log(r)
// => { x: 0.000243, y: 0.000207, z: 97.2944768248678 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
r = await interp2(ps, p, { scale: 1000 })
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486855 }

//for interp2.wk.umd.js
ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
r = interp2(ps, p, { useSync: true }) //使用interp2.wk.umd.js則不支援sync模式
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486813 }
Parameters:
Name Type Attributes Default Description
psSrc Array

輸入點陣列,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列

psTar Array | Object

輸入點陣列或點物件,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列,或{x:x1,y:y1}點物件

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x座標欄位字串,預設'x'

keyY String <optional>
'y'

輸入點物件之y座標欄位字串,預設'y'

keyZ String <optional>
'z'

輸入點物件之z座標或值欄位字串,預設'z'

scale Number <optional>
1

輸入正規化範圍數值,因處理多邊形時有數值容許誤差,故須通過縮放值域來減少問題,預設1是正規化0至1之間,使用scaleXY則是正規化為0至scaleXY之間,預設1

method String <optional>
'naturalNeighbor'

輸入內插方法字串,可選'naturalNeighbor'、'kriging',預設'naturalNeighbor'

model String <optional>
'exponential'

輸入若method='kriging'時之擬合模式字串,可選'exponential'、'gaussian'、'spherical',預設'exponential'

sigma2 Number <optional>
0

輸入若method='kriging'時之自動擬合參數sigma2數值,預設0

alpha Number <optional>
100

輸入若method='kriging'時之自動擬合參數alpha數值,預設100

returnWithVariogram Boolean <optional>
false

輸入若method='kriging'時之是否回傳擬合半變異數結果布林值,預設false

useSync Boolean <optional>
false

輸入是否使用同步函數布林值,預設false

Returns:

回傳Promise或點物件陣列或點物件,若useSync=false則回傳Promise,resolve為回傳點物件陣列或點物件,reject為失敗訊息,若useSync=true則回傳點物件陣列或點物件,若發生錯誤則回傳錯誤訊息物件

Type
Promise | Array | Object

(async, static) interp2Grid(pts, xmin, xmax, dx, ymin, ymax, dy, optopt) → {Object}

Description:
  • 不規則點內插至規則網格

    Unit Test: Github

Source:
Example
let ps
let r
let xmin = 0
let xmax = 1200
let dx = 100
let ymin = 0
let ymax = 400
let dy = 50

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = await interp2Grid(ps, xmin, xmax, dx, ymin, ymax, dy)
console.log(JSON.stringify(r))
// => {"xnum":13,"xmin":0,"xmax":1200,"dx":100,"ynum":9,"ymin":0,"ymax":400,"dy":50,"zmin":27.716420638718002,"zmax":229.9346471582616,"grds":[[44.75150359539468,33.373113045618794,33.89828595915838,75.7547049098998,111.95710473149644,141.14982654621605,162.94590093717213,178.58593009365336,191.4829386115651,208.81802511395395,199.48735656973935,162.30106522787239,139.5822916387848],[43.27848738559962,36.56178372212405,43.70097267468331,81.3441145925311,118.98473675109194,149.02943152384705,170.11407784661236,183.17995238983585,190.7561365867844,203.31673250583682,190.93888531046233,152.18106412879206,131.13037328401273],[43.188448792811485,44.651404666899325,58.49967415560389,90.7364184599852,128.7782694260302,158.79276063034376,178.11277546086842,187.40687634934446,185.3791304293,183.41945619591084,166.72664102123193,135.5945265305882,119.75833215759124],[43.01723687928732,53.80526318172193,74.78037419059014,102.8093108917395,141.2308220822185,170.46799156406368,186.77594170674791,191.60033532320656,175.79675777808637,159.46469201580493,139.126174723786,114.04299018304454,106.38160257786299],[41.08480660653146,61.698862792555914,100.50549432728168,120.40751273285129,155.77538965247686,183.9818177781901,195.76812296601497,193.3040612514098,159.6797783607955,136.06558026941212,112.82889049769918,89.27300522673185,92.85373380938937],[35.96748845888605,65.74413088706496,124.5372066072104,142.93975356224172,170.6014830855453,199.17487480394007,205.0642462793919,187.868001472236,136.21583771497808,117.90972253067659,91.6262819436449,62.41761369022669,82.44922512861154],[27.716420638718002,66.37302553896835,123.09560307481105,153.9089017619669,182.78671416843497,215.58411971399806,214.7143054081681,183.4416893350021,136.16098981693074,109.45391646724518,80.86241021849614,45.287458404590105,79.54913115775582],[31.84799135435849,69.51355338700839,120.62450343623689,156.78399055536207,189.72044252659893,229.9346471582616,221.71844479339634,181.54689685389988,139.24108529554456,108.74457142842628,81.95639661703339,66.50915956750916,84.78931182091034],[48.714341720984095,77.18149833637362,120.04944872983206,156.36419684697117,190.18663173864468,226.80390649899172,218.0338522947777,179.1554914349331,141.35776216308057,111.63930150324168,88.90310614105951,81.63042177986947,90.77494563964606]]}

ps = [{ a: 243, b: 206, c: 95 }, { a: 233, b: 225, c: 146 }, { a: 21, b: 325, c: 22 }, { a: 953, b: 28, c: 223 }, { a: 1092, b: 290, c: 39 }, { a: 744, b: 200, c: 191 }, { a: 174, b: 3, c: 22 }, { a: 537, b: 368, c: 249 }, { a: 1151, b: 371, c: 86 }, { a: 814, b: 252, c: 125 }]
r = await interp2Grid(ps, xmin, xmax, dx, ymin, ymax, dy, { keyX: 'a', keyY: 'b', keyZ: 'c' })
console.log(JSON.stringify(r))
// => {"xnum":13,"xmin":0,"xmax":1200,"dx":100,"ynum":9,"ymin":0,"ymax":400,"dy":50,"zmin":27.716420638718002,"zmax":229.9346471582616,"grds":[[44.75150359539468,33.373113045618794,33.89828595915838,75.7547049098998,111.95710473149644,141.14982654621605,162.94590093717213,178.58593009365336,191.4829386115651,208.81802511395395,199.48735656973935,162.30106522787239,139.5822916387848],[43.27848738559962,36.56178372212405,43.70097267468331,81.3441145925311,118.98473675109194,149.02943152384705,170.11407784661236,183.17995238983585,190.7561365867844,203.31673250583682,190.93888531046233,152.18106412879206,131.13037328401273],[43.188448792811485,44.651404666899325,58.49967415560389,90.7364184599852,128.7782694260302,158.79276063034376,178.11277546086842,187.40687634934446,185.3791304293,183.41945619591084,166.72664102123193,135.5945265305882,119.75833215759124],[43.01723687928732,53.80526318172193,74.78037419059014,102.8093108917395,141.2308220822185,170.46799156406368,186.77594170674791,191.60033532320656,175.79675777808637,159.46469201580493,139.126174723786,114.04299018304454,106.38160257786299],[41.08480660653146,61.698862792555914,100.50549432728168,120.40751273285129,155.77538965247686,183.9818177781901,195.76812296601497,193.3040612514098,159.6797783607955,136.06558026941212,112.82889049769918,89.27300522673185,92.85373380938937],[35.96748845888605,65.74413088706496,124.5372066072104,142.93975356224172,170.6014830855453,199.17487480394007,205.0642462793919,187.868001472236,136.21583771497808,117.90972253067659,91.6262819436449,62.41761369022669,82.44922512861154],[27.716420638718002,66.37302553896835,123.09560307481105,153.9089017619669,182.78671416843497,215.58411971399806,214.7143054081681,183.4416893350021,136.16098981693074,109.45391646724518,80.86241021849614,45.287458404590105,79.54913115775582],[31.84799135435849,69.51355338700839,120.62450343623689,156.78399055536207,189.72044252659893,229.9346471582616,221.71844479339634,181.54689685389988,139.24108529554456,108.74457142842628,81.95639661703339,66.50915956750916,84.78931182091034],[48.714341720984095,77.18149833637362,120.04944872983206,156.36419684697117,190.18663173864468,226.80390649899172,218.0338522947777,179.1554914349331,141.35776216308057,111.63930150324168,88.90310614105951,81.63042177986947,90.77494563964606]]}

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = await interp2Grid(ps, xmin, xmax, dx, ymin, ymax, dy, { scale: 1000 })
console.log(JSON.stringify(r))
// => {"xnum":13,"xmin":0,"xmax":1200,"dx":100,"ynum":9,"ymin":0,"ymax":400,"dy":50,"zmin":27.716420638719953,"zmax":229.93464715826363,"grds":[[44.75150359539723,33.3731130456213,33.898285959160816,75.75470490990179,111.95710473149887,141.1498265462182,162.9459009371747,178.5859300936557,191.48293861156722,208.81802511395625,199.48735656974148,162.3010652278742,139.58229163878707],[43.278487385601736,36.56178372212586,43.70097267468564,81.34411459253306,118.98473675109445,149.02943152384924,170.1140778466147,183.179952389838,190.7561365867865,203.31673250583924,190.93888531046477,152.18106412879473,131.1303732840151],[43.188448792813944,44.65140466690163,58.49967415560579,90.73641845998743,128.7782694260323,158.79276063034584,178.11277546087098,187.40687634934702,185.37913042930217,183.4194561959133,166.72664102123443,135.5945265305907,119.75833215759324],[43.01723687928934,53.805263181724015,74.78037419059208,102.80931089174139,141.2308220822208,170.46799156406598,186.77594170674982,191.60033532320872,175.79675777808842,159.46469201580726,139.1261747237881,114.04299018304688,106.38160257786514],[41.08480660653358,61.698862792557975,100.50549432728357,120.4075127328534,155.7753896524789,183.98181777819244,195.76812296601736,193.304061251412,159.6797783607982,136.06558026941445,112.82889049770114,89.27300522673426,92.8537338093916],[35.967488458888354,65.74413088706663,124.53720660721237,142.9397535622437,170.60148308554733,199.17487480394269,205.06424627939438,187.86800147223812,136.21583771498067,117.90972253067889,91.6262819436468,62.417613690228954,82.44922512861409],[27.716420638719953,66.37302553897003,123.09560307481306,153.90890176196856,182.78671416843704,215.5841197140003,214.71430540817065,183.44168933500427,136.1609898169329,109.45391646724778,80.8624102184981,45.28745840459231,79.54913115775784],[31.847991354360566,69.51355338701046,120.62450343623853,156.78399055536397,189.72044252660112,229.93464715826363,221.71844479339836,181.5468968539019,139.24108529554678,108.74457142842883,81.95639661703564,66.50915956751138,84.78931182091229],[48.71434172098658,77.18149833637538,120.04944872983332,156.36419684697321,190.18663173864695,226.8039064989942,218.03385229477985,179.15549143493547,141.35776216308315,111.63930150324393,88.90310614106163,81.63042177987194,90.7749456396484]]}

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = await interp2Grid(ps, xmin, xmax, dx, ymin, ymax, dy, { model: 'gaussian' })
console.log(JSON.stringify(r))
// => {"xnum":13,"xmin":0,"xmax":1200,"dx":100,"ynum":9,"ymin":0,"ymax":400,"dy":50,"zmin":-384.9201026300543,"zmax":751.2486667428893,"grds":[[158.4482759179864,102.91948079701615,0.6427517504198477,-76.00797355886607,-68.61483684207815,36.665182208944316,199.83602440246614,345.00056213926655,396.5981895665918,315.1995415714464,114.98419154713338,-144.3509008078363,-384.9201026300543],[-2.804444662458991,-2.4952083123462216,-60.97934153869028,-111.66170902352133,-96.02852249400712,5.207837377654869,160.5808502566615,302.76790555566186,362.1489304061961,301.11674822207897,131.5364918945761,-92.16170607212916,-298.50266437656865],[-118.93900065626804,-56.340223227791284,-68.73471627734216,-96.72954345654944,-81.85939091966793,2.020786152976143,134.65918081245218,260.47611794230215,318.44862005717914,274.1365497524548,136.8288381582006,-45.894921513683585,-211.18795045322622],[-186.25795259313963,-57.13678728956256,-22.92129248260062,-32.59210483370771,-27.8351209619359,25.59859956942455,121.05320514790401,217.5277153486495,264.99722601877875,233.4224463794908,129.30048060534682,-8.057124315122564,-126.42995914376297],[-204.6982411436402,-7.390837633351111,72.13154973463315,75.65547666719249,61.266778354751295,72.2993374763264,117.60932224509997,173.09761839135172,201.734808129484,178.928047108584,108.22019594248195,19.480190656797276,-47.36329745889998],[-177.70454124452772,86.69644962914026,208.46936428354638,219.66178929024136,178.06125662916565,136.71746638113837,121.3145643337175,126.31575766424248,129.1573951962073,111.48613425033363,73.78789676929591,35.622695265119546,23.390294461762096],[-111.78240342620666,215.85784505185075,375.2536623066626,388.57921593784704,313.24173519090436,212.2249882690594,128.66033199911908,76.46368709732087,48.391715239609766,32.82513522314184,27.15561605971925,40.124916167271294,83.86576457299452],[-15.788129694388772,368.6553909168142,559.7541046391179,570.0412080583301,456.43269708112166,291.61788155091926,136.04813556018962,23.157013756701417,-38.78597402585001,-54.49378940718998,-29.636587407456318,33.58501755302677,132.8379551795224],[99.95941993298584,532.539599799884,748.4812810539061,751.2486667428893,597.1137915874442,367.79370328149344,140.18765012677795,-33.51285171881864,-129.99549037223733,-147.21704968592712,-93.80481946551481,17.364755515549405,169.84006648967988]]}

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = await interp2Grid(ps, xmin, xmax, dx, ymin, ymax, dy, { sigma2: 0.001, alpha: 70 })
console.log(JSON.stringify(r))
// => {"xnum":13,"xmin":0,"xmax":1200,"dx":100,"ynum":9,"ymin":0,"ymax":400,"dy":50,"zmin":26.701776096728345,"zmax":231.16722254290013,"grds":[[44.11259991617855,32.58450881510232,32.76678140889048,74.2917476479156,110.8906140074769,140.71177964055232,163.06616115295472,179.11502822658102,192.29078928968042,209.95815571466474,200.55109691937588,162.85705779717352,139.89170721934147],[42.61820720122279,35.71041576002229,42.20317945504952,79.46948139766397,117.76066932315202,148.59606792401644,170.29707464354252,183.76349937447452,191.5061647507026,204.2911682442632,191.7981952284658,152.53751223841732,131.30395530835756],[42.539549140517906,43.8682532885825,56.67719512603222,88.39339544912986,127.49833508140833,158.44006523651268,178.39437462529554,188.06459836041196,185.98874971121745,183.9624064738573,167.1064571105411,135.6435755796063,119.76026775033723],[42.40373922516747,53.363687192570794,73.04828246858823,100.13694358752468,140.12379463484046,170.29909587800478,187.1850067213191,192.35842981670092,176.16886158624536,159.48169146034536,138.9684068006453,113.70615799956849,106.20087092877779],[40.475947890621654,61.84636782352866,100.87164130491789,118.51969471321917,155.17367785922463,184.10530910814234,196.31283310410095,194.0800848116069,159.58692053597147,135.55390133035564,112.17296618268094,88.50580626168168,92.52730118195944],[35.241030309738626,66.37032301391976,127.92631718109324,143.48034347842253,170.73957790937519,199.67024834314628,205.7419513911939,188.38823643531202,135.36768638962553,117.01563653626947,90.61097302023494,61.19704954557336,82.09912411624504],[26.701776096728345,67.08365868969182,126.02587930956292,155.6532451767952,183.60847488953968,216.47538395931667,215.53334174966398,183.76978391699137,135.4260482049657,108.47833203695497,79.76360673569025,43.90263898577459,79.40538262088131],[30.87691293677275,70.13688477331618,122.88731890916635,158.7167710050036,190.97418094947915,231.16722254290013,222.66784391843683,181.84273299017318,138.739345167688,107.91389402110133,81.0648238841768,65.98340433363867,85.04412844530214],[48.14919037640777,77.76315260022243,121.8147111056278,158.17170146686848,191.6135973149057,228.14610013364904,219.01737089705114,179.49014246253026,141.06205182632874,111.03450527633353,88.31839228901936,81.59594088565929,91.24372341789248]]}
Parameters:
Name Type Attributes Default Description
pts Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

xmin Number

輸入網格x向最小座標數字

xmax Number

輸入網格x向最大座標數字

dx Number

輸入網格x向間距數字

ymin Number

輸入網格y向最小座標數字

ymax Number

輸入網格y向最大座標數字

dy Number

輸入網格y向間距數字

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x座標欄位字串,預設'x'

keyY String <optional>
'y'

輸入點物件之y座標欄位字串,預設'y'

keyZ String <optional>
'z'

輸入點物件之z座標或值欄位字串,預設'z'

modePick String <optional>
'min'

輸入挑選方式字串,可選'min'、'max',預設'min'

funValid function <optional>
(x,y)=>{return true}

輸入確認點座標(x,y)是否有效函數,回傳布林值,可使用Promise回傳,預設(x,y)=>{return true}

funKriging function <optional>
interp2Kriging

輸入克利金處理函數,預設使用內建interp2Kriging

variogram_model String <optional>
'spherical'

輸入內建interp2Kriging之變異函數模型字串,預設'spherical'

nlags Number <optional>
9

輸入內建interp2Kriging之分箱數量整數,預設9

funAdjust function <optional>
(x,y,z)=>{return z}

輸入內插後值調整函數,用於修正不合理值或做後處理,回傳布林值,可使用Promise回傳,預設(x,y,z)=>{return z}

returnGrid Boolean <optional>
true

輸入是否回傳規則網格物件布林值,若false則回傳內插後點物件陣列,預設true

inverseKeyY Boolean <optional>
false

輸入是否反轉y方向索引布林值,用於輸出grds之y向(列)順序,預設false

Returns:

回傳規則網格物件,物件內grds為規則網格之二維陣列

Type
Object

(static) interp2Kriging(psSrc, psTar, optopt) → {Array|Object}

Description:
  • 克利金法(Kriging)內外插點數值

    克利金法計算與實際運算瓶頸問題可詳見: https://github.com/lvisei/web-developer-resources/blob/master/webassembly/kriging.md

    若是Node.js端使用須更高計算速度,可使用w-kriging: https://github.com/yuda-lyu/w-kriging

    Unit Test: Github

Source:
Example
let ps
let p
let r

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 205,
}
r = interp2Kriging(ps, p)
console.log(r)
// => { x: 243, y: 205, z: 94.88479948418721 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 283,
    y: 205,
}
r = interp2Kriging(ps, p)
console.log(r)
// => { x: 283, y: 205, z: 116.32333499687805 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 1160,
    y: 380,
}
r = interp2Kriging(ps, p)
console.log(r)
// => { x: 1160, y: 380, z: 87.27045807621836 }

ps = [{ a: 243, b: 206, c: 95 }, { a: 233, b: 225, c: 146 }, { a: 21, b: 325, c: 22 }, { a: 953, b: 28, c: 223 }, { a: 1092, b: 290, c: 39 }, { a: 744, b: 200, c: 191 }, { a: 174, b: 3, c: 22 }, { a: 537, b: 368, c: 249 }, { a: 1151, b: 371, c: 86 }, { a: 814, b: 252, c: 125 }]
p = {
    a: 243,
    b: 205,
}
r = interp2Kriging(ps, p, { keyX: 'a', keyY: 'b', keyZ: 'c' })
console.log(r)
// => { a: 243, b: 205, c: 94.88479948418721 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = [
    {
        x: 243,
        y: 205,
    },
    {
        x: 283,
        y: 205,
    },
]
r = interp2Kriging(ps, p)
console.log(r)
// => [
//   { x: 243, y: 205, z: 94.88479948418721 },
//   { x: 283, y: 205, z: 116.32333499687805 }
// ]

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 205,
}
r = interp2Kriging(ps, p, { scale: 1000 })
console.log(r)
// => { x: 243, y: 205, z: 94.88479948418878 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 205,
}
r = interp2Kriging(ps, p, { model: 'gaussian' })
console.log(r)
// => { x: 243, y: 205, z: 92.39124139470005 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 205,
}
r = interp2Kriging(ps, p, { sigma2: 0.001, alpha: 70 })
console.log(r)
// => { x: 243, y: 205, z: 90.88702949276343 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 205,
}
r = interp2Kriging(ps, p, { returnWithVariogram: true })
console.log(r)
// => {
//   result: { x: 243, y: 205, z: 94.88479948418721 },
//   variogram: {
//     t: [
//       0.32158590308370044,
//       0.5462555066079295,
//       0,
//       0.8854625550660793,
//       0.07488986784140969,
//       0.7444933920704846,
//       0,
//       1,
//       0.28193832599118945,
//       0.45374449339207046
//     ],
//     x: [
//       0.19646017699115045,
//       0.18761061946902655,
//       0,
//       0.8247787610619469,
//       0.947787610619469,
//       0.6398230088495576,
//       0.13539823008849558,
//       0.45663716814159294,
//       1,
//       0.7017699115044248
//     ],
//     y: [
//       0.5168141592920354,
//       0.5336283185840708,
//       0.6221238938053097,
//       0.35929203539823007,
//       0.5911504424778761,
//       0.511504424778761,
//       0.33716814159292036,
//       0.6601769911504425,
//       0.6628318584070797,
//       0.5575221238938053
//     ],
//     nugget: 0.33528534923428144,
//     range: 0.9818274204120488,
//     sill: 0.4584580333443075,
//     A: 0.3333333333333333,
//     n: 10,
//     model: [Function: kriging_variogram_exponential],
//     svpd: { data: [Array], bars: [Array] },
//     K: [
//          -75.8517004175245,       67.925722923484, -0.16335841036964677,
//        0.24131518978270877,  -0.04234246865048732,   0.8770518396328912,
//          5.616960362170279,     1.621659637440227, 0.027888001651894635,
//       -0.21415853416652803,     67.92572292348402,   -75.61786478824868,
//          5.413232079727064,   0.04906943438385958,  0.03679113229348465,
//       -0.11847139352698677,    0.3142012767297917,   1.9531078854430024,
//        0.14216377854055343, -0.026503104672525174,   -0.163358410369651,
//          5.413232079727067,   -10.341088741602475,    0.707690256415205,
//         0.2717259477481375,    -0.032751338327818,   2.4021510467734406,
//         1.1039529303204958,    0.9343241199626711,  0.17593910677199553,
//        0.24131518978268823,   0.04906943438388453,   0.7076902564152006,
//        -11.195895809332818,    3.6318326767168267,   3.0935386508887035,
//         1.0451553499568136,   0.07681115159025198,   0.5500520981253416,
//          2.176928207710048,  -0.04234246865049055,  0.03679113229348578,
//        0.27172594774813813,    3.6318326767168188,  -21.833991833397526,
//        -0.3703544567031784,    0.1631940797086814,   0.1478485285302121,
//         14.592661153646349,     3.529640759660949,    0.877051839632884,
//       -0.11847139352697111, -0.032751338327819686,   3.0935386508886986,
//       -0.37035445670318073,   -23.428385057803695,   0.8346909075984952,
//          3.683800415485778,  -0.07094528659968152,   15.630834782735722,
//          5.616960362170238,   0.31420127672983256,   2.4021510467734397,
//          1.045155349956815,   0.16319407970868527,   0.8346909075984923,
//         -11.15967643574728,   0.47980505727623907,   0.7525119639869473,
//        -0.0399020216261384,    1.6216596374402739,   1.9531078854429533,
//         1.1039529303204962,   0.07681115159024962,   0.1478485285302013,
//         3.6838004154857935,      0.47980505727624,  -11.594555930753835,
//         0.9237284214140226,    1.8947859772223308, 0.027888001651917377,
//        0.14216377854053472,    0.9343241199626732,   0.5500520981253476,
//         14.592661153646347,   -0.0709452865996735,   0.7525119639869486,
//         0.9237284214140111,   -18.251230245653318,    0.837959693391809,
//       -0.21415853416654693, -0.026503104672517874,   0.1759391067719989,
//          2.176928207710053,     3.529640759660952,   15.630834782735704,
//       -0.03990202162613744,     1.894785977222343,   0.8379596933918148,
//         -23.89204017145281
//     ],
//     M: [
//       15.107775528173802,
//       -17.52355316402437,
//       4.974279767668829,
//       -6.014370838628359,
//       7.175095294789402,
//       -3.7572657339807183,
//       4.210920521157788,
//       -6.064323143863013,
//       -2.2280724452952487,
//       5.035785385549117
//     ]
//   }
// }
Parameters:
Name Type Attributes Default Description
psSrc Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

psTar Array | Object

輸入二維座標點陣列或點物件,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列,或{x:x1,y:y1}點物件

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x欄位字串,為座標,預設'x'

keyY String <optional>
'y'

輸入點物件之y欄位字串,為座標,預設'y'

keyZ String <optional>
'z'

輸入點物件之z欄位字串,為觀測值,預設'z'

scale Number <optional>
1

輸入正規化範圍數值,因處理多邊形時有數值容許誤差,故須通過縮放值域來減少問題,預設1是正規化0至1之間,使用scaleXY則是正規化為0至scaleXY之間,預設1

model String <optional>
'exponential'

輸入擬合模式字串,可選'exponential'、'gaussian'、'spherical',預設'exponential'

sigma2 Number <optional>
0

輸入自動擬合參數sigma2數值,預設0

alpha Number <optional>
100

輸入自動擬合參數alpha數值,預設100

returnWithVariogram Boolean <optional>
false

輸入是否回傳擬合半變異數結果布林值,預設false

Returns:

回傳點物件陣列或點物件,若使用returnWithVariogram=true則回傳物件資訊,若發生錯誤則回傳錯誤訊息物件

Type
Array | Object

(static) interp2NaturalNeighbor(psSrc, psTar, optopt) → {Array|Object}

Description:
  • 自然鄰點內插法(Natural Neighbor Interpolation)內插點數值

    A Fast and Accurate Algorithm for Natural Neighbor Interpolation https://gwlucastrig.github.io/TinfourDocs/NaturalNeighborTinfourAlgorithm/index.html

    An Introduction to Natural Neighbor Interpolation https://gwlucastrig.github.io/TinfourDocs/NaturalNeighborIntro/index.html

    [wiki]Natural neighbor interpolation https://en.wikipedia.org/wiki/Natural_neighbor_interpolation

    Natural neighbor interpolation https://observablehq.com/@karlerss/natural-neighbor-interpolation

    d3-delaunay https://github.com/d3/d3-delaunay

    online test https://cartography-playground.gitlab.io/playgrounds/triangulation-delaunay-voronoi-diagram/

    Unit Test: Github

Source:
Example
let ps
let p
let r

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
r = interp2NaturalNeighbor(ps, p)
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486813 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 1243,
    y: 1207,
}
r = interp2NaturalNeighbor(ps, p)
console.log(r)
// => { x: 1243, y: 1207, z: null }

ps = [{ x: 243, y: 206, z: 95 }, { x: null, y: 201, z: 122 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
let funInterpFragment = (msg) => {
    // console.log('funInterpFragment', msg)
    return msg.v //預設回傳msg.v, 三角形三角點各點v為rA*z, 故三點之rA合為1, 指定內插值z為三角點v之總和(v1,v2,v3)
}
r = interp2NaturalNeighbor(ps, p, { funInterpFragment })
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486813 }

ps = [{ x: 243, y: 206, z: 95 }, { x: null, y: 201, z: 122 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 1243,
    y: 1207,
}
let funInterpFragmentNoUse = (msg) => {
    // console.log('funInterpFragmentNoUse', msg)
    return msg.v //預設回傳msg.v, 此處因內插點於原始點所形成最小凸多邊形之外, 故無法內插, 亦不會呼叫funInterpFragment
}
r = interp2NaturalNeighbor(ps, p, { funInterpFragment: funInterpFragmentNoUse })
console.log(r)
// => { x: 1243, y: 1207, z: null }

ps = [{ x: 243, y: 206, z: 95 }, { x: null, y: 201, z: 122 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
let funInterpFragments = (msg) => {
    // console.log('funInterpFragments', msg)
    // let v = ps[0].v + ps[1].v + ps[2].v
    return msg.v //預設回傳msg.v, 三角形三角點為msg.ps, 各點v為rA*z, 故三點之rA合為1, 指定內插值z為三角點v之總和(v1,v2,v3)
}
r = interp2NaturalNeighbor(ps, p, { funInterpFragments })
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486813 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 283,
    y: 207,
}
r = interp2NaturalNeighbor(ps, p)
console.log(r)
// => { x: 283, y: 207, z: 114.43040421951908 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 1160,
    y: 380,
}
r = interp2NaturalNeighbor(ps, p)
console.log(r)
// => { x: 1160, y: 380, z: null }

ps = [{ a: 243, b: 206, c: 95 }, { a: 233, b: 225, c: 146 }, { a: 21, b: 325, c: 22 }, { a: 953, b: 28, c: 223 }, { a: 1092, b: 290, c: 39 }, { a: 744, b: 200, c: 191 }, { a: 174, b: 3, c: 22 }, { a: 537, b: 368, c: 249 }, { a: 1151, b: 371, c: 86 }, { a: 814, b: 252, c: 125 }]
p = {
    a: 243,
    b: 207,
}
r = interp2NaturalNeighbor(ps, p, { keyX: 'a', keyY: 'b', keyZ: 'c' })
console.log(r)
// => { a: 243, b: 207, c: 97.29447682486813 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = [
    {
        x: 243,
        y: 207,
    },
    {
        x: 283,
        y: 207,
    },
]
r = interp2NaturalNeighbor(ps, p)
console.log(r)
// => [
//   { x: 243, y: 207, z: 97.29447682486813 },
//   { x: 283, y: 207, z: 114.43040421951908 }
// ]

ps = [{ x: 0.000243, y: 0.000206, z: 95 }, { x: 0.000233, y: 0.000225, z: 146 }, { x: 0.000021, y: 0.000325, z: 22 }, { x: 0.000953, y: 0.000028, z: 223 }, { x: 0.001092, y: 0.00029, z: 39 }, { x: 0.000744, y: 0.000200, z: 191 }, { x: 0.000174, y: 0.000003, z: 22 }, { x: 0.000537, y: 0.000368, z: 249 }, { x: 0.001151, y: 0.000371, z: 86 }, { x: 0.000814, y: 0.000252, z: 125 }]
p = {
    x: 0.000243,
    y: 0.000207,
}
r = interp2NaturalNeighbor(ps, p)
console.log(r)
// => { x: 0.000243, y: 0.000207, z: 97.2944768248678 }

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
p = {
    x: 243,
    y: 207,
}
r = interp2NaturalNeighbor(ps, p, { scale: 1000 })
console.log(r)
// => { x: 243, y: 207, z: 97.29447682486855 }
Parameters:
Name Type Attributes Default Description
psSrc Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

psTar Array | Object

輸入二維座標點陣列或點物件,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列,或{x:x1,y:y1}點物件

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x欄位字串,為座標,預設'x'

keyY String <optional>
'y'

輸入點物件之y欄位字串,為座標,預設'y'

keyZ String <optional>
'z'

輸入點物件之z欄位字串,為觀測值,預設'z'

scale Number <optional>
1

輸入正規化範圍數值,因處理多邊形時有數值容許誤差,故須通過縮放值域來減少問題,預設1是正規化0至1之間,使用scaleXY則是正規化為0至scaleXY之間,預設1

Returns:

回傳點物件陣列或點物件,若發生錯誤則回傳錯誤訊息物件

Type
Array | Object

(static) interp2Normalize(ps, optopt) → {Object}

Description:
  • 內插用正規化數據

    Unit Test: Github

Source:
Example
let ps
let r

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = interp2Normalize(ps)
delete r.nv
delete r.inv
console.log(JSON.stringify(r))
// => {"ps":[{"x":0.19646017699115045,"y":0.5168141592920354,"z":0.32158590308370044,"ind":null},{"x":0.18761061946902655,"y":0.5336283185840708,"z":0.5462555066079295,"ind":null},{"x":0,"y":0.6221238938053097,"z":0,"ind":null},{"x":0.8247787610619469,"y":0.35929203539823007,"z":0.8854625550660793,"ind":null},{"x":0.947787610619469,"y":0.5911504424778761,"z":0.07488986784140969,"ind":null},{"x":0.6398230088495576,"y":0.511504424778761,"z":0.7444933920704846,"ind":null},{"x":0.13539823008849558,"y":0.33716814159292036,"z":0,"ind":null},{"x":0.45663716814159294,"y":0.6601769911504425,"z":1,"ind":null},{"x":1,"y":0.6628318584070797,"z":0.28193832599118945,"ind":null},{"x":0.7017699115044248,"y":0.5575221238938053,"z":0.45374449339207046,"ind":null}],"psMinMax":{"xmin":0,"xmax":1,"ymin":0.33716814159292036,"ymax":0.6628318584070797,"zmin":0,"zmax":1},"st":{"x":{"min":21,"max":1151,"range":1130},"y":{"min":-378,"max":752,"range":1130},"z":{"min":22,"max":249,"range":227}}}

ps = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = interp2Normalize(ps, { scale: 100 })
delete r.nv
delete r.inv
console.log(JSON.stringify(r))
// => {"ps":[{"x":19.646017699115045,"y":51.681415929203546,"z":32.158590308370044,"ind":null},{"x":18.761061946902654,"y":53.36283185840708,"z":54.62555066079295,"ind":null},{"x":0,"y":62.21238938053097,"z":0,"ind":null},{"x":82.47787610619469,"y":35.92920353982301,"z":88.54625550660793,"ind":null},{"x":94.77876106194691,"y":59.11504424778761,"z":7.488986784140969,"ind":null},{"x":63.982300884955755,"y":51.1504424778761,"z":74.44933920704845,"ind":null},{"x":13.539823008849558,"y":33.716814159292035,"z":0,"ind":null},{"x":45.663716814159294,"y":66.01769911504425,"z":100,"ind":null},{"x":100,"y":66.28318584070797,"z":28.193832599118945,"ind":null},{"x":70.17699115044248,"y":55.75221238938053,"z":45.37444933920705,"ind":null}],"psMinMax":{"xmin":0,"xmax":100,"ymin":33.716814159292035,"ymax":66.28318584070797,"zmin":0,"zmax":100},"st":{"x":{"min":21,"max":1151,"range":1130},"y":{"min":-378,"max":752,"range":1130},"z":{"min":22,"max":249,"range":227}}}

ps = [{ x: 243, y: 206, z: 95, ind: 101 }, { x: 233, y: 225, z: 146, ind: 102 }, { x: 21, y: 325, z: 22, ind: 103 }, { x: 953, y: 28, z: 223, ind: 104 }, { x: 1092, y: 290, z: 39, ind: 105 }, { x: 744, y: 200, z: 191, ind: 106 }, { x: 174, y: 3, z: 22, ind: 107 }, { x: 537, y: 368, z: 249, ind: 108 }, { x: 1151, y: 371, z: 86, ind: 109 }, { x: 814, y: 252, z: 125, ind: 110 }]
r = interp2Normalize(ps, { keyInd: 'ind' })
delete r.nv
delete r.inv
console.log(JSON.stringify(r))
// => {"ps":[{"x":0.19646017699115045,"y":0.5168141592920354,"z":0.32158590308370044,"ind":101},{"x":0.18761061946902655,"y":0.5336283185840708,"z":0.5462555066079295,"ind":102},{"x":0,"y":0.6221238938053097,"z":0,"ind":103},{"x":0.8247787610619469,"y":0.35929203539823007,"z":0.8854625550660793,"ind":104},{"x":0.947787610619469,"y":0.5911504424778761,"z":0.07488986784140969,"ind":105},{"x":0.6398230088495576,"y":0.511504424778761,"z":0.7444933920704846,"ind":106},{"x":0.13539823008849558,"y":0.33716814159292036,"z":0,"ind":107},{"x":0.45663716814159294,"y":0.6601769911504425,"z":1,"ind":108},{"x":1,"y":0.6628318584070797,"z":0.28193832599118945,"ind":109},{"x":0.7017699115044248,"y":0.5575221238938053,"z":0.45374449339207046,"ind":110}],"psMinMax":{"xmin":0,"xmax":1,"ymin":0.33716814159292036,"ymax":0.6628318584070797,"zmin":0,"zmax":1},"st":{"x":{"min":21,"max":1151,"range":1130},"y":{"min":-378,"max":752,"range":1130},"z":{"min":22,"max":249,"range":227}}}
Parameters:
Name Type Attributes Default Description
ps Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x欄位字串,為座標,預設'x'

keyY String <optional>
'y'

輸入點物件之y欄位字串,為座標,預設'y'

keyZ String <optional>
'z'

輸入點物件之z欄位字串,為觀測值,預設'z'

keyInd String <optional>
'ind'

輸入點物件之ind欄位字串,正規化後可反查原始數據之指標,預設'ind'

scale Number <optional>
1

輸入正規化範圍數值,因處理多邊形時有數值容許誤差,故須通過縮放值域來減少問題,預設1是正規化0至1之間,使用scaleXY則是正規化為0至scaleXY之間,預設1

Returns:

回傳正規化數據物件

Type
Object

(async, static) interp2Raster(ops, optopt) → {Object}

Description:
  • 不規則點資料先聚合再內插至規則網格

    Unit Test: Github

Source:
Example
let ps
let r

ps = [
    { x: 121.48571681415929, y: 25.058614130434783, z: 95 },
    { x: 121.48500884955752, y: 25.062228260869563, z: 146 },
    { x: 121.47, y: 25.08125, z: 22 },
    { x: 121.53598230088495, y: 25.02475543478261, z: 223 },
    { x: 121.54582300884955, y: 25.074592391304346, z: 39 },
    { x: 121.52118584070796, y: 25.057472826086958, z: 191 },
    { x: 121.48083185840707, y: 25.02, z: 22 },
    { x: 121.50653097345132, y: 25.089429347826087, z: 249 },
    { x: 121.55, y: 25.09, z: 86 },
    { x: 121.52614159292035, y: 25.067364130434783, z: 125 }
]
r = await interp2Raster(ps, { dx: 0.000979087 * 10, dy: 0.000906247 * 5 })
console.log(JSON.stringify(r))
// => {"xnum":9,"xmin":121.47,"xmax":121.55,"dx":0.00979087,"ynum":16,"ymin":25.02,"ymax":25.09,"dy":0.004531235,"zmin":25.008503223085306,"zmax":230.692207620399,"grds":[[53.29695613753195,90.9878283681276,143.06087191384637,200.32429562431122,230.692207620399,180.40204907064341,136.1530241094394,100.59943015055649,82.14770016468049],[33.18615340480098,82.53745908262893,136.89266690219813,189.57557481421284,211.01267466303997,174.01759815374774,129.8648554713684,90.3775726907702,69.76202213840641],[30.649106928513838,78.18086957161364,129.87666573494295,175.36672144691707,192.14083300446975,165.43595632681556,123.45781065492382,80.89449160839146,55.909387880686836],[44.35784386605923,78.19215023386876,123.34728621362704,162.59334238706708,178.14944804497486,158.24273885280672,118.72593945913597,77.34481966112054,47.557053415271795],[54.59624175640077,79.97235367298671,117.80692991239255,152.5691700549194,169.3604923358124,155.84955967852204,117.47530627008295,84.12984269825354,61.541566831759006],[61.921968156117515,81.52387857586544,113.0710912563389,145.1243482533917,165.07967283545923,161.80751391298088,126.65650015693579,97.96229710366745,79.82779997828177],[66.83219014217913,82.1918706583026,108.82981182150552,139.51924993924777,163.39654235447964,175.8727178307613,144.86370463051009,114.17834904512225,97.09515848645559],[69.71941699919188,82.20986544471259,105.48343246225039,134.8766711857756,161.6209193581903,185.51610085077323,159.2203228863815,129.86565172082058,112.88018028969536],[70.82153526794654,81.40365825844987,102.52998415554532,130.44222819267918,158.20368573475835,179.40458853522884,166.87690247501067,143.74286964403262,127.15417129624454],[70.24547760586455,79.10219254059587,98.72806515388253,125.74805126341245,153.60756995565745,173.79734055412013,171.50300218848182,155.95696527327257,140.05755661594753],[68.06294143513142,74.97983328526666,93.69964174320266,120.64337719371085,148.81678189404954,170.3067562843946,176.08450938057823,167.37076517487893,151.7970112583186],[64.40679807848441,68.87644483066734,87.36596771611377,115.20448065026856,144.34102924872468,168.44082899163902,181.65959964982952,178.91839896983052,162.45918562235704],[59.579516621263224,60.65421884945618,79.85418875855228,109.67073197494572,140.27156102781217,167.4089506411862,188.16721978253224,191.29745012452534,171.7427174412858],[54.25750734739524,50.16380421262544,71.68195808846065,104.45932666464594,136.53145068212558,166.22770388291246,194.18596156854792,204.55151424952277,178.67429685300704],[49.84400365402098,37.301157966447214,64.30077984326395,100.16770574008851,133.04693099333764,163.94549799236063,195.79253736299714,213.05406176918385,181.76602702017865],[48.51705283717487,25.008503223085306,60.667024580062325,97.41331557750496,129.82668100790102,160.1190717664935,189.93474888031673,202.82202458292304,180.33605168933383]],"pts":[{"x":121.48571681415929,"y":25.058614130434783,"z":95},{"x":121.47,"y":25.08125,"z":22},{"x":121.53598230088495,"y":25.02475543478261,"z":223},{"x":121.54582300884955,"y":25.074592391304346,"z":39},{"x":121.52118584070796,"y":25.057472826086958,"z":191},{"x":121.48083185840707,"y":25.02,"z":22},{"x":121.50653097345132,"y":25.089429347826087,"z":249},{"x":121.55,"y":25.09,"z":86},{"x":121.52614159292035,"y":25.067364130434783,"z":125}]}

ps = [
    { x: 121.48571681415929, y: 25.058614130434783, z: 95 },
    { x: 121.48500884955752, y: 25.062228260869563, z: 146 },
    { x: 121.47, y: 25.08125, z: 22 },
    { x: 121.53598230088495, y: 25.02475543478261, z: 223 },
    { x: 121.54582300884955, y: 25.074592391304346, z: 39 },
    { x: 121.52118584070796, y: 25.057472826086958, z: 191 },
    { x: 121.48083185840707, y: 25.02, z: 22 },
    { x: 121.50653097345132, y: 25.089429347826087, z: 249 },
    { x: 121.55, y: 25.09, z: 86 },
    { x: 121.52614159292035, y: 25.067364130434783, z: 125 }
]
r = await interp2Raster(ps, { dx: 0.000979087 * 10, dy: 0.000906247 * 5, dxAgr: 0.000979087 * 15, dyAgr: 0.000906247 * 7.5 })
console.log(JSON.stringify(r))
// => {"xnum":9,"xmin":121.47,"xmax":121.55,"dx":0.00979087,"ynum":16,"ymin":25.02,"ymax":25.09,"dy":0.004531235,"zmin":24.823924446215038,"zmax":231.7567577657555,"grds":[[53.62369559375291,97.28753826038451,151.99569385250032,206.01329420379795,231.7567577657555,181.74456038323083,136.9337797009959,100.82047078083103,82.07708777678545],[33.35769875360963,92.00300714953804,149.54057920145087,198.09758546908188,214.41704248676362,175.7821324384034,130.5283656577402,90.4093497431664,69.54075119287774],[33.694057708538715,92.54101428394036,147.39251200590925,187.06516519367833,197.62513561758846,167.6668963058992,123.98735585892726,80.78686225833944,55.66889834101754],[52.64381088478393,99.03900142300567,146.65595863609053,176.99055560470293,185.00298561118308,160.73147948072238,119.0363573373561,77.12115108746592,47.37939731126598],[66.61879668531361,107.79408272120735,147.016778115003,168.30294933707412,176.7095557492657,158.26543997764273,117.45655109967052,83.80309340175263,61.27750967567075],[75.2589561237669,113.5537749334791,144.98709654332248,159.8929007644603,172.0170905880976,163.84236052111794,126.4398496041521,97.63064967940787,79.59691654868394],[78.68117509942893,106.5552658165186,128.80117256854788,150.87976018747153,169.2068860796617,177.25446108422068,144.68301313512228,113.99037990431796,97.05253698651693],[78.27805645580389,92.10986466514447,109.16559772934329,141.9067311649439,165.99935683226428,186.4085110016602,159.21170852439775,129.94467107234337,113.13480709391158],[75.97241978508316,84.57378980579321,102.53683374775467,134.05122593259682,161.25691801191817,180.48459348365037,167.21602941206322,144.15358853414438,127.76309289265961],[72.80173195680102,79.76140615655008,97.9321023375592,127.31339852980325,155.6482200843788,174.98245027782707,172.19374986330374,156.6933278368807,141.02867176590735],[68.90918098278021,74.55268398871439,92.65277069488342,121.15239269012386,150.1775616972252,171.49822261670596,177.0133654786484,168.35817943753946,153.09719732545554],[64.2076980316679,67.96041083663675,86.26929074220435,115.22108595764789,145.29251688553296,169.59539950565747,182.68489882975817,180.02516814884666,164.02895337420648],[58.78869152147344,59.58502468707952,78.83089710760079,109.49913670429187,141.00843456843626,168.5245314234247,189.15870248800343,192.34693759552368,173.52110450762643],[53.17781904277413,49.19131322151639,70.82515273215796,104.26247139846541,137.18674389853737,167.33735247437988,195.08169367782963,205.34921468759225,180.6373824848832],[48.65930356588191,36.65719928223353,63.659890609431685,100.02829363193082,133.710205844732,165.11253891467507,196.727588357127,213.69062065298513,183.9600610036589],[47.296028443616365,24.823924446215038,60.196676193427145,97.36489712827152,130.55697396278424,161.41612787019466,191.2045850563283,204.15009289540566,182.84604795685374]],"pts":[{"x":121.48571681415929,"y":25.058614130434783,"z":95},{"x":121.48500884955752,"y":25.062228260869563,"z":146},{"x":121.47,"y":25.08125,"z":22},{"x":121.53598230088495,"y":25.02475543478261,"z":223},{"x":121.54582300884955,"y":25.074592391304346,"z":39},{"x":121.52118584070796,"y":25.057472826086958,"z":191},{"x":121.48083185840707,"y":25.02,"z":22},{"x":121.50653097345132,"y":25.089429347826087,"z":249},{"x":121.55,"y":25.09,"z":86},{"x":121.52614159292035,"y":25.067364130434783,"z":125}]}
Parameters:
Name Type Attributes Default Description
ops Array

輸入二維座標加觀測數據點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件之x欄位字串,為座標,預設'x'

keyY String <optional>
'y'

輸入點物件之y欄位字串,為座標,預設'y'

keyZ String <optional>
'z'

輸入點物件之z欄位字串,為觀測值,預設'z'

modePick String <optional>
'min'

輸入挑選方式字串,可選'min'、'max',預設'min'

dx Number <optional>
0.000979087

輸入網格x向間距數字,預設0.000979087,基於WGS84經緯度之數據點,代表約100m

dx Number <optional>
0.000906247

輸入網格y向間距數字,預設0.000906247,基於WGS84經緯度之數據點,代表約100m

dxAgr Number <optional>
opt.dx*2

輸入先聚合時網格x向間距數字,預設opt.dx*2

dyAgr Number <optional>
opt.dy*2

輸入先聚合時網格y向間距數字,預設opt.dy*2

funValid function <optional>
(x,y)=>{return true}

輸入確認點座標(x,y)是否有效函數,回傳布林值,可使用Promise回傳,預設(x,y)=>{return true}

funKriging function <optional>
interp2Kriging

輸入克利金處理函數,預設使用內建interp2Kriging

funAdjust function <optional>
(x,y,z)=>{return z}

輸入內插後值調整函數,用於修正不合理值或做後處理,回傳布林值,可使用Promise回傳,預設(x,y,z)=>{return z}

scale Number <optional>
1

輸入當funKriging使用interp2Kriging時,正規化範圍數值,因處理多邊形時有數值容許誤差,故須通過縮放值域來減少問題,預設1是正規化0至1之間,使用scaleXY則是正規化為0至scaleXY之間,預設1

model String <optional>
'exponential'

輸入當funKriging使用interp2Kriging時,擬合模式字串,可選'exponential'、'gaussian'、'spherical',預設'exponential'

sigma2 Number <optional>
0

輸入當funKriging使用interp2Kriging時,自動擬合參數sigma2數值,預設0

alpha Number <optional>
100

輸入當funKriging使用interp2Kriging時,自動擬合參數alpha數值,預設100

Returns:

回傳規則網格物件,物件內grds為規則網格之二維陣列

Type
Object

(async, static) interp3(psSrc, psTar) → {Promise|Array|Object}

Description:
  • 針對不規則三維數據進行指定內插點數值

    Unit Test: Github

Source:
Example
async function test() {

    let ps
    let p
    let r

    ps = [{ x: 243, y: 206, z: 95, v: 2.2 }, { x: 233, y: 225, z: 146, v: 15.1 }, { x: 21, y: 325, z: 22, v: 7.9 }, { x: 953, y: 28, z: 223, v: 5.1 }, { x: 1092, y: 290, z: 39, v: 17.5 }, { x: 744, y: 200, z: 191, v: 6.6 }, { x: 174, y: 3, z: 22, v: 1.4 }, { x: 537, y: 368, z: 249, v: 2.9 }, { x: 1151, y: 371, z: 86, v: 7.3 }, { x: 814, y: 252, z: 125, v: 8.2 }]
    p = {
        x: 243,
        y: 207,
        z: 100,
    }
    r = await interp3(ps, p)
    console.log(r)
    // => { x: 243, y: 207, z: 100, v: 3.4894028270041137 }

    ps = [{ x: 243, y: 206, z: 95, v: 2.2 }, { x: 233, y: 225, z: 146, v: 15.1 }, { x: 21, y: 325, z: 22, v: 7.9 }, { x: 953, y: 28, z: 223, v: 5.1 }, { x: 1092, y: 290, z: 39, v: 17.5 }, { x: 744, y: 200, z: 191, v: 6.6 }, { x: 174, y: 3, z: 22, v: 1.4 }, { x: 537, y: 368, z: 249, v: 2.9 }, { x: 1151, y: 371, z: 86, v: 7.3 }, { x: 814, y: 252, z: 125, v: 8.2 }]
    p = {
        x: 283,
        y: 207,
        z: 100,
    }
    r = await interp3(ps, p)
    console.log(r)
    // => { x: 283, y: 207, z: 100, v: 2.5832273787671967 }

    ps = [{ x: 243, y: 206, z: 95, v: 2.2 }, { x: 233, y: 225, z: 146, v: 15.1 }, { x: 21, y: 325, z: 22, v: 7.9 }, { x: 953, y: 28, z: 223, v: 5.1 }, { x: 1092, y: 290, z: 39, v: 17.5 }, { x: 744, y: 200, z: 191, v: 6.6 }, { x: 174, y: 3, z: 22, v: 1.4 }, { x: 537, y: 368, z: 249, v: 2.9 }, { x: 1151, y: 371, z: 86, v: 7.3 }, { x: 814, y: 252, z: 125, v: 8.2 }]
    p = {
        x: 1160,
        y: 380,
        z: 100,
    }
    r = await interp3(ps, p)
    console.log(r)
    // => { x: 1160, y: 380, z: null }

    ps = [{ a: 243, b: 206, c: 95, d: 2.2 }, { a: 233, b: 225, c: 146, d: 15.1 }, { a: 21, b: 325, c: 22, d: 7.9 }, { a: 953, b: 28, c: 223, d: 5.1 }, { a: 1092, b: 290, c: 39, d: 17.5 }, { a: 744, b: 200, c: 191, d: 6.6 }, { a: 174, b: 3, c: 22, d: 1.4 }, { a: 537, b: 368, c: 249, d: 2.9 }, { a: 1151, b: 371, c: 86, d: 7.3 }, { a: 814, b: 252, c: 125, d: 8.2 }]
    p = {
        a: 243,
        b: 207,
        c: 100,
    }
    r = await interp3(ps, p, { keyX: 'a', keyY: 'b', keyZ: 'c', keyV: 'd' })
    console.log(r)
    // => { a: 243, b: 207, c: 100, d: 3.4894028270041137 }

    ps = [{ x: 243, y: 206, z: 95, v: 2.2 }, { x: 233, y: 225, z: 146, v: 15.1 }, { x: 21, y: 325, z: 22, v: 7.9 }, { x: 953, y: 28, z: 223, v: 5.1 }, { x: 1092, y: 290, z: 39, v: 17.5 }, { x: 744, y: 200, z: 191, v: 6.6 }, { x: 174, y: 3, z: 22, v: 1.4 }, { x: 537, y: 368, z: 249, v: 2.9 }, { x: 1151, y: 371, z: 86, v: 7.3 }, { x: 814, y: 252, z: 125, v: 8.2 }]
    p = [
        {
            x: 243,
            y: 207,
            z: 100,
        },
        {
            x: 283,
            y: 207,
            z: 100,
        },
    ]
    r = await interp3(ps, p)
    console.log(r)
    // => [
    //   { x: 243, y: 207, z: 100, v: 3.4894028270041137 },
    //   { x: 283, y: 207, z: 100, v: 2.5832273787671967 }
    // ]

    ps = [{ x: 0.000243, y: 0.000206, z: 0.000095, v: 2.2 }, { x: 0.000233, y: 0.000225, z: 0.000146, v: 15.1 }, { x: 0.000021, y: 0.000325, z: 0.000022, v: 7.9 }, { x: 0.000953, y: 0.000028, z: 0.000223, v: 5.1 }, { x: 0.001092, y: 0.00029, z: 0.000039, v: 17.5 }, { x: 0.000744, y: 0.0002, z: 0.000191, v: 6.6 }, { x: 0.000174, y: 0.000003, z: 0.000022, v: 1.4 }, { x: 0.000537, y: 0.000368, z: 0.000249, v: 2.9 }, { x: 0.001151, y: 0.000371, z: 0.000086, v: 7.3 }, { x: 0.000814, y: 0.000252, z: 0.000125, v: 8.2 }]
    p = {
        x: 0.000243,
        y: 0.000207,
        z: 0.0001,
    }
    r = await interp3(ps, p)
    console.log(r)
    // => { x: 0.000243, y: 0.000207, z: 100, v: 3.489402827004115 }

}
test()
    .catch((err) => {
        console.log(err)
    })
Parameters:
Name Type Attributes Default Description
psSrc Array

輸入點陣列,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列

psTar Array | Object

輸入點陣列或點物件,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列,或{x:x1,y:y1}點物件

opt.keyX String <optional>
'x'

輸入點物件之x座標欄位字串,預設'x'

opt.keyY String <optional>
'y'

輸入點物件之y座標欄位字串,預設'y'

opt.keyZ String <optional>
'z'

輸入點物件之z座標或值欄位字串,預設'z'

Returns:

回傳Promise或點物件陣列或點物件,若useSync=false則回傳Promise,resolve為回傳點物件陣列或點物件,reject為失敗訊息,若useSync=true則回傳點物件陣列或點物件,若發生錯誤則回傳錯誤訊息物件

Type
Promise | Array | Object

(static) intersectMultiPolygon(pgs1, pgs2, optopt) → {Array}

Description:
  • 針對MultiPolygon進行交集(intersect)處理

    Unit Test: Github

Source:
Example
let pgs1
let pgs2
let r

pgs1 = 'not array'
pgs2 = [[[[2, 0], [4, 0], [4, 4], [2, 4]]]] //multiPolygon
try {
    r = intersectMultiPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs1

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = 'not array'
try {
    r = intersectMultiPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid pgs2

pgs1 = [[[[0, 0], [1, 0], [1, 1], [0, 1]]]] //multiPolygon
pgs2 = []
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[1,0],[1,1],[0,1],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[2,0],[4,0],[4,4],[2,4],[2,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 0], [2, 2], [0, 2]]] //polygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[2,0],[2,2],[0,2],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 2], [0, 4]]] //polygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[2,2],[0,4],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[-1, 0], [2, 1], [-1, 4]]] //polygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0.3333333333333333],[2,1],[0,3],[0,0.3333333333333333]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[2, 0], [4, 0], [4, 4], [2, 4]]]] //multiPolygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[2,0],[4,0],[4,4],[2,4],[2,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[0, 0], [2, 0], [2, 2], [0, 2]]]] //multiPolygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[2,0],[2,2],[0,2],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[0, 0], [2, 2], [0, 4]]]] //multiPolygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[2,2],[0,4],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[-1, 0], [2, 1], [-1, 4]]]] //multiPolygon
r = intersectMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0.3333333333333333],[2,1],[0,3],[0,0.3333333333333333]]]]
Parameters:
Name Type Attributes Default Description
pgs1 Array

輸入第1個MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

pgs2 Array

輸入第2個MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) intersectPolygon(pgs1, pgs2, optopt) → {Array}

Description:
  • 針對Polygon進行交集(intersect)處理

    Unit Test: Github

Source:
Example
let pgs1
let pgs2
let r

pgs1 = 'not array'
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
try {
    r = intersectPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs1

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = 'not array'
try {
    r = intersectPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid pgs2

pgs1 = [[[0, 0], [1, 0], [1, 1], [0, 1]]] //polygon
pgs2 = []
r = intersectPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[0,0],[1,0],[1,1],[0,1],[0,0]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
r = intersectPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[2,0],[2,4],[4,4]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 0], [2, 2], [0, 2]]] //polygon
r = intersectPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[2,2],[2,0],[0,0],[0,2],[2,2]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 2], [0, 4]]] //polygon
r = intersectPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[2,2],[0,0],[0,4],[2,2]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[-1, 0], [2, 1], [-1, 4]]] //polygon
r = intersectPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[2,1],[0,0.3333333333333333],[0,3],[2,1]]]
Parameters:
Name Type Attributes Default Description
pgs1 Array

輸入第1個Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

pgs2 Array

輸入第2個Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
epsilon Number <optional>
0.000000000001

輸入 polybooljs 計算容許誤差

Returns:

回傳Polygon陣列

Type
Array

(static) invCoordMultiPolygon(pgs) → {Array}

Description:
  • 針對MultiPolygon進行(x,y)座標交換

Source:
Example
詳見invCoordMultiPolygonOrMultiPolyline
Parameters:
Name Type Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

Returns:

回傳MultiPolygon陣列

Type
Array

(static) invCoordMultiPolygonOrMultiPolyline(pgs) → {Array}

Description:
  • 針對MultiPolygon進行(x,y)座標交換,因為turf的point是先經再緯,於GeoJSON也是,但跟leaflet相反,故需交換座標

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [[[ //multiPolygon
    [0.1, 0],
    [5.2, 1],
    [3.7, 2],
    [0.6, 3],
]]]
r = invCoordMultiPolygonOrMultiPolyline(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0.1],[1,5.2],[2,3.7],[3,0.6]]]]

try {
    pgs = [[ //polygon
        [0.1, 0],
        [5.2, 1],
        [3.7, 2],
        [0.6, 3],
    ]]
    r = invCoordMultiPolygonOrMultiPolyline(pgs)
}
catch (err) {
    r = err.message
}
console.log(JSON.stringify(r))
// => "invalid point depth[2]!=3"

try {
    pgs = [ //ringString
        [0.1, 0],
        [5.2, 1],
        [3.7, 2],
        [0.6, 3],
    ]
    r = invCoordMultiPolygonOrMultiPolyline(pgs)
}
catch (err) {
    r = err.message
}
console.log(JSON.stringify(r))
// => "invalid point depth[1]!=3"
Parameters:
Name Type Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

Returns:

回傳MultiPolygon陣列

Type
Array

(static) invCoordMultiPolyline(pgs) → {Array}

Description:
  • 針對MultiPolyline進行(x,y)座標交換

Source:
Example
詳見invCoordMultiPolygonOrMultiPolyline
Parameters:
Name Type Description
pgs Array

輸入MultiPolyline資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

Returns:

回傳MultiPolyline陣列

Type
Array

(static) invCoordPolygon(pgs) → {Array}

Description:
  • 針對Polygon進行(x,y)座標交換,主要因為turf的point是先經再緯,於GeoJSON也是,但跟leaflet相反,故需交換座標

Source:
Example
詳見invCoordPolygonOrPolyline
Parameters:
Name Type Description
pgs Array

輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

Returns:

回傳Polygon陣列

Type
Array

(static) invCoordPolygonOrPolyline(pgs) → {Array}

Description:
  • 針對Polygon進行(x,y)座標交換,主要因為turf的point是先經再緯,於GeoJSON也是,但跟leaflet相反,故需交換座標

    Unit Test: Github

Source:
Example
let pgs
let r

try {
    pgs = [[[ //multiPolygon
        [0.1, 0],
        [5.2, 1],
        [3.7, 2],
        [0.6, 3],
    ]]]
    r = invCoordPolygonOrPolyline(pgs)
}
catch (err) {
    r = err.message
}
console.log(JSON.stringify(r))
// => "invalid point depth[3]!=2"

pgs = [[ //polygon
    [0.1, 0],
    [5.2, 1],
    [3.7, 2],
    [0.6, 3],
]]
r = invCoordPolygonOrPolyline(pgs)
console.log(JSON.stringify(r))
// => [[[0,0.1],[1,5.2],[2,3.7],[3,0.6]]]

try {
    pgs = [ //ringString
        [0.1, 0],
        [5.2, 1],
        [3.7, 2],
        [0.6, 3],
    ]
    r = invCoordPolygonOrPolyline(pgs)
}
catch (err) {
    r = err.message
}
console.log(JSON.stringify(r))
// => "invalid point depth[1]!=2"
Parameters:
Name Type Description
pgs Array

輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

Returns:

回傳Polygon陣列

Type
Array

(static) invCoordPolyline(pgs) → {Array}

Description:
  • 針對Polyline進行(x,y)座標交換,主要因為turf的point是先經再緯,於GeoJSON也是,但跟leaflet相反,故需交換座標

Source:
Example
詳見invCoordPolygonOrPolyline
Parameters:
Name Type Description
pgs Array

輸入Polyline資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

Returns:

回傳Polyline陣列

Type
Array

(static) isPointInPolygons(p, pgs, optopt) → {Boolean}

Description:
  • 判斷點陣列[x,y]或點物件{x,y}是否位於多邊形陣列內

    Unit Test: Github

Source:
Example
let p
let pgs
let b

p = [0.5, 0.5]
pgs = [
    [0, 0],
    [0, 1],
    [1, 1],
    [1, 0],
    [0, 0],
]
b = isPointInPolygons(p, pgs)
console.log(b)
// => true

p = [1.5, 0.5]
pgs = [
    [0, 0],
    [0, 1],
    [1, 1],
    [1, 0],
    [0, 0],
]
b = isPointInPolygons(p, pgs)
console.log(b)
// => false
Parameters:
Name Type Attributes Default Description
p Array | Object

輸入點陣列或點物件,為[x,y]或{x,y}

pgs Array

輸入多邊形陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

toTurfMultiPolygon Boolean <optional>
true

輸入是否轉換多邊形為Turf的MultiPolygon,若須加速可於外部先轉好就不用於函數內再轉,預設true

Returns:

回傳是否位於多邊形陣列內布林值

Type
Boolean

(static) normalizeArray(arr) → {Array|Object}

Description:
  • 針對一維或二維陣列正規化

    Unit Test: Github

Source:
Example
let arr
let r

arr = [
    [243, 206, 95],
    [233, 225, 146],
    [21, 325, 22],
    [953, 28, 223],
    [1092, 290, 39],
    [744, 200, 191],
    [174, 3, 22],
    [537, 368, 249],
    [1151, 371, 86],
    [814, 252, 125]
]
r = normalizeArray(arr)
console.log(r)
// => [
//   {
//     arr: [
//       0.19646017699115045,
//       0.18761061946902655,
//       0,
//       0.8247787610619469,
//       0.947787610619469,
//       0.6398230088495576,
//       0.13539823008849558,
//       0.45663716814159294,
//       1,
//       0.7017699115044248
//     ],
//     min: 21,
//     max: 1151,
//     range: 1130,
//     avg: 596.2
//   },
//   {
//     arr: [
//       0.5516304347826086,
//       0.6032608695652174,
//       0.875,
//       0.06793478260869565,
//       0.779891304347826,
//       0.5353260869565217,
//       0,
//       0.9918478260869565,
//       1,
//       0.6766304347826086
//     ],
//     min: 3,
//     max: 371,
//     range: 368,
//     avg: 226.8
//   },
//   {
//     arr: [
//       0.32158590308370044,
//       0.5462555066079295,
//       0,
//       0.8854625550660793,
//       0.07488986784140969,
//       0.7444933920704846,
//       0,
//       1,
//       0.28193832599118945,
//       0.45374449339207046
//     ],
//     min: 22,
//     max: 249,
//     range: 227,
//     avg: 119.8
//   }
// ]

arr = [
    243, 233, 21,
    953, 1092, 744,
    174, 537, 1151,
    814
]
r = normalizeArray(arr)
console.log(r)
// => {
//   arr: [
//     0.19646017699115045,
//     0.18761061946902655,
//     0,
//     0.8247787610619469,
//     0.947787610619469,
//     0.6398230088495576,
//     0.13539823008849558,
//     0.45663716814159294,
//     1,
//     0.7017699115044248
//   ],
//   min: 21,
//   max: 1151,
//   range: 1130,
//   avg: 596.2
// }

arr = [{ x: 243, y: 206, z: 95 }, { x: 233, y: 225, z: 146 }, { x: 21, y: 325, z: 22 }, { x: 953, y: 28, z: 223 }, { x: 1092, y: 290, z: 39 }, { x: 744, y: 200, z: 191 }, { x: 174, y: 3, z: 22 }, { x: 537, y: 368, z: 249 }, { x: 1151, y: 371, z: 86 }, { x: 814, y: 252, z: 125 }]
r = normalizeArray(arr, ['x', 'y', 'z'])
console.log(r)
// => [
//   {
//     arr: [
//       0.19646017699115045,
//       0.18761061946902655,
//       0,
//       0.8247787610619469,
//       0.947787610619469,
//       0.6398230088495576,
//       0.13539823008849558,
//       0.45663716814159294,
//       1,
//       0.7017699115044248
//     ],
//     min: 21,
//     max: 1151,
//     range: 1130,
//     avg: 596.2
//   },
//   {
//     arr: [
//       0.5516304347826086,
//       0.6032608695652174,
//       0.875,
//       0.06793478260869565,
//       0.779891304347826,
//       0.5353260869565217,
//       0,
//       0.9918478260869565,
//       1,
//       0.6766304347826086
//     ],
//     min: 3,
//     max: 371,
//     range: 368,
//     avg: 226.8
//   },
//   {
//     arr: [
//       0.32158590308370044,
//       0.5462555066079295,
//       0,
//       0.8854625550660793,
//       0.07488986784140969,
//       0.7444933920704846,
//       0,
//       1,
//       0.28193832599118945,
//       0.45374449339207046
//     ],
//     min: 22,
//     max: 249,
//     range: 227,
//     avg: 119.8
//   }
// ]
Parameters:
Name Type Description
arr Array

輸入資料陣列,為[x1,x2,...]之一維陣列,或[[x1,y1],[x2,y2],...]之二維陣列

Returns:

回傳正規化數據之物件或陣列

Type
Array | Object

(static) ptXYtoObj(p, optopt) → {Object}

Description:
  • 提取點陣列[x,y]或點物件{x,y}為點物件{x,y}

    Unit Test: Github

Source:
Example
let p
let r

p = [1, 2]
r = ptXYtoObj(p)
console.log(r)
// => { x: 1, y: 2 }

p = { x: 1, y: 2 }
r = ptXYtoObj(p)
console.log(r)
// => { x: 1, y: 2 }
Parameters:
Name Type Attributes Default Description
p Array | Object

輸入點陣列或點物件,為[x,y]或{x,y}

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

Returns:

回傳點物件{x,y}

Type
Object

(static) ptsXYZVtoArr(ps, optopt) → {Array}

Description:
  • 提取點陣列內之點[0,1,2,3]或{x,y,z,v}或指定鍵值成為點{x,y,z,v}物件陣列

    Unit Test: Github

Source:
Example
let ps
let r

ps = [[243, 206, 95, 2.2], [233, 225, 146, 15.1], [21, 325, 22, 7.9]]
r = ptsXYZVtoArr(ps)
console.log(r)
// => [
//   { x: 243, y: 206, z: 95, v: 2.2, ind: 0 },
//   { x: 233, y: 225, z: 146, v: 15.1, ind: 1 },
//   { x: 21, y: 325, z: 22, v: 7.9, ind: 2 }
// ]

ps = [{ 'x': 243, 'y': 206, 'z': 95, 'v': 2.2 }, { 'x': 233, 'y': 225, 'z': 146, 'v': 15.1 }, { 'x': 21, 'y': 325, 'z': 22, 'v': 7.9 }]
r = ptsXYZVtoArr(ps)
console.log(r)
// => [
//   { x: 243, y: 206, z: 95, v: 2.2, ind: 0 },
//   { x: 233, y: 225, z: 146, v: 15.1, ind: 1 },
//   { x: 21, y: 325, z: 22, v: 7.9, ind: 2 }
// ]

ps = [{ 'a': 243, 'b': 206, 'c': 95, 'd': 2.2 }, { 'a': 233, 'b': 225, 'c': 146, 'd': 15.1 }, { 'a': 21, 'b': 325, 'c': 22, 'd': 7.9 }]
r = ptsXYZVtoArr(ps, { keyX: 'a', keyY: 'b', keyZ: 'c', keyV: 'd' })
console.log(r)
// => [
//   { x: 243, y: 206, z: 95, v: 2.2, ind: 0 },
//   { x: 233, y: 225, z: 146, v: 15.1, ind: 1 },
//   { x: 21, y: 325, z: 22, v: 7.9, ind: 2 }
// ]
Parameters:
Name Type Attributes Default Description
ps Array

輸入點陣列,為[{x:x1,y:y1,z:z1,v:v1},{x:x2,y:y2,z:z2,v:v2},...]點物件之陣列,或[[x1,y1,z1,v1],[x2,y2,z2,v2],...]點座標陣列之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

keyY String <optional>
'z'

輸入點物件z座標鍵字串,預設'z'

keyV String <optional>
'v'

輸入點物件v座標鍵字串,預設'v'

keyInd String <optional>
'ind'

輸入點物件指標鍵字串,預設'ind'

returnObjArray Boolean <optional>
true

輸入是否回傳物件陣列,若true代表回傳點為物件{x,y,z,v}之陣列,若false回傳點陣列[x,y,z,v]之陣列,預設true

Returns:

回傳點{x,y,z,v}陣列

Type
Array

(static) ptsXYZtoArr(ps, optopt) → {Array}

Description:
  • 提取點陣列內之點[0,1,2]或{x,y,z}或指定鍵值成為點{x,y,z}物件陣列

    Unit Test: Github

Source:
Example
let ps
let r

ps = [[243, 206, 95], [233, 225, 146], [21, 325, 22]]
r = ptsXYZtoArr(ps)
console.log(r)
// => [
//   { x: 243, y: 206, z: 95, ind: 0 },
//   { x: 233, y: 225, z: 146, ind: 1 },
//   { x: 21, y: 325, z: 22, ind: 2 }
// ]

ps = [{ 'x': 243, 'y': 206, 'z': 95 }, { 'x': 233, 'y': 225, 'z': 146 }, { 'x': 21, 'y': 325, 'z': 22 }]
r = ptsXYZtoArr(ps)
console.log(r)
// => [
//   { x: 243, y: 206, z: 95, ind: 0 },
//   { x: 233, y: 225, z: 146, ind: 1 },
//   { x: 21, y: 325, z: 22, ind: 2 }
// ]

ps = [{ 'a': 243, 'b': 206, 'c': 95 }, { 'a': 233, 'b': 225, 'c': 146 }, { 'a': 21, 'b': 325, 'c': 22 }]
r = ptsXYZtoArr(ps, { keyX: 'a', keyY: 'b', keyZ: 'c' })
console.log(r)
// => [
//   { x: 243, y: 206, z: 95, ind: 0 },
//   { x: 233, y: 225, z: 146, ind: 1 },
//   { x: 21, y: 325, z: 22, ind: 2 }
// ]
Parameters:
Name Type Attributes Default Description
ps Array

輸入點陣列,為[{x:x1,y:y1,z:z1},{x:x2,y:y2,z:z2},...]點物件之陣列,或[[x1,y1,z1],[x2,y2,z2],...]點座標陣列之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

keyY String <optional>
'z'

輸入點物件z座標鍵字串,預設'z'

keyInd String <optional>
'ind'

輸入點物件指標鍵字串,預設'ind'

returnObjArray Boolean <optional>
true

輸入是否回傳物件陣列,若true代表回傳點為物件{x,y,z}之陣列,若false回傳點陣列[x,y,z]之陣列,預設true

Returns:

回傳點{x,y,z}陣列

Type
Array

(static) ptsXYtoArr(ps, optopt) → {Array}

Description:
  • 提取點陣列內之點[0,1]或{x,y}或指定鍵值成為點{x,y}物件陣列

    Unit Test: Github

Source:
Example
let ps
let r

ps = [[243, 206], [233, 225], [21, 325]]
r = ptsXYtoArr(ps)
console.log(r)
// => [
//   { x: 243, y: 206, ind: 0 },
//   { x: 233, y: 225, ind: 1 },
//   { x: 21, y: 325, ind: 2 }
// ]

ps = [{ 'x': 243, 'y': 206 }, { 'x': 233, 'y': 225 }, { 'x': 21, 'y': 325 }]
r = ptsXYtoArr(ps)
console.log(r)
// => [
//   { x: 243, y: 206, ind: 0 },
//   { x: 233, y: 225, ind: 1 },
//   { x: 21, y: 325, ind: 2 }
// ]

ps = [{ 'a': 243, 'b': 206 }, { 'a': 233, 'b': 225 }, { 'a': 21, 'b': 325 }]
r = ptsXYtoArr(ps, { keyX: 'a', keyY: 'b' })
console.log(r)
// => [
//   { x: 243, y: 206, ind: 0 },
//   { x: 233, y: 225, ind: 1 },
//   { x: 21, y: 325, ind: 2 }
// ]
Parameters:
Name Type Attributes Default Description
ps Array

輸入點陣列,為[{x:x1,y:y1},{x:x2,y:y2},...]點物件之陣列,或[[x1,y1],[x2,y2],...]點座標陣列之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyY String <optional>
'y'

輸入點物件y座標鍵字串,預設'y'

keyInd String <optional>
'ind'

輸入點物件指標鍵字串,預設'ind'

returnObjArray Boolean <optional>
true

輸入是否回傳物件陣列,若true代表回傳點為物件{x,y}之陣列,若false回傳點陣列[x,y]之陣列,預設true

Returns:

回傳點陣列

Type
Array

(static) ptsXtoArr(ps, optopt) → {Array}

Description:
  • 提取點陣列內之點[0]或{x}或指定鍵值成為點{x}物件陣列

    Unit Test: Github

Source:
Example
let ps
let r

ps = [[243], [233], [21]]
r = ptsXtoArr(ps)
console.log(r)
// => [
//   { x: 243, ind: 0 },
//   { x: 233, ind: 1 },
//   { x: 21, ind: 2 }
// ]

ps = [{ 'x': 243 }, { 'x': 233 }, { 'x': 21 }]
r = ptsXtoArr(ps)
console.log(r)
// => [
//   { x: 243, ind: 0 },
//   { x: 233, ind: 1 },
//   { x: 21, ind: 2 }
// ]

ps = [{ 'a': 243 }, { 'a': 233 }, { 'a': 21 }]
r = ptsXtoArr(ps, { keyX: 'a' })
console.log(r)
// => [
//   { x: 243, ind: 0 },
//   { x: 233, ind: 1 },
//   { x: 21, ind: 2 }
// ]
Parameters:
Name Type Attributes Default Description
ps Array

輸入點陣列,為[{x:x1},{x:x2},...]點物件之陣列,或[[x1],[x2],...]點座標陣列之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
keyX String <optional>
'x'

輸入點物件x座標鍵字串,預設'x'

keyInd String <optional>
'ind'

輸入點物件指標鍵字串,預設'ind'

returnObjArray Boolean <optional>
true

輸入是否回傳物件陣列,若true代表回傳點為物件{x}之陣列,若false回傳點陣列[x]之陣列,預設true

Returns:

回傳點陣列

Type
Array

(static) simplifyMultiPolygon(pgs, optopt) → {Array}

Description:
  • 針對MultiPolygon進行Simplify處理

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 0.9],
        [10, 1],
        [0, 1],
    ]
]
r = simplifyMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[10,0],[10,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [9.995, 0],
        [9.995, 0.995],
        [10, 1],
        [0, 1],
    ]
]
r = simplifyMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[9.995,0],[10,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [9.99, 0],
        [9.99, 0.99],
        [10, 1],
        [0, 1],
    ]
]
r = simplifyMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[9.99,0],[9.99,0.99],[10,1],[0,1],[0,0]]]]

pgs = [ //polygon
    [
        [0, 0],
        [9.99, 0],
        [9.99, 0.99],
        [10, 1],
        [0, 1],
    ]
]
r = simplifyMultiPolygon(pgs, { tolerance: 0.01 })
console.log(JSON.stringify(r))
// => [[[[0,0],[9.99,0],[10,1],[0,1],[0,0]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [10, 0],
        [10, 0.9],
        [10, 1],
        [0, 1],
    ]
]]
r = simplifyMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[10,0],[10,1],[0,1],[0,0]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [9.995, 0],
        [9.995, 0.995],
        [10, 1],
        [0, 1],
    ]
]]
r = simplifyMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[9.995,0],[10,1],[0,1],[0,0]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [9.99, 0],
        [9.99, 0.99],
        [10, 1],
        [0, 1],
    ]
]]
r = simplifyMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[9.99,0],[9.99,0.99],[10,1],[0,1],[0,0]]]]

pgs = [[ //multiPolygon
    [
        [0, 0],
        [9.99, 0],
        [9.99, 0.99],
        [10, 1],
        [0, 1],
    ]
]]
r = simplifyMultiPolygon(pgs, { tolerance: 0.01 })
console.log(JSON.stringify(r))
// => [[[[0,0],[9.99,0],[10,1],[0,1],[0,0]]]]
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

tolerance Number <optional>
0.005

輸入簡化容許值數字,代表點到線的最大允許距離,故跟座標係有關,預設0.005

highQuality Boolean <optional>
true

輸入處理模式布林值,true代表品質優先,false代表速度優先,預設true

Returns:

回傳MultiPolygon陣列

Type
Array

(static) splineMultiPolygon(pgs, optopt) → {Array}

Description:
  • 針對MultiPolygon進行BezierSpline處理

    Unit Test: Github

Source:
Example
Parameters:
Name Type Attributes Default Description
pgs Array

輸入MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

resolution Number <optional>
10000

輸入曲線解析度數字,代表每段曲線細分多少距離,預設10000

sharpness Number <optional>
0.05

輸入曲線緊繃程度數字,0為平滑,代表取最小彎曲度,1為折線,代表切線指定很長會比較有彎度,預設0.05

Returns:

回傳MultiPolygon陣列

Type
Array

(static) toMultiPoint(v) → {Array}

Description:
  • 轉換點陣列成為MultiPoint

    Unit Test: Github

Source:
Example
let pgs
let r

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = toMultiPoint(pgs)
console.log(JSON.stringify(r))
// => {"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[0,0],[100,0],[100,1],[0,1],[0,0]]}}

pgs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = toMultiPoint(pgs)
console.log(JSON.stringify(r))
// => {"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[0,0],[100,0],[100,1],[0,1]]}}

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = toMultiPoint(pgs)
console.log(JSON.stringify(r))
// => {"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[0,0],[100,0],[100,1],[0,1]]}}

pgs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toMultiPoint(pgs)
console.log(JSON.stringify(r))
// => {"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[0,0],[10,0],[10,1],[0,1]]}}

pgs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toMultiPoint(pgs)
console.log(JSON.stringify(r))
// => {"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[0,0],[100,0],[100,1],[0,1],[0,0],[10,0],[10,1],[0,1]]}}

pgs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = toMultiPoint(pgs)
console.log(JSON.stringify(r))
// => {"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[0,0],[100,0],[100,1],[0,1],[0,0],[10,0],[10,1],[0,1]]}}
Parameters:
Name Type Description
v Array

輸入點陣列

Returns:

回傳資料陣列

Type
Array

(static) toMultiPolygon(v, optopt) → {Array}

Description:
  • 轉換RingString、polygon、MultiPolygon成為MultiPolygon

    Unit Test: Github

Source:
Example
let rs
let r

rs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = toMultiPolygon(rs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1],[0,0]]]]

rs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = toMultiPolygon(rs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]]]]

rs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = toMultiPolygon(rs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]]]]

rs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toMultiPolygon(rs)
console.log(JSON.stringify(r))
// => [[[[0,0],[10,0],[10,1],[0,1]]]]

rs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toMultiPolygon(rs) //預設polygon轉multiPolygon使用視為polygons, 故其內會是2個polygons
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]]],[[[0,0],[10,0],[10,1],[0,1]]]]

rs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toMultiPolygon(rs, { supposeType: 'ringStrings' }) //為多層套疊polygon時轉multiPolygon須使用ringStrings
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]],[[0,0],[10,0],[10,1],[0,1]]]]

rs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = toMultiPolygon(rs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]],[[0,0],[10,0],[10,1],[0,1]]]]
Parameters:
Name Type Attributes Default Description
v Array

輸入資料陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) toPolygon(v) → {Array}

Description:
  • 轉換RingString、polygon、MultiPolygon成為Polygon

    Unit Test: Github

Source:
Example
let rs
let r

rs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
    [0, 0], //閉合
]
r = toPolygon(rs)
console.log(JSON.stringify(r))
// => [[[0,0],[100,0],[100,1],[0,1],[0,0]]]

rs = [ //ringString
    [0, 0],
    [100, 0],
    [100, 1],
    [0, 1],
]
r = toPolygon(rs)
console.log(JSON.stringify(r))
// => [[[0,0],[100,0],[100,1],[0,1]]]

rs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ]
]
r = toPolygon(rs)
console.log(JSON.stringify(r))
// => [[[0,0],[100,0],[100,1],[0,1]]]

rs = [ //polygon
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toPolygon(rs)
console.log(JSON.stringify(r))
// => [[[0,0],[10,0],[10,1],[0,1]]]

rs = [ //polygon
    [
        [0, 0],
        [100, 0],
        [100, 1],
        [0, 1],
    ],
    [
        [0, 0],
        [10, 0],
        [10, 1],
        [0, 1],
    ]
]
r = toPolygon(rs)
console.log(JSON.stringify(r))
// => [[[0,0],[100,0],[100,1],[0,1]],[[0,0],[10,0],[10,1],[0,1]]]

rs = [ //multiPolygon
    [
        [
            [0, 0],
            [100, 0],
            [100, 1],
            [0, 1],
        ],
        [
            [0, 0],
            [10, 0],
            [10, 1],
            [0, 1],
        ]
    ]
]
r = toPolygon(rs)
console.log(JSON.stringify(r))
// => [[[0,0],[100,0],[100,1],[0,1]],[[0,0],[10,0],[10,1],[0,1]]]
Parameters:
Name Type Description
v Array

輸入資料陣列

Returns:

回傳資料陣列

Type
Array

(static) unionMultiPolygon(pgs1, pgs2, optopt) → {Array}

Description:
  • 針對MultiPolygon進行聯集(union)處理

    Unit Test: Github

Source:
Example
let pgs1
let pgs2
let r

pgs1 = 'not array'
pgs2 = [[[[2, 0], [4, 0], [4, 4], [2, 4]]]] //multiPolygon
try {
    r = unionMultiPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs1

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = 'not array'
try {
    r = unionMultiPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid pgs2

pgs1 = [[[[0, 0], [1, 0], [1, 1], [0, 1]]]] //multiPolygon
pgs2 = []
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[1,0],[1,1],[0,1],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 0], [2, 2], [0, 2]]] //polygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 2], [0, 4]]] //polygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[0,0]]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[-1, 0], [2, 1], [-1, 4]]] //polygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[-1,0],[0,0.3333333333333333],[0,0],[4,0],[4,4],[0,4],[0,3],[-1,4],[-1,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[2, 0], [4, 0], [4, 4], [2, 4]]]] //multiPolygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[0, 0], [2, 0], [2, 2], [0, 2]]]] //multiPolygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[0, 0], [2, 2], [0, 4]]]] //multiPolygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[0,0],[4,0],[4,4],[0,4],[0,0]]]]

pgs1 = [[[[0, 0], [4, 0], [4, 4], [0, 4]]]] //multiPolygon
pgs2 = [[[[-1, 0], [2, 1], [-1, 4]]]] //multiPolygon
r = unionMultiPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[[-1,0],[0,0.3333333333333333],[0,0],[4,0],[4,4],[0,4],[0,3],[-1,4],[-1,0]]]]
Parameters:
Name Type Attributes Default Description
pgs1 Array

輸入第1個MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

pgs2 Array

輸入第2個MultiPolygon資料陣列,為[[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
supposeType String <optional>
'polygons'

輸入提取模式字串,當數據座標深度為2時,使用polygons代表每個其內多邊形為獨立polygon,若為ringStrings則表示其內多邊形為交錯的ringString(代表聯集與剔除),預設'polygons'

Returns:

回傳MultiPolygon陣列

Type
Array

(static) unionPolygon(pgs1, pgs2, optopt) → {Array}

Description:
  • 針對Polygon進行聯集(union)處理

    Unit Test: Github

Source:
Example
let pgs1
let pgs2
let r

pgs1 = 'not array'
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
try {
    r = unionPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => no pgs1

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = 'not array'
try {
    r = unionPolygon(pgs1, pgs2, {})
}
catch (err) {
    r = err.message
}
console.log(r)
// => invalid pgs2

pgs1 = [[[0, 0], [1, 0], [1, 1], [0, 1]]] //polygon
pgs2 = []
r = unionPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[0,0],[1,0],[1,1],[0,1],[0,0]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[2, 0], [4, 0], [4, 4], [2, 4]]] //polygon
r = unionPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[0,0],[0,4],[4,4]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 0], [2, 2], [0, 2]]] //polygon
r = unionPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[0,0],[0,4],[4,4]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[0, 0], [2, 2], [0, 4]]] //polygon
r = unionPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[0,0],[0,4],[4,4]]]

pgs1 = [[[0, 0], [4, 0], [4, 4], [0, 4]]] //polygon
pgs2 = [[[-1, 0], [2, 1], [-1, 4]]] //polygon
r = unionPolygon(pgs1, pgs2, {})
console.log(JSON.stringify(r))
// => [[[4,4],[4,0],[0,0],[0,0.3333333333333333],[-1,0],[-1,4],[0,3],[0,4],[4,4]]]
Parameters:
Name Type Attributes Default Description
pgs1 Array

輸入第1個Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

pgs2 Array

輸入第2個Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]構成之陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
epsilon Number <optional>
0.000000000001

輸入 polybooljs 計算容許誤差

Returns:

回傳Polygon陣列

Type
Array