GithubHelp home page GithubHelp logo

fabric-io-rodrigues / geotiffcog Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 2.0 3.94 MB

Open Cloud Optimized GeoTiffs in C# Console Library

License: MIT License

C# 96.96% QML 3.04%
geotiff csharp latitude-and-longitude cog cloud-optimized-geotiff elevation xy libtiff-library

geotiffcog's People

Contributors

fabric-io-rodrigues avatar jackclouseau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

geotiffcog's Issues

Bilinear Interpolation

Hello,

as I understand, the getElevation code always takes the sample next up-left to the given coordinate. This is no problem for flat areas. But what along a steep coast or in regions like the european Alps? I did some simple experiments with this code. As a result, I calculate the elevation from all four points around the point of interest. The resulting height simply is taken from a bilinear interpolation along x and y path. My code is as follows (not tested well, needs optimyzation):

public float GetElevationAtLatLon(double latitude, double longitude)
{
float[] h = new float[4];
double h12, h34, xratio, yratio;
Utils.GetXYFromLatLon(metadata, latitude, longitude, out int x, out int y);

if (x < 0) throw new Exception($"Error longitude: {longitude} not valid to [{metadata.PhysicalStartLon}, {metadata.PhysicalEndLon}] offsetX: {x}");
if (y < 0) throw new Exception($"Error latitude: {latitude} not valid to [{metadata.PhysicalStartLat}, {metadata.PhysicalEndLat}] offsetY: {y}");

h[0] = GetElevationAtPoint(x, y);
h[1] = GetElevationAtPoint(x + 1, y);
h[2] = GetElevationAtPoint(x, y - 1);
h[3] = GetElevationAtPoint(x + 1, y - 1);
// now do bilinear interpolation
xratio = (longitude - metadata.PhysicalStartLon - x*metadata.pixelSizeX) / metadata.pixelSizeX;
yratio = (latitude - metadata.PhysicalStartLat + (metadata.Height-y-1) * metadata.pixelSizeY) / metadata.pixelSizeY;
h12 = (double)h[0] + ((double)(h[1] - h[0])) * xratio;
h34 = (double)h[2] + ((double)(h[3] - h[2])) * xratio;
return (float) (h12 + (h34 - h12) * yratio);
}

No data at point

Hi,

I have been doing some further testing and come across a potential problem.

I am using this file: au_ga_AUSGeoid2020_20180201.tif with coordinates -34.5; 133.5
The height value returned is -32768.

Do you think we should add some more conditions to this:

GetElevationAtPoint::

if (heightValue > 32768)
{
heightValue = metadata.NoDataValueFloat;
}

such that NoDataValueFloat is returned (when the height value is -32768).

Thanks.

Performance ?

This looks incredible ! :) The only lib so far which supports geotiffs... and especially reading a damn geocoordinate pixel value from them.

I see you are still pretty active on here, may i ask about performance concerns ? How fast is one "GetHeight" operation and how much allocation happens ? And are only COGS supported or also normal GeoTiffs ?

A quick look at the source code reveals a have use of classes and other allocations. Couldnt the performance be further increased by converting a lot of the classes to structs instead ?

How to install this Library in Nuget packages with c#

Hi
I find out this library is very useful in getting elevation with lat and lon in any Tiff files
so I decided to use this library for getting elevation in my app
But there is no way to use this lib in Nuget (including keyword), I want the keyword to find out this library in nuget package with visual studio
Thanks for any help!

GDAL_METADATA

I am working with this file: ca_nrc_CGG2013ai08.tif
and these coordinates: 50, -90

The height value returned is an integer value and is 30624.

I think there are a couple of problems with this example.

  1. The integer value should really be 32 bits (BitsPerSample in the metadata = 32). The code assumes integers are 16 bits. It is also signed.
  2. The value of 30624 needs to be scaled by the scale value obtained from GDAL_METADATA. See here: https://github.com/OSGeo/PROJ/blob/master/docs/source/specifications/geodetictiffgrids.rst

In this example, the scale value is 0.001. Applying this to 30624 * scale = 30.624m. Which is a more believable result.

GeoTiff.cs crash if no metadata. Fix.

GeoTiff.cs, Line 385, exception because TiffFile.GetField((TiffTag)42112) returns null.

// TIFF Tag GDAL_METADATA 42112
var xml = TiffFile.GetField((TiffTag)42112)[1].ToString().Trim('\0');
...

Fix: Add null conditional operator "?" and "if" check:

// Set default scale.
_metadata.Scale = 1;
// TIFF Tag GDAL_METADATA 42112
var xml = TiffFile.GetField((TiffTag)42112)?[1].ToString().Trim('\0');
// If metadata supplied then...
if (!string.IsNullOrEmpty(xml))
{
	var gd = ParseXml(xml);
	_metadata.Offset = gd.Offset;
	_metadata.Scale = gd.Scale;
}

Wrong pixel value returned ?

So i got it working, it works for the sample geotiff file.

However i wanna use it for my own files... its called "pnv_biome.type_biome00k_c_1km_s0..0cm_2000..2017_v0.1" and contains a value from 0 to 31 for each pixel. Basically natural vegetation and biomes.

When i run the program for my desired geocoordinate, it returns insanly high values. Wrong values. Furhermore, one single "GetElevationAtLAtLong" call generates about 500mb garbage.

Any help here ?

Is https://registry.opendata.aws/terrain-tiles/ not a supported format?

I was hoping to use this library in my little project and using https://registry.opendata.aws/terrain-tiles/ as the elevation source as its freely available.

using aws s3 cp --no-sign-request s3://elevation-tiles-prod/geotiff/10/926/626.tif c:\626.tif to download a file (I might have downloaded the wrong tif file, but not too fussed at this point)

GeoTiff COG - version: 0.1
--------------------------
Unhandled Exception: System.Exception: Error in ParseGeoDataAtPoint: Index was outside the bounds of the array.
   at GeoTiffCOG.GeoTiff.GetElevationAtPoint(Int32 x, Int32 y) in C:\Data\\GeoTiffCOG\GeoTiff.cs:line 202
   at GeoTiffCOG.GeoTiff.GetElevationAtLatLon(Double latitude, Double longitude) in C:\Data\GeoTiffCOG\GeoTiff.cs:line 150
   at GeoTiffCOGConsole.Program.Main(String[] args) in C:\Data\GeoTiffCOGConsole\Program.cs:line 32

Hardcoded the GPS location I am looking for, and modified the URL to use a local file:

//double lat = Convert.ToDouble(args[1]);
//double lon = Convert.ToDouble(args[2]);
double lat = -37.4075974;
double lon = 145.7524722;

//GeoTiff geoTiff = new GeoTiff(new Uri(url), directoryTemp);
GeoTiff geoTiff = new GeoTiff(url);

When using "SLV_wind-speed_50m.tif" as the input file, the elevation comes back as zero without crashing. Assuming zero is the default when the location is not within the tif file.

Does not look like GeoTiffCOG is happy with the format of the tif file from the S3 bucket?

Incorrect value being returned

Hi,
nice work! I have just tried to use your project with a GeoTiff file I am using for my test purposes.

I tried this: .\GeoTiffCOGConsole.exe https://cdn.proj.org/fr_ign_ggm00v2.tif 14.5 -61
and I get an incorrect result of 0. The correct result should be around -40 m.

I verified it against this:
https://www.unavco.org/software/geodetic-utilities/geoid-height-calculator/geoid-height-calculator.html

I think it might be something to do with the way untiled files are handled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.