Re: [gdal-dev] Creating derived raster bands using python

2009-03-08 Thread Antonio Valentino
Il giorno Thu, 05 Mar 2009 09:26:51 -0500
Frank Warmerdam  ha scritto:

> Antonio Valentino wrote:
> > Hi list,
> > I'm trying to create a *Derived* raster band in a virtual dataset.
> > 
> > All my attempts seems to fail:
> > 
>  ds.AddBand(options={'subClass': 'VRTDerivedRasterBand'})
> > 
> > raises an exception while
> > 
>  ds.AddBand(options='subClass="VRTDerivedRasterBand"')
>  ds.AddBand(options=['subClass="VRTDerivedRasterBand"'])
> 
> Antonio,
> 
> I believe the correct syntax is:
> 
>ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> 
> The options should be a list of name=value pairs.  Your extra double
> quotes within the string will make the class name comparison fail
> since you are effectively passing "\"VRTDerivedRasterBand\"" in C
> terms.
> 
> Best regards,

Hi Frank,
thanks for helping.

I'm still having problems trying to create a derived raster bands via
python.
I'm using Ubuntu 8.10

$ uname -a
Linux mac1 2.6.27-13-generic #1 SMP Thu Feb 26 07:31:49 UTC 2009 x86_64
GNU/Linux

with GDAL 1.5.4 package from UbuntuGIS repo
(python-gdal_1.5.4-2~intreid3).

The execution of the following test script produces a segmentation
fault:

### BEGIN CODE
from osgeo import gdal
driver = gdal.GetDriverByName('VRT')
source_xml = '''
  test.tif
'''

md = {'Description': 'Magnitude', 'PixelFunctionType': 'module',
'source_0': source_xml}

ds = driver.Create('test.vrt', 100, 100)
b = ds.GetRasterBand(1)
b.SetMetadata({'source_0': source_xml}, 'new_vrt_sources')
ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
b = ds.GetRasterBand(2)
b.SetMetadata(md, 'new_vrt_sources')
del ds
print open('test.vrt').read()
### END CODE

$ python test_derivedband.py
ERROR 1: Corrupt or empty VRT source XML document.
Segmentation fault


Maybe I'm still doing something wrong but the segfault is anomalous in
any case.

Should I create a ticket for this?


Regards

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


[gdal-dev] ogr2ogr: Dataset creation option (format specific)

2009-03-08 Thread Hermann Peifer

Hi,

The ogr2ogr man page has some limited documentation on the -dsco switch:

-dsco NAME=VALUE: Dataset creation option (format specific)

Can someone point me to some more specific information?

Thanks in advance, Hermann

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


Re: [gdal-dev] ogr2ogr: Dataset creation option (format specific)

2009-03-08 Thread Even Rouault
Hermann,

As suggested by the man page of ogr2ogr, dataset creation options are specific 
to each driver. So you have to look at the documentation of the OGR driver 
you're interested in to see which dataset creation options it offers : 
http://gdal.org/ogr/ogr_formats.html

Even

Le Sunday 08 March 2009 19:26:17 Hermann Peifer, vous avez écrit :
> Hi,
>
> The ogr2ogr man page has some limited documentation on the -dsco switch:
>
> -dsco NAME=VALUE: Dataset creation option (format specific)
>
> Can someone point me to some more specific information?
>
> Thanks in advance, Hermann
>
> ___
> gdal-dev mailing list
> gdal-dev@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


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


Re: [gdal-dev] Creating derived raster bands using python

2009-03-08 Thread Even Rouault
Antonio,

There are 2 issues :
-  the "ERROR 1: Corrupt or empty VRT source XML document." comes from the 
line 'b.SetMetadata(md, 'new_vrt_sources')'. However I'm not sure how to 
achieve what you want to do. I've the feeling you can't really define the 
pixel function that way. You should call GDALAddDerivedBandPixelFunc to do 
that, but as it is not available in Python bindings, I think you're only 
solution is to generate the whole XML at hand.

- the crash comes from the fact that you don't have defined a pixel function 
for the derived band. I've created ticket 
http://trac.osgeo.org/gdal/ticket/2877 about that one.

Best regards,
Even

Le Sunday 08 March 2009 13:30:05 Antonio Valentino, vous avez écrit :
> Il giorno Thu, 05 Mar 2009 09:26:51 -0500
>
> Frank Warmerdam  ha scritto:
> > Antonio Valentino wrote:
> > > Hi list,
> > > I'm trying to create a *Derived* raster band in a virtual dataset.
> > >
> > > All my attempts seems to fail:
> >  ds.AddBand(options={'subClass': 'VRTDerivedRasterBand'})
> > >
> > > raises an exception while
> > >
> >  ds.AddBand(options='subClass="VRTDerivedRasterBand"')
> >  ds.AddBand(options=['subClass="VRTDerivedRasterBand"'])
> >
> > Antonio,
> >
> > I believe the correct syntax is:
> >
> >ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> >
> > The options should be a list of name=value pairs.  Your extra double
> > quotes within the string will make the class name comparison fail
> > since you are effectively passing "\"VRTDerivedRasterBand\"" in C
> > terms.
> >
> > Best regards,
>
> Hi Frank,
> thanks for helping.
>
> I'm still having problems trying to create a derived raster bands via
> python.
> I'm using Ubuntu 8.10
>
> $ uname -a
> Linux mac1 2.6.27-13-generic #1 SMP Thu Feb 26 07:31:49 UTC 2009 x86_64
> GNU/Linux
>
> with GDAL 1.5.4 package from UbuntuGIS repo
> (python-gdal_1.5.4-2~intreid3).
>
> The execution of the following test script produces a segmentation
> fault:
>
> ### BEGIN CODE
> from osgeo import gdal
> driver = gdal.GetDriverByName('VRT')
> source_xml = '''
>   test.tif
> '''
>
> md = {'Description': 'Magnitude', 'PixelFunctionType': 'module',
> 'source_0': source_xml}
>
> ds = driver.Create('test.vrt', 100, 100)
> b = ds.GetRasterBand(1)
> b.SetMetadata({'source_0': source_xml}, 'new_vrt_sources')
> ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> b = ds.GetRasterBand(2)
> b.SetMetadata(md, 'new_vrt_sources')
> del ds
> print open('test.vrt').read()
> ### END CODE
>
> $ python test_derivedband.py
> ERROR 1: Corrupt or empty VRT source XML document.
> Segmentation fault
>
>
> Maybe I'm still doing something wrong but the segfault is anomalous in
> any case.
>
> Should I create a ticket for this?
>
>
> Regards


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


Re: [gdal-dev] Creating derived raster bands using python

2009-03-08 Thread Even Rouault
Forget what I told about GDALAddDerivedBandPixelFunc ... This is certainly not 
the way to define the function name.

Le Sunday 08 March 2009 20:51:46 Even Rouault, vous avez écrit :
> Antonio,
>
> There are 2 issues :
> -  the "ERROR 1: Corrupt or empty VRT source XML document." comes from the
> line 'b.SetMetadata(md, 'new_vrt_sources')'. However I'm not sure how to
> achieve what you want to do. I've the feeling you can't really define the
> pixel function that way. You should call GDALAddDerivedBandPixelFunc to do
> that, but as it is not available in Python bindings, I think you're only
> solution is to generate the whole XML at hand.
>
> - the crash comes from the fact that you don't have defined a pixel
> function for the derived band. I've created ticket
> http://trac.osgeo.org/gdal/ticket/2877 about that one.
>
> Best regards,
> Even
>
> Le Sunday 08 March 2009 13:30:05 Antonio Valentino, vous avez écrit :
> > Il giorno Thu, 05 Mar 2009 09:26:51 -0500
> >
> > Frank Warmerdam  ha scritto:
> > > Antonio Valentino wrote:
> > > > Hi list,
> > > > I'm trying to create a *Derived* raster band in a virtual dataset.
> > > >
> > > > All my attempts seems to fail:
> > >  ds.AddBand(options={'subClass': 'VRTDerivedRasterBand'})
> > > >
> > > > raises an exception while
> > > >
> > >  ds.AddBand(options='subClass="VRTDerivedRasterBand"')
> > >  ds.AddBand(options=['subClass="VRTDerivedRasterBand"'])
> > >
> > > Antonio,
> > >
> > > I believe the correct syntax is:
> > >
> > >ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> > >
> > > The options should be a list of name=value pairs.  Your extra double
> > > quotes within the string will make the class name comparison fail
> > > since you are effectively passing "\"VRTDerivedRasterBand\"" in C
> > > terms.
> > >
> > > Best regards,
> >
> > Hi Frank,
> > thanks for helping.
> >
> > I'm still having problems trying to create a derived raster bands via
> > python.
> > I'm using Ubuntu 8.10
> >
> > $ uname -a
> > Linux mac1 2.6.27-13-generic #1 SMP Thu Feb 26 07:31:49 UTC 2009 x86_64
> > GNU/Linux
> >
> > with GDAL 1.5.4 package from UbuntuGIS repo
> > (python-gdal_1.5.4-2~intreid3).
> >
> > The execution of the following test script produces a segmentation
> > fault:
> >
> > ### BEGIN CODE
> > from osgeo import gdal
> > driver = gdal.GetDriverByName('VRT')
> > source_xml = '''
> >   test.tif
> > '''
> >
> > md = {'Description': 'Magnitude', 'PixelFunctionType': 'module',
> > 'source_0': source_xml}
> >
> > ds = driver.Create('test.vrt', 100, 100)
> > b = ds.GetRasterBand(1)
> > b.SetMetadata({'source_0': source_xml}, 'new_vrt_sources')
> > ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> > b = ds.GetRasterBand(2)
> > b.SetMetadata(md, 'new_vrt_sources')
> > del ds
> > print open('test.vrt').read()
> > ### END CODE
> >
> > $ python test_derivedband.py
> > ERROR 1: Corrupt or empty VRT source XML document.
> > Segmentation fault
> >
> >
> > Maybe I'm still doing something wrong but the segfault is anomalous in
> > any case.
> >
> > Should I create a ticket for this?
> >
> >
> > Regards
>
> ___
> gdal-dev mailing list
> gdal-dev@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


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


Re: [gdal-dev] Creating derived raster bands using python

2009-03-08 Thread Antonio Valentino
Il giorno Sun, 8 Mar 2009 20:51:46 +0100
Even Rouault  ha scritto:

> Antonio,
> 
> There are 2 issues :

[cut]

> - the crash comes from the fact that you don't have defined a pixel
> function for the derived band. I've created ticket 
> http://trac.osgeo.org/gdal/ticket/2877 about that one.

Even, 
I didn't say in previous post but the test.tif actually exists and the
pixel function "module" is defined. I did it via a fake plugin that
registers pixel-functions and then put it in the GDAL_DRIVER_PATH.

If I manually write the VRT file all works well:

$ cat test1.vrt 

   Magnitude
module

  test.tif
  1

  


$ gdal_translate test1.vrt out.tif
Input file size is 100, 100
0...10...20...30...40...50...60...70...80...90...100 - done.

I'm just not able to write the VRT file using python.

thanks for help

