jump to navigation

Two pairs of eyes August 14, 2007

Posted by grimmeister in Geoinformatics.
trackback

I am writing some Python code using the OGR libary. It essentially ingests text files dropped onto a filesystem and turns them into features amongst other things. The data provided are x and y coordinates and some attributes. So, no problem, turn them into points. Trouble is, I needed to turn the points into square buffers of size 3km. I built a buffering routine but it was behaving oddly, generating buffers for all text files in a given directory on one pass, but only generating buffers for one text file on another pass. Eventually, the problem emerged: segmentation fault. I had been pulling my hair out for days trying to understand the problem.

The thing is, one gets commited to one’s code, trying to adjust it in tiny bits and pieces, rather than trying something new. This is where a second pair of eyes comes in. A second person overlooking your work does not have any emotional?? attachment to it and can happily suggest throwing code out and trying a new approach. End result: no more segmentation fault and a program that runs much more efficiently. Thanks Shriram!

Update:

More hair-pulling out! As my colleague Lee points out, if you want to know what is really going on in your code, don’t use wrappers! It took me hours to figure out that OGR (admittedly, a rather older version thereof), when used with its Python bindings, does not seem to enjoy having too many OGR objects used within a single method/routine. Thusly, in my method that ultimately buffers a point geometry and stores the new polygon geometry in a shapefile, I was unable to do a ‘contains’ test on the point geometry without getting weird and woolly segmentation faults and glibc double-linked list errors. This geometry test had to be done in a completely different part of the application.

Now, Lee suggested I rewrite the geometry testing code. The heresy of it!! I still like OGR and put it down to my own inexperience with the libraries. There is more chance of our *illustrious* President firing our unspeakable Health Minister than there is of me writing a usable geometry library. Those of you in the know about current SA politics will agree on the futility of it…

Buzzfuse*

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: