Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1001 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1001 delphine 1
<?php
2
 
3
include_once("proj4php.php");
4
 
5
$error = false;
6
 
7
/**
8
 * Geometry-Points
9
 */
10
if( isset( $_GET['GEOM'] ) ) {
11
    list($x, $y) = explode( ' ', $_GET['GEOM'] );
12
} else {
13
    if( isset( $_GET['x'] ) ) {
14
        $x = $_GET['x'];
15
    }
16
    else
17
        $error = true;
18
 
19
    if( isset( $_GET['y'] ) ) {
20
        $y = $_GET['y'];
21
    }
22
    else
23
        $error = true;
24
}
25
 
26
/**
27
 * Source-CRS
28
 */
29
if( isset( $_GET['SOURCECRS'] ) ) {
30
    $srcProjection = str_replace( '::', ':', $_GET['SOURCECRS'] );
31
} else if( isset( $_GET['projectionxy'] ) ) {
32
    $srcProjection = $_GET['projectionxy'];
33
    $srcProjection = str_replace( '::', ':', $srcProjection );
34
}
35
else
36
    $srcProjection = 'EPSG:2154';
37
 
38
/**
39
 * Target-CRS
40
 */
41
if( isset( $_GET['TARGETCRS'] ) ) {
42
    $tgtProjection = str_replace( '::', ':', $_GET['TARGETCRS'] );
43
} else if( isset( $_GET['projection'] ) ) {
44
    $tgtProjection = $_GET['projection'];
45
    $tgtProjection = str_replace( '::', ':', $tgtProjection );
46
}
47
else
48
    $tgtProjection = 'EPSG:4326';
49
 
50
/**
51
 * Format
52
 */
53
if( isset( $_GET['format'] ) ) {
54
    $format = $_GET['format'];
55
    if( !($format == 'xml' || $format == 'json') )
56
        $error = true;
57
}
58
else
59
    $format = 'xml';
60
 
61
 
62
$proj4 = new Proj4php();
63
$projsource = new Proj4phpProj( $srcProjection, $proj4 );
64
$projdest = new Proj4phpProj( $tgtProjection, $proj4 );
65
 
66
// check the projections
67
if( Proj4php::$defs[$srcProjection] == Proj4php::$defs['WGS84'] && $srcProjection != 'EPSG:4326' )
68
    $error = true;
69
if( Proj4php::$defs[$tgtProjection] == Proj4php::$defs['WGS84'] && $tgtProjection != 'EPSG:4326' )
70
    $error = true;
71
 
72
if( $error === true ) {
73
    if( $format == 'json' ) {
74
        echo "{\"status\":\"error\", \"erreur\": {\"code\": 2, \"message\": \"Wrong parameters.\"} }";
75
        exit;
76
    } else {
77
        echo "<reponse>";
78
        echo "  <erreur>";
79
        echo "    <code>2</code>";
80
        echo "    <message>Wrong parameters</message>";
81
        echo "  </erreur>";
82
        echo "</reponse>";
83
        exit;
84
    }
85
}
86
 
87
$pointSrc = new proj4phpPoint( $x, $y );
88
$pointDest = $proj4->transform( $projsource, $projdest, $pointSrc );
89
 
90
$tgtProjection = str_replace( ':', '::', $tgtProjection );
91
 
92
if( $format == 'json' ) {
93
    echo "{\"status\" :\"success\", \"point\" : {\"x\":" . $pointDest->x . ", \"y\":" . $pointDest->y . ",\"projection\" :\"" . $tgtProjection . "\"}}";
94
    exit;
95
} else {
96
    header ("Content-Type:text/xml");
97
    echo "<reponse>";
98
    echo "<point>";
99
    echo "<x>" . $pointDest->x . "</x>";
100
    echo "<y>" . $pointDest->y . "</y>";
101
    echo "<projection>" . $tgtProjection . "</projection>";
102
    echo "</point>";
103
    echo "</reponse>";
104
}