Skip to content

FIX: project -G use angular unit #8727

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

Merged
merged 1 commit into from
May 14, 2025

Conversation

Dengda98
Copy link
Contributor

Hi, GMT!

I found that gmt project -G<dist> uses wrong interval when <dist> appending angular unit d|m|e. For example,

$ gmt project -C125/33 -E146/46 -G1d -Q | head -n3
125     33      0
125.000007565   33.0000063736   0.001
125.00001513    33.0000127473   0.002

looks like there's a strange 1e-3 scale. I checked project.c, and I guess maybe we need to add an if statement here, to check whether -G use angular unit.

gmt/src/project.c

Lines 847 to 848 in 640f1e6

if (Ctrl->Q.active && Ctrl->G.unit != 'k' && !Ctrl->G.number)
Ctrl->G.inc *= 0.001 / GMT->current.map.dist[GMT_MAP_DIST].scale; /* Now in km */

So I imitate some lines for -Z,

gmt/src/project.c

Lines 783 to 793 in 640f1e6

if (Ctrl->Z.mode && Ctrl->Z.unit != 'k') { /* Degenerate ellipse with diameter given in units */
if (gmt_init_distaz (GMT, Ctrl->Z.unit, Ctrl->Z.mode, GMT_MAP_DIST) == GMT_NOT_A_VALID_TYPE)
Return (GMT_NOT_A_VALID_TYPE);
if (GMT->current.map.dist[GMT_MAP_DIST].arc) { /* Got angular measures, convert to km */
Ctrl->Z.minor *= (GMT->current.proj.KM_PR_DEG / GMT->current.map.dist[GMT_MAP_DIST].scale); /* Now in km */
Ctrl->Z.major *= (GMT->current.proj.KM_PR_DEG / GMT->current.map.dist[GMT_MAP_DIST].scale); /* Now in km */
}
else {
Ctrl->Z.minor /= (GMT->current.map.dist[GMT_MAP_DIST].scale * METERS_IN_A_KM); /* Now in km */
Ctrl->Z.major /= (GMT->current.map.dist[GMT_MAP_DIST].scale * METERS_IN_A_KM); /* Now in km */
}

I add an if statement for -G,

if (Ctrl->Q.active && Ctrl->G.unit != 'k' && !Ctrl->G.number){
	if (GMT->current.map.dist[GMT_MAP_DIST].arc) {
		Ctrl->G.inc *= (GMT->current.proj.KM_PR_DEG / GMT->current.map.dist[GMT_MAP_DIST].scale); /* Now in km */
	}
	else {
		Ctrl->G.inc /= METERS_IN_A_KM * GMT->current.map.dist[GMT_MAP_DIST].scale;	/* Now in km */
	}
}

After recompiling, I test it with same command, the result seems fine.

$ gmt project -C125/33 -E146/46 -G1d -Q | head -n3
125     33      0
125.848042113   33.705854159    111.195051975
126.710079013   34.4058180505   222.39010395

Copy link

welcome bot commented May 14, 2025

💖 Thanks for opening this pull request! 💖

Please make sure you read our Contributing Guide and abide by our Code of Conduct.

A few things to keep in mind:

  • If you need help writing tests, take a look at the existing ones for inspiration. If you don't know where to start, let us know and we'll walk you through it.
  • All new features should be documented. It helps to write the comments below for your functions describing the it, all arguments, and return types before writing the code. This will help you think about your code design and results in better code.
  • We are grateful that you put in the effort to do this! 🎉

Copy link
Member

@joa-quim joa-quim left a comment

Choose a reason for hiding this comment

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

Thanks for finding this and even more for providing a fix.

@joa-quim joa-quim merged commit cd47fef into GenericMappingTools:master May 14, 2025
12 of 13 checks passed
Copy link

welcome bot commented May 14, 2025

🎉🎉🎉 Congrats on merging your first pull request and welcome to the team! 🎉🎉🎉

We hope that this was a good experience for you. Let us know if there is any way that the contributing process could be improved.

@Dengda98 Dengda98 deleted the fix_project_-G branch May 14, 2025 17:05
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