Two pairs of eyes August 14, 2007Posted by grimmeister in Geoinformatics.
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!
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…