Skip to content

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

Merged
lossyrob merged 6 commits into
locationtech:masterfrom
s22s:feature/tiff-color-table
Nov 15, 2016
Merged

lossyrob merged 6 commits into
locationtech:masterfrom
s22s:feature/tiff-color-table

Conversation

@metasim

@metasim metasim commented Nov 14, 2016

Copy link
Copy Markdown
Member

No description provided.

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

@lossyrob lossyrob left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


if(geoTiff.options.colorSpace == ColorSpace.Palette) {

val bitsPerSample = imageData.bandType.bitsPerSample

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added compatibility check and associated exception here.


import java.nio.ByteOrder

import geotrellis.raster.render.IndexedColorMap

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as note above, for import placement

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

else throw new MalformedGeoTiffException(
"Colormap without Photometric Interpetation = 3."
)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

BasicTags._colorMap set arr.toSeq)
} else throw new MalformedGeoTiffException(
}
else throw new MalformedGeoTiffException(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

} else
  throw new MalformedGeoTiffException(

  )

or do {} for the else body

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

shorts(i + divider).toShort,
shorts(i + 2 * divider).toShort
)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space for proper formatting

@lossyrob

Copy link
Copy Markdown
Member

🎉

@lossyrob
lossyrob merged commit 869ef08 into locationtech:master Nov 15, 2016
@metasim
metasim deleted the feature/tiff-color-table branch November 16, 2016 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants