locationtech / geotrellis

GeoTrellis is a geographic data processing engine for high performance applications.
http://geotrellis.io
Other
1.33k stars 360 forks source link

FileCOGLayerReader can't read on Windows operating system #2608

Open Frophie opened 6 years ago

Frophie commented 6 years ago

Tried the COG example on Windows 10 locally, seems FileCOGLayerReader can't read on Windows.

java.net.URISyntaxException: Illegal character in authority at index 7: file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff
    at java.net.URI$Parser.fail(URI.java:2848)
    at java.net.URI$Parser.parseAuthority(URI.java:3186)
    at java.net.URI$Parser.parseHierarchical(URI.java:3097)
    at java.net.URI$Parser.parse(URI.java:3053)
    at java.net.URI.<init>(URI.java:588)
    at geotrellis.spark.io.file.cog.FileCOGLayerReader$$anonfun$read$3.apply(FileCOGLayerReader.scala:70)
    at geotrellis.spark.io.file.cog.FileCOGLayerReader$$anonfun$read$3.apply(FileCOGLayerReader.scala:70)
    at geotrellis.spark.io.cog.COGLayerReader$$anonfun$7$$anonfun$apply$3$$anonfun$apply$4.apply(COGLayerReader.scala:265)
    at geotrellis.spark.io.cog.COGLayerReader$$anonfun$7$$anonfun$apply$3$$anonfun$apply$4.apply(COGLayerReader.scala:262)
jbouffard commented 6 years ago

@Frophie I think the issue is with how the file path is formatted rather than with the FileCOGLayerReader. As the path you're trying to read can't be turned into a URI

scala> new URI("file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff")
<console>:1: error: invalid escape character
new URI("file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff")
                   ^
<console>:1: error: invalid escape character
new URI("file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff")
                        ^
<console>:1: error: invalid escape character
new URI("file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff")
                                ^
<console>:1: error: invalid escape character
new URI("file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff")
                                    ^
<console>:1: error: invalid escape character
new URI("file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff")
                                            ^

From this StackOverflow issue, it looks like you can replace the \s in your file path with /s, and it should still work.

Could you try doing that and seeing if it works?

Frophie commented 6 years ago

Actually my input is /, "file://E:\Work\GeoTiff\COG\catalog\zoom_cog_layer\0_0\0.tiff" is a path after some inner transform. Here is my code:

    val reader = FileCOGLayerReader("E:/Work/GeoTiff/COG/catalog")(sc)

    val layer = reader.read[SpatialKey, MultibandTile](LayerId("zoom_cog_layer", 13))
    println(layer.count())
Frophie commented 6 years ago

And FileLayerReader("E:/Work/GeoTiff/COG/fileCatalog")(sc) works well with it's catalog, so I think we need to check why FileCOGLayerReader is different.

jbouffard commented 6 years ago

@Frophie Ah, I see. I'm looking into the issue now. Would you be okay with testing out possible solutions? I don't have a Windows machine or virtual environment to test on.

Frophie commented 6 years ago

@jbouffard Yes, of course, just tell me what to do, and I will try.

jbouffard commented 6 years ago

Thanks, @Frophie. I'll probably contact on Gitter later today to go over some possible solutions.

jbouffard commented 6 years ago

@Frophie If possible, could you please pull down this branch? https://github.com/jbouffard/geotrellis/tree/bug-fix/cogs/windows-path It's basically the current master with some added printlns for debugging.

Once you pulled it down could you then please run this in the terminal?

    val reader = FileCOGLayerReader("E:/Work/GeoTiff/COG/catalog")(sc)

    val layer = reader.read[SpatialKey, MultibandTile](LayerId("zoom_cog_layer", 13))
    println(layer.count())

After you run the above code, could you then send me all of the output? It'll help me pinpoint where things get messed up.

Frophie commented 6 years ago

@lossyrob You are right about the "\" to "/" suggestion. The path turns into "\" after File.getAbsolutePath, so I do a replace after it:

(index: BigInt) => new File(f, Index.encode(index, maxWidth)).getAbsolutePath
      .replaceAll("\\\\", "/")

Then, the reading process succeed.