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

NTS库学习,找bug中......

 

基础知识
Coordinate: 表示一个二维坐标点,包括 X 和 Y 坐标值。
CoordinateSequence: 由一系列 Coordinate 对象组成的序列,可以表示线、多边形等几何对象的顶点。
CoordinateFilter: 用于对几何对象的坐标进行过滤或修改的接口。

Geometry: 表示一个几何对象的抽象基类。它有许多具体的子类,如 Point、LineString、Polygon 等,用于表示不同类型的几何对象。
GeometryFactory: 用于创建几何对象的工厂类,提供了创建不同类型几何对象的方法。
GeometryCollection: 表示多个几何对象的集合,可以包含各种类型的几何对象。
GeometryTransformer: 用于对几何对象进行转换的工具类,包括坐标系转换、平移、旋转、缩放等操作。

Envelope: 表示一个矩形边界框,可以用于表示几何对象的边界范围。

IntersectionMatrix: 描述几何对象之间的拓扑关系的矩阵,包含 9 个位置值(Dimensional Extended Nine-Intersection Model)。

PrecisionModel: 用于控制几何对象坐标的精度和舍入规则。
Point: 表示一个点的几何对象,由一个坐标构成。

LineString: 表示一条线段或曲线的几何对象,由一系列有序的坐标点构成。

LinearRing: 表示一个封闭的线环,通常用于定义多边形的外环或内环。

Polygon: 表示一个多边形的几何对象,由一个外环和零个或多个内环组成。

MultiPoint: 表示多个点的集合,每个点都是一个独立的几何对象。
MultiLineString: 表示多条线段或曲线的集合,每条线段都是一个独立的几何对象。
MultiPolygon: 表示多个多边形的集合,每个多边形都是一个独立的几何对象。

DistanceOp: 用于计算几何对象之间的距离和最近点的工具类。

IntersectionMatrix: 描述几何对象之间的拓扑关系的矩阵,包含 9 个位置值(Dimensional Extended Nine-Intersection Model)。

引用库:

代码如下:

//using GeoAPI.Geometries;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite;
using NetTopologySuite.IO;
using Coordinate = NetTopologySuite.Geometries.Coordinate;
//using GeoAPI;
using NetTopologySuite.Operation.Polygonize;
using System.Threading;
using Point = NetTopologySuite.Geometries.Point;
using Polygon = NetTopologySuite.Geometries.Polygon;
using NetTopologySuite.Index.Quadtree;
using NetTopologySuite.Index.Strtree;
using NetTopologySuite.Triangulate;
using NetTopologySuite.Operation.Linemerge;
using System.Windows.Media;
using GeometryCollection = NetTopologySuite.Geometries.GeometryCollection;
using NetTopologySuite.Operation.Distance;
using NetTopologySuite.Algorithm;
using NetTopologySuite.Index.Bintree;
using System.Net.NetworkInformation;
using GeoAPI.Geometries;
using NetTopologySuite.IO.Esri.Shapefiles;
using NetTopologySuite.IO.Esri.Dbf;
using System.Collections;
[assembly: CommandClass(typeof(IfoxDemo.NTS自己))]//只允许此类快捷键命令namespace IfoxDemo
{public class NTS自己{[CommandMethod("xx")]public static void shp(){var ed = Env.Editor;"ad".Print();// 创建一个点对象var point = new Point(10, 20);ed.WriteMessage("// 创建一个点对象 point :" + point + "\n");// 创建一条线段对象var line = new LineString(new[] { new Coordinate(0, 0),new Coordinate(10, 10),new Coordinate(20, 0)});ed.WriteMessage("// 创建一条线段对象 line :" + line + "\n");// 创建一个多边形对象var polygon = new Polygon(new LinearRing(new[] {new Coordinate(0, 0),new Coordinate(0, 10),new Coordinate(10, 10),new Coordinate(10, 0),new Coordinate(0, 0)}));ed.WriteMessage("//  创建一个多边形对象 polygon : " + polygon + "\n");// 计算两个几何对象之间的距离var distance = point.Distance(line);ed.WriteMessage("//  计算两个几何对象之间的距离 distance: " + distance + "\n");// 计算一个几何对象的缓冲区var buffer = polygon.Buffer(0.5);Env.Editor.WriteMessage("//计算一个几何对象的缓冲区 buffer: " + buffer + "\n");// 判断两个几何对象是否相交var isIntersect = line.Intersects(polygon);ed.WriteMessage("//判断两个几何对象是否相交 isIntersect: " + isIntersect + "\n");// 创建一个包含所有几何对象的边界框//var envelope = line.Envelope.Union(polygon.Envelope);//    public void Insert(Envelope itemEnv, T item)//{//    CollectStats(itemEnv);//    var insertEnv = EnsureExtent(itemEnv, _minExtent);//    _root.Insert(insertEnv, item);//}// 创建一个 Quadtree 索引//var index = new Quadtree<NetTopologySuite.Geometries.Geometry>();//    index.Insert(envelope,line);//有bug//index.Insert(polygon);// 在索引中查找与一个几何对象相交的对象// var results = index.Query(line.EnvelopeInternal);// Env.Editor.WriteMessage("查找与一个几何对象相交的对象 results : " + results);GeometryFactory geometryFactory = new GeometryFactory();// 创建点Point point1 = geometryFactory.CreatePoint(new Coordinate(1.0, 1.0));Point point2 = geometryFactory.CreatePoint(new Coordinate(2.0, 12.0));Point point3 = geometryFactory.CreatePoint(new Coordinate(21.0, 22.0));Point point4 = geometryFactory.CreatePoint(new Coordinate(23.0, 32.0));Point point5 = geometryFactory.CreatePoint(new Coordinate(25.0, 42.0));Point point6 = geometryFactory.CreatePoint(new Coordinate(27.0, 52.0));Point point7 = geometryFactory.CreatePoint(new Coordinate(29.0, 62.0));// 使用 DistanceOp 计算两点之间的距离DistanceOp distanceOp = new DistanceOp(point1, point2);double dist = distanceOp.Distance();Env.Editor.WriteMessage("//计算两点之间的距离 dist : " + dist + "\n");// 创建线段LineString lineString = geometryFactory.CreateLineString(new Coordinate[] {new Coordinate(0, 0),new Coordinate(1, 1),new Coordinate(2, 2)});// 创建多边形Polygon polygon2 = geometryFactory.CreatePolygon(new Coordinate[] {new Coordinate(0, 0),new Coordinate(0, 1),new Coordinate(1, 1),new Coordinate(1, 0),new Coordinate(0, 0)});//计算两条线段的夹角(不区分方向)逆时针为正var 夹角不区分方向 = AngleUtility.AngleBetween(point1.Coordinate, point3.Coordinate, point2.Coordinate);ed.WriteMessage("//夹角不区分方向,逆时针为正" + 夹角不区分方向 + "\n");//计算两条线段的夹角(区分方向)var 夹角区分方向 = AngleUtility.AngleBetweenOriented(point1.Coordinate, point3.Coordinate, point2.Coordinate);ed.WriteMessage("//夹角区分方向" + 夹角区分方向 + "\n");// 生成 Delaunay 三角网DelaunayTriangulationBuilder dtb = new DelaunayTriangulationBuilder();dtb.SetSites(new MultiPoint(new Point[] { point1, point2, point3, point4, point5, point6, point7 }));GeometryCollection triangles = (GeometryCollection)dtb.GetTriangles(geometryFactory);Env.Editor.WriteMessage("//Delaunay 三角网 triangles: " + triangles + "\n");// 合并线段LineMerger lineMerger = new LineMerger();lineMerger.Add(lineString);System.Collections.ICollection mergedLines = (System.Collections.ICollection)lineMerger.GetMergedLineStrings();Env.Editor.WriteMessage("//合并线段 mergedLines : " + mergedLines + "\n");//创建集合图形// 几何创建工厂(也可不使用工厂模式直接创建几何图形)var gf = new GeometryFactory();var pg3 = gf.CreatePolygon(new[]{new Coordinate(612, 612),new Coordinate(144, 355),new Coordinate(165, 188),new Coordinate(277, 328),new Coordinate(612, 612)});Env.Editor.WriteMessage(" //创建几何图形Polygon pg3 : " + pg3 + "\n");var pg4 = gf.CreatePolygon(new[]{new Coordinate(412, 612),new Coordinate(555, 455),new Coordinate(655, 188),new Coordinate(577, 328),new Coordinate(412, 612)});//求并集方法var union = pg3.Union(pg4);Env.Editor.WriteMessage("//求并集:union  " + union + "\n");//求差集方法var difference = pg3.Difference(pg4);Env.Editor.WriteMessage("//求差集:difference  " + difference + "\n");// 创建一个包含多个点的集合Coordinate[] coordinates = new Coordinate[]{new Coordinate(0, 0),new Coordinate(5, 0),new Coordinate(3, 3),new Coordinate(0, 5),new Coordinate(2, 2),new Coordinate(1, 4)};GeometryFactory geometryFactory2 = new GeometryFactory();MultiPoint points = geometryFactory2.CreateMultiPointFromCoords(coordinates);Env.Editor.WriteMessage("//包含多个点的集合MultiPoint: " + points + "\n");// 使用 NetTopologySuite 计算二维凸包ConvexHull convexHull = new ConvexHull(points);var geo = new ConvexHull(points.Coordinates, GeometryFactory.Default).GetConvexHull();var 二维凸包 = convexHull.GetConvexHull();Env.Editor.WriteMessage("//计算二维凸包geo: " + geo + "\n");Env.Editor.WriteMessage("//计算二维凸包Convex hull geometry: " + 二维凸包 + "\n");//检测一个环是否是简单的(IsSimple)复杂的示例(IsSimple=false,自相交):var points2 = new Coordinate[] {new Coordinate(2,1), new Coordinate(3, 1),new Coordinate(1,4), new Coordinate(4, 4),new Coordinate(2, 1),};var ring = new LinearRing(points2);ed.WriteMessage("//检测一个环是否是简单的(true)、(自相交false) " + ring.IsSimple + "\n");var ring2 = new LinearRing(points2);ed.WriteMessage("//检测多边形的顺逆时针 rings2是: " + (ring2.IsCCW ? "逆时针" : "顺时针") + "\n");多边形的凹凸(convex / concave) 和 顺(Clockwise)/ 逆(CounterClockwise)时针3.1 多边形的凹凸定义:凸多边形(convex): 所有的内角都小于180°;凹多边形(concave): 至少有一个内角大于180°;/////在C#环境中,使用NetTopologySuite.IO.ShapeFile通常涉及以下步骤://1.引入必要的NuGet包,如NetTopologySuite和NetTopologySuite.IO。//2.创建`ShapefileReader`或`ShapefileWriter`对象来读取或写入Shapefile。//3.使用`ReadShape()`或`ReadFeature()`方法获取Shapefile中的几何对象和属性。//4.对数据进行操作,如计算几何、筛选属性等。//5.使用`WriteShape()`或`WriteFeature()`方法将修改后的数据写回Shapefile。string path = @"C:\Users\Administrator\Desktop\黄岗寺\黄岗寺.shp";// 检查文件是否存在if (!File.Exists(path)){ed.WriteMessage("Shapefile not found.\n");return;}ShapefileReader reader = new ShapefileReader(path);/*****             读取dbf文件                   ******/string dbfPath = @"C:\Users\Administrator\Desktop\黄岗寺\黄岗寺.dbf";if (!File.Exists(dbfPath)){ed.WriteMessage("dbf not found.\n");return;}using var dbf = new DbfReader(dbfPath);foreach (var record in dbf){foreach (var fieldName in record.GetNames()){ed.WriteMessage($"{fieldName,10} {record[fieldName]}\n");}}/************    读取shp文件     *************/string shpPath = @"C:\Users\Administrator\Desktop\黄岗寺\黄岗寺.shp";if (!File.Exists(shpPath)){ed.WriteMessage("dbf not found.\n");return;}//foreach (var geometry in Shapefile.ReadAllGeometries(shpPath))//{//    Console.WriteLine(geometry);//}var features = NetTopologySuite.IO.Esri.Shapefile.ReadAllFeatures(shpPath);int i = 0;foreach (var feature in features){i++;//此时通过NTS库读取的Geometry SRID为0,没有坐标系var geometry = feature.Geometry;ed.WriteMessage(@$"geometry{i}:" + geometry + "\n");//这一步为Geometry添加4326坐标系var geometryForWGS84 = GeometryFactory.Default.WithSRID(4326).CreateGeometry(geometry);ed.WriteMessage("wkbForWGS84:"+ geometryForWGS84 + "\n");}}}
}

相关文章:

NTS库学习,找bug中......

基础知识 Coordinate: 表示一个二维坐标点&#xff0c;包括 X 和 Y 坐标值。 CoordinateSequence: 由一系列 Coordinate 对象组成的序列&#xff0c;可以表示线、多边形等几何对象的顶点。 CoordinateFilter: 用于对几何对象的坐标进行过滤或修改的接口。 Geometry: 表示一个几…...

五十天精通硬件设计第40天-硬件测试流程

目录 一、硬件测试流程概述 二、详细测试流程 1. 需求分析与测试计划 2. 测试环境搭建 3. 测试执行 3.1 基本功能测试 3.2 性能测试 3.3 环境与可靠性测试 3.4 安全与合规性测试 4. 问题分析与调试 5. 回归测试与报告输出 三、关键注意事项 四、常见问题与解决 五…...

R语言安装教程(附安装包)R语言4.3.2版本安装教程

文章目录 前言一、安装包下载二、R-4.3.2安装步骤三、rtools43安装步骤四、RStudio安装步骤 前言 本教程将详细、全面地为你介绍在 Windows 系统下安装 R 语言 4.3.2 的具体步骤。无论你是初涉数据领域的新手&#xff0c;还是希望更新知识体系的专业人士&#xff0c;只要按照本…...

数据库 安装initializing database不通过

出现一下情况时&#xff1a; 处理方法&#xff1a; 将自己的电脑名称 中文改成英文 即可通过...

自动驾驶两个传感器之间的坐标系转换

有两种方式可以实现两个坐标系的转换。 车身坐标系下一个点p_car&#xff0c;需要转换到相机坐标系下&#xff0c;旋转矩阵R_car2Cam&#xff0c;平移矩阵T_car2Cam。点p_car在相机坐标系下记p_cam. 方法1&#xff1a;先旋转再平移 p_cam T_car2Cam * p_car T_car2Cam 需要注…...

信号——进程间通信(20250225)

1. 信号 管道&#xff1a;进程间数据通信&#xff08;同步通信&#xff09; 信号&#xff1a;进程间通信,用来发送通知(异步通信&#xff0c;中断) 1&#xff09;同步通信:发送端和接收端&#xff0c;使用同一时钟通信 异步通信:发送端和接收端使用不同时钟通信 …...

transformer架构嵌入层位置编码之动态NTK-aware位置编码

前文,我们已经构建了一个小型的字符级语言模型,是在transformer架构基础上实现的最基本的模型,我们肯定是希望对该模型进行改进和完善的。所以我们的另外一篇文章也从数据预处理、模型架构、训练策略、评估方法、代码结构、错误处理、性能优化等多个方面提出具体的改进点,但…...

东信营销科技巨额补贴仍由盈转亏:毛利率大幅下滑,现金流告急

《港湾商业观察》施子夫 近期&#xff0c;东信营销科技有限公司&#xff08;以下简称&#xff0c;东信营销科技&#xff09;递表港交所&#xff0c;联席保荐机构为海通国际和中银国际。 东信营销科技的国内运营主体为深圳市东信时代信息技术有限公司。尽管期内收入规模有所提…...

[电感、磁珠、0欧姆电阻]的区别与应用特性

1. 电感(Inductor) 基础特性: 储能元件:通过磁场存储能量,阻碍电流突变()。 核心参数:电感值(L)、额定电流、直流电阻(DCR)、自谐振频率(SRF)。 频率特性:感抗 ,(通直流、阻交流),低频时阻抗低,高频时阻抗高(但受SRF限制)。 电路符号及实物:多为绕线结…...

车载诊断架构 --- LIN节点路由转发注意事项

我是穿拖鞋的汉子,魔都中坚持长期主义的汽车电子工程师。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 简单,单纯,喜欢独处,独来独往,不易合同频过着接地气的生活,除了生存温饱问题之外,没有什么过多的欲望,表面看起来很高冷,内心热情,如果你身…...

前端 AJAX 二、AJAX使用

环境准备&#xff1a; 使用AJAX技术我们需要用到HTML/CSS/JS/jQuery/JavaWeb相关知识,原生的JS也可以进行AJAX的操作,但是相对比较繁琐也没有必要,故此我们使用jQuery封装后的AJAX技术来进行学习; 创建AJAX请求 $.ajax({url : "ajax/getName?id"id,// ajax请求的…...

Windows - 通过ssh打开带有图形界面的程序 - 一种通过计划任务的曲折实现方式

Windows(奇思妙想) - 通过ssh打开带有图形界面的程序 - 一种通过计划任务的曲折实现方式 前言 Windows启用OpenSSH客户端后就可以通过SSH的方式访问Windows了。但是通过SSH启动的程序&#xff1a; 无法显示图形界面会随着SSH进程的结束而结束 于是想到了一种通过执行“计划…...

Android ViewStub延迟初始化加载布局View,Kotlin

Android ViewStub延迟初始化加载布局View&#xff0c;Kotlin activity_my.xml: <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_…...

Web自动化之Selenium下Chrome与Edge的Webdriver常用Options参数

目录 引言 说明 Add_argument() 添加方式 常用参数 Add_experimental_option() 添加方式 常用方法 任务结束后仍然保持浏览器打开 禁用“Chrome 正受到自动测试软件的控制”提示 设置下载路径 禁用弹窗拦截 禁用图片加载 禁用 JavaScript 注意 引言 …...

数据安全_笔记系列05:数据合规与隐私保护(GDPR、CCPA、中国《数据安全法》)深度解析

数据安全_笔记系列05&#xff1a;数据合规与隐私保护&#xff08;GDPR、CCPA、中国《数据安全法》&#xff09;深度解析 在全球数据跨境流动和隐私保护强监管的背景下&#xff0c;企业需同时满足多法域合规要求。以下从 法规要点、核心差异、实施策略、跨境传输、典型案例 等维…...

AF3 DataPipeline类process_multiseq_fasta 方法解读

AlphaFold3 data_pipeline 模块DataPipeline类的 process_multiseq_fasta 方法用于处理多序列 FASTA 文件,生成 AlphaFold3 结构预测所需的特征,适用于多链复合物的预测。它结合了 Minkyung Baek 在 Twitter 上提出的“AlphaFold-Gap”策略,即通过在多链 MSA 中插入固定长度…...

中国的Cursor! 字节跳动推出Trae,开放Windows版(附资源),开发自己的网站,内置 GPT-4o 强大Al模型!

Trae是什么 Trae 是字节跳动推出的免费 AI IDE&#xff0c;通过 AI 技术提升开发效率。支持中文&#xff0c;集成了 Claude 3.5 和 GPT-4 等主流 AI 模型&#xff0c;完全免费使用。Trae 的主要功能包括 Builder 模式和 Chat 模式&#xff0c;其中 Builder 模式可帮助开发者从…...

图片爬取案例

修改前的代码 但是总显示“失败” 原因是 修改之后的代码 import requests import os from urllib.parse import unquote# 原始URL url https://cn.bing.com/images/search?viewdetailV2&ccidTnImuvQ0&id5AE65CE4BE05EE7A79A73EEFA37578E87AE19421&thidOIP.TnI…...

Go语言中的信号量:原理与实践指南

Go语言中的信号量&#xff1a;原理与实践指南 引言 在并发编程中&#xff0c;控制对共享资源的访问是一个经典问题。Go语言提供了丰富的并发原语&#xff08;如sync.Mutex&#xff09;&#xff0c;但当我们需要灵活限制并发数量时&#xff0c;信号量&#xff08;Semaphore&am…...

Qt如何将数据传入labview,Qt又如何从labview中读取数据?

Qt如何将数据传入labview,Qt又如何从labview中读取数据? Qt如何将数据传入labviewQt如何从labview中读取数据 Qt如何将数据传入labview Qt如何从labview中读取数据...

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

Chapter03-Authentication vulnerabilities

文章目录 1. 身份验证简介1.1 What is authentication1.2 difference between authentication and authorization1.3 身份验证机制失效的原因1.4 身份验证机制失效的影响 2. 基于登录功能的漏洞2.1 密码爆破2.2 用户名枚举2.3 有缺陷的暴力破解防护2.3.1 如果用户登录尝试失败次…...

逻辑回归:给不确定性划界的分类大师

想象你是一名医生。面对患者的检查报告&#xff08;肿瘤大小、血液指标&#xff09;&#xff0c;你需要做出一个**决定性判断**&#xff1a;恶性还是良性&#xff1f;这种“非黑即白”的抉择&#xff0c;正是**逻辑回归&#xff08;Logistic Regression&#xff09;** 的战场&a…...

React19源码系列之 事件插件系统

事件类别 事件类型 定义 文档 Event Event 接口表示在 EventTarget 上出现的事件。 Event - Web API | MDN UIEvent UIEvent 接口表示简单的用户界面事件。 UIEvent - Web API | MDN KeyboardEvent KeyboardEvent 对象描述了用户与键盘的交互。 KeyboardEvent - Web…...

ArcGIS Pro制作水平横向图例+多级标注

今天介绍下载ArcGIS Pro中如何设置水平横向图例。 之前我们介绍了ArcGIS的横向图例制作&#xff1a;ArcGIS横向、多列图例、顺序重排、符号居中、批量更改图例符号等等&#xff08;ArcGIS出图图例8大技巧&#xff09;&#xff0c;那这次我们看看ArcGIS Pro如何更加快捷的操作。…...

docker 部署发现spring.profiles.active 问题

报错&#xff1a; org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...

站群服务器的应用场景都有哪些?

站群服务器主要是为了多个网站的托管和管理所设计的&#xff0c;可以通过集中管理和高效资源的分配&#xff0c;来支持多个独立的网站同时运行&#xff0c;让每一个网站都可以分配到独立的IP地址&#xff0c;避免出现IP关联的风险&#xff0c;用户还可以通过控制面板进行管理功…...

Web后端基础(基础知识)

BS架构&#xff1a;Browser/Server&#xff0c;浏览器/服务器架构模式。客户端只需要浏览器&#xff0c;应用程序的逻辑和数据都存储在服务端。 优点&#xff1a;维护方便缺点&#xff1a;体验一般 CS架构&#xff1a;Client/Server&#xff0c;客户端/服务器架构模式。需要单独…...

Kafka主题运维全指南:从基础配置到故障处理

#作者&#xff1a;张桐瑞 文章目录 主题日常管理1. 修改主题分区。2. 修改主题级别参数。3. 变更副本数。4. 修改主题限速。5.主题分区迁移。6. 常见主题错误处理常见错误1&#xff1a;主题删除失败。常见错误2&#xff1a;__consumer_offsets占用太多的磁盘。 主题日常管理 …...