Re: [gdal-dev] OGR drivers written in Python

2018-11-12 Thread deduikertjes

I'd love to have the possibility to add drivers to GDAl using Python.

Use case for me is all those services/ datasets containing useful geo
data but adhere to no standard. Being able to create a driver quickly to get
it in QGIS or an ETL proces is
really useful.

Did this proposal ever make it to GDAL? I couldn't find it in any
changelogs.
If not, do you expect it to make it some day?

MArco



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] Fwd: Re: [Tiff] Libtiff will be released soon

2018-11-12 Thread Robert Coup
Hi Even,

On Mon, 12 Nov 2018 at 07:57, Even Rouault 
wrote:

>
> Not completely sure what to do with GDAL 2.3 branch, as it already had
> ZStd
> (if using its internal libtiff copy). I feel it is probably wise to also
> update the modified value of COMPRESSION_ZSTD there to avoid the risk of
> people creating files with the now obsolete tag value ?
>

How about:

1. Read both values as enabling ZSTD
2. Output a warning when the old value is encountered
3. Always write the new value

Rob :)
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] OGR drivers written in Python

2018-11-12 Thread Even Rouault
On lundi 12 novembre 2018 01:48:03 CET deduikertjes wrote:
> I'd love to have the possibility to add drivers to GDAl using Python.
> 
> Use case for me is all those services/ datasets containing useful geo
> data but adhere to no standard. Being able to create a driver quickly to get
> it in QGIS or an ETL proces is
> really useful.
> 
> Did this proposal ever make it to GDAL? I couldn't find it in any
> changelogs.

No, it has remained a toy experiment.

> If not, do you expect it to make it some day?

I won't risk myself at predicting the future. All I can say is I haven't any 
immediate plan for it.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] Fwd: Re: [Tiff] Libtiff will be released soon

2018-11-12 Thread Even Rouault
On lundi 12 novembre 2018 08:48:59 CET Robert Coup wrote:
> Hi Even,
> 
> On Mon, 12 Nov 2018 at 07:57, Even Rouault 
> 
> wrote:
> > Not completely sure what to do with GDAL 2.3 branch, as it already had
> > ZStd
> > (if using its internal libtiff copy). I feel it is probably wise to also
> > update the modified value of COMPRESSION_ZSTD there to avoid the risk of
> > people creating files with the now obsolete tag value ?
> 
> How about:
> 
> 1. Read both values as enabling ZSTD
> 2. Output a warning when the old value is encountered
> 3. Always write the new value

Yeah, that's just what I have done. But only in 2.3 branch, not in master, as 
I patched the internal libtiff copy for that, and don't intend to upstream 
that hack or make the internal libtiff in master diverge from official 
libtiff.

$ gdalinfo ../autotest/gcore/data/byte_zstd.tif
Warning 1: TIFFInitZSTD:Value of Compression Tag is 34926, which is the 
deprecated value for ZStd. Please use the new value of 5 by recreating/
patching this file. Next GDAL releases won't recognize this file.
Driver: GTiff/GeoTIFF
Files: ../autotest/gcore/data/byte_zstd.tif
[...]

Note: if you build GDAL 2.3 with the shiny new libtiff 4.0.10 as external 
libtiff, those files with 34926 won't be recognized.

Even


-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Re: [gdal-dev] OGR drivers written in Python

2018-11-12 Thread deduikertjes
Even,

I think your 'toy' is a real gem which deserves to live (if only as
something flagged 'experimental').

AFAIK this would be the only option for GDAL users to extend GDAL on run
time.
Confining this technique to run time only extensions IMHO addresses the main
concerns in the discussion. 

Marco



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

[gdal-dev] Dataset's ReadRaster/WriteRaster throws exception on c#

2018-11-12 Thread Gigas002
Hi all.
I've rewritten some python code from gdal2tiles.py on c#, using GDAL.NET
nuget package (ver. 2.3.1). Here you can see the working python code:

def create_overview_tiles(input_file, output_file):
tile_driver = 'PNG'
tile_size = 256
tilebands = 4
resampling = 'bilinear'

mem_driver = gdal.GetDriverByName('MEM')
out_driver = gdal.GetDriverByName(tile_driver)

dsquery = mem_driver.Create('', 2 * tile_size, 2 * tile_size, tilebands)
dstile = mem_driver.Create('', tile_size, tile_size, tilebands)
dsquerytile = gdal.Open(input_file, gdal.GA_ReadOnly)

dsquery.WriteRaster(0, 0, tile_size, tile_size, 
dsquerytile.ReadRaster(0,
0, tile_size, tile_size), band_list=list(range(1, tilebands + 1)))
scale_query_to_tile(dsquery, dstile, resampling)
out_driver.CreateCopy(output_file, dstile, strict=0)


