Skip to content

Let @J in GMT/OGR files set -fg if implying degree coordinates#6057

Merged
PaulWessel merged 6 commits intomasterfrom
ogr-degree-selection
Nov 25, 2021
Merged

Let @J in GMT/OGR files set -fg if implying degree coordinates#6057
PaulWessel merged 6 commits intomasterfrom
ogr-degree-selection

Conversation

@PaulWessel
Copy link
Member

Basically, if a GMT/OGR file (or a shapefile converted to one under the hood) has projection information that says it is a lon,lat file then we can set -fg internally since we know it is in degrees.

Basically, if a shapefile or GMT/OGR file has projection information that says it is a long,lat file then we should set -fg internally since we know it is in degrees.
@PaulWessel PaulWessel added the enhancement Improving an existing feature label Nov 25, 2021
@PaulWessel PaulWessel added this to the Future release milestone Nov 25, 2021
@PaulWessel PaulWessel requested a review from joa-quim November 25, 2021 02:53
@PaulWessel PaulWessel self-assigned this Nov 25, 2021
src/gmt_io.c Outdated
GMT->current.io.ogr = GMT_OGR_FALSE;
return (false);
case 'e': k = 0; /* EPSG code */
if (strstr (Jstring, "4326")) /* 4326 means we have lon/lat degree coordinates and thus should set -fig */
Copy link
Member

Choose a reason for hiding this comment

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

Several other EPSGs are also lat/long

src/gmt_io.c Outdated
break;
case 'g': k = 1; break; /* GMT proj code. If given then data are projected */
case 'p': k = 2; /* Proj.4 code */
if (strstr (Jstring, "+proj=longlat")) /* +proj=longlat means we have lon/lat degree coordinates and thus should set -fig */
Copy link
Member

Choose a reason for hiding this comment

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

"+pronj=latlong" is also valid

src/gmt_io.c Outdated
gmt_set_geographic (GMT, GMT_IN);
break;
case 'w': k = 3; /* OGR WKT representation */
if (strstr (Jstring, "Degree")) /* UNIT as Degree means we have lon/lat degree coordinates and thus should set -fig */
Copy link
Member

Choose a reason for hiding this comment

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

Nope. It would be degree but I think many many WKTs have UNIT["degree",0.0174532925199433.
AS I said, the only way I know out of this is to convert the WKT to PROJ4 and parse that.

@PaulWessel
Copy link
Member Author

Thanks, I will redo this a bit introducing some enums for the 4 cases and a separate function to make this decision. While at it, I see we initialize 3 of the 4 proj strings to degrees basically, but leave out the EPSG:

	TH->ogr->proj[GMTIO_GMTJ] = strdup ("\"-Jx1d --PROJ_ELLIPSOID=WGS84\"");
	TH->ogr->proj[GMTIO_PROJ4] = strdup ("\"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs\"");
	TH->ogr->proj[GMTIO_GCS] = strdup ("\"GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]\"");

Would it be OK to add (for @Je)

TH->ogr->proj[GMTIO_EPSG] = strdup ("\"4326"");

in that context?

@joa-quim
Copy link
Member

Dies this answer the question?

julia> epsg2proj(4326)
"+proj=longlat +datum=WGS84 +no_defs"

@PaulWessel
Copy link
Member Author

The update places the decision after we have read all the 0-4 @J statements and then checks them in the order proj4, GMT, EPGS and WKT. If you think there should be changes here please make them. I could not find EPGS other than 4326 but I suppose there may be one for other ellipsoids. We can add more as they are detected.

src/gmt_io.c Outdated
if (S->proj[GMTIO_GCS]) { /* See if we have degree units */
if (strstr (S->proj[GMTIO_GCS], "UNIT[\"Degree\",0.0174532925199433]")) {
if (S->proj[GMTIO_WKT]) { /* See if we have degree units */
if (strstr (S->proj[GMTIO_WKT], "UNIT[\"Degree\",0.0174532925199433]")) {
Copy link
Member

Choose a reason for hiding this comment

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

No. This is wrong. Se for example

julia> epsg2proj(2000)
"+proj=tmerc +lat_0=0 +lon_0=-62 +k=0.9995 +x_0=400000 +y_0=0 +a=6378249.145 +rf=293.465 +units=m +no_defs"


julia> println(epsg2wkt(2000))
PROJCS["Anguilla 1957 / British West Indies Grid",
    GEOGCS["Anguilla 1957",
        DATUM["Anguilla_1957",
            SPHEROID["Clarke 1880 (RGS)",6378249.145,293.465,
                AUTHORITY["EPSG","7012"]],
            AUTHORITY["EPSG","6600"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I have removed that check. So currently no check on WKT but presumably any of the other 2-3 will be more helpful.

@PaulWessel PaulWessel merged commit 5ee0449 into master Nov 25, 2021
@PaulWessel PaulWessel deleted the ogr-degree-selection branch November 25, 2021 21:30
@seisman seisman removed this from the Future release milestone Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants