[sqlalchemy] Need help using PostGIS + GeoAlchemy

2012-08-09 Thread Vlad K.


Hello,


I'm trying to use PostGIS with GeoAlchemy, being totally new to both. 
According to available documentation and what I need (A point 
representing longitude and latitude of row), I have


   class PointOfInterest(Base):
__tablename__ = ...

...

geom = geoalchemy.GeometryColumn(Point(2))



To read from geom column, I apparently need:

   poi = PointOfInterest()

   lon = session.scalar(poi.geom.x)
   lat = session.scalar(poi.geom.y)


And to set the value I need

   poi.geom = geoalchemy.WKTSpatialElement(POINT({lon}
   {lat}).format(lon, lat))


Of course, the above is possibly vulnerable for sql injections so I must 
make sure lon and lat are really numbers.



But is there a simpler/safer/saner way to do both? Can I update the geom 
column somehow to set only one value of the pair?



Also, I'm not quite sure how to query rows with X, Y being with N units 
of a reference point X0, Y0?



Thanks.


--


.oO V Oo.


Work Hard,
Increase Production,
Prevent Accidents,
and
Be Happy!  ;)

--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Postgres migration issue

2012-08-09 Thread Warwick Prince
Hi

I usually use MySQL to develop on, however I need to work with Postgres for the 
first time today so I fired it up.  I have a routine which converts a non-SQL 
database into the database of choice, converting its schema into a new table in 
the target database using SQA, and then copies all the data in the source 
database into the new SQL table.   

That all worked fine into the Postgres+pg8000 database.  My problem is when I 
then attempt to open up a table again using auto reflection I get an error I've 
never seen before, and I don't get how this can be, given the table was created 
via sqlalchemy?  The data looks fine in the table, and all columns are created 
as I expected (converting to the correct Postrgres column types etc.

Error when I issue   t = Table('my_table', meta, autoload=True) is; (sorry 
about the screen shot, I'm working in a bad RDP client and can't cut/paste into 
my Mac. :-(



So it appears to be having some problem in the reflection, but I can't see why 
- I hope there is a setting in the connection or something I can do to fix this 
up?  I've never used Postgres before, so I'm groping in the dark..   From 
Googling around, it appears that there is some issue with determining the 
schema or some such, but it's all assuming I know a lot more about Postgres 
than I do!

Cheers
Warwick

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

inline: PastedGraphic-1.png

[sqlalchemy] Re: Postgres migration issue

2012-08-09 Thread Warwick Prince

 Hi
 
 I usually use MySQL to develop on, however I need to work with Postgres for 
 the first time today so I fired it up.  I have a routine which converts a 
 non-SQL database into the database of choice, converting its schema into a 
 new table in the target database using SQA, and then copies all the data in 
 the source database into the new SQL table.   
 
 That all worked fine into the Postgres+pg8000 database.  My problem is when I 
 then attempt to open up a table again using auto reflection I get an error 
 I've never seen before, and I don't get how this can be, given the table was 
 created via sqlalchemy?  The data looks fine in the table, and all columns 
 are created as I expected (converting to the correct Postrgres column types 
 etc.
 
 Error when I issue   t = Table('my_table', meta, autoload=True) is; (sorry 
 about the screen shot, I'm working in a bad RDP client and can't cut/paste 
 into my Mac. :-(
 
 PastedGraphic-1.png
 
 So it appears to be having some problem in the reflection, but I can't see 
 why - I hope there is a setting in the connection or something I can do to 
 fix this up?  I've never used Postgres before, so I'm groping in the dark..   
 From Googling around, it appears that there is some issue with determining 
 the schema or some such, but it's all assuming I know a lot more about 
 Postgres than I do!
 
 Cheers
 Warwick
 

Further to the above - I looked into my code for the database cloning explained 
above, to see how IT opened the table.  It worked because I was still using the 
same MetaData object, therefore the column defs were cached.  The error happens 
on a virgin MetaData object with autoload.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Postgres migration issue

2012-08-09 Thread David Moore
- Original Message -

 Hi

 I usually use MySQL to develop on, however I need to work with
 Postgres for the first time today so I fired it up. I have a routine
 which converts a non-SQL database into the database of choice,
 converting its schema into a new table in the target database using
 SQA, and then copies all the data in the source database into the
 new SQL table.

 That all worked fine into the Postgres+pg8000 database. My problem is
 when I then attempt to open up a table again using auto reflection I
 get an error I've never seen before, and I don't get how this can
 be, given the table was created via sqlalchemy? The data looks fine
 in the table, and all columns are created as I expected (converting
 to the correct Postrgres column types etc.

 Error when I issue t = Table('my_table', meta, autoload=True) is;
 (sorry about the screen shot, I'm working in a bad RDP client and
 can't cut/paste into my Mac. :-(

 So it appears to be having some problem in the reflection, but I
 can't see why - I hope there is a setting in the connection or
 something I can do to fix this up? I've never used Postgres before,
 so I'm groping in the dark.. From Googling around, it appears that
 there is some issue with determining the schema or some such, but
 it's all assuming I know a lot more about Postgres than I do!

 Cheers
 Warwick

Hi Warwick, 

You are using pg8000 1.08 and PostgreSQL = 9.0. Upgrade to pg8000 1.09, it 
fixes this issue (there are new PostgreSQL types introduced in version 9 which 
pg8000 didn't know of in 1.08, and added in 1.09). 

regards 
-- 

David Moore 
Senior Software Engineer 
St. James Software 
Email: dav...@sjsoft.com 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

attachment: PastedGraphic-1.png