Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raster export with non-usual RGB values #168

Open
riccardoklinger opened this issue Dec 9, 2014 · 7 comments
Open

raster export with non-usual RGB values #168

riccardoklinger opened this issue Dec 9, 2014 · 7 comments

Comments

@riccardoklinger
Copy link
Contributor

I have received a tiff file with DEM-values (file: https://www.dropbox.com/s/adfa62i6rcbhd9w/mdt_clipped.tif?dl=0) which are more or less higher than 255... when it exports it treats each value as RGB-values which results in this:
original_values
when saved as a new file with check "save as shown" and exported using the plugin it shows well on the screen:
with_representatioon

this alsco counts for values below 1 in the raster image and non-integer values.
the line that does the storage is:
if str(i.dataProvider().metadata()[0:4]) == 'JPEG' and str(i.crs().authid()) == 'EPSG:4326':
shutil.copyfile(in_raster+".aux.xml", out_raster + ".aux.xml")
shutil.copyfile(in_raster, out_raster)
else:
processing.runalg("gdalogr:warpreproject",str(in_raster),str(i.crs().authid()),"EPSG:4326",0,1,"",prov_raster)
format = "jpeg"
driver = gdal.GetDriverByName( format )
src_ds = gdal.Open(prov_raster)
dst_ds = driver.CreateCopy( out_raster, src_ds, 0 )
dst_ds = None #free the dataset
src_ds = None #free the dataset

@tomchadwin
Copy link
Contributor

So to handle this, we need to do two things:

  1. Detect when rasters are not plain RGBs - presumably by looking at the band render type, and I'm not sure how to get to that in the API
  2. Find out how to "Save raster layer as rendered image" via the API, which I also don't know how to do

@tomchadwin
Copy link
Contributor

1 is rasterlayer.rasterType(), which returns:

GrayOrUndefined
Palette
Multiband
ColorLayer

@riccardoklinger
Copy link
Contributor Author

I'll close #133 and paste the last comment here as this one is vital:

Use gdalwarp to transform the original coordinates to EPSG:4326 the standard for leaflet in a temporary file, for example:
gdalwarp -s_srs EPSG:2100 -t_srs EPSG:4326 -r bilinear " + filename +".tif " + filename + ".tiff"

Use gdal_translate to convert the temporary file to PNG:
gdal_translate -of PNG -scale " + filename + ".tiff " + filename + ".png"
A nice touch would be an option to automatically convert black or white to transparent for scanned images that have no alpha channel.

Get the coordinates from the PNG file:
ds = gdal.Open(filename+".png")
width = ds.RasterXSize
height = ds.RasterYSize
gt = ds.GetGeoTransform()
minx = gt[0]
miny = gt[3] + widthgt[4] + heightgt[5]
maxx = gt[0] + widthgt[1] + heightgt[2]
maxy = gt[3]
tmp = "["+str(miny)+","+str(minx)+"],["+str(maxy)+","+str(maxx)+"]"
ds = None

Delete the temporary TIFF file.

Repeat for next graphic.

@riccardoklinger
Copy link
Contributor Author

there seems no easy way to save a raster as rendered via the API ATM. I added a hint in the instruction to do this by hand.

@tomchadwin
Copy link
Contributor

I wonder if Nathan's qgis2img achieves this: https://github.com/DMS-Aus/qgis2img

@tomchadwin
Copy link
Contributor

I also got an answer on StackExchange:

http://gis.stackexchange.com/questions/68803/qgis-save-raster-as-rendered-image?noredirect=1#comment207705_68803

Is this compatible with the new raster code?

@riccardoklinger
Copy link
Contributor Author

The proposed solution will work.
we do have the problem of translating this into .jpg . Therefore I will
used the solution form gis.stackexcchange and store a temp tif and
translate it to .jpg via
processing.runalg("gdalogr:translate",...)

will do this this week!


Geolicious GbR
Agentur für Geo-Kommunikation

Riccardo Klinger
Geschäftsführer

mobil: 0176 63437298
e-mail: riccardo.klinger@geolicious.de
web: www.geolicious.de

Geolicious GbR
c/o Daniel Kerkow
Binzstraße 48
13189 Berlin

Gesellschafter:
Riccardo Klinger
Daniel Kerkow
Jakob Hafner

Sitz der Gesellschaft: Berlin
Ust-ID: DE289107523

On Mon, Apr 20, 2015 at 10:56 AM, Tom Chadwin notifications@github.com
wrote:

I also got an answer on StackExchange:

http://gis.stackexchange.com/questions/68803/qgis-save-raster-as-rendered-image?noredirect=1#comment207705_68803

Is this compatible with the new raster code?


Reply to this email directly or view it on GitHub
#168 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants