Skip to content

Ensure geographic datasets passed by memory files are seen as geographic - #5092

Merged
PaulWessel merged 5 commits into
masterfrom
fix-matrix-geo
Apr 5, 2021
Merged

PaulWessel merged 5 commits into
masterfrom
fix-matrix-geo

Conversation

@PaulWessel

Copy link
Copy Markdown
Contributor

Externals (in this case PyGMT) may pass data into GMT modules. These may be created and data added, and the creator may know the data are geographic and may flag that via the bit-flag GMT_GRID_IS_GEO in GMT_Create_Data. Unfortunately, this was not honored. Furthermore, this concept should not be restricted to grids: The user may know that the created dataset, grid, image, matrix, or vector is geographic and would like to pass that information into the data structure. This PR allows for that while fixing the grid-specific bug. Now,

  1. GMT_GRID_IS_GEO is deprecated and we use GMT_DATA_IS_GEO instead for all the above data types (the old enum is kept for backwards compatibility)
  2. The bit-flag, if set, calls gmt_set_geographic for the chosen direction (input or output source)
  3. When GMT_Create_Data builds the various structures we check on that and add a grdtype flag for grids, images, matrices (same value and meaning as in hidden grid header) and a geographic = 0|1 flag for datasets and vectors
  4. When gmt_init_module checks if an input file (if found) is a remote data set (and hence sets geographic) we also check if given a memory file to see if it is known to be geographic.
  5. When we call GMT_Read_Data and the sources is a memory file we are now able to process the hidden geographic information.

With these changes, a memory file passed that is known to be geographic will trigger an automatic geographic projection if none had been selected explicitly with -J.

Note: Tested with the original PyGMT problem. I assume it will work similarly for images and grids, as well as data sets and vectors, but there are no such external tests (yet). I also updated the API doc to mention the purpose of the GMT_DATA_IS_DATA flag under GMT_Create_Data.

And furthermore that we recognize this so that default projection is selected to be geographic.
Since the concept applies to all dataset it should be DATA, not GRID, but we retain it for backwards compatibility.
@PaulWessel PaulWessel added this to the 6.2.0 milestone Apr 5, 2021
@PaulWessel
PaulWessel requested a review from seisman April 5, 2021 00:33
@PaulWessel PaulWessel self-assigned this Apr 5, 2021

@seisman seisman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that it solves the initial PyGMT problem.

GMT_GRID_IS_GEO is deprecated and we use GMT_DATA_IS_GEO instead for all the above data types (the old enum is kept for backwards compatibility)

Do you mean that PyGMT should pass GMT_GRID_IS_CARTESIAN for a Cartesian grid, and GMT_DATA_IS_GEO for a geographic grid?

@PaulWessel

Copy link
Copy Markdown
Contributor Author

No need to pass GMT_GRID_IS_CARTESIAN which is 0 so I dont think that would work - it is sort of the default. So either GMT_DATA_IS_GEO or nothing. It probably should not have been added to gmt_resources.h but...

This branch was previously deployed

1 inactive deployment
Preview — 4c47f4e8 Deployed Apr 5, 2021 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants