r7847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7846‎ | r7847 | r7848 >
Date:10:09, 24 March 2005
Author:egilk
Status:old
Tags:
Comment:
Support maparea, which extracts points for an area in a format compatible with Wikimaps
Modified paths:
  • /trunk/extensions/gis/database.php (modified) (history)
  • /trunk/extensions/gis/geo.php (modified) (history)
  • /trunk/extensions/gis/index.php (modified) (history)
  • /trunk/extensions/gis/maparea.php (added) (history)
  • /trunk/extensions/gis/mapsources.php (modified) (history)
  • /trunk/extensions/gis/neighbors.php (modified) (history)

Diff [purge]

Index: trunk/extensions/gis/geo.php
@@ -121,12 +121,20 @@
122122 $this->londeg_min = $this->londeg_max = $this->londeg;
123123 if ($this->pieces[0] == "to") {
124124 array_shift($this->pieces);
125 - # FIXME: Shows only 2nd part
126125 $this->get_coor();
127 - $this->latdeg_max = $this->latdeg;
128 - $this->londeg_max = $this->londeg;
 126+ if ($this->latdeg < $this->latdeg_max) {
 127+ $this->latdeg_min = $this->latdeg;
 128+ } else {
 129+ $this->latdeg_max = $this->latdeg;
 130+ }
 131+ if ($this->londeg < $this->londeg_max) {
 132+ $this->londeg_min = $this->londeg;
 133+ } else {
 134+ $this->londeg_max = $this->londeg;
 135+ }
129136 $this->latdeg = ($this->latdeg_max+$this->latdeg_min) / 2;
130137 $this->londeg = ($this->londeg_max+$this->londeg_min) / 2;
 138+ $this->coor = array();
131139 }
132140 }
133141
@@ -227,6 +235,28 @@
228236 }
229237
230238 /**
 239+ * Given decimal degrees latitude and longitude, convert to
 240+ * string
 241+ */
 242+ function make_position( $lat, $lon )
 243+ {
 244+ $a = geo_param::make_minsec( $lat );
 245+ $b = geo_param::make_minsec( $lon );
 246+ $outa = intval(abs($a['deg'])) . "&deg;&nbsp;";
 247+ $outb = intval(abs($b['deg'])) . "&deg;&nbsp;";
 248+ if ($a['min'] != 0 or $b['min'] != 0
 249+ or $a['sec'] != 0 or $b['sec'] != 0) {
 250+ $outa .= intval($a['min']) . "&prime;&nbsp;";
 251+ $outb .= intval($b['min']) . "&prime;&nbsp;";
 252+ if ($a['sec'] != 0 or $b['sec'] != 0) {
 253+ $outa .= $a['sec']. "&Prime;&nbsp;";
 254+ $outb .= $b['sec']. "&Prime;&nbsp;";
 255+ }
 256+ }
 257+ return $outa . $a['NS'] . " " . $outb . $b['EW'];
 258+ }
 259+
 260+ /**
231261 * Get the additional attributes in an associative array
232262 */
233263 function get_attr()
@@ -289,8 +319,14 @@
290320 {
291321 $n = count($this->coor);
292322
293 - # FIXME: how to show a range...
294 - if ($n == 4) {
 323+ if ($n == 0) {
 324+ # Range is special case
 325+ return $this->make_position( $this->latdeg_min,
 326+ $this->londeg_min )
 327+ . " to "
 328+ . $this->make_position( $this->latdeg_max,
 329+ $this->londeg_max );
 330+ } elseif ($n == 4) {
295331 return $this->coor[0].'&deg;&nbsp;'.
296332 $this->coor[1].' '.
297333 $this->coor[2].'&deg;&nbsp;'.
Index: trunk/extensions/gis/neighbors.php
@@ -48,35 +48,33 @@
4949
5050 function show()
5151 {
52 - global $wgOut;
 52+ global $wgOut, $wgUser, $wgContLang;
5353
5454 /* No reason for robots to follow map links */
5555 $wgOut->setRobotpolicy( 'noindex,nofollow' );
5656
5757 $wgOut->setPagetitle( "Neighbors" );
58 - $this->showList();
59 - }
60 -
61 - function showList()
62 - {
63 - global $wgOut, $wgUser, $wgContLang;
6458
6559 if (($e = $this->p->get_error()) != "") {
6660 $wgOut->addHTML(
67 - "<p>".
68 - htmlspecialchars( $e ));
 61+ "<p>" . htmlspecialchars( $e ) . "</p>");
6962 $wgOut->output();
7063 wfErrorExit();
7164 return;
7265 }
7366
 67+ $wgOut->addWikiText( $this->make_output() );
 68+ }
 69+
 70+ function make_output()
 71+ {
7472 $lat0 = $this->p->latdeg;
7573 $lon0 = $this->p->londeg;
7674
7775 $g = new gis_database();
7876 $g->select_radius_m( $lat0, $lon0, $this->d * 1000);
7977 $all = array();
80 - $all_pos = array();
 78+ $all_pos = array(); /* temporary store reqd due to sort */
8179
8280 while (($x = $g->fetch_position())) {
8381 $id = $x->gis_id;
@@ -97,20 +95,20 @@
9896 asort($all, SORT_NUMERIC);
9997 reset($all);
10098
101 - /* Output */
 99+ /* Generate output */
102100 $out .= "''List of ". count($all)
103101 . " locations within approx. ".$this->d." km of ";
104102 if ($this->title != "") {
105103 $out .= $this->title . ", ";
106104 }
107105 $out .= "coordinates "
108 - . $this->show_position($lat0,$lon0)
 106+ . $this->p->make_position($lat0,$lon0)
109107 . "''<br /><hr />\r\n";
110108
111109 while (list($id, $d) = each($all)) {
112110 $out .= $this->show_location($id, $d, $all_pos[$id]);
113111 }
114 - $wgOut->addWikiText( $out );
 112+ return $out;
115113 }
116114
117115 function show_location( $id, $d, $pos )
@@ -136,29 +134,10 @@
137135 }
138136 $out .= $d." km ";
139137 }
140 - return $out . $pos['octant'] . ", bearing "
 138+ return $out . $pos['octant'] . " (bearing "
141139 . round($pos['heading']) . "&deg; towards "
142 - . $this->show_position($pos['lat'],$pos['lon'])
143 - . "<br />\r\n";
 140+ . $this->p->make_position($pos['lat'],$pos['lon'])
 141+ . ")<br />\r\n";
144142 }
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'])) . "&deg;&nbsp;";
151 - $outb = intval(abs($b['deg'])) . "&deg;&nbsp;";
152 - if ($a['min'] != 0 or $b['min'] != 0
153 - or $a['sec'] != 0 or $b['sec'] != 0) {
154 - $outa .= intval($a['min']) . "&prime;&nbsp;";
155 - $outb .= intval($b['min']) . "&prime;&nbsp;";
156 - if ($a['sec'] != 0 or $b['sec'] != 0) {
157 - $outa .= $a['sec']. "&Prime;&nbsp;";
158 - $outb .= $b['sec']. "&Prime;&nbsp;";
159 - }
160 - }
161 -
162 - return $outa . $a['NS'] . " " . $outb . $b['EW'];
163 - }
164143 }
165144 ?>
Index: trunk/extensions/gis/mapsources.php
@@ -67,8 +67,7 @@
6868
6969 if (($e = $this->p->get_error()) != "") {
7070 $wgOut->addHTML(
71 - "<p>".
72 - htmlspecialchars( $e ));
 71+ "<p>" . htmlspecialchars( $e ) . "</p>");
