1
|
/*
|
2
|
Author: Nedjo Rogers nedjo ATgworks.ca
|
3
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
4
|
|
5
|
$Id$
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Parse OGC Simple Features for SQL WKT into GML.
|
10
|
* @constructor
|
11
|
*/
|
12
|
function WktParser() {
|
13
|
|
14
|
/**
|
15
|
* Do parsing.
|
16
|
* @param geom Geometry in WKT format.
|
17
|
*/
|
18
|
this.parse = function(geom) {
|
19
|
geomTypeExp=/(\D+)\(([^)]+)\)/;
|
20
|
pointExp=/(-?[0-9]+\.[0-9]+)\s+(-?[0-9]+\.[0-9]+)/;
|
21
|
ringExp=/\(([^)]+)\)/;
|
22
|
if (match = geomTypeExp.exec(geom)) {
|
23
|
switch(match[1]) {
|
24
|
case 'POINT':
|
25
|
if (pt = pointExp.exec(match[2])) {
|
26
|
out = '<gml:Point><gml:coordinates decimal="." cs="," ts=" "><gml:coord>' + pt[1] + ',' + pt[2] + '</gml:coord></gml:coordinates></gml:Point>';
|
27
|
}
|
28
|
break;
|
29
|
case 'LINESTRING':
|
30
|
out = '<gml:Linestring><gml:coordinates decimal="." cs="," ts=" ">';
|
31
|
while (pt = pointExp.exec(match[2])) {
|
32
|
out += '<gml:coord>' + pt[1] + ',' + pt[2] + '</gml:coord>';
|
33
|
match[2] = match[2].replace(pt[0], '');
|
34
|
}
|
35
|
out += '</gml:coordinates></gml:Linestring>';
|
36
|
break;
|
37
|
}
|
38
|
}
|
39
|
return out;
|
40
|
}
|
41
|
}
|