[gdal-dev] Best method to extract regions from a raster into a memory buffer

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Best method to extract regions from a raster into a memory buffer

Aurélien Albert

Hi,

 

I'm doing C++ applications and I'm familiar with GDAL 1.7 C/C++ API. For a new application, I'm switching to GDAL 2.2.

In this application, I have the need to extract a region from a raster :

 

Let's say I have 4000px x 4000px elevation raster, covering the whole earth, in EPSG 4326.

Now I want to extract the rectangle region between two points (lat_1/long_1) and (lat_2/long_2) in a 128px x 128px tile.

I don't want to extract this region in a file, but in memory, to create a data buffer and then work on this buffer with my application.

 

Which is the best/more performant way to do this ?

 

Knowing that :

 1/ the region extraction may need some resampling, so I need to be able to configure the resampling method

 2/ the extracted region boundaries do no necessary fit on exact pixels of the original dataset

 3/ the SRS will not be modified, but I may need a vertical datum shift (EGM96 to WGS84 for example)

 4/ the extraction will be repeated a lot (a lot !) to extract several "tiles" with different bounds : the application can work on really big rasters, so I prefer to avoid complex objects initialization for each extraction

 

Should I :

 

- create a wrapped dataset (VRTDataSet) and make RasterIO on it ? This seems to solve 1/ and 3/ and 4/, but what about 2/ ?

 

- use a WarpOperation and then execute WarpRegionToBuffer method ? This seems to solve 1/ and 2/ and 3/, but what about 4/ ?

 

Any help will be appreciated.

 

 

Thanks



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

Re: Best method to extract regions from a raster into a memory buffer

Joaquim Luis

Hi,

 

I think you need an extra point. If you will be doing resampling than you need extra row/columns for the boundary conditions (one for linear, two for spline/bicubic). Regarding 2) the options are:  round to closest node, or to the inner or to the outer node.

 

Joaquim

 

 

From: gdal-dev <[hidden email]> On Behalf Of Aurélien Albert
Sent: Thursday, October 11, 2018 11:28 AM
To: [hidden email]
Subject: [gdal-dev] Best method to extract regions from a raster into a memory buffer

 

Hi,

 

I'm doing C++ applications and I'm familiar with GDAL 1.7 C/C++ API. For a new application, I'm switching to GDAL 2.2.

In this application, I have the need to extract a region from a raster :

 

Let's say I have 4000px x 4000px elevation raster, covering the whole earth, in EPSG 4326.

Now I want to extract the rectangle region between two points (lat_1/long_1) and (lat_2/long_2) in a 128px x 128px tile.

I don't want to extract this region in a file, but in memory, to create a data buffer and then work on this buffer with my application.

 

Which is the best/more performant way to do this ?

 

Knowing that :

 1/ the region extraction may need some resampling, so I need to be able to configure the resampling method

 2/ the extracted region boundaries do no necessary fit on exact pixels of the original dataset

 3/ the SRS will not be modified, but I may need a vertical datum shift (EGM96 to WGS84 for example)

 4/ the extraction will be repeated a lot (a lot !) to extract several "tiles" with different bounds : the application can work on really big rasters, so I prefer to avoid complex objects initialization for each extraction

 

Should I :

 

- create a wrapped dataset (VRTDataSet) and make RasterIO on it ? This seems to solve 1/ and 3/ and 4/, but what about 2/ ?

 

- use a WarpOperation and then execute WarpRegionToBuffer method ? This seems to solve 1/ and 2/ and 3/, but what about 4/ ?

 

Any help will be appreciated.

 

 

Thanks

 


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

Re: Best method to extract regions from a raster into a memory buffer

Aurélien Albert

Yes, you're right, I may need some extra pixels on the boundaries (depend on the resampling method).


Does not GDAL manage this by itself ? I mean, if you ask for a warp, it doesn't read all necessary pixel to do the resampling ?


Since GDAL 2.0, there is some API changes, and I'm looking for the most efficient way to do my operation : extract a region specified with geographic coordinates (in the same SRS as the data source) to a fixed size pixel buffer. Resampling should occur because the pixel count of the extracted region (source) and pixel count of the buffer (destination) will not fit.




De : gdal-dev <[hidden email]> de la part de Joaquim Manuel Freire Luís <[hidden email]>
Envoyé : jeudi 11 octobre 2018 16:47:27
À : [hidden email]
Objet : Re: [gdal-dev] Best method to extract regions from a raster into a memory buffer
 

Hi,

 

I think you need an extra point. If you will be doing resampling than you need extra row/columns for the boundary conditions (one for linear, two for spline/bicubic). Regarding 2) the options are:  round to closest node, or to the inner or to the outer node.

 

Joaquim

 

 

From: gdal-dev <[hidden email]> On Behalf Of Aurélien Albert
Sent: Thursday, October 11, 2018 11:28 AM
To: [hidden email]
Subject: [gdal-dev] Best method to extract regions from a raster into a memory buffer

 

Hi,

 

I'm doing C++ applications and I'm familiar with GDAL 1.7 C/C++ API. For a new application, I'm switching to GDAL 2.2.

In this application, I have the need to extract a region from a raster :

 

Let's say I have 4000px x 4000px elevation raster, covering the whole earth, in EPSG 4326.

Now I want to extract the rectangle region between two points (lat_1/long_1) and (lat_2/long_2) in a 128px x 128px tile.

I don't want to extract this region in a file, but in memory, to create a data buffer and then work on this buffer with my application.

 

Which is the best/more performant way to do this ?

 

Knowing that :

 1/ the region extraction may need some resampling, so I need to be able to configure the resampling method

 2/ the extracted region boundaries do no necessary fit on exact pixels of the original dataset

 3/ the SRS will not be modified, but I may need a vertical datum shift (EGM96 to WGS84 for example)

 4/ the extraction will be repeated a lot (a lot !) to extract several "tiles" with different bounds : the application can work on really big rasters, so I prefer to avoid complex objects initialization for each extraction

 

Should I :

 

- create a wrapped dataset (VRTDataSet) and make RasterIO on it ? This seems to solve 1/ and 3/ and 4/, but what about 2/ ?

 

- use a WarpOperation and then execute WarpRegionToBuffer method ? This seems to solve 1/ and 2/ and 3/, but what about 4/ ?

 

Any help will be appreciated.

 

 

Thanks

 


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