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) 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))
// => [[[[-1.001141328901417,0.0016753375821097873],[-0.9828471338128442,-0.16972115991069422],[-0.9267373199338761,-0.3346332604401984],[-0.8349336578934242,-0.48675182181191506],[-0.7109147085413277,-0.6202345462697216],[-0.559394180587721,-0.729923376805404],[-0.38615360668544263,-0.811541439833041],[-0.19783329290733154,-0.8618623554235615],[-0.0016872193065963293,-0.8788447694463676],[100.00168721930659,-0.8788447694463676],[100.19783329290733,-0.8618623554235615],[100.38615360668544,-0.811541439833041],[100.55939418058772,-0.7299233768054038],[100.71091470854132,-0.6202345462697216],[100.83493365789343,-0.48675182181191484],[100.92673731993388,-0.3346332604401984],[100.98284713381284,-0.16972115991069422],[101.00114132890143,0.0016753375821097873],[101.00130637437861,0.9962692468004231],[100.98342526263642,1.166068608930073],[100.92842740011626,1.3296521767917848],[100.8383471832878,1.4808799222131859],[100.71652842614444,1.614052695861241],[100.56751027969496,1.7241206065185686],[100.3968695299825,1.806872516804512],[100.21102286823793,1.859099826845344],[100.01699438082024,1.878727728773804],[-0.016994380820243554,1.878727728773804],[-0.21102286823793245,1.859099826845344],[-0.3968695299824859,1.806872516804512],[-0.5675102796949614,1.7241206065185688],[-0.7165284261444422,1.6140526958612413],[-0.8383471832878048,1.4808799222131859],[-0.9284274001162607,1.329652176791785],[-0.9834252626364106,1.166068608930073],[-1.00130637437862,0.9962692468004231],[-1.001141328901417,0.0016753375821097873]]]]
pgs = [ //ringString
[0, 0],
[100, 0],
[100, 1],
[0, 1],
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-1.001141328901417,0.0016753375821097873],[-0.9828471338128442,-0.16972115991069422],[-0.9267373199338761,-0.3346332604401984],[-0.8349336578934242,-0.48675182181191506],[-0.7109147085413277,-0.6202345462697216],[-0.559394180587721,-0.729923376805404],[-0.38615360668544263,-0.811541439833041],[-0.19783329290733154,-0.8618623554235615],[-0.0016872193065963293,-0.8788447694463676],[100.00168721930659,-0.8788447694463676],[100.19783329290733,-0.8618623554235615],[100.38615360668544,-0.811541439833041],[100.55939418058772,-0.7299233768054038],[100.71091470854132,-0.6202345462697216],[100.83493365789343,-0.48675182181191484],[100.92673731993388,-0.3346332604401984],[100.98284713381284,-0.16972115991069422],[101.00114132890143,0.0016753375821097873],[101.00130637437861,0.9962692468004231],[100.98342526263642,1.166068608930073],[100.92842740011626,1.3296521767917848],[100.8383471832878,1.4808799222131859],[100.71652842614444,1.614052695861241],[100.56751027969496,1.7241206065185686],[100.3968695299825,1.806872516804512],[100.21102286823793,1.859099826845344],[100.01699438082024,1.878727728773804],[-0.016994380820243554,1.878727728773804],[-0.21102286823793245,1.859099826845344],[-0.3968695299824859,1.806872516804512],[-0.5675102796949614,1.7241206065185688],[-0.7165284261444422,1.6140526958612413],[-0.8383471832878048,1.4808799222131859],[-0.9284274001162607,1.329652176791785],[-0.9834252626364106,1.166068608930073],[-1.00130637437862,0.9962692468004231],[-1.001141328901417,0.0016753375821097873]]]]
pgs = [ //polygon
[
[0, 0],
[100, 0],
[100, 1],
[0, 1],
]
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-1.001141328901417,0.0016753375821097873],[-0.9828471338128442,-0.16972115991069422],[-0.9267373199338761,-0.3346332604401984],[-0.8349336578934242,-0.48675182181191506],[-0.7109147085413277,-0.6202345462697216],[-0.559394180587721,-0.729923376805404],[-0.38615360668544263,-0.811541439833041],[-0.19783329290733154,-0.8618623554235615],[-0.0016872193065963293,-0.8788447694463676],[100.00168721930659,-0.8788447694463676],[100.19783329290733,-0.8618623554235615],[100.38615360668544,-0.811541439833041],[100.55939418058772,-0.7299233768054038],[100.71091470854132,-0.6202345462697216],[100.83493365789343,-0.48675182181191484],[100.92673731993388,-0.3346332604401984],[100.98284713381284,-0.16972115991069422],[101.00114132890143,0.0016753375821097873],[101.00130637437861,0.9962692468004231],[100.98342526263642,1.166068608930073],[100.92842740011626,1.3296521767917848],[100.8383471832878,1.4808799222131859],[100.71652842614444,1.614052695861241],[100.56751027969496,1.7241206065185686],[100.3968695299825,1.806872516804512],[100.21102286823793,1.859099826845344],[100.01699438082024,1.878727728773804],[-0.016994380820243554,1.878727728773804],[-0.21102286823793245,1.859099826845344],[-0.3968695299824859,1.806872516804512],[-0.5675102796949614,1.7241206065185688],[-0.7165284261444422,1.6140526958612413],[-0.8383471832878048,1.4808799222131859],[-0.9284274001162607,1.329652176791785],[-0.9834252626364106,1.166068608930073],[-1.00130637437862,0.9962692468004231],[-1.001141328901417,0.0016753375821097873]]]]
pgs = [ //polygon
[
[0, 0],
[10, 0],
[10, 1],
[0, 1],
]
]
r = bufferMultiPolygon(pgs, 1)
console.log(JSON.stringify(r))
// => [[[[-1.001155553386317,0.00020218490746980633],[-0.9820125492690016,-0.19485767359241968],[-0.9251387932224696,-0.38243348696414925],[-0.8327132969498687,-0.555321279824778],[-0.7082782159291466,-0.7068780908504364],[-0.5566054036321767,-0.8312763302163503],[-0.3835158174465588,-0.9237277892855092],[-0.19565803014640396,-0.9806686460552702],[-0.0002538669037234854,-0.9998981048986327],[10.000253866903723,-0.9998981048986327],[10.195658030146403,-0.9806686460552702],[10.38351581744656,-0.9237277892855092],[10.556605403632176,-0.8312763302163495],[10.708278215929147,-0.7068780908504364],[10.83271329694987,-0.5553212798247783],[10.925138793222468,-0.3824334869641492],[10.982012549269001,-0.1948576735924193],[11.001155553386317,0.00020218490746980633],[11.001308157005216,0.9996428211826395],[10.982257682211564,1.1945218799229023],[10.925533315715452,1.3819493209356362],[10.83329851355212,1.55473889694727],[10.709077513563999,1.7062614400017102],[10.557623401764781,1.8306986246098138],[10.384738788703551,1.9232666900056332],[10.197055258170192,1.9804014175926012],[10.001779585080351,1.9998969422657566],[-0.0017795850803521507,1.9998969422657566],[-0.19705525817019212,1.9804014175926012],[-0.3847387887035519,1.9232666900056334],[-0.5576234017647811,1.8306986246098143],[-0.7090775135639995,1.7062614400017102],[-0.8332985135521189,1.5547388969472695],[-0.9255333157154515,1.3819493209356362],[-0.9822576822115646,1.1945218799229025],[-1.0013081570052154,0.9996428211826395],[-1.001155553386317,0.00020218490746980633]]]]
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))
// => [[[[-1.001141328901417,0.0016753375821097873],[-0.9829652373939834,-0.1691864014690503],[-0.9828759068893769,-0.16944903103545159],[-0.9828471338128442,-0.16972115991069422],[-0.9642267691588657,-0.22433433005943731],[-0.9272069363899038,-0.3336248371138306],[-0.9269149700562374,-0.33410950396501116],[-0.9267373199338761,-0.3346332604401984],[-0.8903308935608486,-0.3948874359058604],[-0.835961623414144,-0.4853886073046619],[-0.8353702250141729,-0.4860270204908466],[-0.8349336578934242,-0.48675182181191506],[-0.7824274110195127,-0.5432159010460509],[-0.7126648789848471,-0.6186859299608387],[-0.7117015302688281,-0.6193864208225881],[-0.7109147085413277,-0.6202345462697216],[-0.6446160295572254,-0.668195147854552],[-0.5619732974171028,-0.7283987267469068],[-0.5605962119581879,-0.729052102669852],[-0.559394180587721,-0.729923376805404],[-0.48212743928754137,-0.7663024921222514],[-0.38960026351833515,-0.8102767443494782],[-0.3878031408082354,-0.8107634164195489],[-0.38615360668544263,-0.811541439833041],[-0.3011494349616489,-0.8342418049314271],[-0.20211072576851202,-0.8611046524848931],[-0.19992548149722325,-0.8613027037048243],[-0.19783329290733154,-0.8618623554235615],[-0.10860444692188248,-0.869583399882044],[-0.006680493376364686,-0.8788351261142445],[9.993416821174632,-0.9217879435862263],[10.188793002259466,-0.9049587543468377],[10.295194455828872,-0.8757829217517078],[100.00168721930659,-0.8788447694463676],[100.19783329290733,-0.8618623554235615],[100.38615360668544,-0.811541439833041],[100.55939418058772,-0.7299233768054038],[100.71091470854132,-0.6202345462697216],[100.83493365789343,-0.48675182181191484],[100.92673731993388,-0.3346332604401984],[100.98284713381284,-0.16972115991069422],[101.00114132890143,0.0016753375821097873],[101.00130637437861,0.9962692468004231],[100.98342526263642,1.166068608930073],[100.92842740011626,1.3296521767917848],[100.8383471832878,1.4808799222131859],[100.71652842614444,1.614052695861241],[100.56751027969496,1.7241206065185686],[100.3968695299825,1.806872516804512],[100.21102286823793,1.859099826845344],[100.01699438082024,1.878727728773804],[-0.016994380820243554,1.878727728773804],[-0.1157204876987387,1.8687373631615178],[-0.20220168724994378,1.8607327892917573],[-0.20650792922949912,1.8595562623618567],[-0.21102286823793245,1.859099826845344],[-0.30714947328128045,1.832073838565868],[-0.3897693406539745,1.8095331541523574],[-0.3931624216058025,1.807913350946488],[-0.3968695299824859,1.806872516804512],[-0.486882794767004,1.7631991356472565],[-0.5622020098330681,1.72730115650303],[-0.5646733033731067,1.7254949738678342],[-0.5675102796949614,1.7241206065185688],[-0.648108542369765,1.664556475139119],[-0.7129290018915503,1.6172692206642851],[-0.7145459093769313,1.6155153014865016],[-0.7165284261444422,1.6140526958612413],[-0.7847445548212969,1.5394316337665401],[-0.8362344707433637,1.4837039152301397],[-0.8371311983072628,1.4822073608091777],[-0.8383471832878048,1.4808799222131859],[-0.8916549506801756,1.3913170253111737],[-0.9274628819987873,1.331737619583264],[-0.9278275532110773,1.3306573138677165],[-0.9284274001162607,1.329652176791785],[-0.9648179595009568,1.221301519242358],[-0.9831829682906137,1.1671732571246638],[-0.9832418919046929,1.1666123607181955],[-0.9834252626364106,1.166068608930073],[-1.00130637437862,0.9962692468004231],[-1.001141328901417,0.0016753375821097873]]]]
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))
// => [[[[-1.001141328901417,0.0016753375821097873],[-0.9828471338128442,-0.16972115991069422],[-0.9267373199338761,-0.3346332604401984],[-0.8349336578934242,-0.48675182181191506],[-0.7109147085413277,-0.6202345462697216],[-0.559394180587721,-0.729923376805404],[-0.38615360668544263,-0.811541439833041],[-0.19783329290733154,-0.8618623554235615],[-0.0016872193065963293,-0.8788447694463676],[100.00168721930659,-0.8788447694463676],[100.19783329290733,-0.8618623554235615],[100.38615360668544,-0.811541439833041],[100.55939418058772,-0.7299233768054038],[100.71091470854132,-0.6202345462697216],[100.83493365789343,-0.48675182181191484],[100.92673731993388,-0.3346332604401984],[100.98284713381284,-0.16972115991069422],[101.00114132890143,0.0016753375821097873],[101.00130637437861,0.9962692468004231],[100.98342526263642,1.166068608930073],[100.92842740011626,1.3296521767917848],[100.8383471832878,1.4808799222131859],[100.71652842614444,1.614052695861241],[100.56751027969496,1.7241206065185686],[100.3968695299825,1.806872516804512],[100.21102286823793,1.859099826845344],[100.01699438082024,1.878727728773804],[-0.016994380820243554,1.878727728773804],[-0.21102286823793245,1.859099826845344],[-0.3968695299824859,1.806872516804512],[-0.5675102796949614,1.7241206065185688],[-0.7165284261444422,1.6140526958612413],[-0.8383471832878048,1.4808799222131859],[-0.9284274001162607,1.329652176791785],[-0.9834252626364106,1.166068608930073],[-1.00130637437862,0.9962692468004231],[-1.001141328901417,0.0016753375821097873]]]]
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.8012541837164568,-0.17340281498851945],[-0.7845905665553953,-0.36227885731056975],[-0.7362060966497698,-0.5362500018687244],[-0.6581257104469943,-0.688322784190506],[-0.5535304542476391,-0.8124108634048052],[-0.4266299774554017,-0.9035630726703152],[-0.2825015231454891,-0.958146676868447],[-0.12690006663656955,-0.9739812775086525],[0.03395545341221722,-0.9504200786900888],[0.19361433624631713,-0.8883763411426563],[0.34563851486033076,-0.7902939089966787],[1.5370514741011896,0.13454100276614617],[9.19064767617874,0.06717684053056396],[9.191364068615226,-0.13595424650179797],[9.20133965362993,-0.13421645399411475],[10.158988901190282,0.9701242544649328],[10.16096403486849,0.9822526475809891],[2.866804797833092,1.137647522096021],[99.68460366306947,-0.7778744465922519],[99.83402263305543,-0.8744779865054448],[99.98971255084359,-0.9368294391315382],[100.14560908372206,-0.9625601240475504],[100.29567676380367,-0.9507068041095973],[100.43412954295192,-0.9017417273394963],[100.55563852611013,-0.817553248360399],[100.65552164066368,-0.7013779275513093],[100.72991078940285,-0.5576858501436441],[100.77589259056286,-0.3920217971362746],[100.79161911635269,-0.21080593328834593],[100.79663729766196,0.7858468460411016],[100.78366780468126,0.9687873923303338],[100.74205919560113,1.1530813676567635],[100.67320841116904,1.331961262596526],[100.57951447407378,1.498814188916489],[100.46430988704897,1.6474303942232118],[100.33175495294144,1.7722428029343886],[-0.3611196144473517,1.784612946923815],[-0.48871675992881103,1.6636298723025738],[-0.5991787964146019,1.5197286583585954],[-0.6887538943585044,1.357969542007828],[-0.754444795325827,1.1840064755905042],[-0.7825727584436893,1.0562001800792606],[-0.784546778721443,1.0465932538060978],[-0.7846866456585744,1.0466026995606184],[-0.7940988404174638,1.003882122853538],[-0.7944829149075918,0.998255844884385],[-0.7957274513076762,0.9922035987885709],[-0.8064662133136347,0.8238140372657559],[-0.8012541837164568,-0.17340281498851945]]]]
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pgs |
Array | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
|||||||||||||||||
w |
Number | 輸入Buffer寬度數字 |
|||||||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
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) convertCoordinate(cdFrom, cdTo, ps) → {Array}
- Description:
座標轉換
Unit Test: Github
- 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) 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 | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳形心座標陣列
- Type
- Array
(static) fixNoCloseMultiPolygon(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 = fixNoCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]]]]
pgs = [ //ringString
[0, 0],
[100, 0],
[100, 1],
[0, 1],
]
r = fixNoCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]]]]
pgs = [ //polygon
[
[0, 0],
[100, 0],
[100, 1],
[0, 1],
]
]
r = fixNoCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[0,0],[100,0],[100,1],[0,1]]]]
pgs = [ //polygon
[
[0, 0],
[10, 0],
[10, 1],
[0, 1],
]
]
r = fixNoCloseMultiPolygon(pgs)
console.log(JSON.stringify(r))
// => [[[[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 = fixNoCloseMultiPolygon(pgs) //預設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]]]]
pgs = [ //polygon
[
[0, 0],
[100, 0],
[100, 1],
[0, 1],
[0, 0],
],
[
[0, 0],
[10, 0],
[10, 1],
[0, 1],
]
]
r = fixNoCloseMultiPolygon(pgs, { 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]]]]
pgs = [ //multiPolygon
[
[
[0, 0],
[100, 0],
[100, 1],
[0, 1],
],
[
[0, 0],
[10, 0],
[10, 1],
[0, 1],
[0, 0],
]
]
]
r = fixNoCloseMultiPolygon(pgs)
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pgs |
Array | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳形心座標陣列
- 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 | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
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)
// => 11364090825.686134
pgs = [ //ringString
[121, 23],
[122, 23],
[122, 24],
[121, 24],
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 11364090825.686134
pgs = [ //polygon
[
[121, 23],
[122, 23],
[122, 24],
[121, 24],
]
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 11364090825.686134
pgs = [ //polygon
[
[121, 23],
[121.5, 23],
[121.5, 24],
[121, 24],
]
]
r = getAreaMultiPolygonSm(pgs)
console.log(r)
// => 5682045412.843067
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)
// => 17046136238.529202
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)
// => 5682045412.843067
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)
// => 5682045412.843067
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pgs |
Array | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
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],...]RingString構成之陣列 |
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資料陣列,為[x,y]點構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳面積數字
- Type
- Number
(static) getBoxPolygon(fts) → {Number}
- Description:
計算點、線、面陣列之外接矩形
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(JSON.stringify(r))
// => [0,0,100,1]
pgs = [ //ringString
[0, 0],
[100, 0],
[100, 1],
[0, 1],
]
r = getBoxPolygon(pgs)
console.log(JSON.stringify(r))
// => [0,0,100,1]
pgs = [ //polygon
[
[0, 0],
[100, 0],
[100, 1],
[0, 1],
]
]
r = getBoxPolygon(pgs)
console.log(JSON.stringify(r))
// => [0,0,100,1]
pgs = [ //polygon
[
[0, 0],
[10, 0],
[10, 1],
[0, 1],
]
]
r = getBoxPolygon(pgs)
console.log(JSON.stringify(r))
// => [0,0,10,1]
pgs = [ //polygon
[
[0, 0],
[100, 0],
[100, 1],
[0, 1],
],
[
[0, 0],
[10, 0],
[10, 1],
[0, 1],
]
]
r = getBoxPolygon(pgs)
console.log(JSON.stringify(r))
// => [0,0,100,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 = getBoxPolygon(pgs)
console.log(JSON.stringify(r))
// => [-10,0,100,123]
Parameters:
Name | Type | Description |
---|---|---|
fts |
Array | 輸入資料陣列,為多點(multiPoint)、線(line)、多線(multiLine)、面(polygon)、多面(multiPolygon)數據陣列 |
Returns:
回傳外接矩形陣列,陣列為4元素分別為[minX, minY, maxX, maxY]
- Type
- Number
(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 | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
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 | 輸入Polygon資料陣列,為[ [[x11,y11],[x12,y12],...], [[x21,y21],[x22,y22],...] ]Polygon構成之陣列 |
||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳形心座標陣列
- Type
- Array
(static) interp1(ps, x, optopt) → {Number|Object}
- Description:
針對不規則一維數據進行指定內插點數值
- Source:
Example
async function test() {
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 }
}
test()
.catch((err) => {
console.log(err)
})
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
|
Returns:
回傳內插結果數值,或是無法內插時之錯誤訊息物件
- Type
- Number | Object
(static) interp2(psSrc, psTar, optopt) → {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 }, { 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.43040421951906 }
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.43040421951906 }
// ]
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 }
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 }
}
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 |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳Promise或點物件陣列或點物件,若useSync=false則回傳Promise,resolve為回傳點物件陣列或點物件,reject為失敗訊息,若useSync=true則回傳點物件陣列或點物件,若發生錯誤則回傳錯誤訊息物件
- Type
- Promise | Array | Object
(static) interp2Kriging(psSrc, psTar, optopt) → {Array|Object}
- Description:
克利金法(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
|
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
Delaunator https://github.com/mapbox/delaunator
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.43040421951906 }
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.43040421951906 }
// ]
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
|
Returns:
回傳點物件陣列或點物件,若發生錯誤則回傳錯誤訊息物件
- Type
- Array | 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) 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) 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
|
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
|
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
|
Returns:
回傳點{x,y}陣列
- 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
|
Returns:
回傳點{x}陣列
- 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
|
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