python 2.7 - Plotting points on Mapnik -


i followed tutorial in mapnik github wiki make world map: https://github.com/mapnik/mapnik/wiki/gettingstartedinpython

i modified example, , have embedded code pyside qt widget. question is, how 1 plot points on map using x , y coordinates, or latitude , longitude points?

here code i'm using generate map , embed in widget:

    import mapnik     m = mapnik.map(1200,600)     m.background = mapnik.color('steelblue')     s = mapnik.style()     r = mapnik.rule()     polygon_symbolizer = mapnik.polygonsymbolizer(mapnik.color('#f2eff9'))     r.symbols.append(polygon_symbolizer)     line_symbolizer = mapnik.linesymbolizer(mapnik.color('rgb(50%,50%,50%)'),0.1)     r.symbols.append(line_symbolizer)     s.rules.append(r)     m.append_style('my style',s)     ds = mapnik.shapefile(file='/home/lee/shapefiles/ne_110m_admin_0_countries.shp')     layer = mapnik.layer('world')     layer.datasource = ds     layer.styles.append('my style')     m.layers.append(layer)     m.zoom_all()       im = mapnik.image(1200,600)     mapnik.render(m, im)      qim = qimage()     qim.loadfromdata(qbytearray(im.tostring('png')))      label = qlabel(self)      label.setpixmap(qpixmap.fromimage(qim))      self.layout.addwidget(label) 

if need geographic coordinate(ie:lat/lon) pixel coordinate, need add converter functions.

the google maps js code follow perhaps : https://developers.google.com/maps/documentation/javascript/examples/map-coordinates

var tile_size = 256;  function bound(value, opt_min, opt_max) {   if (opt_min != null) value = math.max(value, opt_min);   if (opt_max != null) value = math.min(value, opt_max);   return value; }  function degreestoradians(deg) {   return deg * (math.pi / 180); }  function radianstodegrees(rad) {   return rad / (math.pi / 180); }  /** @constructor */ function mercatorprojection() {   this.pixelorigin_ = new google.maps.point(tile_size / 2,       tile_size / 2);   this.pixelsperlondegree_ = tile_size / 360;   this.pixelsperlonradian_ = tile_size / (2 * math.pi); }  mercatorprojection.prototype.fromlatlngtopoint = function(latlng,     opt_point) {   var me = this;   var point = opt_point || new google.maps.point(0, 0);   var origin = me.pixelorigin_;    point.x = origin.x + latlng.lng() * me.pixelsperlondegree_;    // truncating 0.9999 limits latitude 89.189.   // third of tile past edge of world tile.   var siny = bound(math.sin(degreestoradians(latlng.lat())), -0.9999,       0.9999);   point.y = origin.y + 0.5 * math.log((1 + siny) / (1 - siny)) *       -me.pixelsperlonradian_;   return point; };  mercatorprojection.prototype.frompointtolatlng = function(point) {   var me = this;   var origin = me.pixelorigin_;   var lng = (point.x - origin.x) / me.pixelsperlondegree_;   var latradians = (point.y - origin.y) / -me.pixelsperlonradian_;   var lat = radianstodegrees(2 * math.atan(math.exp(latradians)) -       math.pi / 2);   return new google.maps.latlng(lat, lng); }; 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -