Read polyline data from postgres/postgis database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • isaacmckensey
    New Member
    • Oct 2009
    • 2

    Read polyline data from postgres/postgis database

    Hi,

    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
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Hi

    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.

    Best

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      isaacmckensey,

      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?

      BV
      Moderator

      Comment

      • isaacmckensey
        New Member
        • Oct 2009
        • 2

        #4
        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:

        010300000001000 0000E000000A857 CA9A564455413AB 4C8B6775B5341B6 D1007E56445541B 81E859B7B5B5341 BE9F1A1B5C44554 1386744457B5B53 4190A0F83D5C445 54165AA1....... ............... ..........

        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

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          You might try MySQLdb (user guide) which works similar to psycopg2.

          Comment

          • Glenton
            Recognized Expert Contributor
            • Nov 2008
            • 391

            #6
            Hi

            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:
            Code:
            myFile = open("yourGISfilename.whatever","r") 
            for i,line in enumerate(myFile):
                if i>10: break
                print i, line
            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.

            Best
            Last edited by Glenton; Oct 22 '09, 12:39 AM. Reason: correcting code

            Comment

            • Jim Panse

              #7
              Hi,

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

              1. your 'coded' geometry means sth. like <geom_type>(Lis t_of_coordinate s), 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

              Comment

              Working...