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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
26require_once DOL_DOCUMENT_ROOT.'/includes/geoPHP/geoPHP.inc.php';
27
28
34{
38 public $db;
39
45 public function __construct($db)
46 {
47 $this->db = $db;
48 }
49
56 public function parseGeoString($value)
57 {
58 $geom = geoPHP::load($value, 'wkt');
59 if ($geom) {
60 '@phan-var-force Geometry $geom';
61 $geojson = $geom->out('json');
62 $centroid = $geom->getCentroid();
63 '@phan-var-force Geometry $centroid';
64 $centroidjson = $centroid->out('json');
65
66 return array('geojson' => $geojson, 'centroid' => $centroid, 'centroidjson' => $centroidjson);
67 } else {
68 return array();
69 }
70 }
71
78 public function getXYString($value)
79 {
80 $value = '';
81
82 $geom = geoPHP::load($value, 'wkt');
83 if ($geom) {
84 '@phan-var-force Geometry $geom';
85 $value = $geom->x().' '.$geom->y();
86 }
87 return $value;
88 }
89
96 public function getPointString($value)
97 {
98 $value = '';
99
100 $geom = geoPHP::load($value, 'wkt');
101 if ($geom) {
102 '@phan-var-force Geometry $geom';
103 $value = get_class($geom) . ' : '. $geom->numPoints() . ' Points';
104 }
105 return $value;
106 }
107
114 public function getWkt($geojson)
115 {
116 $value_key = '';
117
118 $geom = geoPHP::load($geojson, 'json');
119 if ($geom) {
120 '@phan-var-force Geometry $geom';
121 $value_key = $geom->out('wkt');
122 }
123 return $value_key;
124 }
125}
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.