Overview

Namespaces

  • api
  • config
  • database
  • PHP
  • Slim
    • Exception
    • Http
    • Middleware
  • utiliy

Classes

  • Api
  • PisApi
  • PssApi
  • SpsApi
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace api;
  4: 
  5: include_once "../../global.inc.php";
  6: include_once PATH_DATABASE . "/SpsSqlManager.php";
  7: include_once PATH_UTILITTY . "/XmlManager.php";
  8: require_once PATH_API . "/Api.php";
  9: 
 10: /**
 11:  * This class provides some spezial SpsAPI methods
 12:  * @author stubbfel
 13:  * @since 20.06.2013
 14:  */
 15: class SpsApi extends Api {
 16: 
 17:     /**
 18:      * Route string for the alias paramter
 19:      * @var string
 20:      */
 21:     public static $routeParameterAlias = "/alias/:alias";
 22: 
 23:     /**
 24:      * Route string for the domain paramter
 25:      * @var string
 26:      */
 27:     public static $routeParameterDomain = "/domain/:domain";
 28: 
 29:     /**
 30:      * Route string for the Longitude paramter
 31:      * @var string
 32:      */
 33:     public static $routeParameterLongitude = "/longitude/:longitude";
 34: 
 35:     /**
 36:      * Route string for the latitude paramter
 37:      * @var string
 38:      */
 39:     public static $routeParameterLatitude = "/latitude/:latitude";
 40: 
 41:     /**
 42:      * Keyword for alias arguments
 43:      * @var string
 44:      */
 45:     public static $keyAlias = "alias";
 46: 
 47:     /**
 48:      * Keyword for domain arguments
 49:      * @var string
 50:      */
 51:     public static $keyDomain = "domain";
 52: 
 53:     /**
 54:      * Keyword for polygon arguments
 55:      * @var string
 56:      */
 57:     public static $keyPoly = "poly";
 58: 
 59:     /**
 60:      * Keyword for longitude arguments
 61:      * @var string
 62:      */
 63:     public static $keyLong = "longitude";
 64: 
 65:     /**
 66:      * Keyword for latitude arguments
 67:      * @var string
 68:      */
 69:     public static $keyLat = "latitude";
 70: 
 71:     /*
 72:      * Varible for the range of the searchpolygon
 73:      * @var float
 74:      */
 75:     private $range = 1;
 76: 
 77:     /*
 78:      * Varible for the fist chars of the string for a Polygon
 79:      * @var string
 80:      */
 81:     private $polyStartStr = "GeomFromText('Polygon((";
 82: 
 83:     /*
 84:      * Varible for the last chars of the string for a Polygon
 85:      * @var string
 86:      */
 87:     private $polyEndStr = "))'";
 88: 
 89:     /**
 90:      * maximum value of latitude
 91:      * @var float
 92:      */
 93:     private $maxLat = 180;
 94: 
 95:     /**
 96:      * minimum value of latitude
 97:      * @var float
 98:      */
 99:     private $minLat = -180;
100: 
101:     /**
102:      * maximum value of longitude
103:      * @var float
104:      */
105:     private $maxLong = 180;
106: 
107:     /**
108:      * minimum value of longitude
109:      * @var float
110:      */
111:     private $minLong = -180;
112: 
113:     /**
114:      * Default-Constructor
115:      */
116:     public function __construct() {
117:         $this->sqlManager = new \database\SpsSqlManager();
118:         parent::__construct();
119:     }
120: 
121:     /**
122:      * Default-DeConstructor
123:      */
124:     public function __destruct() {
125:         parent::__destruct();
126:     }
127: 
128:     /**
129:      * Method start a sps-query(alias)
130:      * @param array $queryArgs
131:      * @return querry result as xml
132:      */
133:     public function sendSpsAliasQuery($queryArgs) {
134:         $result = $this->sqlManager->sendSpsAliasQuery($queryArgs);
135:         return \utiliy\XmlManager::arrayToSpsXml($result);
136:     }
137: 
138:     /**
139:      * Method start a sps-query(Coordinates)
140:      * @param array $queryArgs
141:      * @return querry result as xml
142:      */
143:     public function sendSpsCoordinateQuery($queryArgs) {
144:         
145:          // check arguments of the query
146:         if (!array_key_exists(SpsApi::$keyLong, $queryArgs) || !array_key_exists(SpsApi::$keyLat, $queryArgs)) {
147:             return null;
148:         }
149:         $latitude = $queryArgs[SpsApi::$keyLat];
150:         $longitude = $queryArgs[SpsApi::$keyLong];
151: 
152:         if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) {
153:             return null;
154:         }
155: 
156:         // build a request polygon
157:         $queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range);
158:         
159:         // send querry
160:         $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
161:         return \utiliy\XmlManager::arrayToSpsXml($result);
162:     }
163: 
164:     /**
165:      * Method check if a string is a valid Longitude
166:      * @param string $string
167:      * @return bool
168:      */
169:     private function validLongitude($string) {
170:         $digitLessPoint = str_replace(".", "", $string);
171:         $digit = str_replace("-", "", $digitLessPoint);
172:         if (ctype_digit($digit)) {
173:             if ($string <= $this->maxLong && $string >= $this->minLong) {
174:                 return TRUE;
175:             }
176:         };
177:         return FALSE;
178:     }
179: 
180:     /**
181:      * Method check if a string is a valid Latitude
182:      * @param strinf $string
183:      * @return bool
184:      */
185:     private function validLatitude($string) {
186:         $digitLessPoint = str_replace(".", "", $string);
187:         $digit = str_replace("-", "", $digitLessPoint);
188:         if (ctype_digit($digit)) {
189:             if ($string <= $this->maxLat && $string >= $this->minLat) {
190:                 return TRUE;
191:             }
192:         };
193:         return FALSE;
194:     }
195: 
196:     /**
197:      * Method create a Polygon
198:      * @param float $latitude
199:      * @param float $longitude
200:      * @param float $range
201:      * @return string
202:      */
203:     private function createPolygon($latitude, $longitude, $range) {
204:         $minLat = $latitude - $range;
205:         $minLong = $longitude - $range;
206:         $maxLat = $latitude + $range;
207:         $maxLong = $longitude + $range;
208:         return $this->polyStartStr . "$minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong" . $this->polyEndStr;
209:     }
210: 
211: }
212: 
213: ?>
214: 
GeoApi API documentation generated by ApiGen 2.8.0