-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
128 lines (116 loc) · 4.42 KB
/
test.php
File metadata and controls
128 lines (116 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
echo "=== PHP PROJ Extension Test ===\n\n";
// 1. Versão
echo "1. proj_get_version()\n";
$version = proj_get_version();
echo " PROJ Version: $version\n\n";
// 2. Validar CRS
echo "2. proj_create_crs_to_crs('EPSG:4326', 'EPSG:3857')\n";
$info = proj_create_crs_to_crs("EPSG:4326", "EPSG:3857");
if ($info !== false) {
echo " ✓ Válido\n";
echo " Source: {$info['source_crs']}\n";
echo " Target: {$info['target_crs']}\n";
if (isset($info['description'])) {
echo " Desc: {$info['description']}\n";
}
} else {
echo " ✗ FALHOU!\n";
}
echo "\n";
// 3. CRS inválido
echo "3. proj_create_crs_to_crs('INVALID', 'EPSG:3857')\n";
$info2 = @proj_create_crs_to_crs("INVALID", "EPSG:3857");
if ($info2 === false) {
echo " ✓ Retornou false corretamente para CRS inválido\n";
} else {
echo " ✗ Deveria ter retornado false!\n";
}
echo "\n";
// 4. Transformar coordenadas (Empire State Building: lon=-73.9857, lat=40.7484)
echo "4. proj_transform('EPSG:4326', 'EPSG:3857', -73.9857, 40.7484)\n";
$result = proj_transform("EPSG:4326", "EPSG:3857", -73.9857, 40.7484);
if ($result !== false) {
echo " ✓ Transformação OK\n";
echo " X: {$result['x']}\n";
echo " Y: {$result['y']}\n";
echo " Z: {$result['z']}\n";
// Valores esperados aprox: X=-8236050, Y=4975301
$expected_x = -8236050.0;
$expected_y = 4975301.0;
$tolerance = 100.0; // metros
if (abs($result['x'] - $expected_x) < $tolerance && abs($result['y'] - $expected_y) < $tolerance) {
echo " ✓ Valores dentro da tolerância esperada\n";
} else {
echo " ⚠ Valores fora do esperado (x≈$expected_x, y≈$expected_y)\n";
}
} else {
echo " ✗ FALHOU!\n";
}
echo "\n";
// 5. Transformar com altitude
echo "5. proj_transform('EPSG:4326', 'EPSG:3857', -73.9857, 40.7484, 443.0)\n";
$result2 = proj_transform("EPSG:4326", "EPSG:3857", -73.9857, 40.7484, 443.0);
if ($result2 !== false) {
echo " ✓ Transformação com altitude OK\n";
echo " X: {$result2['x']}\n";
echo " Y: {$result2['y']}\n";
echo " Z: {$result2['z']}\n";
} else {
echo " ✗ FALHOU!\n";
}
echo "\n";
echo "6. Benchmark: 1000 transformações (proj_transform individual)\n";
$start = microtime(true);
for ($i = 0; $i < 1000; $i++) {
proj_transform("EPSG:4326", "EPSG:3857", -73.9857 + ($i * 0.001), 40.7484);
}
$elapsed_individual = microtime(true) - $start;
echo " Tempo: " . round($elapsed_individual * 1000, 2) . " ms\n";
echo " Média: " . round(($elapsed_individual / 1000) * 1000000, 2) . " µs/transformação\n";
echo "\n";
// 7. Transformar array de coordenadas
echo "7. proj_transform_array('EPSG:4326', 'EPSG:3857', [[lon,lat], ...])\n";
$points = [
[-73.9857, 40.7484], // Empire State Building
[-43.1729, -22.9068], // Rio de Janeiro
[2.3522, 48.8566], // Paris
[139.6917, 35.6895], // Tokyo
[-73.9857, 40.7484, 443.0], // Empire State Building com altitude
];
$results = proj_transform_array("EPSG:4326", "EPSG:3857", $points);
if ($results !== false) {
echo " ✓ Transformação de " . count($results) . " pontos OK\n";
$labels = ['Empire State', 'Rio de Janeiro', 'Paris', 'Tokyo', 'Empire State (alt)'];
foreach ($results as $i => $r) {
echo " {$labels[$i]}: X={$r['x']}, Y={$r['y']}, Z={$r['z']}\n";
}
} else {
echo " ✗ FALHOU!\n";
}
echo "\n";
// 8. proj_transform_array com array vazio
echo "8. proj_transform_array com array vazio\n";
$empty = proj_transform_array("EPSG:4326", "EPSG:3857", []);
if (is_array($empty) && count($empty) === 0) {
echo " ✓ Retornou array vazio corretamente\n";
} else {
echo " ✗ FALHOU!\n";
}
echo "\n";
// 9. Benchmark: proj_transform_array vs proj_transform individual
echo "9. Benchmark: 1000 transformações (proj_transform_array batch)\n";
$batch_points = [];
for ($i = 0; $i < 1000; $i++) {
$batch_points[] = [-73.9857 + ($i * 0.001), 40.7484];
}
$start = microtime(true);
$batch_results = proj_transform_array("EPSG:4326", "EPSG:3857", $batch_points);
$elapsed_batch = microtime(true) - $start;
echo " Tempo: " . round($elapsed_batch * 1000, 2) . " ms\n";
echo " Média: " . round(($elapsed_batch / 1000) * 1000000, 2) . " µs/transformação\n";
if ($elapsed_individual > 0) {
echo " Speedup: " . round($elapsed_individual / $elapsed_batch, 1) . "x mais rápido que individual\n";
}
echo "\n";
echo "=== Todos os testes concluídos ===\n";