[mapserver-users] Calculating pixel coordinates from latlong

Ken Patterson kap at qwest.net
Tue Aug 13 02:26:06 EDT 2002


Hello,

We hope to liven up our backgrounds using Mapserver output from either the perl interface or using shp2img.  At this time we are trying to figure out how to map a world coordinates (lat/long) to pixel coordinates (from Perl).  I can create a background image with Perl Mapserver and save it to a png file then to be loaded back in w/ GD::newFromPng().  What Information do I need in order to translate from World (lat/long) to a pixel coordinate?  Is this something that can be done w/in the Perl Mapserver interface?  Has anyone gone through this and can provide some direction?

>From searching through the Mapserver archives it seems that the "true" Extent needs to be found and that a projection needs to take place.  I've seen some references to a Perl interface to Proj.4 but could not retrieve the files.  

Any help of ideas would be greatly appreciated!

Thanks,
    Ken

$map_path = <Path>/my.map";
$amap = new mapObj( "$map_path );

# ---------------------------- Set the image w/h 
$amap->{width} = 200;
$amap->{height} = 100;

# ------------------------------ Create my extent (Arizona) 
$myExtent = new rectObj();
$myExtent->{maxx} = -111.35;
$myExtent->{minx} = -112.97;
$myExtent->{maxy} = 33.62;
$myExtent->{miny} = 33.19;
$amap->{extent} = $myExtent;

# ----------------------------- Draw the maps
$image = $amap->draw();                                 
                                                                            
# ----------------------------- Save the bitmap 
$image_url = $image->saveImage( "/tmp/test.png", $mapscript::MS_PNG, 1, 1, 95 );

# ----------------------------- Get the image file to a GD image
my $backGroundImage = GD::Image->newFromPng( "/tmp/test.png" );

# ---------------------------- Want try draw some stuff on the image
my ( $vx, $vy ) = TranslateToViewport( ... )
# Draw my stuff at/around pt ( $vx, $vy )

If I'm understanding it correctly Mapserver is using a projection and the extent is altered as well.  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20020812/ce3a18e1/attachment.html


More information about the mapserver-users mailing list