fabric-io-rodrigues / geotiffcog Goto Github PK
View Code? Open in Web Editor NEWOpen Cloud Optimized GeoTiffs in C# Console Library
License: MIT License
Open Cloud Optimized GeoTiffs in C# Console Library
License: MIT License
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);
}
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.
In this example, the scale value is 0.001. Applying this to 30624 * scale = 30.624m. Which is a more believable result.
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.
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;
}
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!
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.
Hello,
I've noticed something weird in GeoTiff.ParseMetadata
. I'm not sure whether it's a bug or if I missed something.
In the following line
double pixelSizeY = BitConverter.ToDouble(modelPixelScale, 8) * -1;
Why is the value multiplied by -1
?
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 ?
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?
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 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.