[Tilesathome] Tiles at home - uploading sea tile index

Frederik Ramm frederik at remote.org
Sun May 20 02:40:07 BST 2007


Hi,

>> Have you read the (numerous) mailing list posts about the idea of
>> seeding the "sea tiles" table with the knowledge we have from Martijn's
>> sea tile index? What do you think about this?
> 
> If someone can provide a script + datafile that does this, I'm happy to run it 
> on the server -- i just haven't got around to developing such a script myself 
> yet.

Such a script is attached. It works on the PNG file that's in SVN 
(tilesAtHome/tools/png2tileinfo) and writes an insert statement for 
every land tile. Output has to be used with mysql command line client, 
with -f option, because many inserts will fail (existing data) - but 
inserts are much faster than "replace intos" and we don't care about the 
failures.

If you prefer to switch the 404 default back to "land", then the script 
needs to be changed to check for TILETYPE_SEA and use type "1" in the 
insert statement.

> Alternatively, someone could upload a set of 69-byte images through the usual 
> upload mechanism.  It's not so efficient as a dedicated script running on the 
> server, but has the advantage of using an existing, tested API for the 
> upload. 

I have done that already for the whole of Europe, or not exactly - since 
you changed the default to water, I had to upload 67-byte tiles for the 
land area. There were about 250,000 67-byte images (level 12 only), and 
it took more than one day. I *could* do that for the rest of the world 
as well, but that would probably keep the server busy for a week or so 
(there are about 2.9 million more level-12 land tiles).

That's why I suggested the SQL way, assuming that it would need a few 
hours max, instead of a week.

We could also choose the "recursive" way where we do not upload four 
level-12 tiles if we can instead upload a level-11 tile, and so on. That 
would require the 404 handler to go reach further down the zoom levels 
before it returns water, but instead of having a total of over 3 million 
"empty land" entries in our database we'd only have about 150k. I have 
done a script identifying the required entries for this as well and can 
provide it (or a ready-made file with SQL insert statements).

Bye
Frederik

                                    ----

#!/usr/bin/perl -w

use strict;
use GD::Image;

use constant TILETYPE_UNKNOWN => 0;
use constant TILETYPE_LAND => 1;
use constant TILETYPE_SEA => 2;
use constant TILETYPE_TILE => 3;

my ($world_fh, $tileinfo_fh);
our $world_im;

open $world_fh, "<oceantiles_12.png" or die;
$world_im = GD::Image->newFromPng( $world_fh, 1 );

for (my $x=0; $x<4096; $x++)
{
     for (my $y=0; $y<4096; $y++)
     {
         if (get_type($world_im, $x, $y) == TILETYPE_LAND)
         {
             print "insert into tiles_blank (x,y,z,layer,type) 
values($x,$y,12,1,2)\n";

         }
     }
}

sub get_type
{
     my($image, $x, $y) = @_;

     my($r,$g,$b) = $image->rgb( $image->getPixel( $x,$y ) );

     return TILETYPE_LAND if $r == 0 && $g == 255 && $b == 0;
     return TILETYPE_SEA if $r == 0 && $g == 0   && $b == 255;
     return TILETYPE_TILE if $r == 255 && $g == 255 && $b == 255;
     return TILETYPE_UNKNOWN if $r == 0 && $g == 0 && $b == 0;

     die "Weird tiletype at [$x,$y]: ($r,$g,$b)\n";
}
-- 
Frederik Ramm  ##  eMail frederik at remote.org  ##  N49°00.09' E008°23.33'




More information about the Tilesathome mailing list