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

Ability to write RasterFrame tile columns directly as raster files. #571

Merged
merged 2 commits into from
Nov 11, 2021

Conversation

metasim
Copy link
Member

@metasim metasim commented Oct 19, 2021

Provides support for writing each row of tiles as a single or multiband tile, as GeoTIFF or PNG, with or without a CSV catalog. Output path is configurable via specified column.

TODO:

  • Documentation
  • Python support

val sample = tileFiles(dest).next()
val tags = SinglebandGeoTiff(sample.toString()).tags.headTags
tags.keys should contain ("testval")
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The result of this looks something like this:
image

Copy link
Member Author

@metasim metasim Oct 19, 2021

Choose a reason for hiding this comment

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

The catalog looks something like this (note the metadata columns):

filename,bbox,crs,label,testval
cat/test/1606317768704.tif,[443422.5|4313647.5|443512.5|4315387.5],+proj=utm +zone=16 +datum=WGS84 +units=m +no_defs,cat,test
dog/train/463856467968.tif,[368295.0|4080315.0|372135.0|4083105.0],+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs,dog,train
dog/train/661424963584.tif,[395175.0|4080315.0|395295.0|4083105.0],+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs,dog,train
...

.withCatalog
.save(dest.toString)

countTiles(dest, ".png") should be (df.count())
Copy link
Member Author

Choose a reason for hiding this comment

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

"Catalog" looks something like this:

filename,bbox,crs
446676598784.png,[364455.0|4086945.0|368295.0|4090785.0],+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
455266533376.png,[387495.0|4106145.0|391335.0|4109985.0],+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
463856467968.png,[368295.0|4080315.0|372135.0|4083105.0],+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
...

val fs = FileSystem.get(pathURI, conf.value)
val localPath = new Path(new Path(pathURI), fName)
copyMerge(fs, hPath, fs, localPath, true, conf.value)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@echeipesh @pomadchin Maybe this could be replaced with something that's more STAC oriented?

// Avoiding commas with this format:
// [0.489|51.28|0.236|51.686]
val bbox = s"[${extent.xmin}|${extent.ymin}|${extent.xmax}|${extent.ymax}]"
Row(finalFilename +: bbox +: crs.toProj4String +: metadata: _*)
Copy link
Member Author

Choose a reason for hiding this comment

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

This effectively drops the raster columns so the coalesce(1) in the catalog write doesn't end up moving raster data across nodes.

val chipTags = tags.copy(headTags = md.updated("base_filename", filename))
val geotiff = new MultibandGeoTiff(MultibandTile(tiles), extent, crs, chipTags, tiffOptions)
geotiff.write(finalPath, hconf.value)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this is bad form or not, but we're basically performing side effects in a mapPartitions. Check other data sources on how to do this?

@metasim metasim merged commit 8d73fbf into locationtech:develop Nov 11, 2021
@metasim metasim deleted the feature/tile-writer branch November 11, 2021 15:13
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.

1 participant