getElementsByTagName('configuration'); $params = $configuration->item(0)->getElementsByTagName('param'); for($i = 0; $i < $params->length; $i++) { $param = $params->item($i); if($param->getAttribute("name") == "projection") { $mapbook_projection = $param->firstChild->nodeValue; } } $y = $_REQUEST['y']; $x = $_REQUEST['x']; $projection = $_REQUEST['projection']; $mode = $_REQUEST['mode']; $input_file_type = $_REQUEST['input_file_type']; $file = $_REQUEST['file']; $script = ""; $delimiter = array(); $delimiter['comma'] = ","; $delimiter['space'] = " "; $delimiter['tab'] = "\t"; $delimiter['gps'] = ","; $epsg4326 = ms_newprojectionobj("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); $epsg2913 = ms_newprojectionobj("+proj=lcc +lat_1=46 +lat_2=44.33333333333334 +lat_0=43.66666666666666 +lon_0=-120.5 +x_0=2500000.0001424 +y_0=0 +ellps=GRS80 +to_meter=0.3048 +no_defs"); if($mode == "save") { $pointsWkt = json_decode(stripslashes($_REQUEST['pointsWkt'])); $fileName = "points"; if($_REQUEST['fileName']) { $fileName = $_REQUEST['fileName']; } header('Content-type: text/csv'); header('Content-Disposition: attachment; filename="' . $fileName . '.csv"'); print("\"Y\",\"X\"\n"); foreach($pointsWkt as $point) { if($projection != $mapbook_projection) { $point = transform($point,$epsg2913,$epsg4326); } $point = ms_shapeObjFromWkt($point); if($projection == "DM") { $str = DECtoDM($point->bounds->miny) . "," . DECtoDM(-$point->bounds->minx) . "\n"; } elseif($projection == "DMS") { $str = DECtoDMS($point->bounds->miny) . "," . DECtoDMS(-$point->bounds->minx) . "\n"; } else { $str = $point->bounds->miny . "," . $point->bounds->minx . "\n"; } print $str; } exit(); } if($mode == 'point') { $lines[0] = $y . "," . $x; $input_file_type = "comma"; } elseif($mode == 'returnFilePoints') { $lines = file($file,FILE_SKIP_EMPTY_LINES); } foreach ($lines as $line) { if(strlen(trim($line)) > 0) { $point = explode($delimiter[$input_file_type],$line); if($input_file_type == "gps" && substr($point[0],1) == "GPGGA") { $x = "-" . DMtoDEC_GPS(trim($point[4])); $y = DMtoDEC_GPS(trim($point[2])); } else { $y = trim($point[0]); $x = trim($point[1]); if($projection == "DM") { $y = explode("-",$y); $x = explode("-",$x); $y = DMtoDEC($y[0],$y[1]); $x = DMtoDEC($x[0],$x[1]); $x = -$x; //Need to get this as a negative to get in west hemisphere } elseif($projection == "DMS") { $y = explode("-",$y); $x = explode("-",$x); $y = DMStoDEC($y[0],$y[1],$y[2]); $x = DMStoDEC($x[0],$x[1],$x[2]); $x = -$x; //Need to get this as a negative to get in west hemisphere } } if(strlen($y) > 0 && strlen($x) > 0) { $pointWkt = "POINT(" . $x . " " . $y . ")"; if($pointWkt && $projection != $mapbook_projection) { $pointWkt = transform($pointWkt,$epsg4326,$epsg2913); } if($pointWkt) { $script .= 'drawSketchPoints.addFeature("' . $pointWkt . '"); '; } } } } header('Content-type: text/xml'); print ""; print ""; print ""; print ""; function transform($pointWkt,$projInObj,$projOutObj) { $point = ms_shapeObjFromWkt($pointWkt); $point->project($projInObj, $projOutObj); $pointWkt = $point->toWKT(); return $pointWkt; } function DMStoDEC($deg,$min,$sec) { return $deg+((($min*60)+($sec))/3600); } function DMtoDEC($deg,$min) { return $deg + ($min/60); } function DMtoDEC_GPS($dm) { $pointLoc = strrpos($dm, '.'); $degree = substr($dm,0,$pointLoc-2); $minute = substr($dm,$pointLoc-2); return $degree + ($minute/60); } function DECtoDM($dec) { $dec = explode(".",$dec); $deg = $dec[0]; $min = "." . $dec[1]; $min = (float)$min*60; return $deg . "-" . $min; } function DECtoDMS($dec) { $dec = explode(".",$dec); $deg = $dec[0]; $min_temp = "." . $dec[1]; $min_temp = (float)$min_temp*60; $min_temp = explode(".",$min_temp); $min = $min_temp[0]; $sec = "." . $min_temp[1]; $sec = (float)$sec*60; return $deg . "-" . $min . "-" . $sec; } ?>