Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "rust_geotiff"
version = "0.0.1"
authors = ["Dominik Bucher <dobucher@ethz.ch>"]
version = "0.0.2"
authors = ["Dominik Bucher <dobucher@ethz.ch>", "Peter Braden <hi@peterbraden.co.uk>"]

[dependencies]
byteorder = "*"
enum_primitive = "*"
num = "*"
miniz_oxide = "0.3"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ x.get_value_at(longitude, latitude);

Where `longitude` corresponds to the `image_length` and `latitude` to the `image_width`. This might be a bit counter intuitive, but seems consistent with GDAL (have to look into this).

NB: GeoTiff files can encode data as integers, or as floating point values - for
simplicity we represent both as f64 values.

Caution: the `longitude` and `latitude` are only in pixels, no coordinate transformations are applied!

## Development and Testing
Expand Down
Binary file added resources/mapzen-geotiff-14-10348-7801.tif
Binary file not shown.
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ extern crate byteorder;
#[macro_use]
extern crate enum_primitive;
extern crate num;
extern crate miniz_oxide;

use num::FromPrimitive;

use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian, LittleEndian};
use std::io::{Read, Seek};
use std::collections::{HashMap, HashSet};
use std::io::Result;
use std::fmt;

mod lowlevel;
mod reader;
pub mod tiff;

use tiff::*;
use reader::*;
pub use tiff::TIFF;

Expand All @@ -30,8 +25,14 @@ impl TIFF {
tiff_reader.load(filename)
}

/// Read from an open file
pub fn read(reader: &mut dyn SeekableReader) -> Result<Box<TIFF>> {
let tiff_reader = TIFFReader;
tiff_reader.read(reader)
}

/// Gets the value at a given coordinate (in pixels).
pub fn get_value_at(&self, lon: usize, lat: usize) -> usize {
pub fn get_value_at(&self, lon: usize, lat: usize) -> f64 {
self.image_data[lon][lat][0]
}
}
Expand Down
33 changes: 21 additions & 12 deletions src/lowlevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn tag_size(t: &TagType) -> u32 {
TagType::SignedRationalTag => 8,
TagType::FloatTag => 4,
TagType::DoubleTag => 8,
_ => 0,
//_ => 0,
}
}

Expand Down Expand Up @@ -85,16 +85,19 @@ pub enum PhotometricInterpretation {
BlackIsZero = 1,
}

/// The compression chosen for this TIFF.
#[repr(u16)]
#[derive(Debug)]
pub enum Compression {
None = 1,
Huffman = 2,
LZW = 5,
OJPEG = 6,
JPEG = 7,
PackBits = 32773,
// The compression chosen for this TIFF.
enum_from_primitive! {
#[repr(u16)]
#[derive(Debug)]
pub enum Compression {
None = 1,
Huffman = 2,
LZW = 5,
OJPEG = 6,
JPEG = 7,
AdobeDeflate = 8,
PackBits = 32773,
}
}

/// The resolution unit of this TIFF.
Expand All @@ -106,7 +109,8 @@ pub enum ResolutionUnit {
Centimetre = 3,
}

/// The sample format of this TIFF.
// The sample format of this TIFF.
enum_from_primitive! {
#[repr(u16)]
#[derive(Debug)]
pub enum SampleFormat {
Expand All @@ -115,6 +119,7 @@ pub enum SampleFormat {
IEEEFloatingPoint = 3,
Undefined = 4,
}
}

/// The image type of this TIFF.
#[derive(Debug)]
Expand Down Expand Up @@ -224,6 +229,10 @@ enum_from_primitive! {
// Extension TIFF Tags
// See http://www.awaresystems.be/imaging/tiff/tifftags/extension.html
XMPTag = 0x02bc,
TileWidth = 0x0142,
TileLength = 0x0143,
TileOffsets = 0x0144,
TileByteCounts = 0x0145,

// Private Tags
PhotoshopTag = 0x8649,
Expand Down
Loading