[mapserver-users] raster creation & use

Lowell Filak lfilak at medinaco.org
Fri May 3 08:47:32 PDT 2002


I think, judging from the bottom of your code the world file looks like:
0.00166666666666667
0
0
0.00166666666666667
-118.9
35.6
Correct?
I don't yet see why that doesn't work. How far off is the registration?
Lowell F.

The following message was sent by Ed McNierney <ed at topozone.com> on Thu, 02 May 2002 16:47:26 -0400.

> Joe -
> 
> The order of elements in a world file is:
> 
> X pixel size
> 0.0
> 0.0
> Y pixel size
> Left
> Top
> 
> You seem to be writing the first four in the wrong order, no?
> 
> 	- Ed
> 
> Ed McNierney
> Chief Mapmaker
> TopoZone.com
> ed at topozone.com
> (978) 251-4242
> 
> 
> -----Original Message-----
> From: Joe Bussell [mailto:joe at otsys.com]
> Sent: Thursday, May 02, 2002 4:24 PM
> To: mapserver-users at lists.gis.umn.edu
> Subject: [mapserver-users] raster creation & use
> 
> 
> I have managed to create a set of png images using mapserver which
> constitute the tile set that I will later use for producing the final
> image product.  I am apparently not producing the *.wld files correctly
> as the rasters do not properly align themselves when drawn.
> 
> The procedure is as follows:
>  determine how many cells to create based on a level
>  for each cell 
>    generate a map
>    get maps actual extent
>    create world file
> 
> I then use gdaltindex to create the shapefiles, then shptree to create
> an index.  I believe that I am incorrectly assigning the world file
> elements.
> 
> Is the pixelSize used for PNG files at all?  Are there issues which 
> I have failed to address?
> 
> Following are the relevant subroutines in my tile production code.
> 
> sub createTiles
> {
>     my %args = 
>     (
>         LEFT    =>  -118.9,
>         TOP     =>  35.6,
>         BOTTOM  =>  33.4,
>         RIGHT   =>  -114.4,
>         XDIM    =>  600,
>         YDIM    =>  600,
>         MAPFILE =>  'td.map',
>         OUTFILE =>  $ENV{PWD}.'/LA',
>         LEVEL   =>  1,
>         X_DIVS  =>  1,
>         Y_DIVS  =>  1,
>         @_,
>     );
>     
>     print "createTiles\n" if $verbose;
>     my $deltaDegree = 1 / $args{LEVEL};
>     my $xDivs = ceil( ( $args{RIGHT} - $args{LEFT} ) / $deltaDegree );
>     my $yDivs = ceil( ( $args{TOP} - $args{BOTTOM} ) / $deltaDegree );
>  
>     my ( $x, $y );
>     
>     my $xDiv = ( $args{LEFT} - $args{RIGHT} ) / ($args{X_DIVS} + 1);
>     my $yDiv = ( $args{BOTTOM} - $args{TOP} ) / ($args{Y_DIVS} + 1);
>     my @files;
>     
>     print "xDIV=$xDivs yDIV=$yDivs \n" if $verbose;
> 
>     for ( $x = 0; $x <= $xDivs; $x++ )
>     {
>         my $left = $args{LEFT} + $x * $deltaDegree;
>         my $right = $left + $deltaDegree;
> 
>         for ( $y = 0; $y <= $yDivs; $y++ )
>         {
>             my $pngFile = $args{OUTFILE} . "level" . $args{LEVEL} . "_" . $x . $y . '.png';
>             my $wldFile = $args{OUTFILE} . "level" . $args{LEVEL} . "_" . $x . $y . '.wld';
> 
>             my $top = $args{TOP} - $y * $deltaDegree;
>             my $bottom = $top - $deltaDegree;
> 
>             my $map = renderMap(    LEFT    => $left,
>                                     RIGHT   =>  $right,
>                                     TOP     =>  $top,
>                                     BOTTOM  =>  $bottom,
>                                     XDIM    =>  $args{XDIM},
>                                     YDIM    =>  $args{YDIM},
>                                     MAPFILE =>  $args{MAPFILE},
>                                     OUTFILE =>  $pngFile        );
>             push( @files, $pngFile );
>             if ( $verbose )
>             {
>                 print STDERR "PNG file created: $pngFile $top $bottom $left $right\n";
>                 print STDERR "minx = $map->{extent}->{minx} maxy = $map->{extent}->{maxy} maxx = $map->{extent}->{maxx} miny = $map->{extent}->{miny}  \n";
>             }
> 
>             $right = $map->{extent}->{maxx};
>             $left = $map->{extent}->{minx};
>             $top = $map->{extent}->{miny};
>             $bottom = $map->{extent}->{maxy};
>              
>             my $xPixelSize = ($right - $left) / $args{XDIM};
>             my $yPixelSize = -($bottom - $top) / $args{YDIM};
> 
>             makeWldFile(    DEST_FILE       => $wldFile,
>                             X_PIXEL_SIZE    => $xPixelSize,
>                             Y_PIXEL_SIZE    => $yPixelSize,
>                             X_ROT           =>  0,
>                             Y_ROT           =>  0,
>                             LEFT            =>  $left,
>                             TOP             =>  $top     );
>             if ( $verbose )
>             {
>                 print STDERR "World file created: $wldFile $xPixelSize, $yPixelSize, 0, 0, $left, $top\n";
>             }
>         }        
>     }
> }
> 
> sub makeWldFile
> {
>     my %args =
>     (
>         DEST_FILE   => 'testOutput.wld',
>         X_PIXEL_SIZE    => 0.033333333,
>         Y_PIXEL_SIZE    => -0.033333333,
>         X_ROT           =>  0,
>         Y_ROT           =>  0,
>         LEFT            =>  -118.236313,
>         TOP             =>  34.049172,
>         @_,
>     );
> 
>     open ( OUT, ">$args{DEST_FILE}" ) || croak "Could not create $args{DEST_FILE}";
> 
>     print OUT "$args{X_PIXEL_SIZE}\n";
>     print OUT "$args{X_ROT}\n";
>     print OUT "$args{Y_ROT}\n";
>     print OUT "$args{Y_PIXEL_SIZE}\n";
>     print OUT "$args{LEFT}\n";
>     print OUT "$args{TOP}\n";
> 
>     close OUT;
> }




More information about the MapServer-users mailing list