proj4: coordinate conversion

This article will introduce the code script that uses the proj4 library to convert points in the CGCS2000 coordinate system into longitude and latitude in the WGS84 coordinate system.

Reference:《Proj4 弐标转换

1. Code framework

To use the proj4 library to convert points in the CGCS2000 coordinate system to latitude and longitude in the WGS84 coordinate system, you first need to make sure the proj4 library is included, or install it. You can install the proj4 library using npm as follows:

npm install proj4

You can then write JavaScript code to perform the coordinate transformation. Here is a sample code:

//const proj4 = require('proj4');
import proj4 from "proj4"

// 定义投影坐标系
// 在这里,您需要提供CGCS2000和WGS84之间的投影转换参数
// 您需要根据您的实际情况提供正确的参数
proj4.defs("CGCS2000", "+proj=xxxx +datum=xxxx +to_meter=1 +axis=enu");
proj4.defs("WGS84", "+proj=longlat +datum=WGS84 +no_defs");

// 源坐标(CGCS2000坐标系)
const sourceCoordinates = [x, y]; // 用实际的坐标替换x和y

// 执行坐标转换
const wgs84Coordinates = proj4("CGCS2000", "WGS84", sourceCoordinates);

// wgs84Coordinates 现在包含了WGS84坐标系的经度和纬度
console.log("WGS84 Coordinates (Longitude, Latitude):", wgs84Coordinates);

In this example, you need to replace x and y to use actual CGCS2000 coordinate values. Additionally, you will need to provide the correct projection transformation parameters, which will depend on your specific data and the coordinate transformation you want to perform. Make sure to provide the correct parameters based on your data source.

This code will convert CGCS2000 coordinates to WGS84 coordinates and then print the result to the console.

2. Code cases

//var proj4 = require('proj4');
import proj4 from "proj4"

var fromProjection = "+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=37500000 +y_0=0 +ellps=CGCS2000 +units=m +no_defs";
var obDest = new proj4.Proj('EPSG:4326');

// 源坐标(CGCS2000坐标系)
var sourceCoordinates = [37360653.05, 4356797.094];

// 执行坐标转换
var wgs84Coordinates = proj4(fromProjection, obDest, sourceCoordinates);

console.log('点2 (WGS84坐标系)', wgs84Coordinates);

Guess you like

Origin blog.csdn.net/yyyyyyyyyyy_9/article/details/134115601