geojson数据抽稀

geojson 数据抽稀

接上一篇手绘地图实现,其中通过借助工具将 svg 导出 geojson 数据,但是通常数据量非常大,而且有很多重复的点数据/非常相近的数据

这样的数据,虽然可以用,但是考虑到前端性能问题,需要将 geojson 数据进行点抽稀
目前有很多的抽稀算法,比如道格拉斯-普克算法、垂距限值法,这里暂时不做讨论

这里可以借助另外一个宝藏工具Turfhttps://github.com/Turfjs/turf/

Turf 的作用就是,对 geojson 数据进行抽稀

接下来我们对黄色板块进行数据抽稀操作

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
const turf = require('@turf/turf');
const fs = require('fs');
// geo数据
const coordinates = [
[
[119.75217242139553, 30.189759022525294],
[119.75329376495, 30.191341051272516],
[119.75388138579581, 30.193125439402152],
[119.75389083220648, 30.19498061401667],
[119.75364757017621, 30.19682967368732],
[119.75340430814606, 30.198678727588927],
[119.75316107959941, 30.200527746745593],
[119.75291781756914, 30.202376731190043],
[119.75267455549948, 30.20422565194926],
[119.75243129346927, 30.206074566932116],
[119.75218806492273, 30.20792344716493],
[119.75194480289247, 30.20977226372723],
[119.75170154086231, 30.211621074507846],
[119.75145827883199, 30.213469850551576],
[119.7512150502854, 30.215318562905622],
[119.75097178825519, 30.217167269455445],
[119.75072852622503, 30.219015941281654],
[119.75048526419477, 30.22086457836592],
[119.75024203564811, 30.22271315175753],
[119.74999877361796, 30.2245617193377],
[119.74975551154819, 30.226410252189183],
[119.74928406155641, 30.228207868281288],
[119.74761288283759, 30.229304112008293],
[119.74552066854585, 30.229743549617893],
[119.74342832024047, 30.230182580053395],
[119.7413360054187, 30.230621608528566],
[119.73924365711338, 30.231060663990448],
[119.73715130880794, 30.231499688561996],
[119.73505899402585, 30.231938711156033],
[119.73296664572041, 30.232377760736327],
[119.73087429741503, 30.232816779409475],
[119.72878198259332, 30.233255796139346],
[119.726689634288, 30.233694839837852],
[119.72459731950573, 30.234133852629597],
[119.7225353203184, 30.23466593849554],
[119.72055616156075, 30.235395978181486],
[119.71868533513208, 30.236314822005255],
[119.71694679205308, 30.237410570177474],
[119.71536300947224, 30.238669267670474],
[119.71395411965767, 30.240074615213686],
[119.71273847941609, 30.24160869315955],
[119.71171819916344, 30.24324594261242],
[119.71090269182696, 30.24496639106664],
[119.71031396554764, 30.24675455249728],
[119.70995898788084, 30.248588141607044],
[119.70984231453554, 30.250444411731706],
[119.70996531897151, 30.25230032848745],
[119.71032656076153, 30.25413288818241],
[119.71092191964237, 30.255919233477897],
[119.71164088594094, 30.257672329564528],
[119.71235988568355, 30.25942536540451],
[119.7130788854659, 30.261178398908626],
[119.71379788524808, 30.26293138664218],
[119.71451685154665, 30.26468435754211],
[119.71523585128949, 30.266437282686965],
[119.71595485107167, 30.26819017653581],
[119.71667385085385, 30.269943053564077],
[119.71739285063603, 30.271695884817703],
[119.71811181689526, 30.273448699230954],
[119.71883081667738, 30.27520146788501],
[119.71954981645962, 30.276954219695995],
[119.72031032018566, 30.2786936910815],
[119.72114307897414, 30.280408282678977],
[119.72204665239758, 30.282095913065177],
[119.72301986801551, 30.283754370722207],
[119.72406175444746, 30.28538138639503],
[119.72517067024563, 30.286975009169225],
[119.72634520850482, 30.288533143574284],
[119.72758412977868, 30.290053636411088],
[119.72888542425943, 30.291534739461213],
[119.73024765144044, 30.2929744009424],
[119.73166906954117, 30.29437072815402],
[119.73314763507352, 30.295722045416014],
[119.73468160621718, 30.297026503497833],
[119.73626900660918, 30.298282383417217],
[119.73790765878721, 30.299488168595076],
[119.73959005933858, 30.300648285929668],
[119.74127852295345, 30.301801882215557],
[119.74296695312438, 30.30295545045672],
[119.74465538325575, 30.304109019595842],
[119.74634384691035, 30.305262575160967],
[119.74803227704166, 30.306416117151883],
[119.74972070721253, 30.30756963109745],
[119.75140917086702, 30.30872314593907],
[119.75309760099844, 30.30987664720557],
[119.75478606465293, 30.311030134896512],
[119.7564744947843, 30.312183594541622],
[119.75816295843879, 30.31333705508085],
[119.7598513885701, 30.314490502043725],
[119.76153981874103, 30.31564392097731],
[119.76322828239552, 30.316797340786565],
[119.76491671252688, 30.31795074700146],
[119.76660551113605, 30.319103763750604],
[119.76823545389868, 30.320317389281954],
[119.7697441006008, 30.32164272966584],
[119.7711211004189, 30.323070831130238],
[119.77235727485055, 30.32459193045797],
[119.77344374702295, 30.32619588889223],
[119.77437395134172, 30.3278714404114],
[119.77514118811979, 30.329607334142167],
[119.77574039927612, 30.331391799351607],
[119.77616766548891, 30.333212719229692],
[119.776419201529, 30.335057804284176],
[119.77649386843933, 30.336914491266043],
[119.77639109676176, 30.33877013117592],
[119.77615731462572, 30.34061738091968],
[119.7759165649336, 30.342463959813983],
[119.77567581524164, 30.344310518321294],
[119.77543506554957, 30.346157013078553],
[119.77519434938057, 30.348003516358816],
[119.77495359968856, 30.349849955904062],
[119.7747128499966, 30.351696360592015],
[119.77447210030442, 30.353542730455487],
[119.77423135061247, 30.35538906545905],
[119.77399060092034, 30.35723538008203],
[119.77374988471195, 30.35908164539609],
[119.77350913502005, 30.360927890326337],
[119.77326838532792, 30.362774085962755],
[119.77302763563591, 30.36462026117826],
[119.77278688594396, 30.366466387114897],
[119.77254613625183, 30.368312492644748],
[119.77230538655982, 30.370158548859578],
[119.77206467035137, 30.372004570237422],
[119.7718239206593, 30.373850556742767],
[119.7715831709674, 30.375696508408637],
[119.77134242127534, 30.377542439659877],
[119.77110167158327, 30.379388321591264],
[119.77086092189131, 30.381234183122146],
[119.77062020572225, 30.38307999533123],
[119.77037945603041, 30.384925787136694],
[119.77013870633823, 30.38677152963548],
[119.76989795664628, 30.3886172444726],
[119.76965720695415, 30.390462917239077],
[119.7694164572622, 30.392308555120607],
[119.76917570757018, 30.394154158149902],
[119.76893499136173, 30.395999747969668],
[119.76869424166966, 30.39784528123937],
[119.76845349197765, 30.3996907796531],
[119.7682127422857, 30.401536243175556],
[119.76797199259363, 30.403381700735764],
[119.76773124290156, 30.40522709450542],
[119.7674904932095, 30.407072453397163],
[119.76724977704066, 30.40891777020728],
[119.76700902734859, 30.410763059339416],
[119.76676827765652, 30.412608342483125],
[119.7663351492817, 30.414267940857812],
[119.7641820022107, 30.414267940857812],
[119.76202885513959, 30.414267940857812],
[119.75987567458492, 30.414267940857812],
[119.75772252751375, 30.414267940857812],
[119.75556938048214, 30.414267940857812],
[119.75341623341114, 30.414267940857812],
[119.75126305285636, 30.414267940857812],
[119.7491100732824, 30.414262907092763],
[119.74695762964387, 30.41426483537417],
[119.74481064620574, 30.414400855409554],
[119.74267766492596, 30.414652167724967],
[119.74056689272822, 30.41501729088901],
[119.73848764212823, 30.415498231357134],
[119.73645073291812, 30.416098872799836],
[119.73446892780879, 30.416823647226394],
[119.7325566309201, 30.41767596055142],
[119.73072955282544, 30.418657434342492],
[119.72900420794201, 30.41976723421041],
[119.72739637385035, 30.421001311697268],
[119.7259199521389, 30.422351920676434],
[119.72459299826193, 30.423813062614997],
[119.72344941210213, 30.425385223583717],
[119.72249793663764, 30.42704981831436],
[119.72154136945056, 30.428709748759317],
[119.72021950725662, 30.430171770287544],
[119.71862262700995, 30.431414092273783],
[119.7168300182567, 30.432439900227138],
[119.71490314979081, 30.433266061151485],
[119.71288684177733, 30.43391543335609],
[119.71081254888651, 30.43441142219072],
[119.70870160923118, 30.43477542444107],
[119.70656846041481, 30.43502594777722],
[119.70442281691396, 30.435178481044403],
[119.70227122750282, 30.435245963859302],
[119.70011821440573, 30.435238967188525],
[119.6979668929821, 30.435205687903476],
[119.69581699524434, 30.435307727987805],
[119.69366706398353, 30.435409760748044],
[119.69151718294819, 30.435511800618897],
[119.68936728517093, 30.43561383316556],
[119.68721740417504, 30.43571586560543],
[119.68506750639784, 30.43581790515603],
[119.68291757513703, 30.435919937382394],
[119.68076767739927, 30.43602196950208],
[119.67861779636388, 30.436124008732335],
[119.67646789862619, 30.43622604063843],
[119.67431798410723, 30.436328079655183],
[119.67216808632986, 30.436430111347775],
[119.67001818855272, 30.43653215016799],
[119.66786829081497, 30.436634181647065],
[119.6657183762959, 30.43673621300246],
[119.66356847851881, 30.436838251502337],
[119.66141858078095, 30.43694028266114],
[119.65926869974555, 30.43704232093043],
[119.65711880196841, 30.437144351875773],
[119.65496887070759, 30.437246382714278],
[119.65281898971159, 30.437348420663383],
[119.6506690919345, 30.437450451288356],
[119.64851919419675, 30.437552489023844],
[119.64636927967769, 30.43765451943537],
[119.64421938190048, 30.437756549740072],
[119.64206948416285, 30.437858587155247],
[119.63991960312745, 30.437960617246475],
[119.63776871718835, 30.438012415651258],
[119.6356289190287, 30.437817568580982],
[119.63353528105085, 30.437389634369012],
[119.63152175340281, 30.43673562094517],
[119.62962091285044, 30.435866347192743],
[119.62786325918825, 30.43479622679601],
[119.62627733274712, 30.433542438211248],
[119.6248893623818, 30.432124780836602],
[119.62372174141342, 30.430566462521696],
[119.62282272373773, 30.42888184629895],
[119.62185949046562, 30.42722184656833],
[119.62077427448202, 30.425618620668672],
[119.61958533210293, 30.42407099431709],
[119.6183021097786, 30.42258032055514],
[119.61693135734214, 30.42114872515795],
[119.61547838419943, 30.419778731060063],
[119.61394818158271, 30.4184727601628],
[119.61234532194192, 30.41723330654412],
[119.61067452844281, 30.41606235155143],
[119.60894052433002, 30.414961883721134],
[119.60714826735227, 30.413933183727593],
[119.60530261461008, 30.412977214384554],
[119.60340860760022, 30.41209436783258],
[119.6014711035416, 30.411284682169295],
[119.59949485908368, 30.410547906439803],
[119.59748459747118, 30.409883125053767],
[119.59544490793525, 30.4092886638644],
[119.59337981020934, 30.408763440807718],
[119.5912932905427, 30.40830543469876],
[119.58918898348873, 30.40791264583146],
[119.58707018856643, 30.40758277099745],
[119.58493983685696, 30.407313607990304],
[119.58280069190448, 30.407102788261753],
[119.58065516563607, 30.4069477842893],
[119.57850530138188, 30.406846314018395],
[119.57635300849876, 30.406795914704304],
[119.57420002892474, 30.406805347414263],
[119.57204711635751, 30.406832771636743],
[119.56989420375072, 30.406860188632052],
[119.56774129118355, 30.4068876128391],
[119.56558834513254, 30.406915037055526],
[119.56343543252592, 30.406942454027657],
[119.56128251995864, 30.40696987821164],
[119.55912960739147, 30.406997295168452],
[119.55697669478468, 30.407024719336945],
[119.55482374873384, 30.407052136278367],
[119.55267083616656, 30.407079560431484],
[119.55051792355982, 30.40710697735743],
[119.5483650109926, 30.407134401495185],
[119.5462120649023, 30.40716181840581],
[119.54405915233502, 30.407189242528133],
[119.54190623976785, 30.40721666664281],
[119.53975332720051, 30.40724408353026],
[119.53760038111028, 30.40727150762949],
[119.53544750202656, 30.407298924501575],
[119.53329455593615, 30.407326348585386],
[119.53114160988531, 30.407353765442068],
[119.52898873080181, 30.40738118951046],
[119.52683579308234, 30.40740860635175],
[119.52468291399873, 30.40743603040481],
[119.52253047877053, 30.40742711055961],
[119.52040223743779, 30.40715862602802],
[119.5183505723719, 30.406602067016664],
[119.51642721281638, 30.405771563374813],
[119.51468130018037, 30.40468815523795],
[119.5131695800523, 30.40336958076469],
[119.51189141592732, 30.401875932772057],
[119.5107244816893, 30.40031541953428],
[119.50959686568001, 30.39873328398801],
[119.50846764174588, 30.39715204017203],
[119.50731025444821, 30.395586062772722],
[119.50610639712676, 30.39404631785399],
[119.5048429050695, 30.392542601962006],
[119.50351039891194, 30.391083895900707],
[119.50210223764276, 30.38967903647162],
[119.50061475326447, 30.388336557524795],
[119.49904607827546, 30.3870645742316],
[119.49739748552707, 30.385870270185848],
[119.49567169682769, 30.384760027218945],
[119.4938735106814, 30.383738782404464],
[119.4920093921923, 30.38280984006053],
[119.49008627128649, 30.381974929489843],
[119.48811205349625, 30.381234139776666],
[119.48609445166443, 30.38058625934596],
[119.48404075578497, 30.380028667500767],
[119.48195813861946, 30.379558028041913],
[119.47985255863472, 30.37917026751093],
[119.4777295722966, 30.378861052104497],
[119.47559398651958, 30.37862567204037],
[119.47344954890332, 30.378459431827253],
[119.47129977258328, 30.378357895835222],
[119.46914721589809, 30.378316787242014],
[119.46699416517134, 30.378331727946758],
[119.46484254642257, 30.378399120008126],
[119.46269304646086, 30.378506450158568],
[119.46054486965517, 30.3784149710158],
[119.4584427001833, 30.378023058954057],
[119.45644238956532, 30.377341287453916],
[119.454597425646, 30.376387727028145],
[119.45303654515584, 30.37512755995587],
[119.45176613162204, 30.373627721781432],
[119.45049575994273, 30.372127918390035],
[119.44922534640898, 30.37062803417888],
[119.44795497472967, 30.369128170326363],
[119.44668456119587, 30.36762824009807],
[119.445414151808, 30.366128286878862],
[119.44414377803605, 30.36462835398821],
[119.44287336556835, 30.36312835475583],
[119.44160295408784, 30.36162833250053],
[119.440332581382, 30.360128330611957],
[119.43906216887478, 30.358628262364604],
[119.43779179616882, 30.357128228915954],
[119.43652138366167, 30.35562811464544],
[119.43525097222062, 30.354127977389396],
[119.43398059947526, 30.352627860472637],
[119.43271018696811, 30.351127677214336],
[119.43129189938901, 30.349733979910667],
[119.43017052866861, 30.348151350743407],
[119.42943614311997, 30.346407966121973],
[119.42916477367692, 30.344575251143382],
[119.42948182619944, 30.34273734153301],
[119.42977602969978, 30.340896564242513],
[119.43005360932904, 30.339053786430966],
[119.43031805670313, 30.337209513902152],
[119.43057135189713, 30.33536412246869],
[119.4308151038623, 30.333517713236702],
[119.43105028974423, 30.33167040182093],
[119.43127783602847, 30.329822376080088],
[119.43149813050121, 30.327973621543308],
[119.43171195153849, 30.326124326103255],
[119.4319194754425, 30.324274446378638],
[119.43210158594422, 30.322422565462148],
[119.43223580328925, 30.320567613369022],
[119.4323024840781, 30.31870998030388],
[119.4322776343696, 30.316851632468527],
[119.43214299097713, 30.314996733945776],
[119.43190110288117, 30.313149882907226],
[119.43157794982335, 30.311312251043688],
[119.43120862509357, 30.309480975857866],
[119.43082121201832, 30.30765242828454],
[119.43043313625964, 30.3058240490398],
[119.43005259601495, 30.30399431979552],
[119.42968451724727, 30.30216279220261],
[119.42932982458643, 30.300329162477112],
[119.42898909009682, 30.298493488358417],
[119.42866207955149, 30.296656030032693],
[119.42834793430018, 30.29481683078646],
[119.42804513988028, 30.292976208689836],
[119.42775376116623, 30.2911340769123],
[119.42747279001657, 30.289290767971053],
[119.42720146704801, 30.287446368628224],
[119.42693900859337, 30.285600965567],
[119.42668496258437, 30.283754616596923],
[119.42643865176717, 30.28190746631067],
[119.42619974126603, 30.280059572514375],
[119.42596755520924, 30.278211021968445],
[119.4257417543381, 30.276361829080344],
[119.42565698745454, 30.27450597649657],
[119.42594232403223, 30.27266524816139],
[119.42659136474947, 30.270894685336728],
[119.42758476199236, 30.269247495981148],
[119.42860463159661, 30.267610477356996],
[119.4293783021273, 30.265875872661567],
[119.43001495899591, 30.264099487669284],
[119.43058123797766, 30.262305320089396],
[119.43110552837203, 30.26050158608244],
[119.43160225467273, 30.258691945333453],
[119.43207972800593, 30.256878422916955],
[119.43254473962526, 30.255062523274646],
[119.43300116214124, 30.25324485390766],
[119.43345237203033, 30.251426196008012],
[119.43390047923492, 30.24960695463679],
[119.43434852725073, 30.24778767959559],
[119.43479691811854, 30.245968486604696],
[119.43524843579627, 30.244149722955086],
[119.43570380361757, 30.242331678042177],
[119.43616492999098, 30.240514757093507],
[119.43663307939738, 30.23869907591927],
[119.43710892494448, 30.236884923975666],
[119.43759433208118, 30.235072532916732],
[119.4380908217853, 30.23326239482823],
[119.43859996324653, 30.231454857148904],
[119.43912284097127, 30.229650180500414],
[119.43966167313124, 30.22784903076044],
[119.4402182162745, 30.22605184225013],
[119.44079428349215, 30.22425925199893],
[119.44139292096503, 30.22247215752556],
[119.44201682428292, 30.220691485396856],
[119.44266867430821, 30.218918220112826],
[119.44335334184223, 30.21715430149156],
[119.44407518682459, 30.21540138000627],
[119.44484007880118, 30.21366220625346],
[119.44565527207067, 30.21194002312791],
[119.44653015243381, 30.210239955405584],
[119.44747652993698, 30.208568749331704],
[119.44851059667837, 30.20693688603302],
[119.44965359035962, 30.205360318863328],
[119.450935453912, 30.203866003171697],
[119.45239588869157, 30.20250037966143],
[119.45408059009725, 30.2013456167235],
[119.45584978171212, 30.200285134818813],
[119.45759651292008, 30.199196992628202],
[119.45933251432348, 30.198096186424067],
[119.4610631916322, 30.196989056291443],
[119.46279190726659, 30.195879684353002],
[119.46452089921979, 30.19477053154202],
[119.4662518214962, 30.193663566685217],
[119.46798509702415, 30.19255957161191],
[119.46972240484166, 30.19146013887432],
[119.4714644149372, 30.190366310994662],
[119.4732112948077, 30.189278290841145],
[119.47496452673568, 30.188197902753885],
[119.47672362497156, 30.18712465475174],
[119.47848985407518, 30.186060139624615],
[119.48026354066957, 30.185005023646127],
[119.48204514535229, 30.183959915194066],
[119.48383520405872, 30.18292553847955],
[119.48563415645884, 30.181902820487807],
[119.48744287352196, 30.180892948791822],
[119.48926159389794, 30.179896647752756],
[119.49109080752157, 30.178914931259015],
[119.49293129738851, 30.177948929152137],
[119.49478391350146, 30.17700052414075],
[119.49664920857674, 30.176070643417802],
[119.49852771440436, 30.175160967113598],
[119.50042021397968, 30.174273378120304],
[119.5023277373981, 30.173409991078273],
[119.50425130634488, 30.172573557743362],
[119.5061914818678, 30.171766569349685],
[119.50814948671177, 30.170992299114232],
[119.51012622525076, 30.1702544836442],
[119.51212280291799, 30.16955769950559],
[119.51414013261626, 30.168907131531213],
[119.51617894281208, 30.16830906509503],
[119.5182402468983, 30.167771291634693],
[119.52032383552336, 30.167302732132214],
[119.52242954111131, 30.166914914138246],
[119.52455552135154, 30.166621363478043],
[119.52669786533289, 30.16643887855294],
[119.52882745497402, 30.16617628618269],
[119.53095258935775, 30.16587682520138],
[119.53307886269823, 30.165583908604702],
[119.5352063168499, 30.165297188923404],
[119.53733490154787, 30.165016695178082],
[119.53946472569288, 30.164743383162246],
[119.5415956719736, 30.164476673706687],
[119.54372769024388, 30.164216798529893],
[119.54586081390818, 30.1639629757383],
[119.54799464941539, 30.163714394428155],
[119.55012912134856, 30.163469664451853],
[119.55226374407636, 30.163225744822583],
[119.55439773867033, 30.16297843599685],
[119.55653028450519, 30.16272142415056],
[119.55865972339097, 30.162446049427558],
[119.56078389476505, 30.1621415665836],
[119.56289996795812, 30.16179769359637],
[119.56500476076167, 30.161405857084517],
[119.56709610412383, 30.16096336289955],
[119.56917274189522, 30.160471397883228],
[119.57123487505658, 30.159936130432897],
[119.57328391051271, 30.159364221422948],
[119.5753215566786, 30.158762940049698],
[119.5773497731758, 30.15813799166807],
[119.57937020141276, 30.15749435757627],
[119.58138406405516, 30.156835802790127],
[119.58339320345289, 30.156166266129773],
[119.58539787093031, 30.15548702181171],
[119.58739955706204, 30.154800908176256],
[119.58939816135756, 30.15410818577263],
[119.5913945715672, 30.15341102683908],
[119.59338929014291, 30.15271001057984],
[119.59538204905772, 30.15200476038507],
[119.59737430552076, 30.151298694095075],
[119.59936490383348, 30.150588944076887],
[119.60135116416052, 30.149870643950422],
[119.60331665575399, 30.14911036630781],
[119.60527613447005, 30.14833861203121],
[119.6072294328506, 30.147555322908474],
[119.60917658433988, 30.146760556625637],
[119.61111737121547, 30.145954225972517],
[119.61305181021908, 30.145136678298584],
[119.61497956639607, 30.144307160143086],
[119.61689996975792, 30.14346529462712],
[119.61881293659553, 30.142610646925462],
[119.62071783044371, 30.14174257938045],
[119.62261386408164, 30.140860309490307],
[119.624500468051, 30.139962909850624],
[119.62637638616263, 30.139048902629668],
[119.62824052972508, 30.138117128581882],
[119.63009165937018, 30.137166022816004],
[119.63192793266921, 30.136193788639133],
[119.63374735651723, 30.135198020864536],
[119.63554716733012, 30.134175995531123],
[119.63732398176143, 30.133124235311826],
[119.63907319395616, 30.13203842250283],
[119.64078879091835, 30.130913341062282],
[119.64246276670468, 30.129742210213166],
[119.6440823753457, 30.12851540944976],
[119.64562944419487, 30.127220536342293],
[119.64707452854742, 30.12584052299367],
[119.6483790890639, 30.124359633157752],
[119.64961943402358, 30.122837346121074],
[119.65081844249721, 30.121290436221727],
[119.65196861103266, 30.11971612071386],
[119.65306963804073, 30.11811564424849],
[119.65413663115214, 30.1164979880718],
[119.65521968653366, 30.11488830289389],
[119.65639916576038, 30.113330547049344],
[119.65772201611622, 30.111861727035276],
[119.65917225919804, 30.110485469024226],
[119.66071184121864, 30.109183694543972],
[119.66231022893936, 30.10793574492979],
[119.6639477589419, 30.106726350352815],
[119.66561237206622, 30.105544992813265],
[119.66729644747022, 30.104384457412763],
[119.66903043484103, 30.103281201516765],
[119.67087273775968, 30.102318168159755],
[119.67279870181238, 30.101486580405563],
[119.67478742421264, 30.100773226411917],
[119.676822591524, 30.100165705004315],
[119.67889199375202, 30.099652164924436],
[119.68098690466047, 30.099222000607725],
[119.68310018915679, 30.09886622899053],
[119.68522704036621, 30.09857693900524],
[119.68736392414706, 30.098347900259427],
[119.68950732333656, 30.098172853198506],
[119.69165552944037, 30.098046842312982],
[119.69380654939295, 30.097966216124377],
[119.69595921071453, 30.097927120242105],
[119.69811227403704, 30.09792633773712],
[119.70026503588838, 30.097961376233812],
[119.70241679279678, 30.0980301780251],
[119.70456672405754, 30.098130917210568],
[119.70671451145807, 30.09826101434865],
[119.70885988697125, 30.09842015054639],
[119.71100208023682, 30.098607166398267],
[119.71314105765265, 30.098820380841147],
[119.71527758973696, 30.099051881889523],
[119.7155232301314, 30.10033266291039],
[119.71490177636963, 30.102116118626526],
[119.71428028908491, 30.10389954217733],
[119.71365876831663, 30.10568304944563],
[119.71303731455487, 30.107466437592123],
[119.71241582727015, 30.109249764586053],
[119.7117943065017, 30.1110331752878],
[119.7111728527006, 30.112816437904343],
[119.71055136545527, 30.11459969729563],
[119.70992984468694, 30.11638301143749],
[119.70930839088572, 30.118166177462925],
[119.70868690364051, 30.119949311312624],
[119.7080653828325, 30.121732528850714],
[119.70744392907096, 30.12351562727079],
[119.7068221403149, 30.125298519659424],
[119.70629639014516, 30.12710397868304],
[119.70593529911048, 30.128939477920085],
[119.70574121205203, 30.13079360086516],
[119.70571521766152, 30.132655134582905],
[119.70585724893226, 30.134512867013342],
[119.70616636788822, 30.136355152368367],
[119.70664098346481, 30.13817098307372],
[119.7072778797729, 30.13994932335777],
[119.70807328836446, 30.141679051340674],
[119.7090224859947, 30.143349770026205],
[119.71011974447543, 30.14495111201765],
[119.71135856529844, 30.146473637370363],
[119.71270829775568, 30.147924156957842],
[119.71406908458795, 30.149367008103013],
[119.715429971871, 30.150809925038885],
[119.71679079214738, 30.152252733974237],
[119.71815157897953, 30.15369552180435],
[119.7195124997462, 30.155138375419583],
[119.72087328657841, 30.15658112103631],
[119.72223410685473, 30.158023845546012],
[119.72359499413773, 30.15946663583513],
[119.72495578097005, 30.16090931812775],
[119.72631660124642, 30.162351979311552],
[119.72767742156225, 30.16379459041913],
[119.72903830884525, 30.1652372962658],
[119.73039909563795, 30.1666798941187],
[119.73175991595377, 30.16812247086031],
[119.73312080323677, 30.169565113368193],
[119.73448159002959, 30.171007647884167],
[119.73584241034541, 30.17245016128723],
[119.73720329762853, 30.173892740450796],
[119.73856411794429, 30.175335211624542],
[119.73992490473711, 30.176777661683474],
[119.74128579202011, 30.17822017749735],
[119.74264661233599, 30.179662585323427],
[119.7440074326123, 30.18110497203277],
[119.74536821940495, 30.182547337624868],
[119.74672910672751, 30.183989768964437],
[119.74808992700389, 30.18543209231882],
[119.74945071379665, 30.18687439455411],
[119.75081160111915, 30.1883167625313],
[119.75217242139553, 30.189759022525294],
],
];

let geojson = turf.polygon(coordinates);
var options = { tolerance: 0.001, highQuality: false };
var simplified = turf.simplify(geojson, options);
console.log(
'输入长度:',
geojson.geometry.coordinates[0].length,
simplified,
'\n输出长度:',
simplified.geometry.coordinates[0].length
);
fs.writeFile('./output.json', JSON.stringify(simplified.geometry), (err) => {
if (err) {
console.error(err);
return;
}
console.log('写入文件成功');
//文件写入成功。
});

如下, 我们运行该 node 脚本查看输出,原 geojson 数据从 604 个点减少到了 55 个点

1
2
3
4
5
6
7
8
$ node utils.js
输入长度: 604 {
type: 'Feature',
properties: {},
geometry: { type: 'Polygon', coordinates: [ [Array] ] }
}
输出长度: 55
写入文件成功

可能遇见的问题 First and last Position are not equivalent

1
2
3
4
5
6
/Users/aiyouwei/Desktop/test/node_modules/@turf/helpers/dist/js/index.js:238
throw new Error("First and last Position are not equivalent.");
^

Error: First and last Position are not equivalent.
at Object.polygon (/Users/aiyouwei/Desktop/test/node_modules/@turf/helpers/dist/js/index.js:238:23)

因为我这里的数据设定的是turf.polygon, 所以有一些数据的coordinates数组中,首位可能有问题,所以需要手动修改一下原先的mapData,将coordinates[0]数组中的第一项拷贝一分放到末尾项

抽稀效果:

我们可以看到图像边缘变锐化了,那么具体锐化程度多少可以接受,需要看具体场景

数据抽稀前:2.1M , 数据抽稀后:102k

感谢阅读,勘误、纠错或其他请联系progerchai@gmail.com,或者点击这里提 issue 给我
欢迎交流 👏,你的每一次指导都可以让我进步


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!