Re: [gdal-dev] unable to create jpeg200 files with self compiled gdal and openjpeg

2016-07-12 Thread Even Rouault
André,

> 
> This code works for geotiff, but not for jpeg2000. There I'm getting the
> error: ERROR 6: GDALDriver::Create() ... no create method implemented
> for this format.

You cannot directly use Create() for any of the JPEG2000 drivers as Create() 
assumes random writing capabilities which the JPEG2000 format doesn't offer. So 
the solution is to create a temporary dataset (for example with the MEM driver 
if it fits into RAM, or with an intermediate GeoTIFF otherwise) and then 
CreateCopy() it to JPEG2000

Something like:

tmp_ds = 
gdal.GetDriverByName('MEM').Create('',img.shape[0],img.shape[1],1,gdal.GDT_UInt16)
 
# here I 
rb = tmp_ds.GetRasterBand(1)
rb.WriteArray(img)
dr.CreateCopy(fn, tmp_ds)
tmp_ds = None

Even

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

[gdal-dev] unable to create jpeg200 files with self compiled gdal and openjpeg

2016-07-12 Thread Andre Hollstein

Dear gdal experts,

I'm compiling gdal and a whole list of other libraries myself. Currently 
I'm using gdal-2.1.0 and openjepeg v2.1.1 and use the libs from python:


import gdal
import numpy as np
gdal.AllRegister()
#driver = 'JP2KAK'
driver = "JP2OpenJPEG"
#driver = "GTiff"
#driver = "JPEG2000" # jasper

fn = "./img_buf.%s" % 
{"GTiff":"tiff",'JP2KAK':"jp2","JP2OpenJPEG":"jp2","JPEG2000":"jp2"}[driver]


sh = (1000,1000)
img = np.ones(sh,dtype=np.int16)
dr = gdal.GetDriverByName(driver)
ds = dr.Create(fn,img.shape[0],img.shape[1],1,gdal.GDT_UInt16) # here I 
get: ERROR 6: GDALDriver::Create() ... no create method implemented for 
this format.

if ds is None: raise ValueError(fn)
rb = ds.GetRasterBand(1)
rb.WriteArray(img)
ds.FlushCache()
ds = None

This code works for geotiff, but not for jpeg2000. There I'm getting the 
error: ERROR 6: GDALDriver::Create() ... no create method implemented 
for this format.


I tested various combinations of various data types without any change 
in behavior.


I guess it should work, what can I do to solve this issue?

I compile openjpeg like this:

cmake . -DCMAKE_INSTALL_PREFIX=$prefix_opt -DCMAKE_C_FLAGS="-O3 -fPIC" 
-DBUILD_SHARED_LIBS:bool=on -DBUILD_CODEC:bool=on


and gdal like that:

kdu_opts=--with-kakadu=$prefix_opt
conda install --yes numpy
./configure \
--prefix $prefix_opt \
--with-openjpeg=$prefix_opt \
--with-jasper=$prefix_opt \
--with-libtiff=$prefix_opt \
--without-libtool \
--with-hdf4=$prefix_opt \
--with-hdf5=no \
--with-netcdf=no \
--with-geotiff=internal \
--with-grass=no \
--with-sqlite3=no \
$kdu_opts \
--with-pic \
--with-python=$prefix_python/bin/python \

make install
make clean

Am I missing any needed flags or options?

Kind regards, André

--
Dr. André Hollstein
Sektion 1.4 Fernerkundung
Tel.: +49 (0)331/288-28969
Fax: +49 (0)331/288-28969
E-Mail: andre.hollst...@gfz-potsdam.de
___

Helmholtz-Zentrum Potsdam
Deutsches GeoForschungsZentrum GFZ
Stiftung des öff. Rechts Land Brandenburg
Telegrafenberg, 14473 Potsdam
Haus 17, Raum 20.23

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev