r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
868 stars 121 forks source link

view mode tm_dots slow without use.WebGL and not working with WebGL #952

Closed mtennekes closed 4 weeks ago

mtennekes commented 1 month ago
x = structure(list(geometry = structure(list(structure(c(253868.145699177, 
470546.085241937), class = c("XY", "POINT", "sfg")), structure(c(224687.299177682, 
487234.402715354), class = c("XY", "POINT", "sfg")), structure(c(199207.599249684, 
500832.378959987), class = c("XY", "POINT", "sfg")), structure(c(197665.299282187, 
483882.907725215), class = c("XY", "POINT", "sfg")), structure(c(223743.472045239, 
473887.912497513), class = c("XY", "POINT", "sfg")), structure(c(249900.089315361, 
472407.3154798), class = c("XY", "POINT", "sfg")), structure(c(187134.75604692, 
506534.260531805), class = c("XY", "POINT", "sfg")), structure(c(208147.313537197, 
524239.244909925), class = c("XY", "POINT", "sfg")), structure(c(174146.01516337, 
466116.928432244), class = c("XY", "POINT", "sfg")), structure(c(247585.130538058, 
478104.103418522), class = c("XY", "POINT", "sfg")), structure(c(236374.54251862, 
509719.502367285), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(185831.438500569, 
467436.922232768), class = c("XY", "POINT", "sfg")), structure(c(210314.293544293, 
479397.040159928), class = c("XY", "POINT", "sfg")), structure(c(206328.823261169, 
380285.421689755), class = c("XY", "POINT", "sfg")), structure(c(247121.752809107, 
478560.360317052), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(199018.833775056, 
497210.987468254), class = c("XY", "POINT", "sfg")), structure(c(178835.786855663, 
537312.563160473), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(134020.811788213, 
481547.156225936), class = c("XY", "POINT", "sfg")), structure(c(208680.400731488, 
472923.061185722), class = c("XY", "POINT", "sfg")), structure(c(174292.893863551, 
516757.724252712), class = c("XY", "POINT", "sfg")), structure(c(171441.717866536, 
418803.112617515), class = c("XY", "POINT", "sfg")), structure(c(240904.089711459, 
487434.630516783), class = c("XY", "POINT", "sfg")), structure(c(247392.953328839, 
478417.184751088), class = c("XY", "POINT", "sfg")), structure(c(233561.213383355, 
560315.879036129), class = c("XY", "POINT", "sfg")), structure(c(250012.718914383, 
476676.575686151), class = c("XY", "POINT", "sfg")), structure(c(188279.604462419, 
507402.037491825), class = c("XY", "POINT", "sfg")), structure(c(198730.118246961, 
467021.903856189), class = c("XY", "POINT", "sfg")), structure(c(210478.766044459, 
515743.09581205), class = c("XY", "POINT", "sfg")), structure(c(181009.991220068, 
524608.743353597), class = c("XY", "POINT", "sfg")), structure(c(264908.8943296, 
488275.595700192), class = c("XY", "POINT", "sfg")), structure(c(197745.391611992, 
489409.30824757), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(244379.285439191, 
481134.277158986), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(235571.681428719, 
478017.970164343), class = c("XY", "POINT", "sfg")), structure(c(192149.928785493, 
506369.417796213), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(210404.79640659, 
498004.965474369), class = c("XY", "POINT", "sfg")), structure(c(183727.693076105, 
517685.062347666), class = c("XY", "POINT", "sfg")), structure(c(193496.083251507, 
455782.923988072), class = c("XY", "POINT", "sfg")), structure(c(140044.757260064, 
483523.125905734), class = c("XY", "POINT", "sfg")), structure(c(199967.588515055, 
356009.308139852), class = c("XY", "POINT", "sfg")), structure(c(222485.006729955, 
473571.313492213), class = c("XY", "POINT", "sfg")), structure(c(165839.282804009, 
464124.343920573), class = c("XY", "POINT", "sfg")), structure(c(166812.992883748, 
464335.45064471), class = c("XY", "POINT", "sfg")), structure(c(237018.41561946, 
485097.103221668), class = c("XY", "POINT", "sfg")), structure(c(199466.406157495, 
563905.746014533), class = c("XY", "POINT", "sfg")), structure(c(256480.508585915, 
534249.482976414), class = c("XY", "POINT", "sfg")), structure(c(198922.772092611, 
467172.748254914), class = c("XY", "POINT", "sfg")), structure(c(173074.384226229, 
483631.987260294), class = c("XY", "POINT", "sfg")), structure(c(95016.1162346207, 
440264.170547843), class = c("XY", "POINT", "sfg")), structure(c(211910.054307578, 
496012.156182436), class = c("XY", "POINT", "sfg")), structure(c(265256.356051607, 
489160.405460297), class = c("XY", "POINT", "sfg")), structure(c(190442.246101107, 
505304.849915737), class = c("XY", "POINT", "sfg")), structure(c(193284.19436536, 
454277.400216125), class = c("XY", "POINT", "sfg")), structure(c(252690.300401593, 
469967.195900872), class = c("XY", "POINT", "sfg")), structure(c(253228.052156322, 
469826.504845435), class = c("XY", "POINT", "sfg")), structure(c(205407.412059394, 
504684.790921142), class = c("XY", "POINT", "sfg")), structure(c(249837.320636796, 
478715.179829884), class = c("XY", "POINT", "sfg")), structure(c(191772.773604753, 
446356.82020425), class = c("XY", "POINT", "sfg")), structure(c(227458.390871487, 
536934.585975391), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(231850.888023411, 
486590.553000102), class = c("XY", "POINT", "sfg")), structure(c(241334.808547039, 
515244.98178537), class = c("XY", "POINT", "sfg")), structure(c(208262.430112398, 
471784.972605986), class = c("XY", "POINT", "sfg")), structure(c(258362.018234174, 
480547.625190494), class = c("XY", "POINT", "sfg")), structure(c(236887.729223572, 
501158.015540084), class = c("XY", "POINT", "sfg")), structure(c(196644.189482866, 
461845.339144104), class = c("XY", "POINT", "sfg")), structure(c(192252.023873924, 
447554.093504844), class = c("XY", "POINT", "sfg")), structure(c(184581.174923046, 
566010.603419702), class = c("XY", "POINT", "sfg")), structure(c(197956.928562968, 
463222.802052016), class = c("XY", "POINT", "sfg")), structure(c(197238.114999044, 
476620.02411661), class = c("XY", "POINT", "sfg")), structure(c(227423.977169756, 
487105.436932122), class = c("XY", "POINT", "sfg")), structure(c(232701.941893923, 
554350.372276065), class = c("XY", "POINT", "sfg")), structure(c(222556.324002739, 
487429.931323886), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(218923.985734003, 
473180.54695925), class = c("XY", "POINT", "sfg")), structure(c(201076.105694111, 
502243.554508853), class = c("XY", "POINT", "sfg")), structure(c(217556.471923465, 
511992.935022148), class = c("XY", "POINT", "sfg")), structure(c(210095.527617845, 
518111.564291064), class = c("XY", "POINT", "sfg")), structure(c(213322.273202879, 
495255.875124674), class = c("XY", "POINT", "sfg")), structure(c(233535.73408031, 
560299.981130843), class = c("XY", "POINT", "sfg")), structure(c(217552.353473934, 
487593.067938544), class = c("XY", "POINT", "sfg")), structure(c(250157.704939741, 
477393.536805194), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(230590.874297821, 
477204.653285422), class = c("XY", "POINT", "sfg")), structure(c(232372.515967686, 
550789.029559601), class = c("XY", "POINT", "sfg")), structure(c(237507.690945977, 
484298.934093617), class = c("XY", "POINT", "sfg")), structure(c(154767.979258706, 
491873.161339562), class = c("XY", "POINT", "sfg")), structure(c(185682.629213229, 
524602.585198475), class = c("XY", "POINT", "sfg")), structure(c(218421.065157578, 
505115.125345622), class = c("XY", "POINT", "sfg")), structure(c(245303.010428707, 
480449.842788151), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(188182.347377913, 
507343.117573296), class = c("XY", "POINT", "sfg")), structure(c(NA_real_, 
NA_real_), class = c("XY", "POINT", "sfg")), structure(c(262087.515594154, 
484372.539052627), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT", 
"sfc"), precision = 0, bbox = structure(c(xmin = 95016.1162346207, 
ymin = 356009.308139852, xmax = 265256.356051607, ymax = 566010.603419702
), class = "bbox"), crs = structure(list(input = "EPSG:28992", 
    wkt = "PROJCRS[\"Amersfoort / RD New\",\n    BASEGEOGCRS[\"Amersfoort\",\n        DATUM[\"Amersfoort\",\n            ELLIPSOID[\"Bessel 1841\",6377397.155,299.1528128,\n                LENGTHUNIT[\"metre\",1]]],\n        PRIMEM[\"Greenwich\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        ID[\"EPSG\",4289]],\n    CONVERSION[\"RD New\",\n        METHOD[\"Oblique Stereographic\",\n            ID[\"EPSG\",9809]],\n        PARAMETER[\"Latitude of natural origin\",52.1561605555556,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8801]],\n        PARAMETER[\"Longitude of natural origin\",5.38763888888889,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8802]],\n        PARAMETER[\"Scale factor at natural origin\",0.9999079,\n            SCALEUNIT[\"unity\",1],\n            ID[\"EPSG\",8805]],\n        PARAMETER[\"False easting\",155000,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8806]],\n        PARAMETER[\"False northing\",463000,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8807]]],\n    CS[Cartesian,2],\n        AXIS[\"easting (X)\",east,\n            ORDER[1],\n            LENGTHUNIT[\"metre\",1]],\n        AXIS[\"northing (Y)\",north,\n            ORDER[2],\n            LENGTHUNIT[\"metre\",1]],\n    USAGE[\n        SCOPE[\"Engineering survey, topographic mapping.\"],\n        AREA[\"Netherlands - onshore, including Waddenzee, Dutch Wadden Islands and 12-mile offshore coastal zone.\"],\n        BBOX[50.75,3.2,53.7,7.22]],\n    ID[\"EPSG\",28992]]"), class = "crs"), n_empty = 12L), 
    id = 1:100), row.names = c(NA, 100L), sf_column = "geometry", agr = structure(c(id = NA_integer_), class = "factor", levels = c("constant", 
"aggregate", "identity")), class = c("sf", "data.frame"))
tmap_mode("view")
tm_shape(x) + tm_dots() + tm_options(use.WebGL= FALSE)

Slow because makeSymbols2 makes a symbol for each row, rather than each unique row.

tmap_mode("view")
tm_shape(x) + tm_dots() + tm_options(use.WebGL= TRUE)

Not working. Only tested in autoCRS branch.

mtennekes commented 1 month ago

use.WebGL mode working with dev-version of leafgl https://github.com/r-spatial/leafgl/issues/98

mtennekes commented 4 weeks ago

Also tmapGridSymbols needs improvement. Especially combining shape numbers and grobs/icons Work-in-progress.

Toy example that already works:


library(grid)
custom_symbol = grobTree(circleGrob(r = unit(.5, "lines"), gp = gpar(fill = "brown")),
                      rectGrob(width = unit(.5, "lines"), height = unit(.5, "lines"), gp = gpar(fill = "red")))

tm_shape(World) + 
    tm_polygons(fill = "grey98") +
    tm_symbols(shape = "income_grp",
               fill = "income_grp",
               fill.scale = tm_scale_categorical(values = c("purple", "steelblue", "forestgreen", "gold", "brown")),
               fill.legend = tm_legend_combine("shape"),
               shape.scale = tm_scale_categorical(values = list(22,21,23,24, custom_symbol)))

image

(in autoCRS branch, need to merge with main)

mtennekes commented 4 weeks ago

webGL improved, by default enabled (if no visual variables are specified that are unsupported for WebGL, e.g. line type).

Only problem is that lines are not sharp when webGL enabled