Tech.Geospatial
1.0.0
dotnet add package Tech.Geospatial --version 1.0.0
NuGet\Install-Package Tech.Geospatial -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tech.Geospatial" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tech.Geospatial" Version="1.0.0" />
<PackageReference Include="Tech.Geospatial" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tech.Geospatial --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tech.Geospatial, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tech.Geospatial@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tech.Geospatial&version=1.0.0
#tool nuget:?package=Tech.Geospatial&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tech.Geospatial - CGCS2000 坐标转换函数库
基于 .NET 10 最佳实践的高性能坐标转换函数库,支持 CGCS2000 地理坐标向任意中央子午线的高斯投影计算。
项目概述
本库使用 ProjNet4GeoAPI 作为底层转换引擎,提供了完整的 CGCS2000 坐标系支持,包括:
- CGCS2000 地理坐标系 (EPSG:4490)
- 高斯-克吕格投影 (3度带、6度带)
- 自定义中央子午线投影
- 批量坐标转换优化
- 坐标系缓存机制
项目结构
D:/Tech.Proj/
├── src/
│ └── Tech.Geospatial/ # 核心库项目
│ ├── CoordinateSystem/
│ │ └── CGCS2000CoordinateSystem.cs # CGCS2000 坐标系定义
│ ├── Transformations/
│ │ ├── ICoordinateTransformer.cs # 转换器接口
│ │ ├── CoordinateTransformer.cs # 核心转换实现
│ │ └── BatchCoordinateTransformer.cs # 批量转换优化
│ ├── Models/
│ │ ├── GeographicCoordinate.cs # 地理坐标 (record struct)
│ │ ├── ProjectedCoordinate.cs # 投影坐标 (record struct)
│ │ └── TransformationResult.cs # 转换结果
│ ├── Caching/
│ │ ├── ICoordinateSystemCache.cs # 缓存接口
│ │ └── CoordinateSystemCache.cs # 缓存实现
│ ├── Configuration/
│ │ ├── ProjectionZone.cs # 投影带配置
│ │ ├── TransformOptions.cs # 转换选项
│ │ └── CoordinateTransformerBuilder.cs # Builder 模式
│ ├── Exceptions/
│ │ └── CoordinateTransformationException.cs
│ └── Tech.Geospatial.csproj
│
├── tests/
│ └── Tech.Geospatial.Tests/ # 单元测试
│ └── Transformations/
│ └── CoordinateTransformerTests.cs
│
└── Tech.Geospatial.sln
核心功能
1. 数据模型 (使用 record struct 优化性能)
// 地理坐标 (经度, 纬度)
public readonly record struct GeographicCoordinate(double Longitude, double Latitude)
{
public bool IsValid => Longitude is >= -180 and <= 180 &&
Latitude is >= -90 and <= 90;
}
// 投影坐标 (东移, 北移)
public readonly record struct ProjectedCoordinate(double Easting, double Northing)
{
public bool IsValid => !double.IsNaN(Easting) && !double.IsNaN(Northing);
}
2. 投影带配置
// 创建3度带
var zone = ProjectionZone.CreateThreeDegreeZone(39);
// ZoneNumber: 39, CentralMeridian: 117°
// 创建6度带
var zone = ProjectionZone.CreateSixDegreeZone(20);
// ZoneNumber: 20, CentralMeridian: 117°
// 自动计算投影带
var zone = ProjectionZone.AutoThreeDegreeZone(116.5);
// 根据经度自动计算
// 自定义中央子午线
var zone = ProjectionZone.CreateCustomCentralMeridian(115.5);
3. 坐标转换
// 使用 Builder 创建转换器
var transformer = CoordinateTransformerBuilder.Create()
.WithParallelProcessing() // 启用并行处理
.Build();
// 地理坐标转投影坐标
var geoCoord = new GeographicCoordinate(116.3912, 39.9075);
var zone = ProjectionZone.AutoThreeDegreeZone(geoCoord.Longitude);
var projected = transformer.TransformToProjected(geoCoord, zone);
// 投影坐标转地理坐标
var geographic = transformer.TransformToGeographic(projected, zone);
// 批量转换
var coordinates = new[] { geoCoord1, geoCoord2, geoCoord3 };
var results = transformer.TransformToProjected(coordinates, zone);
4. 转换选项
// 默认选项
var options = TransformOptions.Default;
// 启用并行处理
var options = TransformOptions.WithParallel;
// 高性能模式 (缓存 + 并行)
var options = TransformOptions.HighPerformance;
// 自定义选项
var options = new TransformOptions
{
EnableParallelProcessing = true,
ParallelThreshold = 500,
EnableCache = true,
Tolerance = 0.001
};
性能优化策略
- 坐标系缓存 - 使用
ConcurrentDictionary缓存 ICoordinateTransformation 对象 - 批量处理 - 支持
ReadOnlySpan批量转换,减少数组拷贝 - 并行处理 - 使用
Parallel.For处理大批量数据 - record struct - 避免堆分配,使用栈上内存
- CollectionsMarshal - 对 List<T> 零拷贝转换为 Span
依赖项
<PackageReference Include="ProjNet4GeoAPI" Version="1.4.1" />
.NET 10 特性应用
- File-scoped namespaces
- Nullable reference types (enabled)
- Records (record struct for performance)
- Pattern matching
- Span<T> for zero-copy operations
- String interpolation (multi-line)
- Required members
构建和测试
# 构建解决方案
dotnet build
# 运行测试
dotnet test
# 发布发布版本
dotnet publish -c Release
测试覆盖
当前测试覆盖率:24 个测试用例,全部通过
- 单坐标转换测试
- 批量转换测试
- 往返转换精度测试
- 异常处理测试
- 投影带计算测试
- Builder 模式测试
使用示例
基本用法
using Tech.Geospatial.Models;
using Tech.Geospatial.Configuration;
using Tech.Geospatial.Transformations;
// 创建转换器
var transformer = CoordinateTransformerBuilder.Create().Build();
// 北京坐标转换
var beijing = new GeographicCoordinate(116.3912, 39.9075);
var zone = ProjectionZone.AutoThreeDegreeZone(beijing.Longitude);
// 转换为投影坐标
var projected = transformer.TransformToProjected(beijing, zone);
Console.WriteLine($"Easting: {projected.Easting}, Northing: {projected.Northing}");
// 转换回地理坐标
var roundTrip = transformer.TransformToGeographic(projected, zone);
Console.WriteLine($"Longitude: {roundTrip.Longitude}, Latitude: {roundTrip.Latitude}");
批量转换
// 批量转换
var cities = new[]
{
new GeographicCoordinate(116.3912, 39.9075), // 北京
new GeographicCoordinate(121.4737, 31.2304), // 上海
new GeographicCoordinate(113.2644, 23.1291), // 广州
};
var zone = ProjectionZone.AutoThreeDegreeZone(116.0);
var results = transformer.TransformToProjected(cities, zone);
foreach (var result in results)
{
Console.WriteLine($"Easting: {result.Easting}, Northing: {result.Northing}");
}
高性能场景
// 大批量数据处理 (自动并行)
var transformer = CoordinateTransformerBuilder.Create()
.WithParallelProcessing(threshold: 1000)
.Build();
// 处理 10 万个坐标点
var largeDataset = Enumerable.Range(0, 100000)
.Select(i => new GeographicCoordinate(116.0 + i * 0.0001, 39.0 + i * 0.0001))
.ToList();
var results = transformer.TransformToProjected(largeDataset, zone);
许可证
MIT License
作者
Generated with Claude Code
更新日志
v1.0.0 (2025-03-21)
- 初始版本
- CGCS2000 坐标系支持
- 高斯-克吕格投影 (3度带、6度带)
- 批量转换优化
- 并行处理支持
- 24 个单元测试,全部通过
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- NetTopologySuite (>= 2.6.0)
- NetTopologySuite.IO.GeoJSON (>= 4.0.0)
- ProjNET4GeoAPI (>= 1.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.0.0 | 137 | 3/21/2026 |
初始版本
- CGCS2000 坐标系支持 (EPSG:4490)
- 高斯-克吕格投影 (3度带、6度带)
- 批量坐标转换优化
- 并行处理支持