Re: [postgis-users] PL/Python

2016-05-23 Thread David Haynes
Hello Remi,

Do you know who, what list I should report this to? In my work I found is
that plpython doesn't work well with the memory drivers for gdal or ogr.
Specifically when I would run the my code it might create the raster
dataset in memory and the for no apparent reason it would terminate the
database connection. I thought this was specific to gdal memory until I
encountered some downstream issues with vector datasets.

The error was resolved choosing actual directories and writing the data
there. I suppose that there would have to a specific plpython memory driver.



On Sat, May 21, 2016 at 5:04 AM, Rémi Cura  wrote:

> Hey,
> debuggin plpython is a bit of a pain.
> Maybe you are aware that you can use
> plpy.notice to print values during execution.
>
> This blog
> 
> seems to indicate that what you do should work:
>
> driver = gdal.GetDriverByName( 'MEM' )
> ds = driver.Create( '', 255, 255, 1, gdal.GDT_Int32)
>
>
> Maybe you can check that executing that in plain python while logged as 
> postgres works?
>
> Cheers,
> Rémi-C
>
>
>
>
>
> 2016-05-18 21:26 GMT+02:00 David Haynes :
>
>> Yes because the second function in my doesn't error.
>>
>> On Wed, May 18, 2016 at 12:06 PM, Martijn Meijers > > wrote:
>>
>>> 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 mailing list
>> postgis-users@lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/postgis-users
>>
>
>
> ___
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/postgis-users
>
___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users

Re: [postgis-users] POINT/MULTIPOINT EMPTY problem in dump

2016-05-23 Thread Jan Michálek
My trick with EWKT doesn't help, but your advice help me.

Thanks Je;

2016-05-23 13:22 GMT+02:00 Leknín Řepánek :

> Hm, maybe i can use EWKT notation instead of binary.
>
> On Sun, May 22, 2016 at 06:10:46PM -0700, Paul Ramsey wrote:
> > Temporarily change column type of the table you're loading from
> > Geometry(Point) to just plain Geometry, then you can load both types
> > and then change the MULTIPOINT EMPTY to POINT EMPTY then change the
> > type back to Geometry(Point)
> >
> > P
> >
> > On Sun, May 22, 2016 at 2:19 PM, Jan Michálek 
> wrote:
> > > I need to solve this problem
> > >
> > > I have in table column POINT, some of values ARE 'POINT EMPTY' (dont
> ask me
> > > why, it is not my table).
> > > MULTIPOINT EMPTY and POINT EMPTY has same representation
> > > (010400).
> > > If i try restore table from dump, it is problem because postgis read
> this as
> > > multipoint empty, but the column has type POINT.
> > > My version of postgis
> > >
> > > jelen=# select postgis_version();
> > > postgis_version
> > > ---
> > >  2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
> > > (1 row)
> > >
> > > Postgre is 9.3.
> > >
> > > Is there somebody who knows how to solve this problem?
> > >
> > > Thanks Je;
> > >
> > > --
> > > jelen=# CREATE TABLE t3 (id serial primary key, geom geometry(POINT,
> 0));
> > > CREATE TABLE
> > > jelen=# insert into t3(geom) VALUES ('POINT EMPTY'::geometry);
> > > INSERT 0 1
> > > jelen=# SELECT geom from t3;
> > > geom
> > > 
> > >  010400
> > > (1 row)
> > >
> > > jelen=# SELECT ST_AsText('010400');
> > > st_astext
> > > --
> > >  MULTIPOINT EMPTY
> > > (1 row)
> > >
> > > jelen=# INSERT INTO t3(geom) values('010400');
> > > ERROR:  Geometry type (MultiPoint) does not match column type (Point)
> > > jelen=# insert into t3(geom) SELECT geom FROM t3;
> > > INSERT 0 1
> > > jelen=#
> > > ---
> > >
> > >
> > > --
> > > Jelen
> > > Starší čeledín datovýho chlíva
> > >
> > > ___
> > > postgis-users mailing list
> > > postgis-users@lists.osgeo.org
> > > http://lists.osgeo.org/mailman/listinfo/postgis-users
> > ___
> > postgis-users mailing list
> > postgis-users@lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/postgis-users
>



-- 
Jelen
Starší čeledín datovýho chlíva
___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users

Re: [postgis-users] POINT/MULTIPOINT EMPTY problem in dump

2016-05-23 Thread Leknín Řepánek
Hm, maybe i can use EWKT notation instead of binary.

On Sun, May 22, 2016 at 06:10:46PM -0700, Paul Ramsey wrote:
> Temporarily change column type of the table you're loading from
> Geometry(Point) to just plain Geometry, then you can load both types
> and then change the MULTIPOINT EMPTY to POINT EMPTY then change the
> type back to Geometry(Point)
> 
> P
> 
> On Sun, May 22, 2016 at 2:19 PM, Jan Michálek  wrote:
> > I need to solve this problem
> >
> > I have in table column POINT, some of values ARE 'POINT EMPTY' (dont ask me
> > why, it is not my table).
> > MULTIPOINT EMPTY and POINT EMPTY has same representation
> > (010400).
> > If i try restore table from dump, it is problem because postgis read this as
> > multipoint empty, but the column has type POINT.
> > My version of postgis
> >
> > jelen=# select postgis_version();
> > postgis_version
> > ---
> >  2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
> > (1 row)
> >
> > Postgre is 9.3.
> >
> > Is there somebody who knows how to solve this problem?
> >
> > Thanks Je;
> >
> > --
> > jelen=# CREATE TABLE t3 (id serial primary key, geom geometry(POINT, 0));
> > CREATE TABLE
> > jelen=# insert into t3(geom) VALUES ('POINT EMPTY'::geometry);
> > INSERT 0 1
> > jelen=# SELECT geom from t3;
> > geom
> > 
> >  010400
> > (1 row)
> >
> > jelen=# SELECT ST_AsText('010400');
> > st_astext
> > --
> >  MULTIPOINT EMPTY
> > (1 row)
> >
> > jelen=# INSERT INTO t3(geom) values('010400');
> > ERROR:  Geometry type (MultiPoint) does not match column type (Point)
> > jelen=# insert into t3(geom) SELECT geom FROM t3;
> > INSERT 0 1
> > jelen=#
> > ---
> >
> >
> > --
> > Jelen
> > Starší čeledín datovýho chlíva
> >
> > ___
> > postgis-users mailing list
> > postgis-users@lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/postgis-users
> ___
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/postgis-users
___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users

Re: [postgis-users] POINT/MULTIPOINT EMPTY problem in dump

2016-05-23 Thread Jan Michálek
I will try.
Thanks.

2016-05-23 3:10 GMT+02:00 Paul Ramsey :

> Temporarily change column type of the table you're loading from
> Geometry(Point) to just plain Geometry, then you can load both types
> and then change the MULTIPOINT EMPTY to POINT EMPTY then change the
> type back to Geometry(Point)
>
> P
>
> On Sun, May 22, 2016 at 2:19 PM, Jan Michálek 
> wrote:
> > I need to solve this problem
> >
> > I have in table column POINT, some of values ARE 'POINT EMPTY' (dont ask
> me
> > why, it is not my table).
> > MULTIPOINT EMPTY and POINT EMPTY has same representation
> > (010400).
> > If i try restore table from dump, it is problem because postgis read
> this as
> > multipoint empty, but the column has type POINT.
> > My version of postgis
> >
> > jelen=# select postgis_version();
> > postgis_version
> > ---
> >  2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
> > (1 row)
> >
> > Postgre is 9.3.
> >
> > Is there somebody who knows how to solve this problem?
> >
> > Thanks Je;
> >
> > --
> > jelen=# CREATE TABLE t3 (id serial primary key, geom geometry(POINT, 0));
> > CREATE TABLE
> > jelen=# insert into t3(geom) VALUES ('POINT EMPTY'::geometry);
> > INSERT 0 1
> > jelen=# SELECT geom from t3;
> > geom
> > 
> >  010400
> > (1 row)
> >
> > jelen=# SELECT ST_AsText('010400');
> > st_astext
> > --
> >  MULTIPOINT EMPTY
> > (1 row)
> >
> > jelen=# INSERT INTO t3(geom) values('010400');
> > ERROR:  Geometry type (MultiPoint) does not match column type (Point)
> > jelen=# insert into t3(geom) SELECT geom FROM t3;
> > INSERT 0 1
> > jelen=#
> > ---
> >
> >
> > --
> > Jelen
> > Starší čeledín datovýho chlíva
> >
> > ___
> > postgis-users mailing list
> > postgis-users@lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/postgis-users
> ___
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/postgis-users




-- 
Jelen
Starší čeledín datovýho chlíva
___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users