2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class Syj_Model_Path extends Syj_Model_Generic
12 protected $_creator_ip;
14 public function setId($id) {
15 $this->_id = (int) $id;
19 public function getId() {
23 public function setGeom(gisconverter\Geometry $geom) {
28 public function getGeom() {
32 public function setCreator(Syj_Model_User $creator = null) {
33 $this->_creator = $creator;
37 public function getCreator() {
38 return $this->_creator;
41 public function isCreator(Syj_Model_User $creator = null) {
42 if (!$creator or !$this->creator) {
45 return ($creator->id == $this->creator->id);
48 public function setTitle($title) {
49 $this->_title = (string) $title;
53 public function getTitle() {
57 public function getDisplayTitle() {
60 } else if ($this->_id) {
61 $title = $this->getTranslator()->translate("route number %d");
62 return str_replace('%d', (string)$this->id, $title);
68 public function setUrlComp($_urlcomp) {
69 $this->_urlcomp = (string) $_urlcomp;
73 public function getUrlComp() {
74 return $this->_urlcomp;
77 public function setCreatorIp($_creator_ip) {
78 $this->_creator_ip = (string) $_creator_ip;
82 public function getCreatorIp() {
83 return $this->_creator_ip;
87 * returns an array containing two arrays. First one is list of distance
88 * from start. Second on is altitude at that point.
89 * @error: ratio of void we accept
91 public function getAltiProfile($altiService, $error = 0) {
92 $points = $altiService->interpolate($this->_geom);
93 $points = array_map(function($point) {
94 if ($point instanceof \gisconverter\Geometry) {
95 return array($point->lon, $point->lat);
99 $altitudes = $altiService->altitude($points);
101 if (is_null($altitudes)) {
102 throw new Syj_Exception_NotImplemented("could not compute altitude profile");
105 $res = array(array(0, $altitudes[0]));
106 $prevpoint = $points[0];
109 $alticount = count($altitudes);
111 foreach (range(1, count($altitudes) - 1) as $idx) {
112 $point = $points[$idx];
113 $delta = $altiService->vincentyDistance($prevpoint[0], $prevpoint[1], $point[0], $point[1]);
114 $dist = $prevdist + $delta;
115 if ($delta == 0) { // we have two similar points side to side
118 if (is_null($altitudes[$idx])) {
124 $res[] = array($dist, $altitudes[$idx]);
127 if ($altinull / $alticount > $error) {
128 throw new Syj_Exception_NotImplemented("too many void in altitude profile");
133 public function getProfileCache($size) {
134 $cacheDir = Zend_Controller_Front::getInstance()->getParam('profileCache');
135 if (is_file($cacheDir) and !is_dir($cacheDir)) {
136 throw new Zend_Exception();
138 if (!is_dir($cacheDir)) {
139 if (@mkdir($cacheDir, 0755, true) === false) {
140 throw new Zend_Exception();
144 return sprintf("%s/%s-%s.png", $cacheDir, (string)$this->_id, $size);
147 public function invalidateCache() {
148 @unlink($this->getProfileCache('small'));
149 @unlink($this->getProfileCache('big'));