Skip to content

grdimage -A -R crops but does not extend image #3106

Closed

Description

@PaulWessel

If -R is used with -A and it crops the image, we get the cropped area back. However, if we use a -R setting that goes beyond the grid, we do not get extra NaN space back, just the same image. It seems to me that if we run

gmt grdmath -R0/20/0/20 -I0.1 X Y MUL = t.nc
gmt grdimage t.nc -JX5i -A1.png
gmt grdimage t.nc -JX5i -A2.png -R0/20/0/30

then image 1.png should be 201x201 while 2.png should be 301x201, but it is still 201x201.

Activity

  1. added
    bug
    on Apr 17, 2020
  2. PaulWessel commented on May 3, 2020

    @PaulWessel
    ContributorAuthor

    Right now, grdimage -A assumes we want the grid (or a subset) to fit exactly in the image. The whole machinery of addressing the pixels assume the first plotted pixel is row = col = 0. However, this is a bad assumption. See the illustration below:

    A

    Here my fake grid is assumed to be geographic with bounds -20/20/10/20, but I am plotting it with -R-25/5/14.2573318521/23.9576963964+r -JL0/15/10/20/15c. This is the full area above in which my grid (gray) is partly clipped on the right side and there is extra space around elsewhere. The pixels are such that I want to fill in the squares. The white squares are outside the grid and should be NaN and hence black or transparent, while the black pixels should be set to color given by the projected grid at those points and the CPT table. The red box is the rectangular outline of the projected lon/lat grid to map units; it has several pixels that are NaN as well (white). The job is to loop over the grid nodes (pixels) inside the red box and assign color, leaving the white pixels outside the red box alone. This means the following changes:

    1. The image that is allocated must match the dimensions of the entire plot (here the fat outline and all the pixels inside it)
    2. The calculation of the image pixel needs to take into account a fixed offset due to the rows above the red box and a a per-row fixed offset due to the pixels to the left of the red box.
    3. These offsets only apply when -A is used, not when PostScript is plotted.

    I think with these changes we can return the correct image above.

  3. PaulWessel commented on May 23, 2020

    @PaulWessel
    ContributorAuthor

    The logic in the loop over the pixels in grdimage.c assumes we are only dealing with the red rectangle, so there is no offsets corresponding to the white areas.

  4. added a commit that references this issue on May 26, 2026
    43b624a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions