I have a database of polygons, and the points are stored in a blob. I
need the get the data into a php array. Each point is a pair of
(64bit) doubles for lat and lon.
Here is the prototype for the function:
// $num_points = Number of points
// $blob_data = A big string. Size is (16*$num_points) chars
// $array = array to be outputed. You can remove this, and
// return the array if you want.
function convert_blob_to_array($num_points, $blob_data, $array) {
}
Here is a file containing 100 points in the specified format:
www.ciagon.com/blob.dat
Here is a c script that generated the file:
#include <stdlib.h>
#include <stdio.h>
typedef struct {
double lat;
double lon;
} point;
int main() {
point mypoint;
int i;
for(i=0; i<100; i++) {
mypoint.lat = i;
mypoint.lon = (100 - i);
fwrite(&mypoint, 1, sizeof(mypoint), stdout);
}
return 0;
}
I prefer a fast algorithm or an elegant solution. Please do not use
popen() and an external program, because it won't be much faster than
my current solution. Code alone is sufficient for an answer.
If the formatting gets messed up, view this question here:
www.ciagon.com/blob.html |