From 9e80b3cf3cc3a5df8415e6143325a87e8fdb8d2e Mon Sep 17 00:00:00 2001
From: bart <bart.knuiman@wur.nl>
Date: Mon, 13 Feb 2023 17:53:02 +0100
Subject: [PATCH] first commit good

---
 README.md                                     |  96 +-------
 README.md.meta                                |   7 +
 Runtime.meta                                  |   8 +
 Runtime/GeoTiffHeight.cs                      | 225 ++++++++++++++++++
 Runtime/GeoTiffHeight.cs.meta                 |  11 +
 Runtime/Plugins.meta                          |   8 +
 .../BitMiracle.LibTiff.NET.2.4.639.meta       |   8 +
 .../BitMiracle.LibTiff.NET.2.4.639.nupkg.meta |   7 +
 .../BitMiracle.LibTiff.NET.2.4.639/lib.meta   |   8 +
 .../lib/netstandard2.0.meta                   |   8 +
 .../BitMiracle.LibTiff.NET.dll.meta           |  33 +++
 .../BitMiracle.LibTiff.NET.xml.meta           |   7 +
 Runtime/TiffStreamForBytes.cs                 |  77 ++++++
 Runtime/TiffStreamForBytes.cs.meta            |  11 +
 Runtime/TiffUtils.cs                          |  14 ++
 Runtime/TiffUtils.cs.meta                     |  11 +
 Runtime/com.wurwander.geotiff.asmdef          |  15 ++
 Runtime/com.wurwander.geotiff.asmdef.meta     |   7 +
 package.json                                  |  19 ++
 package.json.meta                             |   7 +
 20 files changed, 495 insertions(+), 92 deletions(-)
 create mode 100644 README.md.meta
 create mode 100644 Runtime.meta
 create mode 100644 Runtime/GeoTiffHeight.cs
 create mode 100644 Runtime/GeoTiffHeight.cs.meta
 create mode 100644 Runtime/Plugins.meta
 create mode 100644 Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639.meta
 create mode 100644 Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/BitMiracle.LibTiff.NET.2.4.639.nupkg.meta
 create mode 100644 Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib.meta
 create mode 100644 Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0.meta
 create mode 100644 Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.dll.meta
 create mode 100644 Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.xml.meta
 create mode 100644 Runtime/TiffStreamForBytes.cs
 create mode 100644 Runtime/TiffStreamForBytes.cs.meta
 create mode 100644 Runtime/TiffUtils.cs
 create mode 100644 Runtime/TiffUtils.cs.meta
 create mode 100644 Runtime/com.wurwander.geotiff.asmdef
 create mode 100644 Runtime/com.wurwander.geotiff.asmdef.meta
 create mode 100644 package.json
 create mode 100644 package.json.meta

