[Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread G. Allegri
Until now I've mostly created vector layers on QGIS, delegating raster
creation to custom GDAL utilities.
Recently I looked into QgsGdalProvider and I saw that it exposes
the QgsRasterDataProvider::Create capability.
I wonder if it's possible to create a brand new raster (geotiff or what
else) using this provider and, in case, what is the right workflow to do
that. I haven't found examples of doing it...

giovanni
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread G. Allegri
Thanks Radim, I wasn't aware of all these news in trunk!
The QgsRasterPipe is really powerful.

Is there some doc about it?
I've run through the code to understand the logic behind QgsRasterPipe
(QRP) and QgsRasterInterface (QRI).
I see that for a QRI must be set a an input QRI (setInput method). If I
understand it correctly a QRP can have various branches made by sequences
of QRI?

giovanni

2012/12/11 Radim Blazek radim.bla...@gmail.com

 On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com wrote:
  Until now I've mostly created vector layers on QGIS, delegating raster
  creation to custom GDAL utilities.
  Recently I looked into QgsGdalProvider and I saw that it exposes the
  QgsRasterDataProvider::Create capability.
  I wonder if it's possible to create a brand new raster (geotiff or what
  else) using this provider and, in case, what is the right workflow to do
  that. I haven't found examples of doing it...

 Yes it is possible. You can use a provider directly

 QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
 )QgsProviderRegistry::instance()-provider( gdal, dataSource );
 provider-write( data, band, width, height, xOffset, yOffset )

 if you your algorithm implemented as QgsRasterInterface you can use
 higher level QgsRasterFileWriter which will do the work splitting
 raster into parts

 QgsRasterPipe* pipe = new QgsRasterPipe();
 pipe-set( inputProvider-clone() );
 pipe-insert( 1, yourInterface );
 QgsRasterFileWriter fileWriter( fileName );
 fileWriter.writeRaster( pipe, width, height, extent, crs );

 Radim


  giovanni
 
  ___
  Qgis-developer mailing list
  Qgis-developer@lists.osgeo.org
  http://lists.osgeo.org/mailman/listinfo/qgis-developer
 

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread Radim Blazek
On Tue, Dec 11, 2012 at 12:23 PM, G. Allegri gioha...@gmail.com wrote:
 Thanks Radim, I wasn't aware of all these news in trunk!
 The QgsRasterPipe is really powerful.

 Is there some doc about it?
 I've run through the code to understand the logic behind QgsRasterPipe (QRP)
 and QgsRasterInterface (QRI).
 I see that for a QRI must be set a an input QRI (setInput method). If I
 understand it correctly a QRP can have various branches made by sequences
 of QRI?

Do you mean QgsRasterInterface with multiple inputs? This is not
currently supported. In theory you can write an interface with
multiple inputs, but for example QgsRasterFileWriter is using some
info from srcInput, i.e. the first interface (provider) in the pipe,
there is no support for multiple srcInput. Most probably it would
work, but there some problems may appear. You could also overwrite
srcInput in your  QgsRasterInterface subclass in which multiple
branches are connected.

Radim


 giovanni


 2012/12/11 Radim Blazek radim.bla...@gmail.com

 On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com wrote:
  Until now I've mostly created vector layers on QGIS, delegating raster
  creation to custom GDAL utilities.
  Recently I looked into QgsGdalProvider and I saw that it exposes the
  QgsRasterDataProvider::Create capability.
  I wonder if it's possible to create a brand new raster (geotiff or what
  else) using this provider and, in case, what is the right workflow to do
  that. I haven't found examples of doing it...

 Yes it is possible. You can use a provider directly

 QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
 )QgsProviderRegistry::instance()-provider( gdal, dataSource );
 provider-write( data, band, width, height, xOffset, yOffset )

 if you your algorithm implemented as QgsRasterInterface you can use
 higher level QgsRasterFileWriter which will do the work splitting
 raster into parts

 QgsRasterPipe* pipe = new QgsRasterPipe();
 pipe-set( inputProvider-clone() );
 pipe-insert( 1, yourInterface );
 QgsRasterFileWriter fileWriter( fileName );
 fileWriter.writeRaster( pipe, width, height, extent, crs );

 Radim


  giovanni
 
  ___
  Qgis-developer mailing list
  Qgis-developer@lists.osgeo.org
  http://lists.osgeo.org/mailman/listinfo/qgis-developer
 


___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread G. Allegri


 Do you mean QgsRasterInterface with multiple inputs? This is not
 currently supported. In theory you can write an interface with
 multiple inputs, but for example QgsRasterFileWriter is using some
 info from srcInput, i.e. the first interface (provider) in the pipe,
 there is no support for multiple srcInput. Most probably it would
 work, but there some problems may appear. You could also overwrite
 srcInput in your  QgsRasterInterface subclass in which multiple
 branches are connected.


Ok, but I wonder what is QgsRasterInterface.setInput [1] meant for? Is the
input supposed to be only a QgsRasterDataProvider? If I see that it
requires a QgsRasterInterface I think it can be whatever
else QgsRasterInterface...

[1]
https://github.com/qgis/Quantum-GIS/blob/master/src/core/raster/qgsrasterinterface.h#L108



 Radim


  giovanni
 
 
  2012/12/11 Radim Blazek radim.bla...@gmail.com
 
  On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com
 wrote:
   Until now I've mostly created vector layers on QGIS, delegating raster
   creation to custom GDAL utilities.
   Recently I looked into QgsGdalProvider and I saw that it exposes the
   QgsRasterDataProvider::Create capability.
   I wonder if it's possible to create a brand new raster (geotiff or
 what
   else) using this provider and, in case, what is the right workflow to
 do
   that. I haven't found examples of doing it...
 
  Yes it is possible. You can use a provider directly
 
  QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
  )QgsProviderRegistry::instance()-provider( gdal, dataSource );
  provider-write( data, band, width, height, xOffset, yOffset )
 
  if you your algorithm implemented as QgsRasterInterface you can use
  higher level QgsRasterFileWriter which will do the work splitting
  raster into parts
 
  QgsRasterPipe* pipe = new QgsRasterPipe();
  pipe-set( inputProvider-clone() );
  pipe-insert( 1, yourInterface );
  QgsRasterFileWriter fileWriter( fileName );
  fileWriter.writeRaster( pipe, width, height, extent, crs );
 
  Radim
 
 
   giovanni
  
   ___
   Qgis-developer mailing list
   Qgis-developer@lists.osgeo.org
   http://lists.osgeo.org/mailman/listinfo/qgis-developer
  
 
 

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread Radim Blazek
On Tue, Dec 11, 2012 at 1:29 PM, G. Allegri gioha...@gmail.com wrote:

 Do you mean QgsRasterInterface with multiple inputs? This is not
 currently supported. In theory you can write an interface with
 multiple inputs, but for example QgsRasterFileWriter is using some
 info from srcInput, i.e. the first interface (provider) in the pipe,
 there is no support for multiple srcInput. Most probably it would
 work, but there some problems may appear. You could also overwrite
 srcInput in your  QgsRasterInterface subclass in which multiple
 branches are connected.


 Ok, but I wonder what is QgsRasterInterface.setInput [1] meant for? Is the
 input supposed to be only a QgsRasterDataProvider? If I see that it requires
 a QgsRasterInterface I think it can be whatever else QgsRasterInterface...

Yes, you are right. Any class inheriting from QgsRasterInterface may
be plugged into the QgsRasterPipe but all interfaces will be in a
single line, no forks.

BTW, you should always test if QgsRasterPipe::insert() was successful,
because if connection of interfaces fails, the interface is not
inserted. Only compatible interfaces may be connected. For example, it
is not possible to connect QgsSingleBandGrayRenderer to an interface
of ARGB32 type, because it needs numerical data as input.
QgsRasterResampleFilter only works with ARGB32 as input etc.

Radim


 [1]
 https://github.com/qgis/Quantum-GIS/blob/master/src/core/raster/qgsrasterinterface.h#L108



 Radim


  giovanni
 
 
  2012/12/11 Radim Blazek radim.bla...@gmail.com
 
  On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com
  wrote:
   Until now I've mostly created vector layers on QGIS, delegating
   raster
   creation to custom GDAL utilities.
   Recently I looked into QgsGdalProvider and I saw that it exposes the
   QgsRasterDataProvider::Create capability.
   I wonder if it's possible to create a brand new raster (geotiff or
   what
   else) using this provider and, in case, what is the right workflow to
   do
   that. I haven't found examples of doing it...
 
  Yes it is possible. You can use a provider directly
 
  QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
  )QgsProviderRegistry::instance()-provider( gdal, dataSource );
  provider-write( data, band, width, height, xOffset, yOffset )
 
  if you your algorithm implemented as QgsRasterInterface you can use
  higher level QgsRasterFileWriter which will do the work splitting
  raster into parts
 
  QgsRasterPipe* pipe = new QgsRasterPipe();
  pipe-set( inputProvider-clone() );
  pipe-insert( 1, yourInterface );
  QgsRasterFileWriter fileWriter( fileName );
  fileWriter.writeRaster( pipe, width, height, extent, crs );
 
  Radim
 
 
   giovanni
  
   ___
   Qgis-developer mailing list
   Qgis-developer@lists.osgeo.org
   http://lists.osgeo.org/mailman/listinfo/qgis-developer
  
 
 


___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread G. Allegri


 Yes, you are right. Any class inheriting from QgsRasterInterface may
 be plugged into the QgsRasterPipe but all interfaces will be in a
 single line, no forks.


Ok, Radim, I'm sorry if I insist on this, it's just to understand it
correctly.
To add a QgsRasterInterface in a QgsRasterPipe I would
use QgsRasterPipe.insert(idx,QgsRasterInterface), but what is
the QgsRasterInterface.setInput(QgsRasterInterface ) for?
If I set a QgsRasterInterface, which will have its own input, as the input
for another QgsRasterInterface, I'm creating a chain
of QgsRasterInterfaces...
Help me to understand it...

giovanni



 BTW, you should always test if QgsRasterPipe::insert() was successful,
 because if connection of interfaces fails, the interface is not
 inserted. Only compatible interfaces may be connected. For example, it
 is not possible to connect QgsSingleBandGrayRenderer to an interface
 of ARGB32 type, because it needs numerical data as input.
 QgsRasterResampleFilter only works with ARGB32 as input etc.

 Radim


  [1]
 
 https://github.com/qgis/Quantum-GIS/blob/master/src/core/raster/qgsrasterinterface.h#L108
 
 
 
  Radim
 
 
   giovanni
  
  
   2012/12/11 Radim Blazek radim.bla...@gmail.com
  
   On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com
   wrote:
Until now I've mostly created vector layers on QGIS, delegating
raster
creation to custom GDAL utilities.
Recently I looked into QgsGdalProvider and I saw that it exposes
 the
QgsRasterDataProvider::Create capability.
I wonder if it's possible to create a brand new raster (geotiff or
what
else) using this provider and, in case, what is the right workflow
 to
do
that. I haven't found examples of doing it...
  
   Yes it is possible. You can use a provider directly
  
   QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
   )QgsProviderRegistry::instance()-provider( gdal, dataSource );
   provider-write( data, band, width, height, xOffset, yOffset )
  
   if you your algorithm implemented as QgsRasterInterface you can use
   higher level QgsRasterFileWriter which will do the work splitting
   raster into parts
  
   QgsRasterPipe* pipe = new QgsRasterPipe();
   pipe-set( inputProvider-clone() );
   pipe-insert( 1, yourInterface );
   QgsRasterFileWriter fileWriter( fileName );
   fileWriter.writeRaster( pipe, width, height, extent, crs );
  
   Radim
  
  
giovanni
   
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer
   
  
  
 
 

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread Radim Blazek
On Tue, Dec 11, 2012 at 2:23 PM, G. Allegri gioha...@gmail.com wrote:

 Yes, you are right. Any class inheriting from QgsRasterInterface may
 be plugged into the QgsRasterPipe but all interfaces will be in a
 single line, no forks.


 Ok, Radim, I'm sorry if I insist on this, it's just to understand it
 correctly.
 To add a QgsRasterInterface in a QgsRasterPipe I would use
 QgsRasterPipe.insert(idx,QgsRasterInterface), but what is the
 QgsRasterInterface.setInput(QgsRasterInterface ) for?

QgsRasterInterface.setInput(QgsRasterInterface ) is used to set input,
but you dont  have to call it if you are using QgsRasterPipe because
it is called by QgsRasterPipe.insert(idx,QgsRasterInterface).

 If I set a QgsRasterInterface, which will have its own input, as the input
 for another QgsRasterInterface, I'm creating a chain of
 QgsRasterInterfaces...

Yes, QgsRasterPipe just helps you to manage such chain. It will
automatically connect the interfaces. QgsRasterPipe represents a chain
of interfaces.

Radim

 Help me to understand it...

 giovanni



 BTW, you should always test if QgsRasterPipe::insert() was successful,
 because if connection of interfaces fails, the interface is not
 inserted. Only compatible interfaces may be connected. For example, it
 is not possible to connect QgsSingleBandGrayRenderer to an interface
 of ARGB32 type, because it needs numerical data as input.
 QgsRasterResampleFilter only works with ARGB32 as input etc.

 Radim


  [1]
 
  https://github.com/qgis/Quantum-GIS/blob/master/src/core/raster/qgsrasterinterface.h#L108
 
 
 
  Radim
 
 
   giovanni
  
  
   2012/12/11 Radim Blazek radim.bla...@gmail.com
  
   On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com
   wrote:
Until now I've mostly created vector layers on QGIS, delegating
raster
creation to custom GDAL utilities.
Recently I looked into QgsGdalProvider and I saw that it exposes
the
QgsRasterDataProvider::Create capability.
I wonder if it's possible to create a brand new raster (geotiff or
what
else) using this provider and, in case, what is the right workflow
to
do
that. I haven't found examples of doing it...
  
   Yes it is possible. You can use a provider directly
  
   QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
   )QgsProviderRegistry::instance()-provider( gdal, dataSource );
   provider-write( data, band, width, height, xOffset, yOffset )
  
   if you your algorithm implemented as QgsRasterInterface you can use
   higher level QgsRasterFileWriter which will do the work splitting
   raster into parts
  
   QgsRasterPipe* pipe = new QgsRasterPipe();
   pipe-set( inputProvider-clone() );
   pipe-insert( 1, yourInterface );
   QgsRasterFileWriter fileWriter( fileName );
   fileWriter.writeRaster( pipe, width, height, extent, crs );
  
   Radim
  
  
giovanni
   
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer
   
  
  
 
 


___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


Re: [Qgis-developer] Creating a new raster qith QgsRasterLayer?

2012-12-11 Thread G. Allegri
Ok, perfect, now it's clear.

giovanni

2012/12/11 Radim Blazek radim.bla...@gmail.com

 On Tue, Dec 11, 2012 at 2:23 PM, G. Allegri gioha...@gmail.com wrote:
 
  Yes, you are right. Any class inheriting from QgsRasterInterface may
  be plugged into the QgsRasterPipe but all interfaces will be in a
  single line, no forks.
 
 
  Ok, Radim, I'm sorry if I insist on this, it's just to understand it
  correctly.
  To add a QgsRasterInterface in a QgsRasterPipe I would use
  QgsRasterPipe.insert(idx,QgsRasterInterface), but what is the
  QgsRasterInterface.setInput(QgsRasterInterface ) for?

 QgsRasterInterface.setInput(QgsRasterInterface ) is used to set input,
 but you dont  have to call it if you are using QgsRasterPipe because
 it is called by QgsRasterPipe.insert(idx,QgsRasterInterface).

  If I set a QgsRasterInterface, which will have its own input, as the
 input
  for another QgsRasterInterface, I'm creating a chain of
  QgsRasterInterfaces...

 Yes, QgsRasterPipe just helps you to manage such chain. It will
 automatically connect the interfaces. QgsRasterPipe represents a chain
 of interfaces.

 Radim

  Help me to understand it...
 
  giovanni
 
 
 
  BTW, you should always test if QgsRasterPipe::insert() was successful,
  because if connection of interfaces fails, the interface is not
  inserted. Only compatible interfaces may be connected. For example, it
  is not possible to connect QgsSingleBandGrayRenderer to an interface
  of ARGB32 type, because it needs numerical data as input.
  QgsRasterResampleFilter only works with ARGB32 as input etc.
 
  Radim
 
 
   [1]
  
  
 https://github.com/qgis/Quantum-GIS/blob/master/src/core/raster/qgsrasterinterface.h#L108
  
  
  
   Radim
  
  
giovanni
   
   
2012/12/11 Radim Blazek radim.bla...@gmail.com
   
On Tue, Dec 11, 2012 at 10:52 AM, G. Allegri gioha...@gmail.com
wrote:
 Until now I've mostly created vector layers on QGIS, delegating
 raster
 creation to custom GDAL utilities.
 Recently I looked into QgsGdalProvider and I saw that it exposes
 the
 QgsRasterDataProvider::Create capability.
 I wonder if it's possible to create a brand new raster (geotiff
 or
 what
 else) using this provider and, in case, what is the right
 workflow
 to
 do
 that. I haven't found examples of doing it...
   
Yes it is possible. You can use a provider directly
   
QgsRasterDataProvider * provider = ( QgsRasterDataProvider*
)QgsProviderRegistry::instance()-provider( gdal, dataSource );
provider-write( data, band, width, height, xOffset, yOffset )
   
if you your algorithm implemented as QgsRasterInterface you can
 use
higher level QgsRasterFileWriter which will do the work splitting
raster into parts
   
QgsRasterPipe* pipe = new QgsRasterPipe();
pipe-set( inputProvider-clone() );
pipe-insert( 1, yourInterface );
QgsRasterFileWriter fileWriter( fileName );
fileWriter.writeRaster( pipe, width, height, extent, crs );
   
Radim
   
   
 giovanni

 ___
 Qgis-developer mailing list
 Qgis-developer@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-developer

   
   
  
  
 
 

___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer