Hi,

I have run into a problem trying to load an MBTiles file with GeoTools
16.2.  The problem is exactly that which is described here:
https://gis.stackexchange.com/questions/270770/geoserver-cant-add-a-jpeg-mbtiles-file

The key information from the stacktrace is
this: "java.lang.IllegalArgumentException: No enum constant
org.geotools.mbtiles.MBTilesMetadata.t_format.JPG at
java.lang.Enum.valueOf(Enum.java:238)"

The MBTilesMetatdata.t_format enum has values JPEG, PNG and PBF.  The
MBTilesReader loads metadata from the file and gets a format string of
"jpg" when it calls the MBTilesMetadata.setFormatStr() an exception is
thrown because there is no "JPG" value in the t_format enum.

I would like to submit a patch for this; I have two proposed solutions that
I have already tested locally, perhaps you could tell me which you prefer,
or propose any modifications?

1) Simple add a "JPG" value to the t_format enumeration, leaving JPEG in
the enumeration. -- The spec says this about the format value: "The file
format of the tile data: pbf, jpg, png, webp, or an IETF media type for
other formats". Even though "jpeg" is not a technically valid value I would
think that at least some MBTiles tools use this value so it should probably
stay.

Adding a "JPG" enumeration is entirely safe as the t_format enumeration is
effectively only used by MBTilesMetadata.setFormatStr().

The code is a single line and we only need to add a couple of lines to the
unit test code.

2) Modify the t_format enum to include a constructor that allows "aliases"
for the format string, and modify the MBTilesMetadata.setFormatStr()
routine to use a static method of the t_format enum to map a format string
to an enumeration value.  I prefer this even though it's more code because
it ensures a "format" has a single enumeration value but it's potentially
"overkill".

Thanks very much,

Murray McDonald
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to