[Mapserver-users] Reference map in PHP Mapscript / HTML

Sebastian Albrecht api at justapi.de
Fri Nov 14 18:12:33 EST 2003


Hi Vinko,

I've just tried a very similar solution that uses the pix2geo method,
too. But the output xy still differs from my input xy click on the
reference map. The further away from the center of the map (lat=0,
lon=0) the input xy is the more different is the output xy.

Is it actually possible to calculate these geo coordinates from the
pixels without having an eye on the projection stuff?

Thanks so far for your help and best regards,
Sebastian Albrecht



> you have to define an extent for the reference map, then you can convert
> your pixel coords to georreferenced ones and then set the main map
> extent accordingly, for instance: (improvised code)

> $x_ref = $reference_map['x'];
> $y_ref = $reference_map['y']; //assuming the form variable for the
>                               //reference map is reference_map

> $reference_click = pix2geo($x_ref,$y_ref,$mapobj->reference->extent,
>                         $mapobj->reference->width,$mapobj->reference->height);

$mapobj->>setextent($reference_click->x - 100, $reference_click->y - 100,
>                    $reference_click->x + 100, $reference_click->y + 100);

>                 //Assuming you'll want to center the map on the point
>                 //clicked on the reference map with 200 units radius

> where pix2geo would be:

> function pix2geo($pix_x,$pix_y,&$extent,$width,$height) {


>                 $pix_x_geo_x = ($extent->maxx - $extent->minx)
>                                  / ($width - 1);
>                 $pix_x_geo_y = ($extent->maxy - $extent->miny) 
>                                 / ($height - 1);

>                 $geo_x = $extent->minx + $pix_x_geo_x*$pix_x;
>                 $geo_y = $extent->maxy - $pix_x_geo_y*$pix_y;

>                 $my_point = ms_newPointObj();
>                 $my_point->setXY($geo_x,$geo_y);

>                 return $my_point;
> }




More information about the mapserver-users mailing list