Skip to content
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

CRS.fromWKT doesn't handle WKT with no EPSG record. #2871

Closed
metasim opened this issue Feb 8, 2019 · 7 comments · Fixed by #3074
Closed

CRS.fromWKT doesn't handle WKT with no EPSG record. #2871

metasim opened this issue Feb 8, 2019 · 7 comments · Fixed by #3074

Comments

@metasim
Copy link
Member

metasim commented Feb 8, 2019

Input

This WKT is from calling org.opengis.referencing.crs.CoordinateReferenceSystem#toWKT on data read from a random shapefile via GeoTools.

CRS.fromWKT("""|GEOGCS["GCS_WGS_1984",
               |DATUM["D_WGS_1984",
               |SPHEROID["WGS_1984", 6378137.0, 298.257223563]],
               |PRIMEM["Greenwich", 0.0],
               |UNIT["degree", 0.017453292519943295],
               |AXIS["Longitude", EAST],
               |AXIS["Latitude", NORTH]]
               |""".stripMargin.replaceAll("\n",""))

Output

None.get
java.util.NoSuchElementException: None.get
	at scala.None$.get(Option.scala:347)
	at scala.None$.get(Option.scala:345)
	at geotrellis.proj4.io.wkt.WKT$.getEpsgCode(WKT.scala:70)
	at geotrellis.proj4.CRS$.fromWKT(CRS.scala:87)

Related: #2870

@metasim metasim added the bug label Feb 8, 2019
@metasim
Copy link
Member Author

metasim commented Feb 8, 2019

I also think it would be beneficial for CRS.fromWKT to automatically call the .replaceAll("\n","").

@CloudNiner
Copy link
Contributor

I'm under the impression from the way the issue here is written that you'd expect the WKT string you provided to be successfully parsed by the CRS.fromWKT method. Is that true? If so, #3074 updates the CRS.fromWKT to return an Option[CRS] rather than crash outright.

As far as I can tell, with existing code, we're only able to parse WKT strings that we can retrieve an EPSG code from or have already parsed parameters for. Unless I'm missing the correct call using some other method, this issue will require a bit more effort to resolve since this WKT string is missing an authority.

@metasim
Copy link
Member Author

metasim commented Sep 16, 2019

@CloudNiner You're correct; I filed this bug before I understood that it only worked for embedded EPSG codes. However, I do think that it will also throw (or swallow?) an exception in the case where it does have an embedded EPSG code, but also has newlines.

@CloudNiner
Copy link
Contributor

Sounds good. For now I'll just check for and address the newline issue if that's still a problem.

@CloudNiner
Copy link
Contributor

Updated #3074 -- WKTParser now automatically strips newlines before attempting to parse. There was an old test that demos how newlines can be stripped manually, updated that to just compare a multiline vs single line string: 24c17c0

@metasim
Copy link
Member Author

metasim commented Sep 16, 2019

Should this be closed then? The "convert all the things" version is probably more of a Proj4j issue anyway...

locationtech/proj4j#49

@CloudNiner
Copy link
Contributor

Certainly looks like it. Will close with the merging of #3074.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants