Changeset 12270
- Timestamp:
- 09/14/07 11:02:29 (1 year ago)
- Files:
-
- branches/MidCOM_2_8/org.routamc.positioning/aerodrome.php (modified) (1 diff)
- branches/MidCOM_2_8/org.routamc.positioning/city.php (modified) (2 diffs)
- branches/MidCOM_2_8/org.routamc.positioning/config/config.inc (modified) (1 diff)
- branches/MidCOM_2_8/org.routamc.positioning/config/mgdschema.sql (modified) (1 diff)
- branches/MidCOM_2_8/org.routamc.positioning/config/mgdschema.xml (modified) (6 diffs)
- branches/MidCOM_2_8/org.routamc.positioning/config/midcom_dba_classes.inc (modified) (1 diff)
- branches/MidCOM_2_8/org.routamc.positioning/exec/geocode.php (added)
- branches/MidCOM_2_8/org.routamc.positioning/geocoder (added)
- branches/MidCOM_2_8/org.routamc.positioning/geocoder.php (added)
- branches/MidCOM_2_8/org.routamc.positioning/geocoder/city.php (added)
- branches/MidCOM_2_8/org.routamc.positioning/geocoder/geonames.php (added)
- branches/MidCOM_2_8/org.routamc.positioning/geocoder/yahoo.php (added)
- branches/MidCOM_2_8/org.routamc.positioning/location.php (modified) (2 diffs)
- branches/MidCOM_2_8/org.routamc.positioning/utils.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/MidCOM_2_8/org.routamc.positioning/aerodrome.php
r3630 r12270 19 19 return parent::__org_routamc_positioning_aerodrome_dba($id); 20 20 } 21 22 /** 23 * @return org_routamc_positioning_city_dba City the airport caters for 24 */ 25 function get_parent_guid_uncached() 26 { 27 if ($this->city) 28 { 29 $parent = new org_routamc_positioning_city_dba($this->city); 30 if (! $parent) 31 { 32 debug_push_class(__CLASS__, __FUNCTION__); 33 debug_add("Could not load City ID {$this->city} from the database, aborting.", 34 MIDCOM_LOG_INFO); 35 debug_pop(); 36 return null; 37 } 38 return $parent->guid; 39 } 40 41 return null; 42 } 43 44 /** 45 * Human-readable label for cases like Asgard navigation 46 */ 47 function get_label() 48 { 49 if (!empty($this->name)) 50 { 51 return "{$this->icao} ({$this->name})"; 52 } 53 return $this->icao; 54 } 55 56 /** 57 * Don't save aerodrome if another aerodrome is in same place or exists with same ICAO 58 */ 59 function _on_creating() 60 { 61 if ( $this->longitude 62 && $this->latitude) 63 { 64 $qb = org_routamc_positioning_aerodrome_dba::new_query_builder(); 65 $qb->add_constraint('longitude', '=', $this->longitude); 66 $qb->add_constraint('latitude', '=', $this->latitude); 67 $qb->set_limit(1); 68 $matches = $qb->execute_unchecked(); 69 if (count($matches) > 0) 70 { 71 // We don't need to save duplicate entries 72 return false; 73 } 74 } 75 76 $qb = org_routamc_positioning_aerodrome_dba::new_query_builder(); 77 $qb->add_constraint('icao', '=', $this->icao); 78 $qb->set_limit(1); 79 $matches = $qb->execute_unchecked(); 80 if (count($matches) > 0) 81 { 82 // We don't need to save duplicate entries 83 return false; 84 } 85 return parent::_on_creating(); 86 } 21 87 } 22 88 ?> branches/MidCOM_2_8/org.routamc.positioning/city.php
r4795 r12270 19 19 return parent::__org_routamc_positioning_city_dba($id); 20 20 } 21 22 /** 23 * Human-readable label for cases like Asgard navigation 24 */ 25 function get_label() 26 { 27 return $this->city; 28 } 29 30 /** 31 * @return org_routamc_positioning_country_dba Country the city is in 32 */ 33 function get_parent_guid_uncached() 34 { 35 if ($this->country) 36 { 37 $qb = org_routamc_positioning_country_dba::new_query_builder(); 38 $qb->add_constraint('code', '=', $this->country); 39 $countries = $qb->execute(); 40 if (count($countries) == 0) 41 { 42 debug_push_class(__CLASS__, __FUNCTION__); 43 debug_add("Could not load Country ID {$this->country} from the database, aborting.", 44 MIDCOM_LOG_INFO); 45 debug_pop(); 46 return null; 47 } 48 return $countries[0]->guid; 49 } 50 51 return null; 52 } 21 53 22 54 /** … … 37 69 return parent::_on_creating(); 38 70 } 71 72 function get_by_name($name) 73 { 74 $qb = org_routamc_positioning_city_dba::new_query_builder(); 75 $qb->begin_group('OR'); 76 $qb->add_constraint('city', '=', $name); 77 $qb->add_constraint('alternatenames', 'LIKE', "%{$name}%"); 78 $qb->end_group(); 79 80 $qb->set_limit(1); 81 82 $matches = $qb->execute_unchecked(); 83 if (count($matches) > 0) 84 { 85 return $matches[0]; 86 } 87 88 return false; 89 } 39 90 } 40 91 ?> branches/MidCOM_2_8/org.routamc.positioning/config/config.inc
r4906 r12270 9 9 10 10 'plazes_developer_key' => '4c637b4469bc11d13e73aa18a55ff6e6', 11 12 'map_provider' => 'google', 13 'map_api_key' => '', 14 15 'yahoo_application_key' => '', branches/MidCOM_2_8/org.routamc.positioning/config/mgdschema.sql
r3680 r12270 53 53 ALTER TABLE org_routamc_positioning_aerodrome ADD COLUMN revised datetime NOT NULL default '0000-00-00 00:00:00'; 54 54 ALTER TABLE org_routamc_positioning_aerodrome ADD COLUMN revision int(11) NOT NULL default '0'; 55 ALTER TABLE org_routamc_positioning_aerodrome ADD COLUMN wmo varchar(255) NOT NULL default ''; 56 ALTER TABLE org_routamc_positioning_aerodrome ADD COLUMN country varchar(2) NOT NULL default ''; 55 57 ## 56 58 #Log branches/MidCOM_2_8/org.routamc.positioning/config/mgdschema.xml
r5935 r12270 2 2 <Schema xmlns="http://www.midgard-project.org/repligard/1.4"> 3 3 4 <!-- Country --> 5 <type name="org_routamc_positioning_country" table="org_routamc_positioning_country"> 6 <property name="id" type="integer" primaryfield="id"/> 7 <!-- Country in ISO 3166-1 alpha-2 two letter format --> 8 <property name="code" type="string"/> 9 <!-- Country in ISO 3166-1 alpha-3 three letter format --> 10 <property name="code3" type="string"/> 11 <property name="codenumeric" type="string"/> 12 <!-- Country in FIPS two letter format --> 13 <property name="fips" type="string"/> 14 15 <property name="name" type="string"/> 16 <!-- TODO: Alternate names should probably be a MultiLang table --> 17 <property name="alternatenames" type="string"/> 18 19 <!-- Metadata --> 20 <property name="population" type="integer"/> 21 <!-- Area is in square km --> 22 <property name="area" type="float"/> 23 <property name="currency" type="string"/> 24 <property name="continent" type="string"/> 25 <property name="capital" type="integer" link="org_routamc_positioning_city:id" reverse="no"/> 26 27 <!-- Coordinates in decimal format --> 28 <property name="bboxwest" type="float"/> 29 <property name="bboxnorth" type="float"/> 30 <property name="bboxeast" type="float"/> 31 <property name="bboxsouth" type="float"/> 32 </type> 33 4 34 <!-- City is used for mapping log entries to "real-world places" --> 5 <type name="org_routamc_positioning_city" table="org_routamc_positioning_city" >35 <type name="org_routamc_positioning_city" table="org_routamc_positioning_city" parentfield="country"> 6 36 <property name="id" type="integer" primaryfield="id"/> 7 <property name="city" type=" text"/>37 <property name="city" type="string"/> 8 38 <!-- Country in ISO 3166-1 alpha-2 two letter format --> 9 <property name="country" type=" text"/>10 <property name="region" type=" text"/>39 <property name="country" type="string" link="org_routamc_positioning_country:code" parentfield="country" reverse="no" /> 40 <property name="region" type="string"/> 11 41 <!-- TODO: Alternate names should probably be a MultiLang table --> 12 <property name="alternatenames" type=" text"/>42 <property name="alternatenames" type="string"/> 13 43 <property name="population" type="integer"/> 14 44 <!-- Coordinates in decimal format --> 15 <property name="latitude" type=" double"/>16 <property name="longitude" type=" double"/>45 <property name="latitude" type="float"/> 46 <property name="longitude" type="float"/> 17 47 <property name="altitude" type="integer"/> 18 19 <!-- required metadata -->20 <property name="revised" type="string"/>21 <property name="revision" type="integer"/>22 <property name="created" type="string"/>23 <property name="creator" link="midgard_person:id" reverse="no" type="integer"/>24 <property name="revisor" link="midgard_person:id" reverse="no" type="integer"/>25 <!-- /required metadata -->26 48 </type> 27 49 … … 29 51 <type name="org_routamc_positioning_aerodrome" table="org_routamc_positioning_aerodrome" parent="org_routamc_positioning_city" parentfield="city"> 30 52 <property name="id" type="integer" primaryfield="id"/> 31 <property name="icao" type="text"/> 32 <property name="iata" type="text"/> 33 <property name="name" type="text"/> 53 <property name="icao" type="string"/> 54 <property name="iata" type="string"/> 55 <property name="wmo" type="string"/> 56 <property name="name" type="string"/> 34 57 <property name="city" link="org_routamc_positioning_city:id" reverse="no" type="integer" parentfield="city"/> 58 <property name="country" link="org_routamc_positioning_country:code" reverse="no" type="string"/> 35 59 <!-- Coordinates in decimal format --> 36 60 <property name="latitude" type="float"/> … … 39 63 <!-- Runway altitude in meters --> 40 64 <property name="altitude" type="float"/> 41 42 <!-- required metadata -->43 <property name="revised" type="string"/>44 <property name="revision" type="integer"/>45 <property name="created" type="string"/>46 <property name="creator" link="midgard_person:id" reverse="no" type="integer"/>47 <property name="revisor" link="midgard_person:id" reverse="no" type="integer"/>48 <!-- /required metadata -->49 65 </type> 50 66 … … 63 79 objectlocation: Location acquired through an object's location 64 80 --> 65 <property name="importer" type=" text"/>81 <property name="importer" type="string"/> 66 82 67 83 <!-- … … 82 98 <!-- Bearing in degrees --> 83 99 <property name="bearing" type="integer"/> 84 85 <!-- required metadata -->86 <property name="revised" type="string"/>87 <property name="revision" type="integer"/>88 <property name="created" type="string"/>89 <property name="creator" link="midgard_person:id" reverse="no" type="integer"/>90 <property name="revisor" link="midgard_person:id" reverse="no" type="integer"/>91 <!-- /required metadata -->92 100 </type> 93 101 94 102 <!-- Locations are used for connecting any Midgard object into real-world positions --> 95 <type name="org_routamc_positioning_location" table="org_routamc_positioning_location" >103 <type name="org_routamc_positioning_location" table="org_routamc_positioning_location" parentfield="log"> 96 104 <property name="id" type="integer" primaryfield="id"/> 97 105 98 106 <!-- Parent object GUID --> 99 <property name="parent" type=" text"/>107 <property name="parent" type="string"/> 100 108 <!-- Parent object class --> 101 <property name="parentclass" type=" text"/>109 <property name="parentclass" type="string"/> 102 110 <!-- Parent component --> 103 <property name="parentcomponent" type=" text"/>111 <property name="parentcomponent" type="string"/> 104 112 105 113 <!-- Log entry this position information is based on if type is set to "10" --> 106 <property name="log" link="org_routamc_positioning_log:id" reverse="no" type="integer"/> 114 <property name="log" link="org_routamc_positioning_log:id" parentfield="log" reverse="no" type="integer"/> 115 <!-- Date maps to XEP-0080 timestamp --> 107 116 <property name="date" type="integer"/> 108 117 … … 115 124 <property name="relation" type="integer"/> 116 125 117 <!-- Coordinates in decimal format -->126 <!-- Coordinates in decimal format, mapping to XEP-0080 lat and lon --> 118 127 <property name="latitude" type="float"/> 119 128 <property name="longitude" type="float"/> 120 129 121 <!-- Altitude in meters -->130 <!-- Altitude in meters, mapping to XEP-0080 alt --> 122 131 <property name="altitude" type="float"/> 123 124 <!-- required metadata --> 125 <property name="revised" type="string"/> 126 <property name="revision" type="integer"/> 127 <property name="created" type="string"/> 128 <property name="creator" link="midgard_person:id" reverse="no" type="integer"/> 129 <property name="revisor" link="midgard_person:id" reverse="no" type="integer"/> 130 <!-- /required metadata --> 132 133 <!-- XEP-0080 compatible civic location elements from http://www.xmpp.org/extensions/xep-0080.html#format --> 134 <property name="area" type="string"/> 135 <property name="building" type="string"/> 136 <property name="country" link="org_routamc_positioning_country:code" reverse="no" type="string"/> 137 <property name="description" type="string"/> 138 <property name="floor" type="string"/> 139 <property name="city" link="org_routamc_positioning_city:id" reverse="no" type="integer"/> 140 <property name="postalcode" type="string"/> 141 <property name="region" type="string"/> 142 <property name="room" type="string"/> 143 <property name="street" type="string"/> 144 <property name="text" type="string"/> 145 <property name="uri" type="string"/> 131 146 </type> 132 147 </Schema> branches/MidCOM_2_8/org.routamc.positioning/config/midcom_dba_classes.inc
r3630 r12270 1 array( 2 'table' => 'org_routamc_positioning_country', 3 'old_class_name' => null, 4 'new_class_name' => 'org_routamc_positioning_country', 5 'midcom_class_name' => 'org_routamc_positioning_country_dba' 6 ), 1 7 array( 2 8 'table' => 'org_routamc_positioning_city', branches/MidCOM_2_8/org.routamc.positioning/location.php
r5420 r12270 19 19 return parent::__org_routamc_positioning_location_dba($id); 20 20 } 21 22 /** 23 * Human-readable label for cases like Asgard navigation 24 */ 25 function get_label() 26 { 27 if ($this->parent) 28 { 29 $parent = $this->get_parent(); 30 if ($parent) 31 { 32 $label = $parent->guid; 33 if (isset($parent->title)) 34 { 35 $label = $parent->title; 36 } 37 elseif (method_exists($parent, 'get_label')) 38 { 39 $label = $parent->get_label(); 40 } 41 return "{$this->parentclass} {$label}"; 42 } 43 } 44 return "{$this->parentclass} #{$this->id}"; 45 } 21 46 22 47 /** … … 30 55 && $this->parentclass) 31 56 { 57 if (!class_exists($this->parentclass)) 58 { 59 if (empty($this->parentcomponent)) 60 { 61 return null; 62 } 63 $_MIDCOM->componentloader->load_graceful($this->parentcomponent); 64 } 32 65 $classname = $this->parentclass; 33 66 $parent = new $classname($this->parent); branches/MidCOM_2_8/org.routamc.positioning/utils.php
r5022 r12270 267 267 case 'org_routamc_positioning_log_dba': 268 268 case 'org_routamc_positioning_city_dba': 269 case 'org_routamc_positioning_aerodrom _dba':269 case 'org_routamc_positioning_aerodrome_dba': 270 270 // Real position entry, query it directly 271 271 $classname = $class; … … 287 287 * @return Array Array of MidCOM DBA objects sorted by proximity 288 288 */ 289 function get_closest($class, $center, $limit, $modifier = 0. 05)289 function get_closest($class, $center, $limit, $modifier = 0.15) 290 290 { 291 291 $classname = org_routamc_positioning_utils::get_positioning_class($class); … … 298 298 $direct = true; 299 299 } 300 301 300 $qb = $_MIDCOM->dbfactory->new_query_builder($classname); 302 301 … … 335 334 336 335 336 if (!isset($current_locale)) 337 { 338 $current_locale = setlocale(LC_NUMERIC,"0"); 339 setlocale(LC_NUMERIC,"C"); 340 } 341 337 342 $qb->begin_group('AND'); 338 $qb->add_constraint('latitude', '<', $from['latitude']);343 $qb->add_constraint('latitude', '<', (float) $from['latitude']); 339 344 $qb->add_constraint('latitude', '>', (float) $to['latitude']); 340 345 $qb->end_group(); … … 381 386 382 387 $modifier = $modifier * 1.05; 388 setlocale(LC_NUMERIC,$current_locale); 383 389 return org_routamc_positioning_utils::get_closest($class, $center, $limit, $modifier); 384 390 } … … 411 417 array_pop($closest); 412 418 } 413 419 setlocale(LC_NUMERIC,$current_locale); 414 420 return $closest; 415 421 }
