$v) if($k!='way' && $k!='geojson' && $v!='') $counteddata[$k]=$v; $feature["properties"] = $counteddata; if($kts===null) { $feature["geometry"]=array(); $feature["geometry"]["coordinates"] = $f->coordinates; $feature["geometry"]["type"] = $f->type; } else { $feature["coordinates"]= getAdjustedCoords($f,$bbox,$kts,$factor); } $features[] = $feature; } pg_free_result($presult); return $features; } function getWayData($geomtxt,$wlyrs,$bbox,$kts) { if($kts!==null) { $factor = $kts / ($bbox[2]-$bbox[0]); } $features=array(); $arr=array("way"=>"planet_osm_line","polygon"=>"planet_osm_polygon"); foreach($arr as $type=>$table) { $wqry = "SELECT * ,ST_AsGeoJSON(ST_Intersection($geomtxt,way)) ". "AS geojson ". "FROM $table WHERE way && $geomtxt AND ". "ST_IsValid(way)"; if($wlyrs[0]!="all") $wqry .= criteria($wlyrs); $wresult = pg_query($wqry); $first=true; while($wrow=pg_fetch_array($wresult,null,PGSQL_ASSOC)) { $feature=array(); $f = json_decode($wrow['geojson']); $tags = array(); foreach($wrow as $k=>$v) if($k!='way' && $k!='geojson' && $v!='') $tags[$k] = $v; $feature["properties"] = $tags; if($kts===null) { $feature["type"] = "Feature"; $feature["geometry"]=array(); $feature["geometry"]["coordinates"] = $f->coordinates; $feature["geometry"]["type"] = $f->type; if(count($feature["geometry"]["coordinates"])>0) $features[] = $feature; } else { $feature["coordinates"]= getAdjustedCoords($f,$bbox,$kts,$factor); $feature["type"] = $f->type; if(count($feature["coordinates"])>0) $features[] = $feature; } } pg_free_result($wresult); } return $features; } function getContourData($geomtxt,$bbox,$kts) { if($kts!==null) { $factor = $kts / ($bbox[2]-$bbox[0]); } $features=array(); $result=pg_query("SELECT ST_AsGeoJSON(ST_Intersection($geomtxt,way)) ". "AS geojson,height ". "FROM contours WHERE way && $geomtxt"); while($row=pg_fetch_array($result,null,PGSQL_ASSOC)) { $feature=array(); $f = json_decode($row['geojson']); $tags = array(); $feature["properties"] = array(); $feature["properties"]["contour"]=$row["height"]; if($kts===null) { $feature["type"]="Feature"; $feature["geometry"]=array(); $feature["geometry"]["coordinates"] = $f->coordinates; $feature["geometry"]["type"] = $f->type; if(count($feature["geometry"]["coordinates"])>0) $features[] = $feature; } else { $feature["coordinates"] = getAdjustedCoords($f,$bbox,$kts,$factor); $feature["type"] = $f->type; if(count($feature["coordinates"])>0) $features[] = $feature; } } return $features; } function getCoastlineData($geomtxt,$bbox,$kts) { if($kts!==null) { $factor = $kts / ($bbox[2]-$bbox[0]); } $features=array(); $result=pg_query("SELECT ST_AsGeoJSON(ST_Intersection($geomtxt,the_geom)) ". "AS geojson ". "FROM coastlines WHERE the_geom && $geomtxt"); while($row=pg_fetch_array($result,null,PGSQL_ASSOC)) { $feature=array(); $f = json_decode($row['geojson']); $tags = array(); $feature["properties"] = array(); $feature["properties"]["natural"] = "land"; if($kts===null) { $feature["type"]="Feature"; $feature["geometry"]=array(); $feature["geometry"]["coordinates"] = $f->coordinates; $feature["geometry"]["type"] = $f->type; if(count($feature["geometry"]["coordinates"])>0) $features[] = $feature; } else { $feature["coordinates"] = getAdjustedCoords($f,$bbox,$kts,$factor); $feature["type"] = $f->type; if(count($feature["coordinates"])>0) $features[] = $feature; } } return $features; } function criteria($lyrs) { $qry=""; if (count($lyrs) != 0) { $qry .= "AND ("; for($i=0; $i '' "; } $qry .= ")"; } return $qry; } function getAdjustedCoords($f,$bbox,$kts,$factor) { $coords=array(); switch($f->type) { case "Point": $x = (int) (($f->coordinates[0] - $bbox[0]) * $factor); $y = (int) (($f->coordinates[1] - $bbox[1]) * $factor); $coords = array($x,$y); break; case "LineString": for($i=0; $icoordinates); $i++) { $x = (int) round(($f->coordinates[$i][0] - $bbox[0]) * $factor); $y = (int) round(($f->coordinates[$i][1] - $bbox[1]) * $factor); // coords of (0,0) seem to screw up rendering $x=($x==0)?1:$x; $y=($y==0)?1:$y; $x=($x==$kts)?$kts-1:$x; $y=($y==$kts)?$kts-1:$y; if($x>=0 && $y>=0 && $x<=$kts && $y<=$kts) $coords[] = array($x,$y); } break; case "MultiLineString": case "Polygon": for($i=0; $icoordinates); $i++) { $coords[$i]=array(); for($j=0; $jcoordinates[$i]); $j++) { $x = (int) round(($f->coordinates[$i][$j][0]-$bbox[0]) * $factor); $y = (int) round(($f->coordinates[$i][$j][1]-$bbox[1]) * $factor); // coords of (0,0) seem to screw up rendering if($f->type=="MultiLineString") { $x=($x==0)?1:$x; $y=($y==0)?1:$y; $x=($x==$kts)?$kts-1:$x; $y=($y==$kts)?$kts-1:$y; } $coords[$i][] = array($x,$y); } } break; case "MultiPolygon": for($i=0; $icoordinates); $i++) { $coords[$i]=array(); for($j=0; $jcoordinates[$i]); $j++) { $coords[$i][$j]=array(); for($k=0; $kcoordinates[$i][$j]); $k++) { $x = (int) round(($f->coordinates[$i][$j][$k][0]-$bbox[0]) * $factor); $y = (int) round(($f->coordinates[$i][$j][$k][1]-$bbox[1]) * $factor); $x=($x==0)?1:$x; $y=($y==0)?1:$y; $x=($x==$kts)?$kts-1:$x; $y=($y==$kts)?$kts-1:$y; $coords[$i][$j][] = array($x,$y); } } } break; } return $coords; } function to_xml(&$data) { echo ""; foreach($data["features"] as $feature) { switch($feature["geometry"]["type"]) { case "Point": poiToXML($feature); break; case "LineString": wayToXML($feature); break; case "Polygon": polygonToXML($feature); break; } } echo ""; } function poiToXML(&$poi) { $x = $poi["geometry"]["coordinates"][0]; $y = $poi["geometry"]["coordinates"][1]; echo ""; foreach($poi["properties"] as $k=>$v) echo ""; echo ""; } function wayToXML(&$way) { echo ""; foreach($way["geometry"]["coordinates"] as $p) { $x = $p[0]; $y = $p[1]; echo ""; } foreach($way["properties"] as $k=>$v) echo ""; echo ""; } function polygonToXML(&$way) { echo ""; foreach($way["geometry"]["coordinates"][0] as $p) { $x = $p[0]; $y = $p[1]; echo ""; } foreach($way["properties"] as $k=>$v) echo ""; echo ""; } function reprojectData(&$data,$outProj) { for($f=0; $f "27700", "GOOGLE" => "900913", "3785" => "900913", "3857" => "900913", "WGS84" => "4326" ); foreach($projAliases as $alias=>$srs) { if($proj==$alias) { $proj=$srs; break; } } } ?>