0

I generated a GeoTiff using the QGIS HeatMap plugin and want to render it on top of some OSM data. The problem is that the raster gets rendered upside-down in the output. Can someone point me in the right direction?

mapnik xml:

<?xml version="1.0" encoding="utf-8"?>
<Map background-color="#f2efe9" srs="+proj=latlong +datum=WGS84">
  <! ... Styles ... -->
  <Layer name="highways" status="on" srs="+proj=latlong +datum=WGS84">
    <StyleName>highways</StyleName>
    <Datasource>
      <Parameter name="type">osm</Parameter>
      <Parameter name="file">data.osm</Parameter>
    </Datasource>
  </Layer>
  <Layer name="heatmap" status="on" srs="+proj=longlat +datum=WGS84 +no_defs">
    <StyleName>heatmap</StyleName>
    <Datasource>
      <Parameter name="type">gdal</Parameter>
      <Parameter name="file">test.tif</Parameter>
      <Parameter name="format">tiff</Parameter>
    </Datasource>
  </Layer>
</Map>

$ gdalinfo test.tif

Driver: GTiff/GeoTIFF
Files: test.tif
Size is 709, 500
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (...)
Pixel Size = (0.000849347874585,0.000849347874585)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
...
Band 1 Block=709x2 Type=Float32, ColorInterp=Gray
  NoData Value=-9999

$ gdalsrsinfo test.tif

PROJ.4 : '+proj=longlat +datum=WGS84 +no_defs '

...

render.py

import mapnik
m = mapnik.Map(1024, 1024)
mapnik.load_map(m, "mapnik_style.xml")
bbox = m.layers[1].envelope()
m.zoom_to_box(bbox)
mapnik.render_to_file(m, "map.png", "png")

edit: I used gdal & numpy to reverse the pixels and it rendered correctly. But then that raster displays upside-down in qgis.

  • 1
    Y pixel size would usually be negative in test.tif, not all tools will apply the transform correctly without that. – mdsumner Apr 11 '14 at 21:47
  • @mdsumner I used gdal to change the y pixel size (in the geotransform) to be negative. This didn't work though. What else would I need to do? – ilia choly Apr 14 '14 at 15:54
  • 1
    I would figure out why it's coming out positive from QGIS, it can be tricky to track down where the interpretations are applied in a workflow like this, we need a reproducible example – mdsumner Apr 14 '14 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.