WorldBank-Transport / open-transit-indicators

An open-source tool to support transport agencies in planning and managing public transit systems
GNU General Public License v3.0
44 stars 21 forks source link

Feature/geotiff endpoint #633

Closed flibbertigibbet closed 9 years ago

notthatbreezy commented 9 years ago

Sorry! Meant to get to this earlier, but was stuck on another project -- I have to do some more digging in the source, but it seems like we should be able to just return bytes here (we're on an older version of GeoTrellis so that's why I'm unsure of how to do it).

Also - not sure much is gained from gzipping since GeoTiff is an already compressed format

flibbertigibbet commented 9 years ago

@notthatbreezy , I looked into the Geotrellis source, and it doesn't look to be directly doable. Although possible, since the bytes would not be streamed, it could only return a max of 2GB.

moradology commented 9 years ago

Sorry to weigh in so late - been jumping around between other things all day and just saw this.

I think just saving the file as Kathryn does here makes sense and probably won't be too weird. Plus it is easier to reason about (at least to me) than sending bytes over the wire somehow else. Perhaps it would be better to try and save the file with jobId as part of the filename to prevent headaches when/if multiple people try to grab one of these files.

notthatbreezy commented 9 years ago

It looks like this returns bytes. How large have these geotiffs been so far? 2gb would be a pretty good size geotiff

One issue I could see happening is some odd race conditions where 2 near simultaneous requests trample on each other.

Keying the filename definitely makes sense too I think.

flibbertigibbet commented 9 years ago

If saved by jobId then we'd need to implement caching/clearing of some sort. Since we're not using the Play library, it's not straightforward to delete a file after it's been downloaded. So I take it people can download results from different calculation jobs at the same time, if there's multiple users in the system.

flibbertigibbet commented 9 years ago

Yes, writeBytes, which would mean calling into the GeoTiff's Encoder thing directly.

flibbertigibbet commented 9 years ago

@notthatbreezy once you have bytes, what would you do with them? There doesn't seem to be any equivalent to the getFromFile directive for sending bytes as a file download.

notthatbreezy commented 9 years ago

I think it should be possible to call

GeoTiff.render(tile, extent, LatLng, <whatever compression you want>)

I don't think you have to touch the encoder since GeoTiff.render handles that. Then you would send the bytes (not sure of the syntax in spray but there is this and some docs in spray that point this as well. The content-type would just need to be whatever is appropriate for returning a GeoTiff/Tiff

moradology commented 9 years ago

I also found this, which discusses content-type: http://spray.io/documentation/1.2.3/spray-httpx/marshalling/#custom-marshallers

flibbertigibbet commented 9 years ago

Judging from the comments, it looks like GeoTiff compression doesn't actually work (LZW results in unreadable file on Macs.)

flibbertigibbet commented 9 years ago

Okay, the HttpData wrap worked fine without the custom marshal stuff. Maybe this is good to go now.

notthatbreezy commented 9 years ago

+1