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

2继续NTS库学习(读取shapefile)

引用库如下:

读取shapefile代码如下:

namespace IfoxDemo
{public class Class1{[CommandMethod("xx")]public static void nts二次学习(){Document doc = Application.DocumentManager.MdiActiveDocument;var ed = doc.Editor;string shpPath = @"C:\Users\Administrator\Desktop\1.shp";var shpPath2 = @"C:\Users\Administrator\Desktop\2.shp";foreach (var feature in NetTopologySuite.IO.Esri.Shapefile.ReadAllFeatures(shpPath2)){foreach (var attrName in feature.Attributes.GetNames()){ed.WriteMessage($"\n字段名为:\"{attrName,10}\" \n 字段内容为: \"{feature.Attributes[attrName]}\"\n");}ed.WriteMessage($"    形状和xy为\"{feature.Geometry}\"\n");break;}ed.WriteMessage("下一个:\n");foreach (var feature in NetTopologySuite.IO.Esri.Shapefile.ReadAllFeatures(shpPath)){foreach (var attrName in feature.Attributes.GetNames()){ed.WriteMessage($"字段名为:\"{attrName,10}\" \n 字段内容为: \"{feature.Attributes[attrName]}\n");}ed.WriteMessage($"     SHAPE: 形状和xy为\"{feature.Geometry}\"\n");break;}}}
}

 读取结果如下:

读取dbf文件如下:

          var ed = Env.Editor;var shpPath = @"C:\Users\Administrator\Desktop\新建文件夹 (2)\zd.shp";var dbfPath = @"C:\Users\Administrator\Desktop\新建文件夹 (2)\zd.dbf";using var dbf = new DbfReader(dbfPath);int id = 0;foreach (var record in dbf){ed.WriteMessage($"\n第{id}条记录: \n");foreach (var fieldName in record.GetNames()){ed.WriteMessage($"\n字段名为:{fieldName,10} ,字段记录内容为{record[fieldName]}。\n");}id++;}

读取shp文件的几何信息:

            var ed = Env.Editor;var shpPath = @"C:\Users\Administrator\Desktop\新建文件夹 (2)\zd.shp";var dbfPath = @"C:\Users\Administrator\Desktop\新建文件夹 (2)\zd.dbf";using var dbf = new DbfReader(dbfPath);int id = 0;foreach (NetTopologySuite.Geometries.Geometry geometry in Shapefile.ReadAllGeometries(shpPath)){id++;ed.WriteMessage($"\n第{id}个geometry:"+geometry.ToString());ed.WriteMessage("\ngeometry的类型为:"+geometry.GetType().ToString()+"\n");// 根据几何类型提取坐标点List<Point3d> points = new List<Point3d>();if (geometry is Point point){// 如果是点类型points.Add(new Point3d(point.X, point.Y, point.Z)); // 假设 Z 坐标为 0}else if (geometry is LineString lineString){// 如果是线类型foreach (Coordinate coord in lineString.Coordinates){points.Add(new Point3d(coord.X, coord.Y, coord.Z)); // 假设 Z 坐标为 0}}else if (geometry is Polygon polygon){// 如果是面类型foreach (Coordinate coord in polygon.ExteriorRing.Coordinates){points.Add(new Point3d(coord.X, coord.Y, coord.Z)); // 假设 Z 坐标为 0}}// 其他几何类型(如 MultiPoint、MultiLineString、MultiPolygon 等)可以类似处理else if (geometry is  MultiPolygon multiPolygon){// 遍历 MultiPolygon 中的每个 Polygonforeach (Polygon polygon1 in multiPolygon.Geometries){// 提取外环的坐标点foreach (Coordinate coord in polygon1.ExteriorRing.Coordinates){points.Add(new Point3d(coord.X, coord.Y, coord.Z)); // 假设 Z 坐标为 0}// 提取内环的坐标点foreach (LineString interiorRing in polygon1.InteriorRings){foreach (Coordinate coord in interiorRing.Coordinates){points.Add(new Point3d(coord.X, coord.Y, coord.Z)); // 假设 Z 坐标为 0}}}}int j = 0;foreach(var pt in points){j++;ed.WriteMessage($"\n第{j}个坐标\n");ed.WriteMessage($"x:{pt.X},y:{pt.X}\n"); }}

double.NaN 是 C# 中表示 非数字(Not a Number) 的特殊值。它是 double 类型的一个常量,用于表示无效或未定义的数值结果。以下是关于 double.NaN 的详细说明:


1. 什么是 double.NaN

  • 定义
    NaN 是 IEEE 754 浮点数标准中定义的一个特殊值,表示 非数字

  • 特点

    • 它不是任何具体的数值。

    • 它用于表示无效的数学运算结果(如 0 / 0 或 Math.Sqrt(-1))。

    • 它与任何值(包括它自己)的比较结果都是 false


http://www.mrgr.cn/news/92746.html

相关文章:

  • Unity TMPro显示中文字体
  • 【通俗讲解电子电路】——从零开始理解生活中的电路(一)
  • Windows对比MacOS
  • 【01游戏——DFS】
  • 使用Semantic Kernel:对DeepSeek添加自定义插件
  • 【AI深度学习基础】NumPy完全指南入门篇:核心功能与工程实践(含完整代码)
  • 工程化与框架系列(4)--Webpack 高级配置详解
  • 大模型WebUI:Gradio全解12——LangChain原理、架构和组件(2)
  • 【Linux第一弹】Linux基础指令(上)
  • BIO、NIO、AIO、Netty从简单理解到使用
  • 【DeepSeek】本地部署,保姆级教程
  • Python 数据结构 2.时间复杂度和空间复杂度
  • 工程化与框架系列(10)--微前端架构
  • 【零基础C语言】第二节 数据类型、运算符、表达式
  • 蓝桥杯 之 填空题-位运算与循环
  • Linux云计算SRE-第十五周
  • 【deepseek第一课】从0到1介绍 采用ollama安装deepseek私有化部署,并实现页面可视化
  • C语言32个关键字
  • 【C++编程探索】01前缀和来临!优点多多!八千字详解
  • 我的AI工具箱Tauri+Django环境开发,支持局域网使用