I optimised some custom tile creation code recently as it was just too
slow to be useable.

I pre-processed the MySQL table first, creating a new spatial 'point'
type column.
I used these functions to convert latitude and longitude values into
floats that ranged from zero to one:

function lonToX($lon){
return ($lon/360)+0.5;
}

function latToY($lat){
return (abs((asinh(tan(deg2rad($lat)))/M_PI/2)-0.5));
}

Then saved these values in the MySQL table as point(x, y).

Finally i created a spatial index on the table using the new point
column as the index key.

Now instead of each query using a complex (and much repeated) series
of trig functions to select rows for a tile i could use the built in
MBRContains() function of MySQL:

$map_max_pixel=(pow(2, $zoom)*256)-1;
$tile_x_min=$tile_x*256;
$tile_y_min=$tile_y*256;
$tile_x_max=$tile_x_min+255;
$tile_y_max=$tile_y_min+255;
$range_x_min=$tile_x_min/$map_max_pixel;
$range_y_min=$tile_y_min/$map_max_pixel;
$range_x_max=$tile_x_max/$map_max_pixel;
$range_y_max=$tile_y_max/$map_max_pixel;
$tile_box="LineStringFromText('LineString($range_x_min $range_y_min,
$range_x_max $range_y_min,$range_x_max $range_y_max,$range_x_min
$range_y_max,$range_x_min $range_y_min)')";
$query="SELECT X(point) AS x, Y(point) AS y FROM my_table WHERE
MBRContains($tile_box, point)";

$map_max_pixel is the size of the map in pixels at the current zoom
level so multiplying that by the x and y values gives me the map pixel
that a row should be displayed at.
And subtracting $tile_x_min or $tile_y_min from that map pixel gives
me the tile pixel - where to draw the row on the tile being created.

The amount of complex computations that this new method did away with
meant the tile creation processed was much more efficient and no
longer was it bogging down the server.

For anything more than a simple table containing latitude and
longitude as float types, the built in spatial data types are the way
to go.

Martin.


On 13 Oct, 04:18, Aaron Kreider <[email protected]> wrote:
> My latest ideas
> -Use C++ instead of php to calculate the heat values for each grid
> square.  This should be ten times faster or better.  I have very
> little C++ experience, so I'm currently stuck on getting it to connect
> to mysql.
> -Try out a trig estimation function or a trig lookup table (both
> options were slower in php, but might go faster in c++)
> -Use interpolation to calculate the heat values for pixels that are
> between two points where I've calculated the exact values.
>
> For making the tiles, fetch the data from mysql for one tile at a time
> to save memory.  (I've recently been trying to do 12 million grid
> squares and it freezes my computer when the script peaks at 1.3 GB ram
> usage, as php is very inefficient in storing data in arrays).

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to