ENH: add guess_wkt_version to return the WKT version of a string#1606
Open
madhavcodez wants to merge 1 commit into
Open
ENH: add guess_wkt_version to return the WKT version of a string#1606madhavcodez wants to merge 1 commit into
madhavcodez wants to merge 1 commit into
Conversation
is_wkt only reports whether a string is WKT. guess_wkt_version wraps proj_context_guess_wkt_dialect and returns the matching pyproj.enums.WktVersion, or None when the string is not WKT. Closes pyproj4#1031
djhoese
reviewed
Jul 3, 2026
Comment on lines
+73
to
+81
| if dialect == PJ_GUESSED_WKT2_2019: | ||
| return WktVersion.WKT2_2019 | ||
| if dialect == PJ_GUESSED_WKT2_2015: | ||
| return WktVersion.WKT2_2015 | ||
| if dialect == PJ_GUESSED_WKT1_GDAL: | ||
| return WktVersion.WKT1_GDAL | ||
| if dialect == PJ_GUESSED_WKT1_ESRI: | ||
| return WktVersion.WKT1_ESRI | ||
| return None |
Contributor
There was a problem hiding this comment.
Maybe this is just the python programmer in me, but this feels like it would work better as a dictionary .get:
return WKT_DIALECTS.get(dialect)where the dictionary is a mapping of the dialect strings and the WktVersion value. I assume these constants being compared against are just strings or integers so the dictionary hashing isn't a problem. I don't feel that strongly about it, but I do think it may be cleaner and more flexible in the long run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ENH: add guess_wkt_version to return the WKT version of a string
What
Adds
pyproj.crs.guess_wkt_version(wkt), which returns thepyproj.enums.WktVersionof a Well-Known Text string, orNonewhen thestring is not WKT.
Why
is_wktonly answers whether a string is WKT (a bool). PROJ'sproj_context_guess_wkt_dialectalready reports the specific dialect, so thisexposes that information. This is the
guess_wkt_versionAPI proposed by themaintainer in #1031.
Dialect mapping:
PJ_GUESSED_WKT2_2019(and its legacy aliasPJ_GUESSED_WKT2_2018) ->WktVersion.WKT2_2019PJ_GUESSED_WKT2_2015->WktVersion.WKT2_2015PJ_GUESSED_WKT1_GDAL->WktVersion.WKT1_GDALPJ_GUESSED_WKT1_ESRI->WktVersion.WKT1_ESRIPJ_GUESSED_NOT_WKT->NoneChanges
pyproj/_crs.pyx: newguess_wkt_versionfunction mirroringis_wkt.pyproj/proj.pxi: declare the currentPJ_GUESSED_WKT2_2019enum member.pyproj/_crs.pyi: type stub.pyproj/crs/__init__.py: export the function and add it to__all__.docs/api/crs/crs.rst: autofunction entry.docs/history.rst: changelog bullet.test/crs/test_crs.py: per-dialect round-trip tests plus a non-WKT case.Test plan
test/crs/test_crs.py.CRS.to_wkt(version=...)returns the matchingWktVersion.None.Closes #1031