2. QGis二次开发项目实践一之技术实现

前言

  • 本文描述了QGis二次开发项目实践一的涉及到的技术点
  • 涉及到的QGis技术点如下
    • 矢量图层加载显示
    • 矢量图层导出
    • dxf矢量图层合并

代码描述

矢量图层加载显示

矢量图层导出

Core库相关类

  • QgsVectorFileWriter文件见链接

A convenience class for writing vector layers to disk based formats (e.g.Shapefiles, GeoPackage).
There are two possibilities how to use this class:

  1. A static call to QgsVectorFileWriter::writeAsVectorFormat(…) which saves the whole vector layer.
  2. Create an instance of the class and issue calls to addFeature(…).
  • 该类的一个函数writeAsVectorFormatV3()可以将矢量图层保存到磁盘
    /**
     * Writes a layer out to a vector file.
     * \param layer source layer to write
     * \param fileName file name to write to
     * \param transformContext coordinate transform context
     * \param options save options
     * \param newFilename potentially modified file name (output parameter)
     * \param newLayer potentially modified layer name (output parameter)
     * \param errorMessage will be set to the error message text, if an error occurs while writing the layer
     * \returns Error message code, or QgsVectorFileWriter.NoError if the write operation was successful
     * \since QGIS 3.20
     */
    static QgsVectorFileWriter::WriterError writeAsVectorFormatV3( QgsVectorLayer *layer,
        const QString &fileName,
        const QgsCoordinateTransformContext &transformContext,
        const QgsVectorFileWriter::SaveVectorOptions &options,
        QString *errorMessage SIP_OUT = nullptr,
        QString *newFilename SIP_OUT = nullptr,
        QString *newLayer SIP_OUT = nullptr );

Gui库相关类

  • QgsVectorLayerSaveAsDialog类详细描述见文档

Class to select destination file, type and CRS for ogr layers.

  • 在本项目中就直接使用了Gui库中的QgsVectorLayerSaveAsDialog类,效果见下图
    在这里插入图片描述

dxf矢量图层合并

  • 矢量图层合并使用了gdal库的命令ogr2ogr

gdal

GDAL is a translator library for raster and vector geospatial data formats that is released under an MIT style Open Source License by the Open Source Geospatial Foundation. As a library, it presents a single raster abstract data model and single vector abstract data model to the calling application for all supported formats. It also comes with a variety of useful command line utilities for data translation and processing.

GDAL(Geospatial Data Abstraction Library)是一个开源的地理空间数据处理库,为读取、写入和处理各种地理空间数据格式提供了广泛的功能支持。它是地理信息系统(GIS)领域中最重要和最常用的开源库之一,被广泛应用于地图制图、遥感影像处理、空间分析和地理空间数据可视化等领域。
GDAL支持数百种栅格和矢量数据格式,如GeoTIFF、ESRI Shapefile、NetCDF等,这使得它成为处理各种地理空间数据的强大工具。此外,GDAL还提供了一系列数据处理功能,如重采样、裁剪、投影转换等,并允许用户在不同的地理空间数据格式之间进行转换。
GDAL的特点在于其跨平台性、开源性和易用性。它可以在多种操作系统上运行,包括Windows、Linux和Mac OS等,并支持多种编程语言,如C/C++、Python、Java、JavaScript等。作为开源项目,GDAL的源代码可供用户自由查看和修改,吸引了大量的开发者和贡献者参与项目的维护和发展。
GDAL中的OGR是其项目的一个分支,主要提供对矢量数据的支持。OGR封装了OpenGIS的矢量数据模型,提供了丰富的几何操作以及空间参考系统的定义等功能。
总的来说,GDAL是一个功能强大的地理空间数据处理库,为GIS领域的研究和应用提供了便捷的数据处理工具。无论是进行空间分析、数据可视化还是构建GIS系统,GDAL都是一个不可或缺的库。

在QGIS中,GDAL/OGR库被用作后端的数据处理引擎,使QGIS能够读取、写入和处理多种栅格和矢量数据格式。这种集成使得QGIS成为一个功能强大的GIS工具,能够处理各种地理空间数据,并为用户提供丰富的空间分析功能。

合并功能实现

在这里插入图片描述

  • ogr2ogr功能很多,这里只用到了两项功能
  1. 首先将.dxf文件转换为追加至all.geojson
ogr2ogr.exe -append -f geojson all.geojson 1.dxf
ogr2ogr.exe -append -f geojson all.geojson 2.dxf
  1. 然后将all.geojson文件转换为.dxf
ogr2ogr.exe -f dxf all.dxf all.geojson
  • 这样就完成了将dxf文件不同类型的图层合并为一个dxf文件的功能

总结

  • 分别介绍了矢量图层加载显示,矢量图层导出和dxf矢量图层合并功能的技术实现
  • 17
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雷动软件工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值