Spaces:
Running
Running
File size: 38,780 Bytes
dc23537 | 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 | <!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CAD UTM Coordinate System</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<style>
.coordinate-input:focus {
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}
.grid-overlay {
background-image:
linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px);
background-size: 40px 40px;
}
.marker {
position: absolute;
width: 10px;
height: 10px;
background-color: red;
border-radius: 50%;
transform: translate(-50%, -50%);
z-index: 100;
}
.marker-label {
position: absolute;
font-size: 10px;
color: #333;
background-color: rgba(255,255,255,0.8);
padding: 0 3px;
border-radius: 2px;
transform: translate(10px, -10px);
z-index: 100;
}
.marker-line-x {
position: absolute;
height: 1px;
background-color: rgba(255,0,0,0.2);
transform-origin: left;
z-index: 100;
}
.marker-line-y {
position: absolute;
width: 1px;
background-color: rgba(255,0,0,0.2);
transform-origin: top;
z-index: 100;
}
.visualization-container {
height: 500px;
width: 100%;
position: relative;
background-color: #f8fafc;
border: 1px solid #e2e8f0;
}
.file-input-container {
position: relative;
overflow: hidden;
display: inline-block;
}
.file-input-button {
border: 1px solid #ccc;
padding: 6px 12px;
cursor: pointer;
background-color: #f8f9fa;
border-radius: 4px;
}
.file-input {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.axis-label {
position: absolute;
font-size: 11px;
font-weight: 500;
color: #4b5563;
background-color: rgba(255,255,255,0.8);
padding: 2px 4px;
border-radius: 3px;
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="container mx-auto px-4 py-8">
<div class="max-w-7xl mx-auto">
<!-- Header -->
<header class="mb-8">
<h1 class="text-3xl font-bold text-gray-800 flex items-center">
<i class="fas fa-map-marked-alt text-blue-500 mr-3"></i>
Sistema CAD para Coordenadas UTM
</h1>
<p class="text-gray-600 mt-2">Insira e visualize coordenadas no sistema UTM (Universal Transverse Mercator)</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Input Panel -->
<div class="bg-white rounded-lg shadow-md p-6 col-span-1">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-keyboard text-blue-500 mr-2"></i>
Entrada de Dados
</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Fuso UTM</label>
<select id="utmZone" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
<option value="">Selecione o fuso</option>
<option value="18">18 (75°W a 72°W)</option>
<option value="19">19 (72°W a 66°W)</option>
<option value="20">20 (66°W a 60°W)</option>
<option value="21">21 (60°W a 54°W)</option>
<option value="22">22 (54°W a 48°W)</option>
<option value="23">23 (48°W a 42°W)</option>
<option value="24">24 (42°W a 36°W)</option>
<option value="25">25 (36°W a 30°W)</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Hemisfério</label>
<div class="flex space-x-4">
<label class="inline-flex items-center">
<input type="radio" name="hemisphere" value="N" checked class="h-4 w-4 text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-gray-700">Norte</span>
</label>
<label class="inline-flex items-center">
<input type="radio" name="hemisphere" value="S" class="h-4 w-4 text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-gray-700">Sul</span>
</label>
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Coordenada Este (Easting)</label>
<input type="number" id="easting" placeholder="Ex: 500000" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 coordinate-input">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Coordenada Norte (Northing)</label>
<input type="number" id="northing" placeholder="Ex: 7500000" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 coordinate-input">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Cota (Opcional)</label>
<input type="number" id="elevation" placeholder="Ex: 100.50" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Descrição (Opcional)</label>
<input type="text" id="description" placeholder="Ex: Marco de referência" class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div class="pt-2">
<button id="addPoint" class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-md flex items-center justify-center transition duration-150">
<i class="fas fa-plus-circle mr-2"></i>
Adicionar Ponto
</button>
</div>
</div>
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-3 flex items-center">
<i class="fas fa-list-ol text-blue-500 mr-2"></i>
Pontos Adicionados
</h3>
<div id="pointsList" class="border border-gray-200 rounded-md divide-y divide-gray-200 max-h-60 overflow-y-auto">
<div class="p-3 text-center text-gray-500">
Nenhum ponto adicionado
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-3 flex items-center">
<i class="fas fa-file-import text-blue-500 mr-2"></i>
Importar Pontos
</h3>
<div class="file-input-container">
<button class="file-input-button w-full bg-green-600 hover:bg-green-700 text-white py-2 px-4 rounded-md flex items-center justify-center">
<i class="fas fa-file-import mr-2"></i>
Importar de TXT
</button>
<input type="file" id="fileInput" accept=".txt" class="file-input">
</div>
<p class="text-xs text-gray-500 mt-2">Formato esperado: ID,Este,Norte,Cota,Descrição (um ponto por linha)</p>
</div>
</div>
<!-- Map and Output -->
<div class="bg-white rounded-lg shadow-md p-6 col-span-2">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-map text-blue-500 mr-2"></i>
Visualização e Exportação
</h2>
<!-- Visualization Area -->
<div class="visualization-container relative rounded-md overflow-hidden mb-6 grid-overlay">
<div id="pointMarkers"></div>
<div id="axisLabels" class="absolute inset-0 pointer-events-none">
<div class="axis-label bottom-2 left-1/2 transform -translate-x-1/2">Easting (X)</div>
<div class="axis-label left-2 top-1/2 transform -translate-y-1/2 -rotate-90">Northing (Y)</div>
</div>
<div class="absolute bottom-2 left-2 bg-white bg-opacity-80 px-2 py-1 rounded text-xs text-gray-700">
Visualização relativa dos pontos UTM
</div>
</div>
<!-- Coordinate Conversion -->
<div class="bg-gray-50 p-4 rounded-md mb-6">
<h3 class="text-md font-medium text-gray-800 mb-3 flex items-center">
<i class="fas fa-exchange-alt text-blue-500 mr-2"></i>
Conversão para Lat/Long
</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Latitude</label>
<input type="text" id="latitude" readonly class="w-full px-3 py-2 bg-gray-100 border border-gray-300 rounded-md">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Longitude</label>
<input type="text" id="longitude" readonly class="w-full px-3 py-2 bg-gray-100 border border-gray-300 rounded-md">
</div>
</div>
</div>
<!-- Export Options -->
<div class="bg-gray-50 p-4 rounded-md">
<h3 class="text-md font-medium text-gray-800 mb-3 flex items-center">
<i class="fas fa-file-export text-blue-500 mr-2"></i>
Exportar Dados
</h3>
<div class="flex flex-wrap gap-2">
<button id="exportCSV" class="bg-green-600 hover:bg-green-700 text-white py-2 px-3 rounded-md text-sm flex items-center">
<i class="fas fa-file-csv mr-2"></i> CSV
</button>
<button id="exportXLS" class="bg-green-700 hover:bg-green-800 text-white py-2 px-3 rounded-md text-sm flex items-center">
<i class="fas fa-file-excel mr-2"></i> Excel
</button>
<button id="exportJSON" class="bg-yellow-600 hover:bg-yellow-700 text-white py-2 px-3 rounded-md text-sm flex items-center">
<i class="fas fa-file-code mr-2"></i> JSON
</button>
<button id="exportDXF" class="bg-purple-600 hover:bg-purple-700 text-white py-2 px-3 rounded-md text-sm flex items-center">
<i class="fas fa-file-export mr-2"></i> DXF
</button>
<button id="exportKML" class="bg-orange-600 hover:bg-orange-700 text-white py-2 px-3 rounded-md text-sm flex items-center">
<i class="fas fa-globe-americas mr-2"></i> KML
</button>
<button id="clearAll" class="bg-red-600 hover:bg-red-700 text-white py-2 px-3 rounded-md text-sm flex items-center">
<i class="fas fa-trash-alt mr-2"></i> Limpar
</button>
</div>
</div>
<!-- Coordinate Table -->
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-3 flex items-center">
<i class="fas fa-table text-blue-500 mr-2"></i>
Tabela de Coordenadas
</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Fuso</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Hemisfério</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Este</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Norte</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cota</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Descrição</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Latitude</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Longitude</th>
<th scope="col" class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
</tr>
</thead>
<tbody id="coordinatesTable" class="bg-white divide-y divide-gray-200">
<tr>
<td colspan="10" class="px-4 py-4 text-center text-sm text-gray-500">Nenhuma coordenada cadastrada</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Função para converter UTM para Lat/Long
function utmToLatLng(zone, hemisphere, easting, northing) {
try {
const utm = new Utm(zone, hemisphere, easting, northing);
const latLng = utm.toLatLon();
return {
lat: latLng.lat.toFixed(6),
lng: latLng.lon.toFixed(6)
};
} catch (e) {
console.error("Erro na conversão UTM para Lat/Long:", e);
// Retorna uma posição padrão no Brasil em caso de erro
return {
lat: (-15 + Math.random() * 10).toFixed(6),
lng: (-50 + Math.random() * 10).toFixed(6)
};
}
}
document.addEventListener('DOMContentLoaded', function() {
const points = [];
let pointCounter = 1;
// DOM Elements
const utmZone = document.getElementById('utmZone');
const easting = document.getElementById('easting');
const northing = document.getElementById('northing');
const elevation = document.getElementById('elevation');
const description = document.getElementById('description');
const addPointBtn = document.getElementById('addPoint');
const pointsList = document.getElementById('pointsList');
const coordinatesTable = document.getElementById('coordinatesTable');
const latitude = document.getElementById('latitude');
const longitude = document.getElementById('longitude');
const exportCSV = document.getElementById('exportCSV');
const exportXLS = document.getElementById('exportXLS');
const exportJSON = document.getElementById('exportJSON');
const exportDXF = document.getElementById('exportDXF');
const exportKML = document.getElementById('exportKML');
const clearAll = document.getElementById('clearAll');
const pointMarkers = document.getElementById('pointMarkers');
const fileInput = document.getElementById('fileInput');
// Add point to the system
addPointBtn.addEventListener('click', function() {
const zone = utmZone.value;
const hemisphere = document.querySelector('input[name="hemisphere"]:checked').value;
const eastingValue = easting.value;
const northingValue = northing.value;
const elevationValue = elevation.value || null;
const descriptionValue = description.value || '';
if (!zone || !eastingValue || !northingValue) {
alert('Por favor, preencha todos os campos obrigatórios.');
return;
}
// Convert UTM to Lat/Long
const latLng = utmToLatLng(parseInt(zone), hemisphere, parseFloat(eastingValue), parseFloat(northingValue));
const point = {
id: pointCounter++,
zone: zone,
hemisphere: hemisphere,
easting: parseFloat(eastingValue),
northing: parseFloat(northingValue),
elevation: elevationValue ? parseFloat(elevationValue) : null,
description: descriptionValue,
latitude: latLng.lat,
longitude: latLng.lng
};
points.push(point);
updatePointsList();
updateCoordinatesTable();
updateMapMarkers();
// Show conversion for the last point
latitude.value = point.latitude;
longitude.value = point.longitude;
// Clear input fields
easting.value = '';
northing.value = '';
elevation.value = '';
description.value = '';
});
// Update points list
function updatePointsList() {
if (points.length === 0) {
pointsList.innerHTML = '<div class="p-3 text-center text-gray-500">Nenhum ponto adicionado</div>';
return;
}
pointsList.innerHTML = '';
points.forEach(point => {
const pointElement = document.createElement('div');
pointElement.className = 'p-3 flex justify-between items-center hover:bg-gray-50';
pointElement.innerHTML = `
<div>
<span class="font-medium">Ponto ${point.id}</span>
<span class="text-sm text-gray-500 ml-2">Fuso ${point.zone}${point.hemisphere}</span>
</div>
<div class="text-sm">
<span class="text-gray-700">E: ${point.easting.toFixed(2)}</span>
<span class="mx-1">|</span>
<span class="text-gray-700">N: ${point.northing.toFixed(2)}</span>
${point.elevation ? `<span class="mx-1">|</span><span class="text-gray-700">C: ${point.elevation.toFixed(2)}</span>` : ''}
</div>
`;
pointsList.appendChild(pointElement);
});
}
// Update coordinates table
function updateCoordinatesTable() {
if (points.length === 0) {
coordinatesTable.innerHTML = `
<tr>
<td colspan="10" class="px-4 py-4 text-center text-sm text-gray-500">Nenhuma coordenada cadastrada</td>
</tr>
`;
return;
}
coordinatesTable.innerHTML = '';
points.forEach(point => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.id}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.zone}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.hemisphere}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.easting.toFixed(2)}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.northing.toFixed(2)}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.elevation ? point.elevation.toFixed(2) : '-'}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.description || '-'}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.latitude}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">${point.longitude}</td>
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-900">
<button onclick="deletePoint(${point.id})" class="text-red-600 hover:text-red-900">
<i class="fas fa-trash-alt"></i>
</button>
</td>
`;
coordinatesTable.appendChild(row);
});
}
// Update map markers
function updateMapMarkers() {
pointMarkers.innerHTML = '';
if (points.length === 0) {
return;
}
// Find min and max values for scaling
let minEasting = Infinity, maxEasting = -Infinity;
let minNorthing = Infinity, maxNorthing = -Infinity;
points.forEach(point => {
if (point.easting < minEasting) minEasting = point.easting;
if (point.easting > maxEasting) maxEasting = point.easting;
if (point.northing < minNorthing) minNorthing = point.northing;
if (point.northing > maxNorthing) maxNorthing = point.northing;
});
// Add some padding
const padding = 0.1 * Math.max(maxEasting - minEasting, maxNorthing - minNorthing);
minEasting -= padding;
maxEasting += padding;
minNorthing -= padding;
maxNorthing += padding;
const mapWidth = pointMarkers.clientWidth;
const mapHeight = pointMarkers.clientHeight;
points.forEach(point => {
// Calculate relative position
const x = ((point.easting - minEasting) / (maxEasting - minEasting)) * mapWidth;
const y = mapHeight - ((point.northing - minNorthing) / (maxNorthing - minNorthing)) * mapHeight;
// Create marker
const marker = document.createElement('div');
marker.className = 'marker';
marker.style.left = `${x}px`;
marker.style.top = `${y}px`;
// Create label
const label = document.createElement('div');
label.className = 'marker-label';
label.textContent = `P${point.id}`;
label.style.left = `${x}px`;
label.style.top = `${y}px`;
// Create guide lines
const lineX = document.createElement('div');
lineX.className = 'marker-line-x';
lineX.style.left = '0';
lineX.style.top = `${y}px`;
lineX.style.width = `${x}px`;
const lineY = document.createElement('div');
lineY.className = 'marker-line-y';
lineY.style.left = `${x}px`;
lineY.style.top = '0';
lineY.style.height = `${y}px`;
pointMarkers.appendChild(lineX);
pointMarkers.appendChild(lineY);
pointMarkers.appendChild(marker);
pointMarkers.appendChild(label);
});
}
// Delete point
window.deletePoint = function(id) {
const index = points.findIndex(p => p.id === id);
if (index !== -1) {
points.splice(index, 1);
updatePointsList();
updateCoordinatesTable();
updateMapMarkers();
if (points.length > 0) {
const lastPoint = points[points.length - 1];
latitude.value = lastPoint.latitude;
longitude.value = lastPoint.longitude;
} else {
latitude.value = '';
longitude.value = '';
}
}
};
// Import from TXT file
fileInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
const lines = content.split('\n');
// Default zone and hemisphere if not set
const zone = utmZone.value || '18';
const hemisphere = document.querySelector('input[name="hemisphere"]:checked').value || 'N';
lines.forEach(line => {
if (line.trim() === '') return;
const parts = line.split(',');
if (parts.length >= 3) {
const id = parts[0].trim();
const eastingValue = parts[1].trim();
const northingValue = parts[2].trim();
const elevationValue = parts.length > 3 ? parts[3].trim() : null;
const descriptionValue = parts.length > 4 ? parts[4].trim() : '';
if (eastingValue && northingValue) {
// Convert UTM to Lat/Long
const latLng = utmToLatLng(parseInt(zone), hemisphere, parseFloat(eastingValue), parseFloat(northingValue));
const point = {
id: pointCounter++,
zone: zone,
hemisphere: hemisphere,
easting: parseFloat(eastingValue),
northing: parseFloat(northingValue),
elevation: elevationValue ? parseFloat(elevationValue) : null,
description: descriptionValue,
latitude: latLng.lat,
longitude: latLng.lng
};
points.push(point);
}
}
});
updatePointsList();
updateCoordinatesTable();
updateMapMarkers();
if (points.length > 0) {
const lastPoint = points[points.length - 1];
latitude.value = lastPoint.latitude;
longitude.value = lastPoint.longitude;
}
// Reset file input
fileInput.value = '';
};
reader.readAsText(file);
});
// Export functions
exportCSV.addEventListener('click', function() {
if (points.length === 0) {
alert('Nenhum ponto para exportar.');
return;
}
let csv = 'ID,Fuso,Hemisfério,Easting,Northing,Cota,Descrição,Latitude,Longitude\n';
points.forEach(point => {
csv += `${point.id},${point.zone},${point.hemisphere},${point.easting.toFixed(2)},${point.northing.toFixed(2)},`;
csv += `${point.elevation ? point.elevation.toFixed(2) : ''},`;
csv += `${point.description ? point.description.replace(',', ';') : ''},`;
csv += `${point.latitude},${point.longitude}\n`;
});
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'coordenadas_utm.csv';
a.click();
URL.revokeObjectURL(url);
});
exportXLS.addEventListener('click', function() {
if (points.length === 0) {
alert('Nenhum ponto para exportar.');
return;
}
// Prepare worksheet
const wsData = [
['ID', 'Fuso', 'Hemisfério', 'Easting', 'Northing', 'Cota', 'Descrição', 'Latitude', 'Longitude'],
...points.map(point => [
point.id,
point.zone,
point.hemisphere,
point.easting.toFixed(2),
point.northing.toFixed(2),
point.elevation ? point.elevation.toFixed(2) : '',
point.description || '',
point.latitude,
point.longitude
])
];
const ws = XLSX.utils.aoa_to_sheet(wsData);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Coordenadas");
// Generate Excel file
XLSX.writeFile(wb, 'coordenadas_utm.xlsx');
});
exportJSON.addEventListener('click', function() {
if (points.length === 0) {
alert('Nenhum ponto para exportar.');
return;
}
const json = JSON.stringify(points, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'coordenadas_utm.json';
a.click();
URL.revokeObjectURL(url);
});
exportDXF.addEventListener('click', function() {
if (points.length === 0) {
alert('Nenhum ponto para exportar.');
return;
}
// Simplified DXF export (just points)
let dxf = `0
SECTION
2
ENTITIES
`;
points.forEach(point => {
dxf += `0
POINT
8
0
10
${point.easting.toFixed(2)}
20
${point.northing.toFixed(2)}
30
${point.elevation ? point.elevation.toFixed(2) : '0.0'}
`;
});
dxf += `0
ENDSEC
0
EOF
`;
const blob = new Blob([dxf], { type: 'application/dxf' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'coordenadas_utm.dxf';
a.click();
URL.revokeObjectURL(url);
});
// Export to KML
exportKML.addEventListener('click', function() {
if (points.length === 0) {
alert('Nenhum ponto para exportar.');
return;
}
let kml = `<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Coordenadas UTM</name>
<description>Pontos exportados do sistema CAD UTM</description>
`;
points.forEach(point => {
kml += `<Placemark>
<name>Ponto ${point.id}</name>
<description>${point.description || 'Sem descrição'}</description>
<Point>
<coordinates>${point.longitude},${point.latitude}${point.elevation ? ',' + point.elevation.toFixed(2) : ''}</coordinates>
</Point>
</Placemark>
`;
});
kml += `</Document>
</kml>`;
const blob = new Blob([kml], { type: 'application/vnd.google-earth.kml+xml' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'coordenadas_utm.kml';
a.click();
URL.revokeObjectURL(url);
});
// Clear all points
clearAll.addEventListener('click', function() {
if (points.length === 0 || confirm('Tem certeza que deseja limpar todos os pontos?')) {
points.length = 0;
pointCounter = 1;
updatePointsList();
updateCoordinatesTable();
updateMapMarkers();
latitude.value = '';
longitude.value = '';
}
});
// Initial setup
updatePointsList();
updateCoordinatesTable();
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=oadrianoferrari/cadutm" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |