当前位置: 首页 > news >正文

C# NetTopologySuite+ProjNet 任意图形类型坐标转换

添加引用:NetTopologySuite、ProjNet、ProjNet.SRID

Program.cs文件:

using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;
using ProjNet.SRID;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Xsl;
using NetTopologySuite.IO;
using NetTopologySuite.Geometries;namespace Reproject2
{internal class Program{static void Main(string[] args){CoordinateSystem projCs = SRIDReader.GetCSbyID(4527);CoordinateSystem geoCs = SRIDReader.GetCSbyID(4490);CoordinateTransformationFactory ctFactory = new CoordinateTransformationFactory();ICoordinateTransformation transformation = ctFactory.CreateFromCoordinateSystems(projCs, geoCs);Polygon original = new Polygon(new LinearRing(new Coordinate[] {new Coordinate(39498340.1151, 4807100.9600),new Coordinate(39499340.1151, 4809100.9600),new Coordinate(39497340.1151, 4806100.9600),new Coordinate(39498340.1151, 4807100.9600)}));foreach (var coor in original.Coordinates){Console.WriteLine("原始坐标: " + coor.X + " ; " + coor.Y);}Geometry after = Transform(original, transformation.MathTransform);foreach (var coor in after.Coordinates){Console.WriteLine("转换后坐标: " + coor.X + " ; " + coor.Y);}Console.ReadKey();}public static Geometry Transform(Geometry geometry, MathTransform mathTransform){geometry = geometry.Copy();geometry.Apply(new MathTransformFilter(mathTransform));return geometry;}}
}

新增文件:MathTransformFilter.cs,用于完成任意geometry的序列化转坐标。

using NetTopologySuite.Geometries;
using ProjNet.CoordinateSystems.Transformations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace Reproject2
{public class MathTransformFilter : ICoordinateSequenceFilter{private readonly MathTransform _mathTransform;public MathTransformFilter(MathTransform mathTransform)=> _mathTransform = mathTransform;public bool Done => false;public bool GeometryChanged => true;public void Filter(CoordinateSequence seq, int i){var (x, y, z) = _mathTransform.Transform(seq.GetX(i), seq.GetY(i), seq.GetZ(i));seq.SetX(i, x);seq.SetY(i, y);seq.SetZ(i, z);}}
}

 

http://www.lryc.cn/news/148375.html

相关文章:

  • Windows笔记本电脑开机黑屏
  • Samb共享用户的设置和修改Linux用户的id号,修改Linux组的id号,加入组,删除组成员等
  • VBA:对Excel单元格进行合并操作
  • HTML5离线储存
  • cmd: Union[List[str], str], ^ SyntaxError: invalid syntax
  • 2023高教社杯数学建模思路 - 案例:异常检测
  • FFDNet-pytorch版本代码测试教程
  • uni-app项目由hbuilder项目转化为cli项目
  • 使用SpaceDesk连接平板作为电脑副屏详细步骤教程
  • 云备份——第三方库使用介绍(下)
  • springboot实战(一)之项目搭建
  • 线性代数的学习和整理16:什么是各种空间(类型),向量空间,距离(类型)?
  • css实现文字翻转效果
  • 19 Linux之Python定制篇-apt软件管理和远程登录
  • WebDAV之π-Disk派盘 + notototo
  • _kbhit() and getch() 在小游戏中用不了。因为控制台函数,仅在控制台程序中可用
  • dayjs格式转换成日期
  • mfc140u.dll丢失如何修复?解析mfc140u.dll是什么文件跟修复方法分享
  • STM32--SPI通信与W25Q64(2)
  • 微信小程序 校园周边美食商城分享系统
  • K8S - 架构、常用K8S命令、yaml资源清单部署、Ingress、故障排查、存储卷
  • micro benchmark 使用经验
  • nodejs发布静态https服务器
  • 国产系统下开发QT程序总结
  • 【Redis】redis入门+java操作redis
  • 无涯教程-Android - Spinner函数
  • 国标GB28181视频平台EasyGBS国标平台智能边缘计算网关关于小区电动车进电梯的应用方案设计
  • supervisorctl(-jar)启动配置设置NACOS不同命名空间
  • 如何解决 Out Of Memory 的问题
  • 代码随想录训练营二刷第九天 | 字符串结束