TFD3 Posted June 17, 2008 Share Posted June 17, 2008 I would like to see if anyone can help me with converting Lat/Lon into X & Y points. Im trying to get a polygon plotted on the map below: http://www.alabamaweather.org/images2/basemap.png An example of points are below with the first and last set being the same so they complete the polygon. 33.20 -99.20 34.43 -95.36 34.83 -95.45 33.20 -99.20 Any ideas on how to do this? I got the Lat/Lon for the upper left corner and lower right if you need it. Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/110607-convert-latlon-to-xy-points/ Share on other sites More sharing options...
TFD3 Posted June 17, 2008 Author Share Posted June 17, 2008 Here is the script that I am using. But the output is not lining up to where it should be. <?php // First we load the background/base map. We assume it's located in same dir // as the script. // This can be any format but we are using JPG in this example // We will also allocate the color for the marker $im = imagecreatefromjpeg("basemap.jpg"); $red = imagecolorallocate ($im, 255,0,0); // Next need to find the base image size. // We need these variables to be able scale the long/lat coordinates. $scale_x = imagesx($im); $scale_y = imagesy($im); $pt = getlocationcoords($lat, $long, $scale_x, $scale_y); // Now mark the point on the map using a red 4 pixel rectangle imagefilledrectangle($im,$pt["x"]-1,$pt["y"]-1,$pt["x"]+1,$pt["y"]+1,$red); imagestring($im,2,1,$scale_y-20,"Courtesy of www.staycanada.ca",$red); // Return the map image. We are using a PNG format as it gives better final image quality than a JPG header("Content-Type: image/png"); imagepng($im); imagedestroy($im); function getlocationcoords($lat, $lon, $width, $height) { $x = (($lon + 180) * (640 / 360)); $y = ((($lat * -1) + 90) * (480 / 180)); return array("x"=>round($x),"y"=>round($y)); } // Now we convert the long/lat coordinates into screen coordinates ?> http://www.alabamaweather.org/scripts/gd/maps/article_4.php?long=-89.077847&lat=29.081553 Link to comment https://forums.phpfreaks.com/topic/110607-convert-latlon-to-xy-points/#findComment-567490 Share on other sites More sharing options...
TFD3 Posted June 17, 2008 Author Share Posted June 17, 2008 I got the points to line up where they should be but im not sure how to add additional points and plot a line linking them together?? Link to comment https://forums.phpfreaks.com/topic/110607-convert-latlon-to-xy-points/#findComment-567522 Share on other sites More sharing options...
TFD3 Posted June 18, 2008 Author Share Posted June 18, 2008 anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/110607-convert-latlon-to-xy-points/#findComment-568350 Share on other sites More sharing options...
Barand Posted June 18, 2008 Share Posted June 18, 2008 www.php.net/imagepolygon Link to comment https://forums.phpfreaks.com/topic/110607-convert-latlon-to-xy-points/#findComment-568426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.