Busy making things: tinycast, github, links, photos, @mc.

From GPX to PostGIS

Posted: January 20th, 2007 | Author: | Filed under: Open Source, Projects | 51 Comments »

Now that I have a RELAX NG Compact schema of GPX, it’s time to figure out how to get my data in to PostGIS. so I can do geospatial queries. I installed PostGIS on my Ubuntu box with these instructions. If I recall correctly, the latest version didn’t work but the previous release did.

GPX makes a great GPS data interchange format, particularly because you can convert just about anything to GPX with GPSBabel. I’m not aware of anything that can convert straight from GPX to PostGIS, but it is a relatively straightforward two-part process.

The first order of business is converting our GPX file to an ESRI Shapefile. This is easiest done by using gpx2shp, a utility written in C that is also available in Ubuntu. Once gpx2shp is installed, run it on your GPX file: gpx2shp filename.gpx.

Once we have a shape file, we can use a utility included with PostGIS to import the shapefile in to postgres. The program is called shp2pgsql, and can be used as such: shp2pgsql -a shapefile.shp tablename. I tend to prefer the -a option which appends data to the table (as long as it’s the same basic type of the existing data). shp2pgsql generates SQL that you can then pipe in to psql as such: shp2pgsql -a shapefile.shp tablename | psql databasename.

