mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 14:01:42 +03:00
1 parent
b37ae30d94
commit
52e0429678
5 files changed
+265
No files matched your search
@@ -171,6 +171,7 @@
|
||||
"flatten-anything": "^4.0.2",
|
||||
"flexsearch": "^0.8.212",
|
||||
"fuse.js": "^7.1.0",
|
||||
"gcoord": "^1.0.7",
|
||||
"generate-schema": "^2.6.0",
|
||||
"get-timezone-offset": "^1.0.5",
|
||||
"ghostscript-wasm-esm": "^1.0.1",
|
||||
@@ -283,6 +284,8 @@
|
||||
"potrace": "^2.1.8",
|
||||
"pp-qr-code": "^0.6.4",
|
||||
"pretty-ms": "^9.3.0",
|
||||
"proj4": "^2.20.2",
|
||||
"proj4-list": "^1.0.4",
|
||||
"properties": "^1.2.1",
|
||||
"punycode": "^2.3.1",
|
||||
"pythonstack.js": "^1.0.2",
|
||||
|
||||
Generated
+38
@@ -402,6 +402,9 @@ importers:
|
||||
fuse.js:
|
||||
specifier: ^7.1.0
|
||||
version: 7.1.0
|
||||
gcoord:
|
||||
specifier: ^1.0.7
|
||||
version: 1.0.7
|
||||
generate-schema:
|
||||
specifier: ^2.6.0
|
||||
version: 2.6.0
|
||||
@@ -738,6 +741,12 @@ importers:
|
||||
pretty-ms:
|
||||
specifier: ^9.3.0
|
||||
version: 9.3.0
|
||||
proj4:
|
||||
specifier: ^2.20.2
|
||||
version: 2.20.2
|
||||
proj4-list:
|
||||
specifier: ^1.0.4
|
||||
version: 1.0.4
|
||||
properties:
|
||||
specifier: ^1.2.1
|
||||
version: 1.2.1
|
||||
@@ -6989,6 +6998,10 @@ packages:
|
||||
fzstd@0.1.1:
|
||||
resolution: {integrity: sha512-dkuVSOKKwh3eas5VkJy1AW1vFpet8TA/fGmVA5krThl8YcOVE/8ZIoEA1+U1vEn5ckxxhLirSdY837azmbaNHA==}
|
||||
|
||||
gcoord@1.0.7:
|
||||
resolution: {integrity: sha512-UCN2iSm69jBOYz2ma2eg5I5imp65Cj70rcTTfMNSNMvZpR1U6oGjmVh080aCvC/6lN1ClkuOoBeaLuebw9AZJg==}
|
||||
engines: {node: '>=16.11.0'}
|
||||
|
||||
generate-schema@2.6.0:
|
||||
resolution: {integrity: sha512-EUBKfJNzT8f91xUk5X5gKtnbdejZeE065UAJ3BCzE8VEbvwKI9Pm5jaWmqVeK1MYc1g5weAVFDTSJzN7ymtTqA==}
|
||||
hasBin: true
|
||||
@@ -8510,6 +8523,9 @@ packages:
|
||||
mermaid@11.12.2:
|
||||
resolution: {integrity: sha512-n34QPDPEKmaeCG4WDMGy0OT6PSyxKCfy2pJgShP+Qow2KLrvWjclwbc3yXfSIf4BanqWEhQEpngWwNp/XhZt6w==}
|
||||
|
||||
mgrs@1.0.0:
|
||||
resolution: {integrity: sha512-awNbTOqCxK1DBGjalK3xqWIstBZgN6fxsMSiXLs9/spqWkF2pAhb2rrYCFSsr1/tT7PhcDGjZndG8SWYn0byYA==}
|
||||
|
||||
micromark-util-character@2.1.1:
|
||||
resolution: {integrity: sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==}
|
||||
|
||||
@@ -9367,6 +9383,12 @@ packages:
|
||||
resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==}
|
||||
engines: {node: '>= 0.6.0'}
|
||||
|
||||
proj4-list@1.0.4:
|
||||
resolution: {integrity: sha512-BMU39s6xU/bIi3ro9unYo94HauD4bO1u1qXVtoqtc+8qdAKtXXe2FV9zGxEVM/tyNeQUdxX8QHPUtGCktFPwAg==}
|
||||
|
||||
proj4@2.20.2:
|
||||
resolution: {integrity: sha512-ipfBRfQly0HhHTO7hnC1GfaX8bvroO7VV4KH889ehmADSE8C/qzp2j+Jj6783S9Tj6c2qX/hhYm7oH0kgXzBAA==}
|
||||
|
||||
properties@1.2.1:
|
||||
resolution: {integrity: sha512-qYNxyMj1JeW54i/EWEFsM1cVwxJbtgPp8+0Wg9XjNaK6VE/c4oRi6PNu5p7w1mNXEIQIjV5Wwn8v8Gz82/QzdQ==}
|
||||
engines: {node: '>=0.10'}
|
||||
@@ -11383,6 +11405,9 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
hasBin: true
|
||||
|
||||
wkt-parser@1.5.2:
|
||||
resolution: {integrity: sha512-1ZUiV1FTwSiSrgWzV9KXJuOF2BVW91KY/mau04BhnmgOdroRQea7Q0s5TVqwGLm0D2tZwObd/tBYXW49sSxp3Q==}
|
||||
|
||||
wmf@1.0.2:
|
||||
resolution: {integrity: sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==}
|
||||
engines: {node: '>=0.8'}
|
||||
@@ -18592,6 +18617,8 @@ snapshots:
|
||||
|
||||
fzstd@0.1.1: {}
|
||||
|
||||
gcoord@1.0.7: {}
|
||||
|
||||
generate-schema@2.6.0:
|
||||
dependencies:
|
||||
commander: 2.20.3
|
||||
@@ -20220,6 +20247,8 @@ snapshots:
|
||||
ts-dedent: 2.2.0
|
||||
uuid: 11.1.0
|
||||
|
||||
mgrs@1.0.0: {}
|
||||
|
||||
micromark-util-character@2.1.1:
|
||||
dependencies:
|
||||
micromark-util-symbol: 2.0.1
|
||||
@@ -21151,6 +21180,13 @@ snapshots:
|
||||
|
||||
process@0.11.10: {}
|
||||
|
||||
proj4-list@1.0.4: {}
|
||||
|
||||
proj4@2.20.2:
|
||||
dependencies:
|
||||
mgrs: 1.0.0
|
||||
wkt-parser: 1.5.2
|
||||
|
||||
properties@1.2.1: {}
|
||||
|
||||
property-information@6.5.0: {}
|
||||
@@ -23555,6 +23591,8 @@ snapshots:
|
||||
siginfo: 2.0.0
|
||||
stackback: 0.0.2
|
||||
|
||||
wkt-parser@1.5.2: {}
|
||||
|
||||
wmf@1.0.2: {}
|
||||
|
||||
word-wrap@1.2.5: {}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import proj4 from 'proj4';
|
||||
import proj4List from 'proj4-list';
|
||||
import type { CRSTypes } from 'gcoord';
|
||||
import gcoord from 'gcoord';
|
||||
|
||||
proj4.defs([
|
||||
proj4List['EPSG:4490'],
|
||||
proj4List['EPSG:4326'],
|
||||
]);
|
||||
|
||||
export const CGCS2000 = 'EPSG:4490';
|
||||
export const WGS84 = 'EPSG:4326';
|
||||
|
||||
export function convertFrom(source: string, lng: number, lat: number) {
|
||||
let wgsLng, wgsLat;
|
||||
switch (source) {
|
||||
case 'CGCS2000': {
|
||||
const [x, y] = proj4(CGCS2000, WGS84, [lng, lat]);
|
||||
wgsLng = x;
|
||||
wgsLat = y;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
const [x, y] = gcoord.transform(
|
||||
[lng, lat],
|
||||
((gcoord as unknown) as Record<string, CRSTypes>)[source] as CRSTypes,
|
||||
gcoord.WGS84,
|
||||
);
|
||||
wgsLng = x;
|
||||
wgsLat = y;
|
||||
}
|
||||
}
|
||||
|
||||
const toLatLng = ([lat, lng]: [number, number]) => ({ lat, lng });
|
||||
// Generate all systems from WGS84
|
||||
return {
|
||||
WGS84: toLatLng([wgsLng, wgsLat]),
|
||||
GCJ02: toLatLng(gcoord.transform([wgsLng, wgsLat], gcoord.WGS84, gcoord.GCJ02)),
|
||||
BD09: toLatLng(gcoord.transform([wgsLng, wgsLat], gcoord.WGS84, gcoord.BD09)),
|
||||
BD09MC: toLatLng(gcoord.transform([wgsLng, wgsLat], gcoord.WGS84, gcoord.BD09MC)),
|
||||
WebMerkator: toLatLng(gcoord.transform([wgsLng, wgsLat], gcoord.WGS84, gcoord.WebMercator)),
|
||||
CGCS2000: toLatLng(proj4(WGS84, CGCS2000, [wgsLng, wgsLat])),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<script setup lang="ts">
|
||||
import detectCSV from 'detect-csv';
|
||||
import { flatten } from 'flatten-anything';
|
||||
import { convertFrom } from './geo-coordinates-converter.service';
|
||||
import { objectArrayToData } from '@/utils/objectarray.export';
|
||||
import { useQueryParam, useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
const sourceSystem = useQueryParamOrStorage({ name: 'type', storageName: 'geo-coord-conv:t', defaultValue: 'BD09' });
|
||||
const inputLatitude = useQueryParam({ tool: 'geo-coord-conv', name: 'lat', defaultValue: 39.915 });
|
||||
const inputLongitude = useQueryParam({ tool: 'geo-coord-conv', name: 'lng', defaultValue: 116.404 });
|
||||
const inputCSV = ref('');
|
||||
const batchRows = ref<string[][]>([]);
|
||||
const resultsData = ref<Record<string, { lat: number; lng: number }>[]>([]);
|
||||
const resultsDisplay = computed(() => {
|
||||
if (resultsData.value.length !== 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const output: { system: string; decimal: string; dms: string }[] = [];
|
||||
for (const [system, { lat: x, lng: y }] of Object.entries(resultsData.value[0])) {
|
||||
output.push({
|
||||
system,
|
||||
decimal: `${x.toFixed(6)}, ${y.toFixed(6)}`,
|
||||
dms: `${toDMS(x)}, ${toDMS(y)}`,
|
||||
});
|
||||
}
|
||||
return output;
|
||||
});
|
||||
|
||||
const columns = [
|
||||
{ title: 'Coordinate System', key: 'system' },
|
||||
{ title: 'Decimal Format (lng, lat)', key: 'decimal' },
|
||||
{ title: 'DMS Format (lng, lat)', key: 'dms' },
|
||||
];
|
||||
|
||||
function convertSingle() {
|
||||
const converted = convertFrom(sourceSystem.value, inputLongitude.value, inputLatitude.value);
|
||||
resultsData.value = [converted];
|
||||
}
|
||||
|
||||
function convertBatch() {
|
||||
const delimiter = detectCSV(inputCSV.value)?.delimiter || ',';
|
||||
batchRows.value = inputCSV.value.trim().split('\n').map(l => l.trim().split(delimiter).map(s => s.trim()));
|
||||
|
||||
if (batchRows.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const output = [];
|
||||
|
||||
for (const row of batchRows.value) {
|
||||
const [lng, lat] = row.map(Number);
|
||||
if (Number.isNaN(Number(lng)) || Number.isNaN(Number(lat))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const converted = convertFrom(sourceSystem.value, lng, lat);
|
||||
|
||||
output.push(converted);
|
||||
}
|
||||
|
||||
resultsData.value = output;
|
||||
}
|
||||
|
||||
function downloadCsv() {
|
||||
const csv = objectArrayToData(resultsData.value.map(r => flatten(r)), 'csv');
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'converted_coordinates.csv';
|
||||
a.click();
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function toDMS(deg: number) {
|
||||
const d = Math.floor(deg);
|
||||
const m = Math.floor((deg - d) * 60);
|
||||
const s = (((deg - d) * 60 - m) * 60).toFixed(2);
|
||||
return `${d}°${m}′${s}″`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-radio-group v-model:value="sourceSystem" mb-2>
|
||||
<n-space justify="center">
|
||||
<n-radio value="WGS84">
|
||||
WGS84/WSG1984/EPSG4326 (Global Standard)
|
||||
</n-radio>
|
||||
<n-radio value="GCJ02">
|
||||
GCJ02/AMap (Gaode, QQ Maps)
|
||||
</n-radio>
|
||||
<n-radio value="BD09">
|
||||
BD09/BD09LL/BMap (Baidu Maps)
|
||||
</n-radio>
|
||||
<n-radio value="BD09MC">
|
||||
BD09MC/BD09Meter (Baidu Meter)
|
||||
</n-radio>
|
||||
<n-radio value="CGCS2000">
|
||||
CGCS2000 (China Geodetic System 2000)
|
||||
</n-radio>
|
||||
<n-radio value="WebMercator">
|
||||
WebMercator/EPSG3857/EPSG900913
|
||||
</n-radio>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
|
||||
<n-tabs type="card" mb-1>
|
||||
<n-tab-pane name="single" tab="Single Lat/Lng Converter">
|
||||
<n-space justify="center">
|
||||
<n-form-item label="Latitude:" label-placement="left">
|
||||
<n-input-number-i18n v-model:value="inputLatitude" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Longitude:" label-placement="left">
|
||||
<n-input-number-i18n v-model:value="inputLongitude" />
|
||||
</n-form-item>
|
||||
</n-space>
|
||||
<n-space justify="center">
|
||||
<n-button type="primary" @click="convertSingle">
|
||||
Convert Single
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-tab-pane>
|
||||
<n-tab-pane name="batch" tab="Batch Lat/Lng Converter">
|
||||
<c-input-text
|
||||
v-model:value="inputCSV"
|
||||
label="CSV Content (Lng, Lat):"
|
||||
placeholder="Put your Longitude and Latitude (in this order) CSV to convert..."
|
||||
multiline
|
||||
rows="5"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-space justify="center">
|
||||
<n-button
|
||||
type="primary"
|
||||
@click="convertBatch"
|
||||
>
|
||||
Convert Batch
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-tab-pane>
|
||||
</n-tabs>
|
||||
|
||||
<c-card v-if="resultsData?.length" title="Conversion Results" mb-2>
|
||||
<n-data-table v-if="resultsDisplay?.length" :columns="columns" :data="resultsDisplay" bordered mb-2 />
|
||||
|
||||
<n-space justify="center">
|
||||
<n-button
|
||||
type="success"
|
||||
:disabled="resultsData.length === 0"
|
||||
@click="downloadCsv"
|
||||
>
|
||||
Download {{ resultsData.length }} Results CSV
|
||||
</n-button>
|
||||
</n-space>
|
||||
</c-card>
|
||||
|
||||
<n-alert type="info" title="Notes" mt-3>
|
||||
Longitude: East is positive, West is negative.<br>
|
||||
Latitude: North is positive, South is negative.
|
||||
</n-alert>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { World } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Geographic Coordinates Converter',
|
||||
path: '/geo-coordinates-converter',
|
||||
description: 'Convert geographic coordinates between WGS84, GCJ02, BD09 and CGCS2000',
|
||||
keywords: ['geo', 'latitude', 'longitude', 'coordinates', 'converter'],
|
||||
component: () => import('./geo-coordinates-converter.vue'),
|
||||
icon: World,
|
||||
createdAt: new Date('2026-01-09'),
|
||||
category: 'Converters',
|
||||
});
|
||||
Reference in new issue
Block a user