469,921 Members | 2,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,921 developers. It's quick & easy.

Read polyline data from postgres/postgis database


I hope i don't spam this thread, I did not want to open a new thread. I'm a noob here (programming). I need help with creating the program. I need to connect to the database- postgres/postgis (only polylines in there) using Python and pull data from it and plot them (visualize on screen). Can someone help? The easiest way for me would have been to have a code which I could adjust to my database.

Thanks a lot
Oct 20 '09 #1
6 3613
391 Expert 256MB

Your best bet is to start a new thread, with more specific details about what you want to do, and what you've tried.

You'll find people happy to engage, with details, but less happy to engage with generalities, or when the impression is given that you haven't tried yourself.

Try to state the big picture of what you're trying to do, as well as the details, because sometimes people with experience know some shortcuts which you haven't thought off.

Oct 21 '09 #2
2,851 Expert Mod 2GB

I created a new thread for your question. Asking a new question in an existing thread is called "hijacking".

Matplotlib would be the obvious choice for plotting the data. Reading the data is the first hurdle. Personally, I have no experience with postgres/postgis. If the data was in a simple text file, I may be able to help you.

Were you planning to read the database using Python?

Oct 21 '09 #3
Thanks for answers!

Yes, I planned to read the database using the Python. I heard for matplotlib, I think it would be the most appropriate for my project. Whether it would be helpful using psycopg lib?- I'm not sure what's the difference, and as I said, I'm complete noob here. I started to read some tutorials and 'Python for beginners', I hope to learn something.
I'm not sure if the data is a simple text file, but in my database i have table with 3 columns: id, admapkey (both 'integer' type) and third column is 'geometry' type of data. Data from third column looks like this:

0103000000010000000E000000A857CA9A564455413AB4C8B6 775B5341B6D1007E56445541B81E859B7B5B5341BE9F1A1B5C 445541386744457B5B534190A0F83D5C44554165AA1....... .........................

I don't know what to do with this 'coded' coordinates :).

I don't know how to start programing but I think that the sequence should look like this; first i have to import libraries, connect to database somehow, then read the database and get the coordinates and the final step would be to show polylines graphically.

Thanks for your help and your time
Oct 21 '09 #4
2,851 Expert Mod 2GB
You might try MySQLdb (user guide) which works similar to psycopg2.
Oct 21 '09 #5
391 Expert 256MB

I think you've got the steps right. It's just a question of putting it all together. Python is almost certainly the right choice for you. A couple of things remain a little unclear to me.

1. the format of your data. For example if you open it with wordpad or some similar text editor what does it look like. You could try something like:
Expand|Select|Wrap|Line Numbers
  1. myFile = open("yourGISfilename.whatever","r") 
  2. for i,line in enumerate(myFile):
  3.     if i>10: break
  4.     print i, line
  5. myFile.close()
This should print out the first ten lines of your file. Post back what you get and it will help us to determine whether this very basic approach will be sufficient, or if you need something more.

2. the decoding of your third column. This string is meaningless to me. However, if you know what it means, then extracting the plotable data should be quite easy. There are a number of tricks. Regular expressions is a common one - hugely powerful, but may take a minute to get your head around if you've not seen them before. Otherwise there are many other functions for fiddling around with strings.

By the time these two are done, the rest is pretty standard. But let's get to the point where you can extract the data, and then we'll move on to the next bit.

Oct 22 '09 #6

allthough the topic is a little old i try to clear some points here.

1. your 'coded' geometry means sth. like <geom_type>(List_of_coordinates), eg. MULTIPOYGON((1 1, 2 2, 0 1), (5 0, 2 1, 3 4)).
2. Do not know if there is the one file that contains whole database-data in postgres.
3. When only want to visualize your databse, why dont you use some GIS-software (QGIS, OpenJump). Then you have many possibilities of adding a layer into your map (for you it might be sth. like add postgis-layer). Or do you want to plot your data into a special browser?

Best regards
Oct 8 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by francis70 | last post: by
1 post views Thread by Julia | last post: by
2 posts views Thread by Ed | last post: by
2 posts views Thread by Christoph Krammer | last post: by
1 post views Thread by =?Utf-8?B?SHVzYW0=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.