def scale_query_to_tile(dsquery, dstile, resampling):
querysize = dsquery.RasterXSize
tilesize = dstile.RasterXSize

if resampling == 'near':
gdal_resampling = gdal.GRA_NearestNeighbour

elif resampling == 'bilinear':
gdal_resampling = gdal.GRA_Bilinear

elif resampling == 'cubic':
gdal_resampling = gdal.GRA_Cubic

elif resampling == 'cubicspline':
gdal_resampling = gdal.GRA_CubicSpline

dsquery.SetGeoTransform((0.0, tilesize / float(querysize), 0.0, 0.0,
0.0, tilesize / float(querysize)))
dstile.SetGeoTransform((0.0, 1.0, 0.0, 0.0, 0.0, 1.0))

gdal.ReprojectImage(dsquery, dstile, None, None, gdal_resampling)


And here's rewritten code on c#:

private static void BuildOverview(string inputFile, string
outputFile)
{
const string tileDriver = "PNG";
const int tileSize = 256;
const int tileBands = 4;
const string resampling = "bilinear";

Driver memDriver = Gdal.GetDriverByName("MEM");
Driver outDriver = Gdal.GetDriverByName(tileDriver);

Dataset dsQuery = memDriver.Create("", 2 * tileSize, 2 *
tileSize, tileBands, DataType.GDT_Byte, null);
Dataset dsTile = memDriver.Create("", tileSize, tileSize,
tileBands, DataType.GDT_Byte, null);
Dataset dsQueryTile = Gdal.Open(inputFile, Access.GA_ReadOnly);

byte[] readRaster = new byte[tileSize * tileSize];
dsQueryTile.ReadRaster(0, 0, tileSize, tileSize, readRaster,
tileSize, tileSize,
tileBands, Enumerable.Range(1, tileBands + 1).ToArray(), 0,
0, 0);
dsQuery.WriteRaster(0, 0, tileSize, tileSize, readRaster,
tileSize, tileSize,
tileBands, Enumerable.Range(1, tileBands + 1).ToArray(), 0,
0, 0);

ScaleQueryToTile(dsQuery, dsTile, resampling);
outDriver.CreateCopy(outputFile, dsTile, 0, null, null, null);
}

private static void ScaleQueryToTile(Dataset dsQuery, Dataset
dsTile, string resampling)
{
int querySize = dsQuery.RasterXSize;
int tileSize = dsTile.RasterXSize;

ResampleAlg gdalResampling;
switch (resampling)
{
case "near":
gdalResampling = ResampleAlg.GRA_NearestNeighbour;
break;
case "bilinear":
gdalResampling = ResampleAlg.GRA_Bilinear;
break;
case "cubicspline":
gdalResampling = ResampleAlg.GRA_CubicSpline;
break;
default:
gdalResampling = ResampleAlg.GRA_Cubic;
break;
}

dsQuery.SetGeoTransform(new[] {0.0, tileSize / (float)
querySize, 0, 0, 0, tileSize / (float) querySize});
dsTile.SetGeoTransform(new[] { 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 });

Gdal.ReprojectImage(dsQuery, dsTile, null, null, gdalResampling,
0, 0, null, null, null);
}


I use these methods to create upper tile (in my case create 10 lvl tile from
11 lvl tile). Python version works without problem, but c#'s throws
"System.AccessViolationException" (Additional information on exception from
VS: Attempted to read or write protected memory. This is often an indication
that other memory is corrupt) on "dsQueryTile.ReadRaster(..." line in
runtime. 
I suppose the exception is thrown because ReadRaster try to create pointer
to byte[] and somehow fails. 

I uploaded the 11 lvl png tile, named "z_x_y.png", and good 10 lvl tile,
done by python. I'm using VS2017, Win10x64 and writing on .net framework
4.7.2.
Hope anyone knows how to fix it!

11_2200_1621.png
  
10_1100_810.png
  



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
___
gdal-dev mailing list
gdal-dev@lists.osgeo.

Re: [gdal-dev] Dataset's ReadRaster/WriteRaster throws exception on c#

2018-11-12 Thread Tamas Szekeres
You did not count the band size when allocating memory for the buffer.
That should be:

byte[] readRaster = new byte[tileSize * tileSize * 4];

Or alternatively use Band.ReadRaster to read just a specific band.

Best regards,

Tamas




Gigas002  ezt írta (időpont: 2018. nov. 12., H, 17:34):

> Hi all.
> I've rewritten some python code from gdal2tiles.py on c#, using GDAL.NET
> nuget package (ver. 2.3.1). Here you can see the working python code:
>
> def create_overview_tiles(input_file, output_file):
> tile_driver = 'PNG'
> tile_size = 256
> tilebands = 4
> resampling = 'bilinear'
>
> mem_driver = gdal.GetDriverByName('MEM')
> out_driver = gdal.GetDriverByName(tile_driver)
>
> dsquery = mem_driver.Create('', 2 * tile_size, 2 * tile_size,
> tilebands)
> dstile = mem_driver.Create('', tile_size, tile_size, tilebands)
> dsquerytile = gdal.Open(input_file, gdal.GA_ReadOnly)
>
> dsquery.WriteRaster(0, 0, tile_size, tile_size,
> dsquerytile.ReadRaster(0,
> 0, tile_size, tile_size), band_list=list(range(1, tilebands + 1)))
> scale_query_to_tile(dsquery, dstile, resampling)
> out_driver.CreateCopy(output_file, dstile, strict=0)
>
>
> def scale_query_to_tile(dsquery, dstile, resampling):
> querysize = dsquery.RasterXSize
> tilesize = dstile.RasterXSize
>
> if resampling == 'near':
> gdal_resampling = gdal.GRA_NearestNeighbour
>
> elif resampling == 'bilinear':
> gdal_resampling = gdal.GRA_Bilinear
>
> elif resampling == 'cubic':
> gdal_resampling = gdal.GRA_Cubic
>
> elif resampling == 'cubicspline':
> gdal_resampling = gdal.GRA_CubicSpline
>
> dsquery.SetGeoTransform((0.0, tilesize / float(querysize), 0.0, 0.0,
> 0.0, tilesize / float(querysize)))
> dstile.SetGeoTransform((0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
>
> gdal.ReprojectImage(dsquery, dstile, None, None, gdal_resampling)
>
>
> And here's rewritten code on c#:
>
> private static void BuildOverview(string inputFile, string
> outputFile)
> {
> const string tileDriver = "PNG";
> const int tileSize = 256;
> const int tileBands = 4;
> const string resampling = "bilinear";
>
> Driver memDriver = Gdal.GetDriverByName("MEM");
> Driver outDriver = Gdal.GetDriverByName(tileDriver);
>
> Dataset dsQuery = memDriver.Create("", 2 * tileSize, 2 *
> tileSize, tileBands, DataType.GDT_Byte, null);
> Dataset dsTile = memDriver.Create("", tileSize, tileSize,
> tileBands, DataType.GDT_Byte, null);
> Dataset dsQueryTile = Gdal.Open(inputFile, Access.GA_ReadOnly);
>
> byte[] readRaster = new byte[tileSize * tileSize];
> dsQueryTile.ReadRaster(0, 0, tileSize, tileSize, readRaster,
> tileSize, tileSize,
> tileBands, Enumerable.Range(1, tileBands + 1).ToArray(), 0,
> 0, 0);
> dsQuery.WriteRaster(0, 0, tileSize, tileSize, readRaster,
> tileSize, tileSize,
> tileBands, Enumerable.Range(1, tileBands + 1).ToArray(), 0,
> 0, 0);
>
> ScaleQueryToTile(dsQuery, dsTile, resampling);
> outDriver.CreateCopy(outputFile, dsTile, 0, null, null, null);
> }
>
> private static void ScaleQueryToTile(Dataset dsQuery, Dataset
> dsTile, string resampling)
> {
> int querySize = dsQuery.RasterXSize;
> int tileSize = dsTile.RasterXSize;
>
> ResampleAlg gdalResampling;
> switch (resampling)
> {
> case "near":
> gdalResampling = ResampleAlg.GRA_NearestNeighbour;
> break;
> case "bilinear":
> gdalResampling = ResampleAlg.GRA_Bilinear;
> break;
> case "cubicspline":
> gdalResampling = ResampleAlg.GRA_CubicSpline;
> break;
> default:
> gdalResampling = ResampleAlg.GRA_Cubic;
> break;
> }
>
> dsQuery.SetGeoTransform(new[] {0.0, tileSize / (float)
> querySize, 0, 0, 0, tileSize / (float) querySize});
> dsTile.SetGeoTransform(new[] { 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 });
>
> Gdal.ReprojectImage(dsQuery, dsTile, null, null,
> gdalResampling,
> 0, 0, null, null, null);
> }
>
>
> I use these methods to create upper tile (in my case create 10 lvl tile
> from
> 11 lvl tile). Python version works without problem, but c#'s throws
> "System.AccessViolationException" (Additional information on exception from
> VS: Attempted to read or write protected memory. This is often an
> indication
> that other memory is corrupt) on "dsQueryTile.ReadRaster(..." line in
> runtime.
> I suppose the exception is thrown because ReadRaster try to create pointer
> to byte[] and somehow fails.
>
> I uploaded the 11