Once the data is in Postgres (don’t forget to spatially-enable your database, you can query it in ways that I’m still figuring out. A basic query like this will return a list of lat/lon pairs that corresponds to my GPS track: select asText(the_geom) from tablename;. I’m llooking forward to wrapping my head around enough jargon to do bounding box selects, finding things nearby a specific point, etc.

The examples in the PostGIS documentation seem pretty good, I just haven’t figured out how to apply it to the data I have. I feel like mastering GIS jargon is one of the biggest hurdles to understanding PostGIS better. Well, that and a masters degree in GIS wouldn’t hurt.

51 Comments on “From GPX to PostGIS”

  1. 1 Jeremy Dunck said at 3:16 pm on January 22nd, 2007:

    Real soon now, I hope to whack on better GIS support in Ellington. I recently read the PostGIS docs and OpenGIS for SQL standard.

    I was left with a similar impression on needing further study, but I may be about 150 pages ahead of you on the query language.

    If you feel stuck, maybe I can help. :)

  2. 2 Carlton Nothnagel said at 3:09 pm on November 8th, 2010:

    This page appears to recieve a large ammount of visitors. How do you promote it? It offers a nice individual twist on things. I guess having something real or substantial to talk about is the most important thing.

  3. 3 Laurence Gerig said at 1:17 am on November 13th, 2010:

    Well, like they say, If a tree falls in the forest, does it make a sound?

  4. 4 salary of respiratory therapist said at 12:25 am on November 16th, 2010:

    Thank you for the great post! I would never have found this myself!

  5. 5 adult said at 2:11 pm on November 24th, 2010:

    very good \o/

  6. 6 Renata Gizzo said at 5:37 pm on November 25th, 2010:

    I like this web site its a master peace ! .

  7. 7 surround sound music said at 1:15 pm on December 14th, 2010:

    family home surround audio devices are the most effective way to get the complete advantage by your audio players

  8. 8 bebek ürünleri said at 7:33 pm on December 15th, 2010:

    very good \o/

  9. 9 Lauryn Matayoshi said at 4:48 pm on December 24th, 2010:

    This post was very well written, and it also contains a lot of useful facts. I appreciated your distinguished manner of writing this post. Thanks, you have made it easy for me to understand. The ear is a self cleaning body part.

  10. 10 Chauncey Barncastle said at 6:47 am on December 28th, 2010:

    I was looking for crucial information on this subject. The information was important as I am about to launch my own portal. Thanks for providing a missing link in my business. These are called chemical miscarriages, and they account for around seventy five percent of all miscarriages.

  11. 11 scooter said at 3:52 am on December 29th, 2010:

    great thanks \o/

  12. 12 Breann Commerford said at 7:31 am on January 2nd, 2011:

    I just desired to comment your blog in addition to claim which i genuinely enjoyed reading your blog submit right here. It had been really useful and i likewise reddit how you publish! Stay the best along with Soon we will be time for study much more down the road…

  13. 13 Denita Rotruck said at 4:44 am on January 3rd, 2011:

    Thanks so much for your intelligent website;this is the stuff that keeps me on track through out these day. I’ve been looking around for this site after asked to visit them from a colleague and was thrilled when I found it after searching for awhile. Being a avid blogger, I’m glad to see others taking initivative and contributing to the community. I would like to comment to show my appreciation for your website as it is very enticing, and many writers do not get appreciation they deserve. I am sure I’ll visit again and will send some of my friends.

  14. 14 WordPress Video said at 3:49 am on January 20th, 2011:

    WordPress Video…

    Many thanks for yet another first-rate article. I am always seeking for super WordPress helpful hints to recommend to my own readers. Thank you for making this article. It’s exactly what I was searching for. Truly terrific post….

  15. 15 Mavis Liptrot said at 10:02 pm on January 22nd, 2011:

    Well I sincerely liked reading it. This tip procured by you is very constructive for correct planning.

  16. 16 propecia said at 5:22 am on January 23rd, 2011:

    WONDERFUL Post.thanks for share..more wait .. …

  17. 17 Spencer Veley said at 10:14 am on January 23rd, 2011:

    This is my first time i go post. I collected so many interesting things in your site especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.Regards

  18. 18 internet marketing services said at 2:52 pm on January 24th, 2011:

    I likewise conceive thence , perfectly indited post! .

  19. 19 Valium said at 5:17 pm on January 25th, 2011:

    The subsequent time I learn a blog, I hope that it doesnt disappoint me as much as this one. I mean, I do know it was my choice to learn, however I actually thought youd have one thing fascinating to say. All I hear is a bunch of whining about something that you may fix should you werent too busy looking for attention.

  20. 20 melatrol said at 1:41 pm on January 26th, 2011:

    Oh my goodness! an incredible article dude. Thank you However I am experiencing challenge with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting identical rss downside? Anybody who is aware of kindly respond. Thnkx

  21. 21 maths tutoring said at 8:32 pm on January 27th, 2011:

    If you believe the science it just might be. This is clinically proven, not just a claim.

  22. 22 nail fungus treatment said at 8:50 pm on January 28th, 2011:

    I discovered your blog website on google and verify a few of your early posts. Continue to maintain up the superb operate. I simply further up your RSS feed to my MSN Information Reader. Seeking forward to reading more from you afterward!…

  23. 23 VigRx said at 8:31 pm on February 1st, 2011:

    WONDERFUL Post.thanks for share..more wait .. …

  24. 24 porno izle said at 6:55 am on February 4th, 2011:

    porno izle

  25. 25 reseerbjudanden said at 10:01 pm on February 4th, 2011:

    keep up the great work on the blog. Do like it! :p Could maybe use some more updates more often, but i’m sure you have got more or better things to do like we all do. =)

  26. 26 mens watches said at 6:14 pm on February 6th, 2011:

    I truly appreciate your production. It seems like a lot of your points are precisely inline with mine. I was going to include you to my friendfeed, but I cant locate the URL of your feed, can you direct me in the correct directon or email me?

  27. 27 Comet Laptops said at 2:43 am on February 7th, 2011:

    What is occurring around all these to the world is really very bad. Related to the problems of that ranking with Egypt tend to be fixed before long. They need to find for any pacific way to the condition and get religious beliefs which the armed service doesn´t please take a violent motion against the protests. It´s obvious the people really want your leader away, nevertheless maybe the issues will be deeper compared to merely taking out the chief executive in a country.

  28. 28 vyvoz stroitelnogo musora said at 1:35 pm on February 7th, 2011:

    vyvoz stroitelnogo musora spb…

    vyvoz musora…

  29. 29 Steven Seagal said at 5:53 pm on February 8th, 2011:

    I in no way realised this earlier than, but you possess a relatively high quality level indeed

  30. 30 Rihanna said at 6:03 pm on February 8th, 2011:

    I in no way realised this just before, but you possess a exceptionally satisfactory point certainly

  31. 31 Steven Seagal said at 7:08 pm on February 8th, 2011:

    Terrific to be stumbling as much as your web site once more, it has been virtually a year for me. Anyway, this is the editorial that i’ve been looking for so long. I can use this document to end my assignment in the school, and it has similar matter like your write-up. Thank you, incredible share.

  32. 32 Porn said at 8:00 am on February 10th, 2011:

    A powerful share, I just given this onto a colleague who was doing a bit of evaluation on this. And he in fact bought me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading extra on this topic. If potential, as you change into experience, would you thoughts updating your weblog with more details? It is extremely helpful for me. Massive thumb up for this blog put up!

  33. 33 Bangkok Reseguide said at 9:18 am on February 10th, 2011:

    i have checked this site a few times now and i have to tell you that i find it quite great actually. it’ll be nice to read more in the future! =)

  34. 34 Beyonce said at 8:32 pm on February 10th, 2011:

    Hello, where do you find such rather good info, I`ll post your web page in my Twitter account

  35. 35 Justin Bieber said at 1:28 am on February 11th, 2011:

    Very well mentioned, mostly, but don’t you really feel as if the issue is considerably more complex than that?

  36. 36 zero friction marketing said at 7:39 am on February 12th, 2011:

    You completed several fine points there. I did a search on the matter and found most folks will consent with your blog.

  37. 37 zero friction marketing said at 6:51 pm on February 12th, 2011:

    You made a number of fine points there. I did a search on the subject and found most people will consent with your blog.

  38. 38 jquery said at 2:38 am on February 14th, 2011:

    i’ve checked this blog a few times now and i have to tell you that i find it quite exeptional actually. continue doing what you’re doing! :p

  39. 39 tory-burch-flip-flops said at 10:28 pm on February 14th, 2011:

    discount tory burch shoes…

    Tory Burch flip flop online sale.For the younger working expat women,look at these tory burch Shoes.these tory burch flip flop are definitely fun,yet the glossy design and round-toe stay these lovely.These tory burch shoes with multiple.New arrivel Tor…

  40. 40 usipgs said at 7:14 am on February 15th, 2011:

    vlOQE5 shsxluaqkjpj, [url=http://htuntdonevmt.com/]htuntdonevmt[/url], [link=http://ijjfmssltwkz.com/]ijjfmssltwkz[/link], http://bflidxqrrucy.com/

  41. 41 resguiden said at 7:40 am on February 15th, 2011:

    actually like the post that you posted actually. it just is not that easy to discover good posts to read (you know really READ and not just going through it like some uniterested and flesh eating zombie before moving on), so cheers mate for not wasting my time! ;)

  42. 42 Resor said at 12:34 am on February 16th, 2011:

    keep up the good work on the blog. Do like it! :p Could maybe use some more updates more often, but i’m sure you have got better or other things to do like we all have to do unfortunately. :p

  43. 43 motel in colorado springs said at 3:30 am on February 16th, 2011:

    Very efficiently written information. It is going to be helpful to anybody who usess it, together with myself. Sustain the nice work – for certain i will check out extra posts.

  44. 44 lightest laptop said at 8:12 am on February 16th, 2011:

    Its like you read my mind! You appear to understand so much about this, like you wrote the e book in it or something. I believe that you simply can do with some % to drive the message house a bit, however instead of that, that is wonderful blog. An excellent read. I will definitely be back.

  45. 45 Lyndsey Ciliberto said at 11:11 am on February 16th, 2011:

    I’d come to engage with you here. Which is not something I typically do! I enjoy reading a post that will make people think. Also, thanks for allowing me to comment!

  46. 46 Pozycjonowanie said at 3:53 pm on February 16th, 2011:

    WONDERFUL Post.thanks for share..extra wait .. …

  47. 47 Telesteps said at 5:48 pm on February 16th, 2011:

    http://www.wap54g.net/upgrading-the-wap54g/ Upgrading the WAP54G

  48. 48 Age Concern Travel Insurance said at 5:49 pm on February 17th, 2011:

    This is definitely a topic thats close to me so Im happy that you wrote about it. Im also happy that you did the subject some justice. Not only do you know a great deal about it, you know how to present in a way that people will want to read more. Im so happy to know someone like you exists on the web.

  49. 49 comet laptops said at 8:30 pm on February 17th, 2011:

    I conceive you have observed some very interesting points , thankyou for the post.

  50. 50 knife blocks said at 10:03 pm on February 17th, 2011:

    http://www.wap54g.net/linksys-wap54g-default-ip/ wap54g default ip

  51. 51 Burton Haynes said at 9:51 pm on February 18th, 2011:

    Apple now has Rhapsody as an app, which is a great start, but it is currently hampered by the inability to store locally on your iPod, and has a dismal 64kbps bit rate. If this changes, then it will somewhat negate this advantage for the Zune, but the 10 songs per month will still be a big plus in Zune Pass’ favor.