r7848 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r7847‎ | r7848 | r7849 >
Date:10:31, 24 March 2005
Author:egilk
Status:old
Tags:
Comment:
Also allow selection by type and by region
Modified paths:
  • /trunk/extensions/gis/database.php (modified) (history)
  • /trunk/extensions/gis/maparea.php (modified) (history)
  • /trunk/extensions/gis/neighbors.php (modified) (history)

Diff [purge]

Index: trunk/extensions/gis/neighbors.php
@@ -37,6 +37,7 @@
3838 var $p;
3939 var $d;
4040 var $title;
 41+ var $attr;
4142
4243 function neighbors( $coor, $dist, $title )
4344 {
@@ -44,6 +45,7 @@
4546 $this->d = $dist;
4647 if ($this->d <= 0) $this->d = 1000; /* default to 1000 km */
4748 $this->title = $title;
 49+ $this->attr = $this->p->get_attr();
4850 }
4951
5052 function show()
@@ -72,7 +74,8 @@
7375 $lon0 = $this->p->londeg;
7476
7577 $g = new gis_database();
76 - $g->select_radius_m( $lat0, $lon0, $this->d * 1000);
 78+ $g->select_radius_m( $lat0, $lon0, $this->d * 1000,
 79+ $this->attr['region'], $this->attr['type'] );
7780 $all = array();
7881 $all_pos = array(); /* temporary store reqd due to sort */
7982
Index: trunk/extensions/gis/database.php
@@ -156,8 +156,9 @@
157157 /**
158158 * Select entities with a certain radius expressed in meters
159159 * FIXME: Does not work properly around the poles...
 160+ * Also select by region and type if specified
160161 */
161 - function select_radius_m( $lat, $lon, $r )
 162+ function select_radius_m( $lat, $lon, $r, $region, $type )
162163 {
163164 $delta_lat = $r / (60 * 1852);
164165 $c = cos($lat * (M_PI / 180));
@@ -172,19 +173,27 @@
173174 $lonmin = $lon - $delta_lon;
174175 $lonmax = $lon + $delta_lon;
175176 return $this->select_area( $latmin, $lonmin,
176 - $latmax, $lonmax );
 177+ $latmax, $lonmax, $region, $type );
177178 }
178179
179180 /**
180181 * Select entities belonging to or overlapping an area
 182+ * Also select by region and type if specified
181183 */
182 - function select_area( $latmin, $lonmin, $latmax, $lonmax )
 184+ function select_area( $latmin, $lonmin, $latmax, $lonmax, $region, $type )
183185 {
184 - $condition = 'gis_latitude_max >= ' . $latmin .
185 - ' AND gis_latitude_min <= ' . $latmax .
186 - ' AND gis_longitude_max >= ' . $lonmin .
187 - ' AND gis_longitude_min <= ' . $lonmax;
 186+ $condition = "gis_latitude_max >= " . $latmin .
 187+ " AND gis_latitude_min <= " . $latmax .
 188+ " AND gis_longitude_max >= " . $lonmin .
 189+ " AND gis_longitude_min <= " . $lonmax;
188190
 191+ if ($region) {
 192+ $condition .= " AND gis_region = '" . $region . "'";
 193+ }
 194+ if ($type) {
 195+ $condition .= " AND gis_type = '" . $type . "'";
 196+ }
 197+
189198 return $this->select_position( $condition );
190199 }
191200
@@ -202,8 +211,8 @@
203212 'gis_latitude_max',
204213 'gis_longitude_min',
205214 'gis_longitude_max',
206 - 'gis_type',
207 - 'gis_region' ),
 215+ 'gis_region',
 216+ 'gis_type' ),
208217 $condition,
209218 $fname );
210219
Index: trunk/extensions/gis/maparea.php
@@ -33,10 +33,12 @@
3434 */
3535 class maparea {
3636 var $p;
 37+ var $attr;
3738
3839 function maparea( $coor )
3940 {
4041 $this->p = new geo_param( $coor );
 42+ $this->attr = $this->p->get_attr();
4143 }
4244
4345 function show()
@@ -63,7 +65,8 @@
6466 {
6567 $g = new gis_database();
6668 $g->select_area( $this->p->latdeg_min, $this->p->londeg_min,
67 - $this->p->latdeg_max, $this->p->londeg_max);
 69+ $this->p->latdeg_max, $this->p->londeg_max,
 70+ $this->attr['region'], $this->attr['type'] );
6871
6972 $out = ";type:abstract\r\n"
7073 . ";comment:"

Status & tagging log