Thinking of rendering based on vector file mapnik

As a GISer, he is now in the transportation industry (the combination of transportation industry and GIS is really an interesting thing). Recently, a vector file with large amount of data was loaded and rendered in the foreground and crashed directly. At this node, I made the following thinking:

  • Rearrange the scene logic to see if you can reduce the amount of data in the background now, and then render in the foreground. The overall idea is: in the background, according to the business logic and the vector merge function union of turf.js, the vector elements are finally formed according to the business indicators (the node information will be merged in the process of merging to reduce the file size). I think it's OK, but... It takes a long time to execute with node (at present, it has been executed for two hours without any result). You can only give up first
  • The above scheme is not feasible, suddenly think of background processing interpolation algorithm density map. For example, try mapnik to render grid directly in the background. The specific code is as follows
var mapnik = require("mapnik");
var fs = require("fs");

 var img = new mapnik.Image(2082,1617);
               data = data.toString().split("\r\n");
                  var tmp=v.split(","),color=[65,105,225,1];
                  if(tmp[1] == 0){
                  }else if( tmp[1] >0 && tmp[1]<=2.5 ){
                  }else if( tmp[1] >2.5 && tmp[1]<=5 ){
                  }else if( tmp[1] >5 && tmp[1]<=10 ){
                  }else if( tmp[1] >10 && tmp[1]<=15 ){
                  }else if( tmp[1] >15 && tmp[1]<=20 ){
                  }else if( tmp[1] >20 && tmp[1]<=25 ){
                  }else if( tmp[1] >25 && tmp[1]<=40 ){
                  }else if( tmp[1] >40){
                  var x=parseInt(tmp[0].substr(0,6))-115423,
                  img.setPixel(x==2082?2081:x,y==1617?1616:y,new mapnik.Color(color[0],color[1],color[2],color[3]));
               img.encode('png', function(err,buffer) {
                  if (err) throw err;
                  fs.writeFile('map.png',buffer, function(err) {
                      if (err) throw err;

ps: the key points are as follows

  • Grid length and width: take the extent range of geographic layer (minx,miny,maxx,maxy)
  • Starting point: the upper left corner of the grid starting point, and the smallest geographical point is the lower left corner

Posted on Sat, 08 Feb 2020 12:03:05 -0500 by drawmack