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

Ability to read/write color tables for GeoTIFFs encoded with palette photometric interpretation #1802

Merged
merged 6 commits into from Nov 15, 2016

Conversation

Projects
2 participants
@metasim
Member

metasim commented Nov 14, 2016

No description provided.

@lossyrob lossyrob added this to the 1.0 milestone Nov 14, 2016

@lossyrob

Looking good, just a couple of nitpicks.

it("should write color map when photometric interpretation is 'Palette'") {
val hundreds = createConsecutiveTile(10).map(_ - 1).convert(ByteCellType)
val colorMap = ColorRamps.HeatmapBlueToYellowToRedSpectrum //ClassificationBoldLandUse

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

Remove comment (or make other test case that uses it?)

private def upsample(c: Int) = (c * 257).toShort
/** Creates an IndexColorMap from sequence of RGB short values. */
private[raster] def fromTiffPalette(tiffPalette: Seq[(Short, Short, Short)]) = new IndexedColorMap(

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

not sure there's a need to make this private to [raster], is there a good reason to hide it?

This comment has been minimized.

@metasim

metasim Nov 15, 2016

Member

Was't sure if in this project making it public meant we had to commit to it as an API. But I'll make public.

for {
cmap geoTiff.options.colorMap
palette = IndexedColorMap.toTiffPalette(cmap)
size = math.min(palette.size, divider)

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

Using = inside a for comprehension isn't idiomatic to the library. Might cause confusion because if it's in the for it seems like it should be a map or flatMap, that's how I read it anyway. Could be extracted to vals inside the body.

@@ -77,6 +79,30 @@ object TiffTagFieldValue {
fieldValues += TiffTagFieldValue(PlanarConfigurationTag, ShortsFieldType, 1, PlanarConfigurations.PixelInterleave)
fieldValues += TiffTagFieldValue(SampleFormatTag, ShortsFieldType, 1, imageData.bandType.sampleFormat)
if(geoTiff.options.colorSpace == ColorSpace.Palette) {
val bitsPerSample = imageData.bandType.bitsPerSample

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

Unclear whether to throw here if it's invalid to have for this BandType, or on creation. I would say perhaps on creation.

This comment has been minimized.

@metasim

metasim Nov 15, 2016

Member

Added compatibility check and associated exception here.

import java.nio.ByteOrder
import geotrellis.raster.render.IndexedColorMap

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

Same as note above, for import placement

This comment has been minimized.

@metasim

metasim Nov 15, 2016

Member

I'm not finding the comment on import placement. Can you repeat it?

This comment has been minimized.

@lossyrob

lossyrob Nov 15, 2016

Member

Ah, I hit "preview" to look at the code, and then failed to hit "Add review comment"...

The order of imports should be as follows:

// GeoTrellis imports, alphabetical
import geotrellis.raster._
import geotrellis.vector._
import geotrellis.vector.io._

// Third party imports, alphabetical
import org.apache.spark._
import spray.json._

// Java and Scala imports, alphabetical
import java.nio._
import scala.collections.mutable

This comment has been minimized.

@metasim

metasim Nov 15, 2016

Member

Got it. Again, out of habit hit my "organize formats" keybinding, which I have set up differently.

This comment has been minimized.

@lossyrob

lossyrob Nov 15, 2016

Member

Are you using IntelliJ? Curious, a lot of people do, but most of the Azavea team doesn't...useful to know if we try it out and have questions :)

"Colormap without Photometric Interpetation = 3."
)
}

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

Better to leave off the curly brackets if it's a single statement method (the if counts as a single statement)

}
(tiffTags &|->
TiffTags._basicTags ^|->
BasicTags._colorMap set arr.toSeq)
} else throw new MalformedGeoTiffException(
}
else throw new MalformedGeoTiffException(

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

else belongs on the same line as the close bracket. Would do

} else
  throw new MalformedGeoTiffException(

  )

or do {} for the else body

This comment has been minimized.

@metasim

metasim Nov 15, 2016

Member

Sorry... Accidentally hit auto-format out of habit.

val arr = Array.ofDim[(Short, Short, Short)](divider)
cfor(0)(_ < divider, _ + 1) { i =>
arr(i) = (
shorts(i).toShort,
shorts(i + divider).toShort,
shorts(i + 2 * divider).toShort
)
)

This comment has been minimized.

@lossyrob

lossyrob Nov 14, 2016

Member

Remove space for proper formatting

metasim added some commits Nov 15, 2016

Added GeoTiffWriter checking of invalid palette color map vs. cell ty…
…pe configurations.

Code review cleanup/fixes.
@lossyrob

This comment has been minimized.

Member

lossyrob commented Nov 15, 2016

🎉

@lossyrob lossyrob merged commit 869ef08 into locationtech:master Nov 15, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@metasim metasim deleted the s22s:feature/tiff-color-table branch Nov 16, 2016

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