Re: [postgis-users] PL/Python

2016-05-18 Thread Martijn Meijers
I think the gdal.getDriver call returns None. Hence the attribute error on the 
line afterwards. Are you sure that 19 is what you should pass as input?

Martijn

Verzonden vanaf mobiel.

 Oorspronkelijk bericht Van: David Haynes 
 Datum:18-05-2016  17:35  (GMT+01:00) 
Aan: postgis-users@lists.osgeo.org Onderwerp: 
[postgis-users] PL/Python 
Hello,

I have a question regarding importing the gdal library using pl/python. 
Specifically, I want to create an in memory raster using the gdal library. This 
is a snippet of code that I have written,

CREATE OR REPLACE FUNCTION terrapop_area_level_to_raster2( sample_geog_level_id 
bigint, raster_variable_id bigint, raster_band bigint) RETURNS text AS
$BODY$   

from osgeo import gdal
import numpy as np
from osgeo import ogr, osr


memDriver = gdal.GetDriver(19)
#memDriver = gdal.GetDriverByName('MEM')
memRast = memDriver.Create('', 10, 10, 1, gdal.GDT_Int32)

This is the error I receive. A python NoneType error. Which seems to that the 
gdal class has not been imported. I have verified that gdal is available on the 
system. 

ERROR: AttributeError: 'NoneType' object has no attribute 'Create'
SQL state: XX000

However, this function on the same server and database returns to me all the 
gdal drivers. Any idea how I can diagnose this problem?

CREATE OR REPLACE FUNCTION gdal_drivers()
  RETURNS SETOF text AS
$BODY$

from osgeo import gdal
driver = gdal.GetDriverByName('MEM')
rast = driver.Create('', 2, 4, 1, gdal.GDT_Int32)

names = []
driverall = gdal.GetDriverCount()
for i in range(gdal.GetDriverCount()):
driver = gdal.GetDriver(i)
drivername = driver.ShortName
names.append([i,drivername])

return names

$BODY$
  LANGUAGE plpythonu VOLATILE





___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users

[postgis-users] PL/Python

2016-05-18 Thread David Haynes
Hello,

I have a question regarding importing the gdal library using pl/python.
Specifically, I want to create an in memory raster using the gdal library.
This is a snippet of code that I have written,

CREATE OR REPLACE FUNCTION terrapop_area_level_to_raster2(
sample_geog_level_id bigint, raster_variable_id bigint, raster_band bigint)
RETURNS text AS
$BODY$
from osgeo import gdal
import numpy as np
from osgeo import ogr, osr

memDriver = gdal.GetDriver(19)
#memDriver = gdal.GetDriverByName('MEM')
memRast = memDriver.Create('', 10, 10, 1, gdal.GDT_Int32)

This is the error I receive. A python NoneType error. Which seems to that
the gdal class has not been imported. I have verified that gdal is
available on the system.

ERROR: AttributeError: 'NoneType' object has no attribute 'Create'
SQL state: XX000

However, this function on the same server and database returns to me all
the gdal drivers. Any idea how I can diagnose this problem?

CREATE OR REPLACE FUNCTION gdal_drivers()
  RETURNS SETOF text AS
$BODY$

from osgeo import gdal
driver = gdal.GetDriverByName('MEM')
rast = driver.Create('', 2, 4, 1, gdal.GDT_Int32)

names = []
driverall = gdal.GetDriverCount()
for i in range(gdal.GetDriverCount()):
driver = gdal.GetDriver(i)
drivername = driver.ShortName
names.append([i,drivername])

return names

$BODY$
  LANGUAGE plpythonu VOLATILE
___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users