7372 $wgOut->output();
7473 wfErrorExit();
7574 return;
Index: trunk/extensions/gis/database.php
@@ -181,9 +181,9 @@
182182 function select_area( $latmin, $lonmin, $latmax, $lonmax )
183183 {
184184 $condition = 'gis_latitude_max >= ' . $latmin .
185 - 'AND gis_latitude_min <= ' . $latmax .
186 - 'AND gis_longitude_max >= ' . $lonmin .
187 - 'AND gis_longitude_min <= ' . $lonmax;
 185+ ' AND gis_latitude_min <= ' . $latmax .
 186+ ' AND gis_longitude_max >= ' . $lonmin .
 187+ ' AND gis_longitude_min <= ' . $lonmax;
188188
189189 return $this->select_position( $condition );
190190 }
Index: trunk/extensions/gis/maparea.php
@@ -0,0 +1,116 @@
 2+<?php
 3+/** @file
 4+ *
 5+ * List all locations within an area in a format compatible with Wikimaps
 6+ *
 7+ * ----------------------------------------------------------------------
 8+ *
 9+ * Copyright 2005, Egil Kvaleberg <egil@kvaleberg.no>
 10+ *
 11+ * This program is free software; you can redistribute it and/or modify
 12+ * it under the terms of the GNU General Public License as published by
 13+ * the Free Software Foundation; either version 2 of the License, or
 14+ * (at your option) any later version.
 15+ *
 16+ * This program is distributed in the hope that it will be useful,
 17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 19+ * GNU General Public License for more details.
 20+ *
 21+ * You should have received a copy of the GNU General Public License
 22+ * along with this program; if not, write to the Free Software
 23+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 24+ */
 25+
 26+
 27+include_once ( "gissettings.php" ) ;
 28+
 29+require_once( "geo.php" );
 30+require_once( "database.php" );
 31+
 32+/**
 33+ * Base class
 34+ */
 35+class maparea {
 36+ var $p;
 37+
 38+ function maparea( $coor )
 39+ {
 40+ $this->p = new geo_param( $coor );
 41+ }
 42+
 43+ function show()
 44+ {
 45+ global $wgOut, $wgUser, $wgContLang;
 46+
 47+ /* No reason for robots to follow map links */
 48+ $wgOut->setRobotpolicy( 'noindex,nofollow' );
 49+
 50+ $wgOut->setPagetitle( "Maparea" );
 51+
 52+ if (($e = $this->p->get_error()) != "") {
 53+ $wgOut->addHTML(
 54+ "<p>" . htmlspecialchars( $e ) . "</p>");
 55+ $wgOut->output();
 56+ wfErrorExit();
 57+ return;
 58+ }
 59+
 60+ $wgOut->addWikiText( $this->make_output() );
 61+ }
 62+
 63+ function make_output()
 64+ {
 65+ $g = new gis_database();
 66+ $g->select_area( $this->p->latdeg_min, $this->p->londeg_min,
 67+ $this->p->latdeg_max, $this->p->londeg_max);
 68+
 69+ $out = ";type:abstract\r\n"
 70+ . ";comment:"
 71+ . $this->map_pos($this->p->latdeg_min,$this->p->londeg_min) . " to "
 72+ . $this->map_pos($this->p->latdeg_max,$this->p->londeg_max) . " ("
 73+ . $this->p->get_markup() . ")\r\n"
 74+ . ";region:include(#*)\r\n"
 75+ . "\r\n";
 76+
 77+ while (($x = $g->fetch_position())) {
 78+ $id = $x->gis_id;
 79+ $lat = ($x->gis_latitude_min+$x->gis_latitude_max)/2;
 80+ $lon = ($x->gis_longitude_min+$x->gis_longitude_max)/2;
 81+ $type = $x->gis_type;
 82+ if ($type == "") $type = "unknown";
 83+ $out .= "==[[" . $g->get_title($id) . "]]==\r\n"
 84+ . ";type:" . $type . "\r\n"
 85+ . ";data:" . $this->map_pos($lat,$lon) . "\r\n"
 86+ . "\r\n";
 87+ }
 88+ return $out;
 89+ }
 90+
 91+ function map_pos( $lat, $lon )
 92+ {
 93+ #
 94+ # NOTE: This is the existing wikmap format
 95+ # Simplify when wikmaps understand decimal degrees
 96+ #
 97+ $a = geo_param::make_minsec( $lat );
 98+ $b = geo_param::make_minsec( $lon );
 99+ $out = "";
 100+ if ($lat < 0) $out .= "-";
 101+ if (intval(abs( $a['deg'])) <= 9) $out .= "0";
 102+ $out .= intval(abs($a['deg']));
 103+ if (intval($a['min']) <= 9) $out .= "0";
 104+ $out .= intval($a['min']);
 105+ if (intval($a['sec']) <= 9) $out .= "0";
 106+ $out .= intval($a['sec']) . ",";
 107+ if ($lon < 0) $out .= "-";
 108+ if (intval(abs( $b['deg'])) <= 9) $out .= "0";
 109+ $out .= intval(abs($b['deg']));
 110+ if (intval($b['min']) <= 9) $out .= "0";
 111+ $out .= intval($b['min']);
 112+ if (intval($b['sec']) <= 9) $out .= "0";
 113+ $out .= intval($b['sec']);
 114+ return $out;
 115+ }
 116+}
 117+?>
Property changes on: trunk/extensions/gis/maparea.php
___________________________________________________________________
Added: svn:eol-style
1118 + native
Added: svn:keywords
2119 + Author Date Id Revision
Index: trunk/extensions/gis/index.php
@@ -45,6 +45,7 @@
4646
4747 require_once( "mapsources.php");
4848 require_once( "neighbors.php");
 49+require_once( "maparea.php");
4950
5051 if ( isset ( $_GET['geo'] ) ) {
5152 $geo = urldecode ( $_GET['geo'] );
@@ -53,11 +54,16 @@
5455 $near = urldecode ( $_GET['near'] ) ;
5556 $dist = urldecode ( $_GET['dist'] ) ;
5657 $title = urldecode ( $_GET['title'] );
 58+} else if ( isset ( $_GET['maparea'] ) ) {
 59+ $maparea = urldecode ( $_GET['maparea'] ) ;
5760 }
5861
5962 # FIXME: if no params, then what?
6063
61 -if ($near != "") {
 64+if ($maparea != "") {
 65+ $bsl = new maparea( $maparea );
 66+ $bsl->show();
 67+} else if ($near != "") {
6268 $bsl = new neighbors( $near, $dist, $title );
6369 $bsl->show();
6470 } else {

Status & tagging log