[gdal-dev] How to estimate the width/height size of output image in a target CRS without running gdalwarp?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] How to estimate the width/height size of output image in a target CRS without running gdalwarp?

bangph
Hi,

I have a hard problem to find the width/height of a 2D GeoTiff file
which is reprojected from a source CRS (e.g: EPSG:4326) to target CRS
(e.g: EPSG:3857) without running gdalwarp. Because, the file could be
large (GBs) and I don't need the projected output file, just need the
width/height of it.

What could be done with gdalwarp is:

gdalwarp  -s_srs EPSG:4326 -t_srs EPSG:3857 full.tif full_3857.tif

gdalinfo full_3857.tif

Size is 879, 811 (width/height).

I've searched a lot and what seems to be good without doing the real
projection is this gdal function: GDALSuggestedWarpOutput2
https://github.com/OSGeo/gdal/blob/106c8288e7a05f4efc1a588c5a3b2da7ec52d915/gdal/alg/gdaltransformer.cpp#L354.
However, it doesn't help because my application developed in Java and it
uses gdal-java (GDAL JNI)
https://search.maven.org/#artifactdetails%7Corg.gdal%7Cgdal%7C1.11.1%7Cpom
as library. Unfortunately, I cannot find this GDALSuggestedWarpOutput2()
from gdal-java http://gdal.org/java/overview-summary.html then cannot
invoke this C++ function from my application to test.

Can anyone please give me a hint to solve this problem?

Thanks,



_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to estimate the width/height size of output image in a target CRS without running gdalwarp?

Even Rouault-2

On jeudi 17 mai 2018 11:33:40 CEST Bang Pham Huu wrote:

> Hi,

>

> I have a hard problem to find the width/height of a 2D GeoTiff file

> which is reprojected from a source CRS (e.g: EPSG:4326) to target CRS

> (e.g: EPSG:3857) without running gdalwarp. Because, the file could be

> large (GBs) and I don't need the projected output file, just need the

> width/height of it.

>

> What could be done with gdalwarp is:

>

> gdalwarp  -s_srs EPSG:4326 -t_srs EPSG:3857 full.tif full_3857.tif

>

> gdalinfo full_3857.tif

>

> Size is 879, 811 (width/height).

>

> I've searched a lot and what seems to be good without doing the real

> projection is this gdal function: GDALSuggestedWarpOutput2

> https://github.com/OSGeo/gdal/blob/106c8288e7a05f4efc1a588c5a3b2da7ec52d915/

> gdal/alg/gdaltransformer.cpp#L354. However, it doesn't help because my

> application developed in Java and it uses gdal-java (GDAL JNI)

> https://search.maven.org/#artifactdetails%7Corg.gdal%7Cgdal%7C1.11.1%7Cpom

> as library. Unfortunately, I cannot find this GDALSuggestedWarpOutput2()

> from gdal-java http://gdal.org/java/overview-summary.html then cannot

> invoke this C++ function from my application to test.

>

> Can anyone please give me a hint to solve this problem?

 

Hi,

 

You can use gdal.AutoCreateWarpedVRT() which will create a in-memory warped

VRT without doing the actual warping.

 

http://gdal.org/java/org/gdal/gdal/gdal.html#AutoCreateWarpedVRT-org.gdal.gdal.Dataset-

 

and query the dimensions of the returned Dataset

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to estimate the width/height size of output image in a target CRS without running gdalwarp?

Deschamps, Benjamin (AAFC/AAC)
In reply to this post by bangph
You could use osr's CoordinateTransformation to evaluate the new location of the four corners in the destination spatial reference:
http://gdal.org/python/osgeo.osr.CoordinateTransformation-class.html

From there a min/max on the four coordinates will give you the extent of the new image space.

If the input and output CRS are very dissimilar you might want to evaluate a regular grid instead to get a more representative extent.


Benjamin Deschamps

Physical Sciences Specialist
Canadian Ice Service, Meteorological Service of Canada
Environment and Climate Change Canada / Government of Canada
[hidden email] / Tel: 613-943-4293

Spécialiste des sciences physiques
Service Canadien des Glaces, Service Météorologique du Canada,
Environnement et Changement climatique Canada / Gouvernement du Canada
[hidden email] / Tél. : 613-943-4293



-----Original Message-----
From: Bang Pham Huu [mailto:[hidden email]]
Sent: May 17, 2018 5:34 AM
To: [hidden email]
Subject: [gdal-dev] How to estimate the width/height size of output image in a target CRS without running gdalwarp?

Hi,

I have a hard problem to find the width/height of a 2D GeoTiff file which is reprojected from a source CRS (e.g: EPSG:4326) to target CRS
(e.g: EPSG:3857) without running gdalwarp. Because, the file could be large (GBs) and I don't need the projected output file, just need the width/height of it.

What could be done with gdalwarp is:

gdalwarp  -s_srs EPSG:4326 -t_srs EPSG:3857 full.tif full_3857.tif

gdalinfo full_3857.tif

Size is 879, 811 (width/height).

I've searched a lot and what seems to be good without doing the real projection is this gdal function: GDALSuggestedWarpOutput2 https://github.com/OSGeo/gdal/blob/106c8288e7a05f4efc1a588c5a3b2da7ec52d915/gdal/alg/gdaltransformer.cpp#L354.
However, it doesn't help because my application developed in Java and it uses gdal-java (GDAL JNI) https://search.maven.org/#artifactdetails%7Corg.gdal%7Cgdal%7C1.11.1%7Cpom
as library. Unfortunately, I cannot find this GDALSuggestedWarpOutput2() from gdal-java http://gdal.org/java/overview-summary.html then cannot invoke this C++ function from my application to test.

Can anyone please give me a hint to solve this problem?

Thanks,




_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to estimate the width/height size of output image in a target CRS without running gdalwarp?

bangph
In reply to this post by Even Rouault-2

Thanks Even, your suggestion works, I found an example here for Python that could help others with this powerful feature: https://gis.stackexchange.com/a/140053/17733


On 05/17/2018 09:02 PM, Even Rouault wrote:

On jeudi 17 mai 2018 11:33:40 CEST Bang Pham Huu wrote:

> Hi,

>

> I have a hard problem to find the width/height of a 2D GeoTiff file

> which is reprojected from a source CRS (e.g: EPSG:4326) to target CRS

> (e.g: EPSG:3857) without running gdalwarp. Because, the file could be

> large (GBs) and I don't need the projected output file, just need the

> width/height of it.

>

> What could be done with gdalwarp is:

>

> gdalwarp  -s_srs EPSG:4326 -t_srs EPSG:3857 full.tif full_3857.tif

>

> gdalinfo full_3857.tif

>

> Size is 879, 811 (width/height).

>

> I've searched a lot and what seems to be good without doing the real

> projection is this gdal function: GDALSuggestedWarpOutput2

> https://github.com/OSGeo/gdal/blob/106c8288e7a05f4efc1a588c5a3b2da7ec52d915/

> gdal/alg/gdaltransformer.cpp#L354. However, it doesn't help because my

> application developed in Java and it uses gdal-java (GDAL JNI)

> https://search.maven.org/#artifactdetails%7Corg.gdal%7Cgdal%7C1.11.1%7Cpom

> as library. Unfortunately, I cannot find this GDALSuggestedWarpOutput2()

> from gdal-java http://gdal.org/java/overview-summary.html then cannot

> invoke this C++ function from my application to test.

>

> Can anyone please give me a hint to solve this problem?

 

Hi,

 

You can use gdal.AutoCreateWarpedVRT() which will create a in-memory warped

VRT without doing the actual warping.

 

http://gdal.org/java/org/gdal/gdal/gdal.html#AutoCreateWarpedVRT-org.gdal.gdal.Dataset-

 

and query the dimensions of the returned Dataset

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com



_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev