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

Expose GDAL Metadata API, expose RasterSources Metadata API #216

Merged
merged 5 commits into from
Aug 1, 2019

Conversation

pomadchin
Copy link
Member

@pomadchin pomadchin commented Jul 18, 2019

Overview

This PR exposes the metadata that is not covered by the RasterSources API, such as tiff tags / extra metadata that can be interpreted as a string.

In terms of this PR we've tried to look how other GIS libraries collect imagery metadata, and it looks like there is no a standard interface to work with rather than a Map[String, String].

Checklist

  • Add entry to CHANGELOG.md

Closes #181

@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch 3 times, most recently from b1b3f85 to 3620ca4 Compare July 18, 2019 18:46
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from 3620ca4 to fe6a5ba Compare July 29, 2019 15:53
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from 3e3fb55 to 0cef544 Compare July 29, 2019 21:54
@pomadchin pomadchin requested a review from echeipesh July 29, 2019 22:00
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from 0cef544 to c3f4a5d Compare July 29, 2019 22:02
@@ -42,41 +42,11 @@ import java.util.ServiceLoader
* @groupdesc reproject Functions to resample raster data in target projection.
* @groupprio reproject 2
*/
trait RasterSource extends CellGrid[Long] with Serializable {
trait RasterSource extends CellGrid[Long] with RasterSourceMetadata with Serializable {
Copy link
Member Author

Choose a reason for hiding this comment

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

Does this mixin makes any sense? CellGrid[Long] with RasterSourceMetadata

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question.... what is gained by having it subclass CellGrid[Long]. Should RasterSourceMetadata be the one to extend it? At least at a superficial level, both feel a bit like responsibility leakage into RasterSource.

There's an argument that the relationship between RasterSource and RasterSourceMetadata should be a "has a" relationship and not an "is a" one. I tend to lean toward smaller, multiply nested types (more "has a"), but that can get annoying to traverse. If I were implementing this I would probably have RasterSource extend neither (or keep CellGrid if it's already depended upon), and then have a method metadata: RasterSourceMetadata that the user hits to get the deets. And then add convenience forwarding methods as needed for a subset of fields such as crs, bandCount, etc. It's an approach emphasizing separation of concerns over convenience, which, like anything, can be taken too far. I think my main argument would be that it's easier to add things later than to take them away if the abstraction isn't quite right.

@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch 2 times, most recently from 3daef0d to e4c4db6 Compare July 30, 2019 17:54
@pomadchin
Copy link
Member Author

pomadchin commented Jul 30, 2019

@echeipesh I am not sure does the commit pomadchin@ec533ea makes things better or not :/ need a pair of fresh eyes here.

I even decided to roll it back, since I don't like it. However I put it into a separate branch for the history / review purposes.

@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from e4c4db6 to 69b5562 Compare July 30, 2019 18:36
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch 2 times, most recently from ec533ea to cffb32a Compare July 30, 2019 20:51
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from cffb32a to 783068b Compare July 30, 2019 20:54
import com.azavea.gdal.GDALWarp

case class GDALDataset(token: Long) extends AnyVal {
def getAllMetadataFlatten(dataset: Int): Map[String, String] =
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️


/** https://github.com/OSGeo/gdal/blob/b1c9c12ad373e40b955162b45d704070d4ebf7b0/gdal/doc/source/development/rfc/rfc43_getmetadatadomainlist.rst */
def getMetadataDomainList(dataset: Int, band: Int): List[String] = {
val arr = Array.ofDim[Byte](100, 1 << 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said before, I think this is half the cause of the performance issues (triggering lots of copies to happen around the JNI boundary). Hoping this signature is considered.

Copy link
Member Author

Choose a reason for hiding this comment

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

@metasim I need to benchmark @jamesmcclain bindings; I think it is a completely separate issue now, as probably requires some investigation time


new String(arr, "UTF-8").trim
}

def getProjection: Option[String] = getProjection(GDALWarp.WARPED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you document something about the (expected) returned string format? If it's guaranteed to be a well-formed/parseable structure, should we type-tag it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Or mb even opaque types (https://github.com/estatico/scala-newtype); but it is not a part of this PR

@@ -42,41 +42,11 @@ import java.util.ServiceLoader
* @groupdesc reproject Functions to resample raster data in target projection.
* @groupprio reproject 2
*/
trait RasterSource extends CellGrid[Long] with Serializable {
trait RasterSource extends CellGrid[Long] with RasterSourceMetadata with Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good question.... what is gained by having it subclass CellGrid[Long]. Should RasterSourceMetadata be the one to extend it? At least at a superficial level, both feel a bit like responsibility leakage into RasterSource.

There's an argument that the relationship between RasterSource and RasterSourceMetadata should be a "has a" relationship and not an "is a" one. I tend to lean toward smaller, multiply nested types (more "has a"), but that can get annoying to traverse. If I were implementing this I would probably have RasterSource extend neither (or keep CellGrid if it's already depended upon), and then have a method metadata: RasterSourceMetadata that the user hits to get the deets. And then add convenience forwarding methods as needed for a subset of fields such as crs, bandCount, etc. It's an approach emphasizing separation of concerns over convenience, which, like anything, can be taken too far. I think my main argument would be that it's easier to add things later than to take them away if the abstraction isn't quite right.

@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch 4 times, most recently from f31ddd5 to ce1e404 Compare July 31, 2019 19:45
@pomadchin pomadchin requested a review from CloudNiner July 31, 2019 19:59
dataset.getMetadata(GDALWarp.SOURCE, domains, 0),
(1 until dataset.bandCount).toList.map(dataset.getMetadata(GDALWarp.SOURCE, domains, _))
)
case FullDomainList =>
Copy link
Member Author

Choose a reason for hiding this comment

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

Mb it should be AllMetadataDomainsList? Or smth like that.

@pomadchin
Copy link
Member Author

Travis is down for some reason :/ in my fork it passes tests https://travis-ci.org/pomadchin/geotrellis-contrib/jobs/566145813

…etadata collection, simplify the metadata concept.
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from ce1e404 to a93ab9e Compare July 31, 2019 22:50
Copy link
Collaborator

@echeipesh echeipesh left a comment

Choose a reason for hiding this comment

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

💯 after GDALWarp.WARPED becomes an ADT and GDALMetadataDomainList gets deleted in favor of GDALRasterSource.metadataForAllDomains

@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from 49978c4 to 35b1167 Compare July 31, 2019 23:34
@pomadchin pomadchin force-pushed the feature/rs-effects-metadata branch from 35b1167 to fade0f4 Compare July 31, 2019 23:40
@echeipesh echeipesh merged commit 81f7c2d into geotrellis:master Aug 1, 2019
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.

RasterSource Metadata API
3 participants