Index: trunk/extensions/gis/geo.php |
— | — | @@ -131,8 +131,8 @@ |
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | | - * Local: |
136 | | - * Get a set of coordinates from parameters |
| 135 | + * Private: |
| 136 | + * Get a set of coordinates from parameters |
137 | 137 | */ |
138 | 138 | function get_coor( ) { |
139 | 139 | if ($this->is_coor($this->pieces[1],$this->pieces[3])) { |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | * Given decimal degrees, convert to |
203 | 203 | * minutes, seconds and direction |
204 | 204 | */ |
205 | | - function make_minsec( $deg ) |
| 205 | + function make_minsec( $deg ) |
206 | 206 | { |
207 | 207 | if ( $deg >= 0) { |
208 | 208 | $NS = "N"; |
Index: trunk/extensions/gis/neighbors.php |
— | — | @@ -1,7 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | /** @file |
4 | 4 | * |
5 | | - * Create a page which link to other articles in Wikipedia |
| 5 | + * Create a page which link to other articles in Wikipedia which are |
| 6 | + * in the neighborhood |
6 | 7 | * |
7 | 8 | * ---------------------------------------------------------------------- |
8 | 9 | * |
— | — | @@ -72,59 +73,92 @@ |
73 | 74 | $lat0 = $this->p->latdeg; |
74 | 75 | $lon0 = $this->p->londeg; |
75 | 76 | |
76 | | - $out .= "''Locations within approx. ".$this->d." km of "; |
77 | | - if ($this->title != "") { |
78 | | - $out .= $this->title . ", "; |
79 | | - } |
80 | | - $out .= "coordinates " |
81 | | - . $lat0."° ".$lon0 . "°''<br>"; |
82 | | - |
83 | 77 | $g = new gis_database(); |
84 | 78 | $g->select_radius_m( $lat0, $lon0, $this->d * 1000); |
| 79 | + $all = array(); |
| 80 | + $all_pos = array(); |
85 | 81 | |
86 | 82 | while (($x = $g->fetch_position())) { |
87 | 83 | $id = $x->gis_id; |
88 | | - $type = $x->gis_type; /* BUG: */ |
| 84 | + $lat = ($x->gis_latitude_min+$x->gis_latitude_max)/2; |
| 85 | + $lon = ($x->gis_longitude_min+$x->gis_longitude_max)/2; |
| 86 | + $gc = new greatcircle($lat,$lon, $lat0, $lon0); |
| 87 | + $all[$id] = $gc->distance; |
| 88 | + $all_pos[$id] = array( |
| 89 | + 'lat' => $lat, |
| 90 | + 'lon' => $lon, |
| 91 | + 'name' => $g->get_title($id), |
| 92 | + 'type' => $x->gis_type, |
| 93 | + 'octant' => $gc->octant(), |
| 94 | + 'heading' => $gc->heading); |
| 95 | + } |
89 | 96 | |
90 | | - if ( $type == "") $type = "unknown"; |
| 97 | + /* Sort by distance */ |
| 98 | + asort($all, SORT_NUMERIC); |
| 99 | + reset($all); |
91 | 100 | |
92 | | - $name_text = $g->get_title( $id ); |
| 101 | + /* Output */ |
| 102 | + $out .= "''List of ". count($all) |
| 103 | + . " locations within approx. ".$this->d." km of "; |
| 104 | + if ($this->title != "") { |
| 105 | + $out .= $this->title . ", "; |
| 106 | + } |
| 107 | + $out .= "coordinates " |
| 108 | + . $this->show_position($lat0,$lon0) |
| 109 | + . "''<br /><hr />\r\n"; |
93 | 110 | |
94 | | - $gc = new greatcircle( |
95 | | - ($x->gis_latitude_min+$x->gis_latitude_max)/2, |
96 | | - ($x->gis_longitude_min+$x->gis_longitude_max)/2, |
97 | | - $lat0, $lon0); |
98 | | - $d = $gc->distance; |
| 111 | + while (list($id, $d) = each($all)) { |
| 112 | + $out .= $this->show_location($id, $d, $all_pos[$id]); |
| 113 | + } |
| 114 | + $wgOut->addWikiText( $out ); |
| 115 | + } |
| 116 | + |
| 117 | + function show_location( $id, $d, $pos ) |
| 118 | + { |
| 119 | + $id = $pos->gis_id; |
99 | 120 | |
100 | | - $out .= "'''[[".$name_text."]]''' "; |
101 | | - if ($type != "" and $type != "unknown") { |
102 | | - $out .= "(".$type .") "; |
| 121 | + $out = "'''[[".$pos['name']."]]''' "; |
| 122 | + |
| 123 | + $type = $pos['type']; |
| 124 | + if ($type != "" and $type != "unknown") { |
| 125 | + $out .= "(".$type .") "; |
| 126 | + } |
| 127 | + if ($d < 1000) { |
| 128 | + $out .= round($d)." m "; |
| 129 | + } elseif ($d < 10000) { |
| 130 | + $out .= round($d/100)/10 ." km "; |
| 131 | + } else { |
| 132 | + $d = round($d/1000); |
| 133 | + if (d >= 1000) { |
| 134 | + $m = floor($d/1000); |
| 135 | + $out .= $m.","; |
| 136 | + $d -= $m*1000; |
103 | 137 | } |
104 | | - if ($d < 1000) { |
105 | | - $out .= round($d)." m"; |
106 | | - } elseif ($d < 10000) { |
107 | | - $out .= round($d/100)/10 ." km"; |
108 | | - } else { |
109 | | - $d = round($d/1000); |
110 | | - if (d >= 1000) { |
111 | | - $m = floor($d/1000); |
112 | | - $out .= $m.","; |
113 | | - $d -= $m*1000; |
114 | | - } |
115 | | - $out .= $d." km"; |
| 138 | + $out .= $d." km "; |
| 139 | + } |
| 140 | + return $out . $pos['octant'] . ", bearing " |
| 141 | + . round($pos['heading']) . "° towards " |
| 142 | + . $this->show_position($pos['lat'],$pos['lon']) |
| 143 | + . "<br />\r\n"; |
| 144 | + } |
| 145 | + |
| 146 | + function show_position( $lat, $lon ) |
| 147 | + { |
| 148 | + $a = geo_param::make_minsec( $lat ); |
| 149 | + $b = geo_param::make_minsec( $lon ); |
| 150 | + $outa = intval(abs($a['deg'])) . "° "; |
| 151 | + $outb = intval(abs($b['deg'])) . "° "; |
| 152 | + if ($a['min'] != 0 or $b['min'] != 0 |
| 153 | + or $a['sec'] != 0 or $b['sec'] != 0) { |
| 154 | + $outa .= intval($a['min']) . "′ "; |
| 155 | + $outb .= intval($b['min']) . "′ "; |
| 156 | + if ($a['sec'] != 0 or $b['sec'] != 0) { |
| 157 | + $outa .= $a['sec']. "″ "; |
| 158 | + $outb .= $b['sec']. "″ "; |
116 | 159 | } |
117 | | - $out .= " bearing ".round($gc->heading)."° " |
118 | | - . $gc->octant()."<br>"; |
119 | 160 | } |
120 | | - $wgOut->addWikiText( $out ); |
| 161 | + |
| 162 | + return $outa . $a['NS'] . " " . $outb . $b['EW']; |
121 | 163 | } |
122 | 164 | } |
123 | | - |
124 | 165 | ?> |
125 | | - |
126 | | - |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | | - |