dolibarr 21.0.0-alpha
dolgeophp.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
26
27
33{
37 public $db;
38
44 public function __construct($db)
45 {
46 $this->db = $db;
47 }
48
55 public function parseGeoString($value)
56 {
57 $geom = geoPHP::load($value, 'wkt');
58 if ($geom) {
59 $geojson = $geom->out('json');
60 $centroid = $geom->getCentroid();
61 $centroidjson = $centroid->out('json');
62
63 return array('geojson' => $geojson, 'centroid' => $centroid, 'centroidjson' => $centroidjson);
64 } else {
65 return array();
66 }
67 }
68
75 public function getXYString($value)
76 {
77 $value = '';
78
79 $geom = geoPHP::load($value, 'wkt');
80 if ($geom) {
81 $value = $geom->x().' '.$geom->y();
82 }
83 return $value;
84 }
85
92 public function getPointString($value)
93 {
94 $value = '';
95
96 $geom = geoPHP::load($value, 'wkt');
97 if ($geom) {
98 $value = get_class($geom) . ' : '. $geom->numPoints() . ' Points';
99 }
100 return $value;
101 }
102
109 public function getWkt($geojson)
110 {
111 $value_key = '';
112
113 $geom = geoPHP::load($geojson, 'json');
114 if ($geom) {
115 $value_key = $geom->out('wkt');
116 }
117 return $value_key;
118 }
119}
Class to manage Geo processing Usage: $dolgeophp=new DolGeoPHP($db);.
parseGeoString($value)
Return data from a value.
getPointString($value)
Return a string with x and y.
getWkt($geojson)
Return wkt.
__construct($db)
Create an object to build an HTML area to edit a large string content.
getXYString($value)
Return a string with x and y.