problems with psconvert

Added by Jose 7 months ago

Hey There,

I am having a problem with psconvert... am on GMT 5.2.1 install on Windows working through cygwin

Here are the commands I am using:

grdimage  flowdepth3.grd    $region -J$project -Cfd.cpt  -K -P -Q  >
psscale  -D$scale_loc_h -Cfd.cpt -Al -B$sc_int_H            -P -O >>
psconvert -A -Tg -W+k -P

Firstly, the resulting png image is not transparent, despite having used the -Q flag in gridimage. the .ps seems to be transparent (also i use grdimage with this file in other places and it plots up on top of other stuff transparently).

Secondly, the resulting .kml does not display the image in Google Earth.

In terms of de-bugging, i have checked with grdinfo and indeed, there are real NaN's in the file:

$ grdinfo -M flowdepth3.grd
flowdepth3.grd: Title: Produced by grdmath
flowdepth3.grd: z_min: 0.10000 at x = 176.50073 y = -37.77288 z_max: 10.62542 at x = 176.47600 y = -37.75306
flowdepth3.grd: 648790 nodes (88.2%) set to NaN

So I really can't figure out what is up with the transparency issue.

With regards to the .kml, i looked in to the .kml file itself and noticed this:


note the second set of numbers in the <LatLonAtltBox> section... in other .kmls produced from the old ps2raster, those were duplicates of the lat/long coordinates seen above. When I manually edit the kml and replace the strange numbers with the lat/longs, then re-open the kml, it shows up as expected in google earth (just not transparent).

Anyway, any help or insights appreciated.


fd.kml (645 Bytes) (177 KB)

fd.png (160 KB)

Replies (6)

RE: problems with psconvert - Added by Joaquim 7 months ago

From the manual

... g means PNG, G means transparent PNG

and than psconvert warns that

psconvert -A -TG -W+k -P
psconvert: Error: To GE images must be in geographical coordinates. Very likely this won't work as you wish inside GE.

RE: problems with psconvert - Added by Jose 7 months ago

Hi Joaquim,

Point taken on the transparency issue. I haven't used this script in a while and was re-using some old code, and the -TG used to work for transparency in ps2raster.

I had looked at the man page but didn't notice the g option. Anyhoo, that is now fixed. Thanks.

now for the kml issue, as far as I can tell, my grid is in geographical coordinates.

line 4 of the grindinfo output (shown below) says 'Geographic Grid', The x and y scaling are in lat/long. Do i need to do something to tell GMT to treat this as a geographic grid?

Note that when I used this code before, i would get the warning about 'Geographic coordinates, but the file still opened as expected in G.E.

In this case, I no longer get the warning, but the image does not show up in google earth unless i hand edit the kml and copy the lat/long values to that lower chunk.

Insight appreciated, thanks!


$ grdinfo -M flowdepth3.grd
flowdepth3.grd: Title: Produced by grdmath
flowdepth3.grd: Command: grdmath -N flowdepth2.grd never_wet.grd MUL = flowdepth3.grd
flowdepth3.grd: Remark:
flowdepth3.grd: Gridline node registration used [Geographic grid]
flowdepth3.grd: Grid file format: nf = GMT netCDF format (32-bit float), COARDS, CF-1.5
flowdepth3.grd: x_min: 176.46000 x_max: 176.53500 x_inc: 0.00011 name: longitude [degrees_east] nx: 662
flowdepth3.grd: y_min: -37.81000 y_max: -37.71000 y_inc: 0.00009 name: latitude [degrees_north] ny: 1111
flowdepth3.grd: z_min: 0.10000 at x = 176.50073 y = -37.77288 z_max: 10.62542 at x = 176.47600 y = -37.75306
flowdepth3.grd: scale_factor: 1.00000 add_offset: 0.00000
flowdepth3.grd: 648790 nodes (88.2%) set to NaN
flowdepth3.grd: format: netCDF-4 chunk_size: 133,139 shuffle: on deflation_level: 3

RE: problems with psconvert - Added by Joaquim 7 months ago

José, nothing has changed regarding the -T option. -TG is needed for transparency but you were using -Tg.

Concerning the kml issue, your grid is geographical but the image is not. It is in Mercator. You have to use -JX in grdimage to create a non projected image.

Finally, adding a psscale really screws it all. You don't want to do that. Please refer to the -B documentation in psconvert to see why.

RE: problems with psconvert - Added by Jose 7 months ago


Thanks for the reply. But my experience does not agree with what you are saying.

In my old script, which i ran under GMT 4.x I produced a .kml that opened perfectly and was transparent using the following commands:

grdimage flowdepth2.grd $region -J$project -Cflow_depth.cpt -K -P -Q > $max_dir/
pstext FD_head2.txt $region -J$project --FONT_ANNOT_PRIMARY=12p,white -O -K -P >> $max_dir/
psscale -D$scale_loc -Cflow_depth.cpt -Al -B$sc_int_H --FONT_LABEL=8p,white --MAP_LABEL_OFFSET=0.1c --FORMAT_FLOAT_OUT=%.f --MAP_FRAME_PEN=0.5p,white --MAP_DEFAULT_PEN=+white --FONT_ANNOT_PRIMARY=8p,white -O >>  $max_dir/
ps2raster -A -TG -P -E300 -W+k $max_dir/

i.e. -TG was capitalized, psscale was in there, as well as a pstext, I used -JM180/0/4i, it complained about being 'non-geographic' but still made a .kml that when double clicked opened up and showed the image in the right place. The inside of the .kml looked like what I have pasted below with the 2nd group of coordinates matching the first. A screen shot of the resulting data plotted and opened in Google Earth is attached.


OK, so fine, I accept that I have made an error with -TG/g Just saying it had worked before and I did not notice there was another option. I will not make that mistake again.

Now, please explain to me why a Mercator image is 'non-geographic' while making a 'non-projected' image using -JX (which is listed in the manual under the section heading 'NON-GEOGRAPHICAL PROJECTIONS') is considered 'geographical'. This seems backwards to me.

I don't think the psscale option 'screws it all' if you keep the scale inside the limits of the image, no? I read the bit in the -B options about making the ticks and labels inside the image to not mess up the extents of the image so it plots properly in google earth.

So yeah, just saying, it worked differently before and I am trying to figure out what I need to do to make it work again.

I will try the -JX for the grdimage and see what happens, but it is not clear to me why a 'NON-GEOGRAPHIC' projection is considered 'GEOGRAPHIC' for the purposes of making a .kml.

Please enlighten me.


RE: problems with psconvert - Added by Jose 7 months ago

An update...

The following commands produce the attached image (noframe.jpg)

grdimage  flowdepth3.grd    $region  -JX3i -Cfd.cpt    --MAP_FRAME_TYPE=inside -K -P -Q > $plot_dir/$plot2 
psscale  -D$scale_loc_h_2 -Cfd.cpt -Al -B$sc_int_H_2   -K -P -O --FONT_LABEL=8p,white --MAP_FRAME_PEN=0.5p,white --FONT_ANNOT_PRIMARY=6p,white --MAP_LABEL_OFFSET=3p --MAP_DEFAULT_PEN=+white --MAP_ANNOT_OFFSET_PRIMARY=2p >>  $plot_dir/$plot2
pstext fd_head_C_h.txt $region    -JX3i     --FONT_ANNOT_PRIMARY=6p,white                   -P -O >> $plot_dir/$plot2
ps2raster -A -TG -W+k -E600 -P  $plot_dir/$plot2

which is pretty much what i am after.

if i want to add a frame around the area i modify grdimage to:

grdimage  flowdepth3.grd   -B $region  -JX3i -Cfd.cpt    --MAP_FRAME_PEN=0.5p,white --MAP_FRAME_TYPE=inside -K -P -Q > $plot_dir/$plot2

which produces the image frame.jpg (attached)

I am still perplexed by what is meant by a geographic vs a non-geographic image. It seems to me that something plotted with a -J flag such as 'M' would be considered 'geographic' where as the -JX option would be 'non-geographic'. Indeed, -JX is listed under 'non-geographical projections' in the manual (page 38), which is somewhat confusing.

But whatever, it seems to have worked.


no_frame.jpg (357 KB)

frame.jpg (329 KB)

RE: problems with psconvert - Added by Joaquim 7 months ago

Take this example

echo 4 52 | mapproject -Jm0/0/1:1 -C -F -R4/5/0/55
445277.963173 6766432.49065

see, we started with a geographical coordinate, converted to Mercator and got something we can call Mercator meters. To make an image we do basically the same thing but to let it fit into a reasonable human sized media we need to apply a scale factor.
So, when we create a projected image it no longer is an image in geographical coordinates. No matter what we may see in the frame annotations.
On the other hand, if we start with a grid in geogs an apply a -JX we are only doing a linear scaling and we can say the image is still in geographical coordinates. Google Earth that uses the <LatLonBox> info in the kml file to do the reverse mapping from pixels to geogs and next project it in the pseudo-mercator projection that it uses.
If the image is not in geogs, as GE expects, it will still do the above operation but the result will be wrong. But for small areas and images in Mercator one might not be able easily to see the difference.

Regarding the psscale, if it is plotted inside the image's region and it doesn't fool the algorithm like it is described for the option -B, than yes, one can use it. But it's risky.

Hope this helps de-perplexing you.