> Le Sunday 08 March 2009 13:30:05 Antonio Valentino, vous avez écrit :
> > Il giorno Thu, 05 Mar 2009 09:26:51 -0500
> >
> > Frank Warmerdam  ha scritto:
> > > Antonio Valentino wrote:
> > > > Hi list,
> > > > I'm trying to create a *Derived* raster band in a virtual
> > > > dataset.
> > > >
> > > > All my attempts seems to fail:
> > >  ds.AddBand(options={'subClass': 'VRTDerivedRasterBand'})
> > > >
> > > > raises an exception while
> > > >
> > >  ds.AddBand(options='subClass="VRTDerivedRasterBand"')
> > >  ds.AddBand(options=['subClass="VRTDerivedRasterBand"'])
> > >
> > > Antonio,
> > >
> > > I believe the correct syntax is:
> > >
> > >ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> > >
> > > The options should be a list of name=value pairs.  Your extra
> > > double quotes within the string will make the class name
> > > comparison fail since you are effectively passing
> > > "\"VRTDerivedRasterBand\"" in C terms.
> > >
> > > Best regards,
> >
> > Hi Frank,
> > thanks for helping.
> >
> > I'm still having problems trying to create a derived raster bands
> > via python.
> > I'm using Ubuntu 8.10
> >
> > $ uname -a
> > Linux mac1 2.6.27-13-generic #1 SMP Thu Feb 26 07:31:49 UTC 2009
> > x86_64 GNU/Linux
> >
> > with GDAL 1.5.4 package from UbuntuGIS repo
> > (python-gdal_1.5.4-2~intreid3).
> >
> > The execution of the following test script produces a segmentation
> > fault:
> >
> > ### BEGIN CODE
> > from osgeo import gdal
> > driver = gdal.GetDriverByName('VRT')
> > source_xml = '''
> >   test.tif
> > '''
> >
> > md = {'Description': 'Magnitude', 'PixelFunctionType': 'module',
> > 'source_0': source_xml}
> >
> > ds = driver.Create('test.vrt', 100, 100)
> > b = ds.GetRasterBand(1)
> > b.SetMetadata({'source_0': source_xml}, 'new_vrt_sources')
> > ds.AddBand(options=['subClass=VRTDerivedRasterBand'])
> > b = ds.GetRasterBand(2)
> > b.SetMetadata(md, 'new_vrt_sources')
> > del ds
> > print open('test.vrt').read()
> > ### END CODE
> >
> > $ python test_derivedband.py
> > ERROR 1: Corrupt or empty VRT source XML document.
> > Segmentation fault
> >
> >
> > Maybe I'm still doing something wrong but the segfault is anomalous
> > in any case.
> >
> > Should I create a ticket for this?
> >
> >
> > Regards
> 
> 



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


Re: [gdal-dev] create 25D MultiPolygon how to

2009-03-08 Thread legeochen
Wow:
I have tried your suggestion. but it won't work. It seems the shp file
create by ogr is a little different from which generated with shplib.
reading shp file ceated by ogr with shplib gives me warning like the dbf.
containe different record than shp. Actually, only the first geometry can be
read out.
2009/3/3 legeochen 

> Wow:
>  Tanks for your suggestion! Yeaph! That maybe where the rub is. I will try
> it out soon.
> cheers!
>
> 2009/3/3 wow <27949...@qq.com>
>
>  Hi,
>>  Your code looks like that you didn't create any field for the feature. At
>> least create one field would ensure success.
>> Like this:
>> OGRFieldDefn oField( "Name", OFTString );
>> oField.SetWidth(32);
>> if( pLayer->CreateField( &oField ) != OGRERR_NONE )
>> {
>> printf( "Creating Name field failed.\n" );
>> exit( 1 );
>> }
>>
>> Xuexia Chen
>>  --
>> To the world you're little, but to a person, maybe you're the world.
>>
>>
>>
>>
>> -- Original --
>>  *From: * "legeochen";
>> *Date: * Fri, Feb 27, 2009 09:47 PM
>> *To: * "Gdal-Dev";
>>  *Subject: * [gdal-dev] create 25D MultiPolygon how to
>>
>>  Hi All
>> I try to create some multipolygons?with OGR.?After creating them, but when
>> I want view them in arcscene, it just make arcscene crash! Then I tried
>> osgviewer with ESRI Shapefile, I was warned:
>> ESRIShape loader: .dbf file containe different record number that .shp
>> file.
>>  .dbf record skipped.
>> Actually, only one feature in the dataset had been readed out.
>> Then, I tried osgviewer with ogr, got warnings like this:
>> Warning something wrong with a polygon in a multi polygon.
>> And, the result is not quite as expected!
>> Here is?my code:
>> ?const char* pszDriverName = "ESRI Shapefile";
>> ?OGRSFDriver *poDriver;
>> ?OGRRegisterAll();
>> ??? poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
>> ??? pszDriverName );
>> ??? if( poDriver == NULL )
>> ??? {
>> ??? printf( "%s driver not available.\n", pszDriverName );
>> ??? return false;
>> ??? }
>> ?OGRDataSource *poDS;
>> ?poDS = poDriver->Open(shpfile,TRUE);
>> ?if(poDS == NULL)
>> ??poDS = poDriver->CreateDataSource(shpfile,NULL);
>> ?if(poDS == NULL)
>> ?{
>> ??printf("Creation of output file failed.\n");
>> ??return false;
>> ?}
>> ?OGRLayer* poLayer = poDS->GetLayerByName (layername);
>> ?if(poLayer == NULL)
>> ?{
>> ??if( !poDS->TestCapability( ODsCCreateLayer ) )
>> ??? {
>> ??? fprintf( stderr,
>> ? "Layer Roadway not found, and CreateLayer not supported by
>> driver." );
>> ??? return FALSE;
>> ??? }
>> ??CPLErrorReset();
>> ??poLayer = poDS->CreateLayer(layername,NULL,wkbMultiPolygon25D,NULL);
>> ??if(poLayer == NULL)
>> ??{
>> ???printf( "Layer creation failed.\n" );
>> ???return false;
>> ??}
>> ?}
>>
>> ?for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw !=
>> _roadwayArr.end();itrw++)
>> ?{
>> ??OGRFeature *poFeature;
>> ??
>> ??OGRMultiPolygon multiPoly;
>> ??poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());
>> ??Roadway::Triangle_list tris = (*itrw)->getTrianglelist();
>> ??for(Triangle_list::const_iterator ittri = tris.begin();ittri !=
>> tris.end();ittri++)
>> ??{
>> ???OGRPolygon polygon;
>> ???OGRLinearRing poRing;
>> ???poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z());
>> ???poRing.addPoint((*ittri).b().x(),(*ittri).b().y(),(*ittri).b().z());
>> ???poRing.addPoint((*ittri).c().x(),(*ittri).c().y(),(*ittri).c().z());
>> ???poRing.addPoint((*ittri).a().x(),(*ittri).a().y(),(*ittri).a().z());
>> ???
>> ???polygon.addRing(&poRing);
>> ???multiPoly.addGeometry(&polygon);
>> ???
>> ??}
>> ??poFeature->SetGeometry(&multiPoly);
>> ??if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
>> ??{
>> ???printf( "Failed to create feature in shapefile.\n" );??
>> ???return false;
>> ??}
>> ??OGRFeature::DestroyFeature( poFeature );
>> ?}
>> ?OGRDataSource::DestroyDataSource( poDS );
>> Any help is appreciated!!?
>> ?
>>
>
>
>
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

[gdal-dev] Re: ogr2ogr: Dataset creation option (format specific)

2009-03-08 Thread Hermann Peifer

Even Rouault wrote:

Hermann,

As suggested by the man page of ogr2ogr, dataset creation options are specific 
to each driver. So you have to look at the documentation of the OGR driver 
you're interested in to see which dataset creation options it offers : 
http://gdal.org/ogr/ogr_formats.html




Even,

Thanks for the hint. I should have been able to find this page myself.

I was actually hoping to find some KML driver options which would allow me to 
remove meaningless coordinate precision from the KML output. Unfortunately 
there aren't any such options at  http://gdal.org/ogr/drv_kml.html

Hermann

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