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

使用NetTopologySuite读写gpkg文件

直接上代码:

优势是什么?纯C#开发,不存在兼容和字符问题。

using NetTopologySuite;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using CdIts.NetTopologySuite.IO;
using CdIts.NetTopologySuite.IO.GeoPackage.FeatureReader;
using CdIts.NetTopologySuite.IO.GeoPackage.FeatureWriter;
using CdIts.NetTopologySuite.IO.GeoPackage.Features;
using CdIts.NetTopologySuite.IO.GeoPackage;namespace WinFormsApp1
{public partial class Form1 : Form{// Define the path for the GeoPackage filestring path = @"D:\temp\test测试.gpkg";public Form1(){InitializeComponent();}private void btnWriter_Click(object sender, EventArgs e){// Ensure the directory existsDirectory.CreateDirectory(Path.GetDirectoryName(path));var writer = new GeoPackageFeatureWriter(path);// Define the spatial reference system (SRID 4326 for WGS84)var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(4543);var point1 = geometryFactory.CreatePoint(new Coordinate(10, 20));var point2 = geometryFactory.CreatePoint(new Coordinate(52, 80));var point3 = geometryFactory.CreatePoint(new Coordinate(150, 60));Feature feature1 = new Feature();feature1.Attributes = new AttributesTable();feature1.Attributes.Add("id", "1");feature1.Geometry = point1;Feature feature2 = new Feature();feature2.Attributes = new AttributesTable();feature2.Attributes.Add("id", "2");feature2.Geometry = point2;Feature feature3 = new Feature();feature3.Attributes = new AttributesTable();feature3.Attributes.Add("id", "3");feature3.Geometry = point3;Feature[] pointFeatures = { feature1, feature2, feature3 };writer.AddLayer(pointFeatures, "testPoint");Coordinate coordinate1 = new Coordinate(10, 20);Coordinate coordinate2 = new Coordinate(52, 80);Coordinate coordinate3 = new Coordinate(150, 60);Coordinate[] coordinates1 = { coordinate1, coordinate2 };var line1 = geometryFactory.CreateLineString(coordinates1);Feature featureLine1 = new Feature();featureLine1.Attributes = new AttributesTable();featureLine1.Attributes.Add("id", "1");featureLine1.Geometry = line1;Coordinate[] coordinates2 = { coordinate2, coordinate3 };var line2 = geometryFactory.CreateLineString(coordinates2);Feature featureLine2 = new Feature();featureLine2.Attributes = new AttributesTable();featureLine2.Attributes.Add("id", "2");featureLine2.Geometry = line2;Coordinate[] coordinates3 = { coordinate1, coordinate3 };var line3 = geometryFactory.CreateLineString(coordinates3);Feature featureLine3 = new Feature();featureLine3.Attributes = new AttributesTable();featureLine3.Attributes.Add("id", "3");featureLine3.Geometry = line3;Feature[] lineFeatures = { featureLine1, featureLine2, featureLine3 };writer.AddLayer(lineFeatures, "testLine");/Coordinate[] coordinates = { coordinate1, coordinate2, coordinate3, coordinate1 };var polygon = geometryFactory.CreatePolygon(coordinates);Feature polygonFeature = new Feature();polygonFeature.Attributes = new AttributesTable();polygonFeature.Attributes.Add("id", "1");polygonFeature.Geometry = polygon;Feature[] polygonFeatures = { polygonFeature };writer.AddLayer(polygonFeatures, "testPolygon");writer.Close();}private void btnReader_Click(object sender, EventArgs e){var reader = new GeoPackageFeatureReader(path);IList<GeoPackageFeatureInfo> featureInfoes = reader.GetFeatureInfos();List<string> tableNames = new List<string>();foreach(var info in featureInfoes){if(tableNames.Contains(info.TableName) == false){tableNames.Add(info.TableName);}}foreach (var name in tableNames){Feature[] features = reader.ReadFeatures(name);foreach (var feature in features){Geometry geo = feature.Geometry;MessageBox.Show($"{geo.Centroid.X},{geo.Centroid.Y}");}}}}
}

相关文章:

使用NetTopologySuite读写gpkg文件

直接上代码&#xff1a; 优势是什么&#xff1f;纯C#开发&#xff0c;不存在兼容和字符问题。 using NetTopologySuite; using NetTopologySuite.Features; using NetTopologySuite.Geometries; using CdIts.NetTopologySuite.IO; using CdIts.NetTopologySuite.IO.GeoPackag…...

什么是http?列出常见方法并解他们?

HTTP 方法是客户端&#xff08;通常是浏览器&#xff09;用来向服务器表明其意图的方式。常见的 HTTP 方法有以下几种&#xff1a; 一、GET 解释&#xff1a;用于请求指定的资源。它是最常见的 HTTP 方法之一。GET 方法应该只用于获取数据&#xff0c;而不应该有任何副作用。例…...

通过修改注册表来提高导出图像的分辨率(PPT尝试)

通过修改注册表来提高 PowerPoint 导出图片的分辨率&#xff0c;可以导致导出的图片尺寸大于您期望的 1920 x 1080 像素。例如&#xff0c;将 ExportBitmapResolution 设置为 300 DPI&#xff0c;可能会导致输出图像的尺寸变得非常大&#xff0c;比如 10240 x 5760 像素。这是因…...

OpenCV 环境配置

首先下载opencv&#xff0c;在opencv官网进行下载。 按照上面的步骤&#xff0c;点击进去 滑至底部&#xff0c;不切换至不同页&#xff0c;选择合适的版本进行下载(Window系统选择Windows版本进行下载)。 接下来以4.1.2版本为例&#xff1a; 点击之后会进入这个页面&#xff…...

使用通义千问模拟ChatGPT-o1进行思考,并以类似于ChatGPT-o1的形式输出

prompt 你是ChatGPT O1&#xff0c;旨在通过第一性原理思维和基于证据的推理来解决用户问题。你的目标是提供清晰、循序渐进的解决方案、基础概念&#xff0c;并从头开始构建答案。 ### 指导原则&#xff1a; 以下是为大模型采用这种方法而设计的系统提示&#xff1a; 1. 理解…...

维生素对于生活的重要性

在探索健康奥秘的旅途中&#xff0c;维生素作为人体不可或缺的微量营养素&#xff0c;扮演着至关重要的角色。它们虽不直接提供能量&#xff0c;却是酶促反应、细胞代谢、免疫功能乃至心理健康的基石。今天&#xff0c;让我们一同深入探讨人体所需补充的维生素&#xff0c;这些…...

STM32学习--4-1 OLED显示屏

接线图 OLED.c #include "stm32f10x.h" #include "OLED_Font.h"/*引脚配置*/ #define OLED_W_SCL(x) GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)(x)) #define OLED_W_SDA(x) GPIO_WriteBit(GPIOB, GPIO_Pin_9, (BitAction)(x))/*引脚初始化*/ void …...

原生 App 上架 Mac App Store 过程总结

随着 macOS 系统的普及&#xff0c;越来越多的开发者希望将他们的原生应用程序发布到 Mac App Store&#xff0c;以便触达更广泛的用户群体。在这篇文章中&#xff0c;我们将详细总结原生 App 上架 Mac App Store 的整个过程&#xff0c;包括必要的准备工作、开发流程、测试、申…...

[实时计算flink]双流JOIN语句

Flink SQL支持对动态表进行复杂而灵活的连接操作&#xff0c;本文为您介绍如何使用双流JOIN语句。 背景信息 实时计算的JOIN和传统批处理JOIN的语义一致&#xff0c;都用于将两张表关联起来。区别为实时计算关联的是两张动态表&#xff0c;关联的结果也会动态更新&#xff0c…...

metahuman如何导入UE5

1.启动 通过EPIC启动UE5(UE5内置有Bridge, 但是UE4是需要单独下在Bridge软件) 2.打开Quixel Bridge 在window(窗口)中打开Quixel Bridge 3.Bridge界面 在弹出的Bridge界面选择模型 需要先下载&#xff0c;然后再导入 4.下载模型 点击需要的模型右上方的绿色箭头下载 5.下…...

Python知识点:基于Python技术,如何使用TensorFlow进行自动驾驶模型训练

开篇&#xff0c;先说一个好消息&#xff0c;截止到2025年1月1日前&#xff0c;翻到文末找到我&#xff0c;赠送定制版的开题报告和任务书&#xff0c;先到先得&#xff01;过期不候&#xff01; 使用TensorFlow进行自动驾驶模型训练的Python技术详解 自动驾驶技术是人工智能领…...

Django的请求与响应

Django的请求与响应 1、常见的请求2、常见的响应3、案例 1、常见的请求 函数的参数request是一个对象&#xff0c;封装了用户发送过来的所有请求相关数据。 get请求一般用来请求获取数据&#xff0c;get请求也可以传参到后台&#xff0c;但是传递的参数显示在地址栏。 post请求…...

[java]Iterable<Integer> 和Iterator<Integer>的区别和用法

Iterable<Integer> 和 Iterator<Integer> 在 Java 中都是用于处理集合数据的重要接口&#xff0c;但它们的角色和用途有所不同。以下是它们之间的主要区别&#xff1a; 1. 接口角色 Iterable<T>&#xff1a;这是一个接口&#xff0c;它定义了如何获取一个…...

JavaScript进行数据可视化:D3.js入门

在数据驱动的世界中&#xff0c;数据可视化是理解和传达数据信息的重要手段。D3.js是一个强大的JavaScript库&#xff0c;它允许开发者将数据转换为可交互的图形和图表。本文将为您介绍D3.js的基本概念、特点以及如何入门使用它进行数据可视化。 D3.js简介 什么是D3.js&#…...

字符串拼接方法性能对比和分析

对字符串进行拼接主要有三种方法&#xff1a; 1.加号 2.concat方法 3.StringBuilder或者StringBuffer的append方法 下面看下性能对比&#xff0c;测试方法为各循环十万次&#xff0c;对比耗费时间。 测试性能 1.”"拼接 long start System.currentTimeMillis();String …...

[Halcon矩阵] 通过手眼标定矩阵计算相机旋转角度

&#x1f4e2;博客主页&#xff1a;https://loewen.blog.csdn.net&#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01;&#x1f4e2;本文由 丶布布原创&#xff0c;首发于 CSDN&#xff0c;转载注明出处&#x1f649;&#x1f4e2;现…...

推荐几本编程入门书目

对于编程入门&#xff0c;推荐以下几本书籍&#xff0c;这些书籍覆盖了不同的编程语言&#xff0c;适合零基础的学习者逐步掌握编程基础&#xff1a; 1. 《Python编程快速上手——让繁琐工作自动化》 特点&#xff1a;以简单易懂的方式介绍了Python的基础知识和编程概念&#…...

每天一个数据分析题(五百零五)- 提升方法

提升方法&#xff08;Boosting&#xff09;&#xff0c;是一种可以用来减小监督式学习中偏差的机器学习算法。基于Boosting的集成学习&#xff0c;其代表算法不包括&#xff1f; A. Adaboost B. GBDT C. XGBOOST D. 随机森林 数据分析认证考试介绍&#xff1a;点击进入 题…...

华为云ECS部署DR模式的LVS

1 概述 LVS是linux内核模块&#xff0c;用于4层的负载均衡&#xff0c;它有多个工作模式&#xff0c;例如NAT模式、DR模式。 DR模式的数据流是这样的&#xff1a; client ---> Director Server&#xff08;即LVS服务器&#xff0c;带VIP&#xff09; ---> Real Serve…...

如何在 Jupyter Notebook 执行和学习 SQL 语句(上)

在Jupyter Notebook中使用SQL&#xff0c;你可以通过以下步骤创建一个数据库并连接到该数据库&#xff1a; 1. 安装SQLite和SQLAlchemy SQLite 是一个轻量级的数据库系统&#xff0c;适合本地小型项目。SQLAlchemy 是一个强大的数据库连接工具&#xff0c;可以在Jupyter中方便…...

智慧医疗能源事业线深度画像分析(上)

引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

微信小程序之bind和catch

这两个呢&#xff0c;都是绑定事件用的&#xff0c;具体使用有些小区别。 官方文档&#xff1a; 事件冒泡处理不同 bind&#xff1a;绑定的事件会向上冒泡&#xff0c;即触发当前组件的事件后&#xff0c;还会继续触发父组件的相同事件。例如&#xff0c;有一个子视图绑定了b…...

黑马Mybatis

Mybatis 表现层&#xff1a;页面展示 业务层&#xff1a;逻辑处理 持久层&#xff1a;持久数据化保存 在这里插入图片描述 Mybatis快速入门 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6501c2109c4442118ceb6014725e48e4.png //logback.xml <?xml ver…...

三维GIS开发cesium智慧地铁教程(5)Cesium相机控制

一、环境搭建 <script src"../cesium1.99/Build/Cesium/Cesium.js"></script> <link rel"stylesheet" href"../cesium1.99/Build/Cesium/Widgets/widgets.css"> 关键配置点&#xff1a; 路径验证&#xff1a;确保相对路径.…...

Java多线程实现之Callable接口深度解析

Java多线程实现之Callable接口深度解析 一、Callable接口概述1.1 接口定义1.2 与Runnable接口的对比1.3 Future接口与FutureTask类 二、Callable接口的基本使用方法2.1 传统方式实现Callable接口2.2 使用Lambda表达式简化Callable实现2.3 使用FutureTask类执行Callable任务 三、…...

2025 后端自学UNIAPP【项目实战:旅游项目】6、我的收藏页面

代码框架视图 1、先添加一个获取收藏景点的列表请求 【在文件my_api.js文件中添加】 // 引入公共的请求封装 import http from ./my_http.js// 登录接口&#xff08;适配服务端返回 Token&#xff09; export const login async (code, avatar) > {const res await http…...

Spring Boot面试题精选汇总

&#x1f91f;致敬读者 &#x1f7e9;感谢阅读&#x1f7e6;笑口常开&#x1f7ea;生日快乐⬛早点睡觉 &#x1f4d8;博主相关 &#x1f7e7;博主信息&#x1f7e8;博客首页&#x1f7eb;专栏推荐&#x1f7e5;活动信息 文章目录 Spring Boot面试题精选汇总⚙️ **一、核心概…...

【OSG学习笔记】Day 16: 骨骼动画与蒙皮(osgAnimation)

骨骼动画基础 骨骼动画是 3D 计算机图形中常用的技术&#xff0c;它通过以下两个主要组件实现角色动画。 骨骼系统 (Skeleton)&#xff1a;由层级结构的骨头组成&#xff0c;类似于人体骨骼蒙皮 (Mesh Skinning)&#xff1a;将模型网格顶点绑定到骨骼上&#xff0c;使骨骼移动…...

MacOS下Homebrew国内镜像加速指南(2025最新国内镜像加速)

macos brew国内镜像加速方法 brew install 加速formula.jws.json下载慢加速 &#x1f37a; 最新版brew安装慢到怀疑人生&#xff1f;别怕&#xff0c;教你轻松起飞&#xff01; 最近Homebrew更新至最新版&#xff0c;每次执行 brew 命令时都会自动从官方地址 https://formulae.…...

Windows电脑能装鸿蒙吗_Windows电脑体验鸿蒙电脑操作系统教程

鸿蒙电脑版操作系统来了&#xff0c;很多小伙伴想体验鸿蒙电脑版操作系统&#xff0c;可惜&#xff0c;鸿蒙系统并不支持你正在使用的传统的电脑来安装。不过可以通过可以使用华为官方提供的虚拟机&#xff0c;来体验大家心心念念的鸿蒙系统啦&#xff01;注意&#xff1a;虚拟…...