diff --git a/README.md b/README.md
index 30be1ba..6cfb20e 100644
--- a/README.md
+++ b/README.md
@@ -1,92 +1,4 @@
-# geotiff
-
-
-
-## Getting started
-
-To make it easy for you to get started with GitLab, here's a list of recommended next steps.
-
-Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
-
-## Add your files
-
-- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
-- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
-
-```
-cd existing_repo
-git remote add origin https://git.wur.nl/wander/geotiff.git
-git branch -M master
-git push -uf origin master
-```
-
-## Integrate with your tools
-
-- [ ] [Set up project integrations](https://git.wur.nl/wander/geotiff/-/settings/integrations)
-
-## Collaborate with your team
-
-- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
-- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
-- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
-- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
-- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
-
-## Test and Deploy
-
-Use the built-in continuous integration in GitLab.
-
-- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
-- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
-- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
-- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
-- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
-
-***
-
-# Editing this README
-
-When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
-
-## Suggestions for a good README
-Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
-
-## Name
-Choose a self-explaining name for your project.
-
-## Description
-Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
-
-## Badges
-On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
-
-## Visuals
-Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
-
-## Installation
-Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
-
-## Usage
-Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
-
-## Support
-Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
-
-## Roadmap
-If you have ideas for releases in the future, it is a good idea to list them in the README.
-
-## Contributing
-State if you are open to contributions and what your requirements are for accepting them.
-
-For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
-
-You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
-
-## Authors and acknowledgment
-Show your appreciation to those who have contributed to the project.
-
-## License
-For open source projects, say how it is licensed.
-
-## Project status
-If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
+# Usage #
+
+var height = GeoTiffHeight( filename, filter=true );
+float h = height.FromRD( rdX, rdY );
diff --git a/README.md.meta b/README.md.meta
new file mode 100644
index 0000000..ed37db2
--- /dev/null
+++ b/README.md.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: deb125bd524a0694fb12cf60ffd0e77b
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime.meta b/Runtime.meta
new file mode 100644
index 0000000..33be90f
--- /dev/null
+++ b/Runtime.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 987bf0e8c299a48458be6bf18c486176
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/GeoTiffHeight.cs b/Runtime/GeoTiffHeight.cs
new file mode 100644
index 0000000..699c79d
--- /dev/null
+++ b/Runtime/GeoTiffHeight.cs
@@ -0,0 +1,225 @@
+
+using BitMiracle.LibTiff.Classic;
+using System;
+using System.IO;
+using UnityEngine;
+
+namespace Wander
+{
+    /* Usage:
+     * 
+     * var height = GeoTiffHeight( fileName.tiff, filter = true );
+     * float h = height.FromRD( rdX, rdY );
+     * 
+     * */
+
+    public struct HeightData
+    {
+        public float[] data;
+        public int width;
+        public int height;
+        public double originX;
+        public double originY;
+        public double pixelSizeX;
+        public double pixelSizeY;
+
+        public float FromRD( double x, double y, bool valideHeight = true )
+        {
+            float h = 0;
+            int xPixel = Mathf.FloorToInt( (float)((x-originX) / pixelSizeX ) );
+            int yPixel = Mathf.FloorToInt( (float)((y-originY) / pixelSizeY ) );
+            if (xPixel >= 0 && xPixel<width && yPixel >= 0 && yPixel<height)
+            {
+                h = data[yPixel*width+xPixel];
+                if (valideHeight)
+                {
+                    GeoTiffHeight.Validate( ref h );
+                }
+            }
+            return h;
+        }
+
+        public float FromUnity( Vector2 unityPos, Vector2 rdCentre, bool valideHeight = true )
+        {
+            unityPos -= rdCentre;
+            return FromRD( unityPos.x, unityPos.y, valideHeight );
+        }
+    }
+
+    public class GeoTiffHeight
+    {
+        static float InvalidLow  = -9000;
+        static float InvalidHigh = 9000;
+        static float InvalidSample = -99999;
+
+        public static HeightData Load( string filename, bool filter = true )
+        {
+            var data = DecodePixelsAsFloat( filename,
+                out int width, out int height,
+                out double originX, out double originY,
+                out double pixelSizeX, out double pixelSizeY );
+
+            if ( data != null && filter )
+            {
+                FilterFloatData( data, width, height );
+            }
+
+            return new HeightData()
+            {
+                data = data,
+                width = width,
+                height = height,
+                originX = originX,
+                originY = originY,
+                pixelSizeX = pixelSizeX,    
+                pixelSizeY = pixelSizeY
+            };
+        }
+
+        public static void Validate(ref float h)
+        {
+            if (h < InvalidLow)
+            {
+                h = 0;
+                return;
+            }
+            if (h > InvalidHigh) h = 0;
+        }
+
+        static float[] DecodePixelsAsFloat( 
+            string path, out int width, out int height,
+            out double originX, out double originY,
+            out double pixelSizeX, out double pixelSizeY 
+            )
+        {
+            width  = 0;
+            height = 0;
+            float[] output = null;
+            byte [] tiffBytes = File.ReadAllBytes( path );
+            TiffStreamForBytes ts = new TiffStreamForBytes(tiffBytes);
+
+            using (Tiff tiff = Tiff.ClientOpen( "bytes", "r", null, ts ))
+            {
+                if (tiff == null)
+                {
+                    throw new InvalidDataException( "Tiff data not valid" );
+                }
+
+                width  = tiff.GetField( TiffTag.IMAGEWIDTH )[0].ToInt();
+                height = tiff.GetField( TiffTag.IMAGELENGTH )[0].ToInt();
+                int tile_width   = tiff.GetField(TiffTag.TILEWIDTH)[0].ToInt();
+                int tile_height  = tiff.GetField( TiffTag.TILELENGTH )[0].ToInt();
+                int tileSize     = tiff.TileSize();
+                byte [] tileData = new byte[tileSize];
+
+                // Obtain coords
+                {
+                    FieldValue[] modelPixelScaleTag = tiff.GetField((TiffTag)33550);
+                    FieldValue[] modelTiepointTag   = tiff.GetField((TiffTag)33922);
+
+                    byte[] modelPixelScale = modelPixelScaleTag[1].GetBytes();
+                    pixelSizeX = BitConverter.ToDouble( modelPixelScale, 0 );
+                    pixelSizeY = BitConverter.ToDouble( modelPixelScale, 8 ) * -1;
+
+                    byte[] modelTransformation = modelTiepointTag[1].GetBytes();
+                    originX = BitConverter.ToDouble( modelTransformation, 24 );
+                    originY = BitConverter.ToDouble( modelTransformation, 32 );
+                }
+
+                // output
+                output = new float[width*height];
+                for (int row = 0;row < height;row += tile_height)
+                {
+                    for (int col = 0;col < width;col += tile_width)
+                    {
+                        // Read the tile into an RGBA array
+                        int res = tiff.ReadTile( tileData, 0, col, row, 0, 0 );
+                        if (res == -1)
+                            throw new InvalidDataException( "Invalid tiff tile" );
+
+                        for (int y = 0;y < tile_height;y++)
+                        {
+                            int y2 = row + y;
+                            if (y2 >= height)
+                                continue;
+                            for (int x = 0;x < tile_width;x++)
+                            {
+                                int x2 = col + x;
+                                if (x2 >= width)
+                                    continue;
+
+                                float h = BitConverter.ToSingle( tileData, (y * tile_width + x) * 4 );
+                                output[y2*width + x2] = h;
+                            }
+                        }
+                    }
+                }
+            }
+
+            return output;
+        }
+
+        static void FilterFloatData( float[] data, int width, int height )
+        {
+            for (int y = 0;y<height;y++)
+            {
+                for (int x = 0;x<width;x++)
+                {
+                    int addr = y*width+x;
+                    float h = data[addr];
+                    if (h < InvalidLow || h > InvalidHigh)
+                    {
+                        bool done=false;
+                        for (int c = 1;c < 5 && !done;c++)
+                        {
+                            for (int y2 = y-c;y2 <= y+c &&!done;y2++)
+                            {
+                                float h2 = GetData(data, x-c, y2, width, height);
+                                if (SetData( data, h2, addr )) { done=true; break; }
+                            }
+                            for (int y2 = y-c;y2 <= y+c &&!done;y2++)
+                            {
+                                float h2 = GetData(data, x+c, y2, width, height);
+                                if (SetData( data, h2, addr )) { done=true; break; }
+                            }
+                            for (int x2 = x-c;x2 <= x+c &&!done;x2++)
+                            {
+                                float h2 = GetData(data, x2, y-c, width, height);
+                                if (SetData( data, h2, addr )) { done=true; break; }
+                            }
+                            for (int x2 = x-c;x2 <= x+c &&!done;x2++)
+                            {
+                                float h2 = GetData(data, x2, y+c, width, height);
+                                if (SetData( data, h2, addr )) { done=true; break; }
+                            }
+                        }
+                        if (!done) // If not done, no neighbour pixel was found.
+                        {
+                            data[addr] = 0; // Set to zero to avoid -inifnity or + infinity which cause invalid vertex height when using this data thereof.
+                        }
+                    }
+                }
+            }
+        }
+
+        static float GetData( float[] data, int x, int y, int width, int height )
+        {
+            if (x < 0 || x >= width || y < 0 || y >= height)
+                return InvalidSample;
+            float h = data[y*width+x];
+            if (h < InvalidLow || h > InvalidHigh)
+                return InvalidSample;
+            return h;
+        }
+
+        static bool SetData( float[] data, float h, int addr )
+        {
+            if (h!=InvalidSample)
+            {
+                data[addr] = h;
+                return true;
+            }
+            return false;
+        }
+    }
+}
\ No newline at end of file
diff --git a/Runtime/GeoTiffHeight.cs.meta b/Runtime/GeoTiffHeight.cs.meta
new file mode 100644
index 0000000..806af39
--- /dev/null
+++ b/Runtime/GeoTiffHeight.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: df3a4e8d9659da24483afda7e9cefffe
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins.meta b/Runtime/Plugins.meta
new file mode 100644
index 0000000..850c21e
--- /dev/null
+++ b/Runtime/Plugins.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 0402ab03cbe19614080efea5e449b35f
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639.meta b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639.meta
new file mode 100644
index 0000000..d93054a
--- /dev/null
+++ b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 91598cb8b9d0b1e418664aa3ce3ccb10
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/BitMiracle.LibTiff.NET.2.4.639.nupkg.meta b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/BitMiracle.LibTiff.NET.2.4.639.nupkg.meta
new file mode 100644
index 0000000..57a0ec2
--- /dev/null
+++ b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/BitMiracle.LibTiff.NET.2.4.639.nupkg.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 94de11e51d2c75f40ad4544bcc64e172
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib.meta b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib.meta
new file mode 100644
index 0000000..84374cf
--- /dev/null
+++ b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 37d25d33f19e67543973c9f37a1dd66b
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0.meta b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0.meta
new file mode 100644
index 0000000..f4e2eb7
--- /dev/null
+++ b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 54c70a3d7d9d014409aea2a713fcc73e
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.dll.meta b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.dll.meta
new file mode 100644
index 0000000..7e5d1fc
--- /dev/null
+++ b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.dll.meta
@@ -0,0 +1,33 @@
+fileFormatVersion: 2
+guid: 2dc2a9bd7ff968e4f840489891beb3b4
+PluginImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  iconMap: {}
+  executionOrder: {}
+  defineConstraints: []
+  isPreloaded: 0
+  isOverridable: 0
+  isExplicitlyReferenced: 0
+  validateReferences: 1
+  platformData:
+  - first:
+      Any: 
+    second:
+      enabled: 1
+      settings: {}
+  - first:
+      Editor: Editor
+    second:
+      enabled: 0
+      settings:
+        DefaultValueInitialized: true
+  - first:
+      Windows Store Apps: WindowsStoreApps
+    second:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.xml.meta b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.xml.meta
new file mode 100644
index 0000000..44c8bb7
--- /dev/null
+++ b/Runtime/Plugins/BitMiracle.LibTiff.NET.2.4.639/lib/netstandard2.0/BitMiracle.LibTiff.NET.xml.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 98bb93bfb40e0ca4c860276762568224
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/TiffStreamForBytes.cs b/Runtime/TiffStreamForBytes.cs
new file mode 100644
index 0000000..9686be6
--- /dev/null
+++ b/Runtime/TiffStreamForBytes.cs
@@ -0,0 +1,77 @@
+using System;
+using System.IO;
+using BitMiracle.LibTiff.Classic;
+
+
+namespace Wander
+{
+    /// <summary>
+    /// Custom read-only stream for byte buffer that can be used
+    /// with Tiff.ClientOpen method.
+    /// </summary>
+    class TiffStreamForBytes : TiffStream
+    {
+        private byte[] m_bytes;
+        private int m_position;
+
+        public TiffStreamForBytes( byte[] bytes )
+        {
+            m_bytes = bytes;
+            m_position = 0;
+        }
+
+        public override int Read( object clientData, byte[] buffer, int offset, int count )
+        {
+            if ( (m_position + count) > m_bytes.Length )
+                return -1;
+
+            Buffer.BlockCopy( m_bytes, m_position, buffer, offset, count );
+            m_position += count;
+            return count;
+        }
+
+        public override void Write( object clientData, byte[] buffer, int offset, int count )
+        {
+            throw new InvalidOperationException( "This stream is read-only" );
+        }
+
+        public override long Seek( object clientData, long offset, SeekOrigin origin )
+        {
+            switch ( origin )
+            {
+                case SeekOrigin.Begin:
+                    if ( offset > m_bytes.Length )
+                        return -1;
+
+                    m_position = (int)offset;
+                    return m_position;
+
+                case SeekOrigin.Current:
+                    if ( (offset + m_position) > m_bytes.Length )
+                        return -1;
+
+                    m_position += (int)offset;
+                    return m_position;
+
+                case SeekOrigin.End:
+                    if ( (m_bytes.Length - offset) < 0 )
+                        return -1;
+
+                    m_position = (int)(m_bytes.Length - offset);
+                    return m_position;
+            }
+
+            return -1;
+        }
+
+        public override void Close( object clientData )
+        {
+            // nothing to do
+        }
+
+        public override long Size( object clientData )
+        {
+            return m_bytes.Length;
+        }
+    }
+}
\ No newline at end of file
diff --git a/Runtime/TiffStreamForBytes.cs.meta b/Runtime/TiffStreamForBytes.cs.meta
new file mode 100644
index 0000000..a6a92d4
--- /dev/null
+++ b/Runtime/TiffStreamForBytes.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1c22357fd685d6142b3dfbf15c650c52
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/TiffUtils.cs b/Runtime/TiffUtils.cs
new file mode 100644
index 0000000..fb1bb6c
--- /dev/null
+++ b/Runtime/TiffUtils.cs
@@ -0,0 +1,14 @@
+using BitMiracle.LibTiff.Classic;
+using System.Collections.Generic;
+using System.IO;
+using System.Drawing;
+using System;
+
+namespace Wander
+{
+    // This utility is specifically for height data in the neterlands. 
+    public class TiffUtils
+    {
+       
+    }
+}
diff --git a/Runtime/TiffUtils.cs.meta b/Runtime/TiffUtils.cs.meta
new file mode 100644
index 0000000..01962e4
--- /dev/null
+++ b/Runtime/TiffUtils.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 14b51670d0dcb4045bc5f3aaf2e10acf
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Runtime/com.wurwander.geotiff.asmdef b/Runtime/com.wurwander.geotiff.asmdef
new file mode 100644
index 0000000..499edb9
--- /dev/null
+++ b/Runtime/com.wurwander.geotiff.asmdef
@@ -0,0 +1,15 @@
+{
+    "name": "GeoTiff",
+    "rootNamespace": "Wander",
+    "references": [
+    ],
+    "includePlatforms": [],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}
\ No newline at end of file
diff --git a/Runtime/com.wurwander.geotiff.asmdef.meta b/Runtime/com.wurwander.geotiff.asmdef.meta
new file mode 100644
index 0000000..c243ca4
--- /dev/null
+++ b/Runtime/com.wurwander.geotiff.asmdef.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: e44d054dba23a8349a137db68e558dce
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..19fc90e
--- /dev/null
+++ b/package.json
@@ -0,0 +1,19 @@
+{
+  "name": "com.wurwander.geotiff",
+  "version": "1.0.0",
+  "displayName": "GeoTiff",
+  "description": "Provides a way to obtain height from GeoTiff data.",
+  "unity": "2021.3",
+  "keywords": [
+    "utility",
+    "library"
+  ],
+  "author": {
+    "name": "Bart Knuiman",
+    "email": "bart.knuiman@wur.nl",
+    "url": "wander.wur.nl"
+  },
+  "type": "sample",
+  "hideInEditor": false,
+  "dependencies": {}
+}
\ No newline at end of file
diff --git a/package.json.meta b/package.json.meta
new file mode 100644
index 0000000..24aacd4
--- /dev/null
+++ b/package.json.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 8a3da5282ee99d846bf93718ea355365
+PackageManifestImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
-- 
GitLab