├── test ├── tenbytenraster.keywords ├── __init__.py ├── tenbytenraster.prj ├── tenbytenraster.asc ├── tenbytenraster.asc.aux.xml ├── tenbytenraster.lic ├── test_resources.py ├── tenbytenraster.qml ├── test_china_transform_tool_dialog.py ├── test_translations.py ├── utilities.py ├── test_init.py ├── test_qgis_environment.py └── qgis_interface.py ├── .idea ├── .gitignore ├── misc.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── china_transform_tool.iml ├── icon.png ├── resources.qrc ├── compile.bat ├── scripts ├── compile-strings.sh ├── run-env-linux.sh └── update-strings.sh ├── i18n └── af.ts ├── help ├── source │ ├── index.rst │ └── conf.py ├── make.bat └── Makefile ├── README.html ├── README.txt ├── metadata.txt ├── __init__.py ├── china_transform_tool_dialog.py ├── pb_tool.cfg ├── plugin_upload.py ├── resources.py ├── ImgTransform.py ├── china_transform_tool_dialog_base.ui ├── Makefile ├── CoordTransform.py ├── china_transform_tool.py ├── pylintrc └── ShpTransform.py /test/tenbytenraster.keywords: -------------------------------------------------------------------------------- 1 | title: Tenbytenraster 2 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yimengyao13/china_transform_tool/HEAD/icon.png -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- 1 | # import qgis libs so that ve set the correct sip api version 2 | import qgis # pylint: disable=W0611 # NOQA -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /test/tenbytenraster.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] -------------------------------------------------------------------------------- /compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | call "C:\OSGeo4W64\o4w_env.bat" 3 | call "C:\OSGeo4W64\qt5_env.bat" 4 | call "C:\OSGeo4W64\py3_env.bat" 5 | 6 | @echo on 7 | pyrcc5 -o resources.py resources.qrc 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /scripts/compile-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LRELEASE=$1 3 | LOCALES=$2 4 | 5 | 6 | for LOCALE in ${LOCALES} 7 | do 8 | echo "Processing: ${LOCALE}.ts" 9 | # Note we don't use pylupdate with qt .pro file approach as it is flakey 10 | # about what is made available. 11 | $LRELEASE i18n/${LOCALE}.ts 12 | done 13 | -------------------------------------------------------------------------------- /i18n/af.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @default 5 | 6 | 7 | Good morning 8 | Goeie more 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/tenbytenraster.asc: -------------------------------------------------------------------------------- 1 | NCOLS 10 2 | NROWS 10 3 | XLLCENTER 1535380.000000 4 | YLLCENTER 5083260.000000 5 | DX 10 6 | DY 10 7 | NODATA_VALUE -9999 8 | 0 1 2 3 4 5 6 7 8 9 9 | 0 1 2 3 4 5 6 7 8 9 10 | 0 1 2 3 4 5 6 7 8 9 11 | 0 1 2 3 4 5 6 7 8 9 12 | 0 1 2 3 4 5 6 7 8 9 13 | 0 1 2 3 4 5 6 7 8 9 14 | 0 1 2 3 4 5 6 7 8 9 15 | 0 1 2 3 4 5 6 7 8 9 16 | 0 1 2 3 4 5 6 7 8 9 17 | 0 1 2 3 4 5 6 7 8 9 18 | CRS 19 | NOTES 20 | -------------------------------------------------------------------------------- /test/tenbytenraster.asc.aux.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Point 4 | 5 | 6 | 7 | 9 8 | 4.5 9 | 0 10 | 2.872281323269 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/china_transform_tool.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /help/source/index.rst: -------------------------------------------------------------------------------- 1 | .. ChinaTransformTool documentation master file, created by 2 | sphinx-quickstart on Sun Feb 12 17:11:03 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to ChinaTransformTool's documentation! 7 | ============================================ 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | 21 | -------------------------------------------------------------------------------- /README.html: -------------------------------------------------------------------------------- 1 | 使用QGIS插件来实现,shp文件和图像文件的坐标系转换,支持wgs84、gcj02、bd09坐标系之间的转换,支持文件格式*.shp、*.jpeg、*.jpg、*.png、*.tif、*.tiff,推荐矢量数据使用shp格式,栅格数据使用png格式。 2 | 插件使用说明,详见: 3 | https://zhuanlan.zhihu.com/p/366940211 4 | 或: 5 | https://blog.csdn.net/sinat_41310868/article/details/116015060 6 | 7 | Use QGIS plugin to achieve, SHP file and image file coordinate system conversion, support WGS84, GCJ02, BD09 coordinate system conversion, support file format *.shp, *.JPEG, *.JPG, *.Png, *.tif、*.tiff 8 | Plugin usage instructions, see: 9 | https://zhuanlan.zhihu.com/p/366940211 10 | or: 11 | https://blog.csdn.net/sinat_41310868/article/details/116015060 12 | -------------------------------------------------------------------------------- /test/tenbytenraster.lic: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Tim Sutton, Linfiniti Consulting CC 5 | 6 | 7 | 8 | tenbytenraster.asc 9 | 2700044251 10 | Yes 11 | Tim Sutton 12 | Tim Sutton (QGIS Source Tree) 13 | Tim Sutton 14 | This data is publicly available from QGIS Source Tree. The original 15 | file was created and contributed to QGIS by Tim Sutton. 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /scripts/run-env-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | QGIS_PREFIX_PATH=/usr/local/qgis-2.0 4 | if [ -n "$1" ]; then 5 | QGIS_PREFIX_PATH=$1 6 | fi 7 | 8 | echo ${QGIS_PREFIX_PATH} 9 | 10 | 11 | export QGIS_PREFIX_PATH=${QGIS_PREFIX_PATH} 12 | export QGIS_PATH=${QGIS_PREFIX_PATH} 13 | export LD_LIBRARY_PATH=${QGIS_PREFIX_PATH}/lib 14 | export PYTHONPATH=${QGIS_PREFIX_PATH}/share/qgis/python:${QGIS_PREFIX_PATH}/share/qgis/python/plugins:${PYTHONPATH} 15 | 16 | echo "QGIS PATH: $QGIS_PREFIX_PATH" 17 | export QGIS_DEBUG=0 18 | export QGIS_LOG_FILE=/tmp/inasafe/realtime/logs/qgis.log 19 | 20 | export PATH=${QGIS_PREFIX_PATH}/bin:$PATH 21 | 22 | echo "This script is intended to be sourced to set up your shell to" 23 | echo "use a QGIS 2.0 built in $QGIS_PREFIX_PATH" 24 | echo 25 | echo "To use it do:" 26 | echo "source $BASH_SOURCE /your/optional/install/path" 27 | echo 28 | echo "Then use the make file supplied here e.g. make guitest" 29 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Plugin Builder Results 2 | 3 | Your plugin ChinaTransformTool was created in: 4 | D:/gismap/QGIS二次开发/plugin\china_transform_tool 5 | 6 | Your QGIS plugin directory is located at: 7 | C:/Users/wujin/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins 8 | 9 | What's Next: 10 | 11 | * Copy the entire directory containing your new plugin to the QGIS plugin 12 | directory 13 | 14 | * Compile the resources file using pyrcc5 15 | 16 | * Run the tests (``make test``) 17 | 18 | * Test the plugin by enabling it in the QGIS plugin manager 19 | 20 | * Customize it by editing the implementation file: ``china_transform_tool.py`` 21 | 22 | * Create your own custom icon, replacing the default icon.png 23 | 24 | * Modify your user interface by opening ChinaTransformTool_dialog_base.ui in Qt Designer 25 | 26 | * You can use the Makefile to compile your Ui and resource files when 27 | you make changes. This requires GNU make (gmake) 28 | 29 | For more information, see the PyQGIS Developer Cookbook at: 30 | http://www.qgis.org/pyqgis-cookbook/index.html 31 | 32 | (C) 2011-2018 GeoApt LLC - geoapt.com 33 | -------------------------------------------------------------------------------- /test/test_resources.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Resources test. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | """ 10 | 11 | __author__ = '827337743@qq.com' 12 | __date__ = '2021-04-21' 13 | __copyright__ = 'Copyright 2021, wudaojian' 14 | 15 | import unittest 16 | 17 | from qgis.PyQt.QtGui import QIcon 18 | 19 | 20 | 21 | class ChinaTransformToolDialogTest(unittest.TestCase): 22 | """Test rerources work.""" 23 | 24 | def setUp(self): 25 | """Runs before each test.""" 26 | pass 27 | 28 | def tearDown(self): 29 | """Runs after each test.""" 30 | pass 31 | 32 | def test_icon_png(self): 33 | """Test we can click OK.""" 34 | path = ':/plugins/ChinaTransformTool/icon.png' 35 | icon = QIcon(path) 36 | self.assertFalse(icon.isNull()) 37 | 38 | if __name__ == "__main__": 39 | suite = unittest.makeSuite(ChinaTransformToolResourcesTest) 40 | runner = unittest.TextTestRunner(verbosity=2) 41 | runner.run(suite) 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /metadata.txt: -------------------------------------------------------------------------------- 1 | # This file contains metadata for your plugin. 2 | 3 | # This file should be included when you package your plugin.# Mandatory items: 4 | 5 | [general] 6 | name=China Transform Tool 7 | qgisMinimumVersion=3.0 8 | description=shp文件坐标系转换工具,支持WGS84\GCJ02\BD09坐标系转换 9 | version=0.1 10 | author=wudaojian 11 | email=827337743@qq.com 12 | 13 | about=shp/img文件坐标系转换工具,支持WGS84/GCJ02/BD09坐标系之间的转换。 14 | 15 | tracker=https://blog.csdn.net/sinat_41310868/article/details/116015060 16 | repository=https://github.com/yimengyao13/china_transform_tool 17 | # End of mandatory metadata 18 | 19 | # Recommended items: 20 | 21 | hasProcessingProvider=no 22 | # Uncomment the following line and add your changelog: 23 | # changelog= 24 | 25 | # Tags are comma separated with spaces allowed 26 | tags=python 27 | 28 | homepage=https://zhuanlan.zhihu.com/p/366940211 29 | category=Plugins 30 | icon=icon.png 31 | # experimental flag 32 | experimental=True 33 | 34 | # deprecated flag (applies to the whole plugin, not just a single version) 35 | deprecated=False 36 | 37 | # Since QGIS 3.8, a comma separated list of plugins to be installed 38 | # (or upgraded) can be specified. 39 | # Check the documentation for more information. 40 | # plugin_dependencies= 41 | 42 | Category of the plugin: Raster, Vector, Database or Web 43 | # category= 44 | 45 | # If the plugin can run on QGIS Server. 46 | server=False 47 | 48 | -------------------------------------------------------------------------------- /scripts/update-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LOCALES=$* 3 | 4 | # Get newest .py files so we don't update strings unnecessarily 5 | 6 | CHANGED_FILES=0 7 | PYTHON_FILES=`find . -regex ".*\(ui\|py\)$" -type f` 8 | for PYTHON_FILE in $PYTHON_FILES 9 | do 10 | CHANGED=$(stat -c %Y $PYTHON_FILE) 11 | if [ ${CHANGED} -gt ${CHANGED_FILES} ] 12 | then 13 | CHANGED_FILES=${CHANGED} 14 | fi 15 | done 16 | 17 | # Qt translation stuff 18 | # for .ts file 19 | UPDATE=false 20 | for LOCALE in ${LOCALES} 21 | do 22 | TRANSLATION_FILE="i18n/$LOCALE.ts" 23 | if [ ! -f ${TRANSLATION_FILE} ] 24 | then 25 | # Force translation string collection as we have a new language file 26 | touch ${TRANSLATION_FILE} 27 | UPDATE=true 28 | break 29 | fi 30 | 31 | MODIFICATION_TIME=$(stat -c %Y ${TRANSLATION_FILE}) 32 | if [ ${CHANGED_FILES} -gt ${MODIFICATION_TIME} ] 33 | then 34 | # Force translation string collection as a .py file has been updated 35 | UPDATE=true 36 | break 37 | fi 38 | done 39 | 40 | if [ ${UPDATE} == true ] 41 | # retrieve all python files 42 | then 43 | echo ${PYTHON_FILES} 44 | # update .ts 45 | echo "Please provide translations by editing the translation files below:" 46 | for LOCALE in ${LOCALES} 47 | do 48 | echo "i18n/"${LOCALE}".ts" 49 | # Note we don't use pylupdate with qt .pro file approach as it is flakey 50 | # about what is made available. 51 | pylupdate4 -noobsolete ${PYTHON_FILES} -ts i18n/${LOCALE}.ts 52 | done 53 | else 54 | echo "No need to edit any translation files (.ts) because no python files" 55 | echo "has been updated since the last update translation. " 56 | fi 57 | -------------------------------------------------------------------------------- /test/tenbytenraster.qml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | 27 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | ChinaTransformTool 5 | A QGIS plugin 6 | shp文件坐标系转换工具,支持WGS84\GCJ02\BD09坐标系转换 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2021-04-21 10 | copyright : (C) 2021 by wudaojian 11 | email : 827337743@qq.com 12 | git sha : $Format:%H$ 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | This script initializes the plugin, making it known to QGIS. 24 | """ 25 | 26 | 27 | # noinspection PyPep8Naming 28 | def classFactory(iface): # pylint: disable=invalid-name 29 | """Load ChinaTransformTool class from file ChinaTransformTool. 30 | 31 | :param iface: A QGIS interface instance. 32 | :type iface: QgsInterface 33 | """ 34 | # 35 | from .china_transform_tool import ChinaTransformTool 36 | return ChinaTransformTool(iface) 37 | -------------------------------------------------------------------------------- /test/test_china_transform_tool_dialog.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Dialog test. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | """ 10 | 11 | __author__ = '827337743@qq.com' 12 | __date__ = '2021-04-21' 13 | __copyright__ = 'Copyright 2021, wudaojian' 14 | 15 | import unittest 16 | 17 | from qgis.PyQt.QtGui import QDialogButtonBox, QDialog 18 | 19 | from china_transform_tool_dialog import ChinaTransformToolDialog 20 | 21 | from utilities import get_qgis_app 22 | QGIS_APP = get_qgis_app() 23 | 24 | 25 | class ChinaTransformToolDialogTest(unittest.TestCase): 26 | """Test dialog works.""" 27 | 28 | def setUp(self): 29 | """Runs before each test.""" 30 | self.dialog = ChinaTransformToolDialog(None) 31 | 32 | def tearDown(self): 33 | """Runs after each test.""" 34 | self.dialog = None 35 | 36 | def test_dialog_ok(self): 37 | """Test we can click OK.""" 38 | 39 | button = self.dialog.button_box.button(QDialogButtonBox.Ok) 40 | button.click() 41 | result = self.dialog.result() 42 | self.assertEqual(result, QDialog.Accepted) 43 | 44 | def test_dialog_cancel(self): 45 | """Test we can click cancel.""" 46 | button = self.dialog.button_box.button(QDialogButtonBox.Cancel) 47 | button.click() 48 | result = self.dialog.result() 49 | self.assertEqual(result, QDialog.Rejected) 50 | 51 | if __name__ == "__main__": 52 | suite = unittest.makeSuite(ChinaTransformToolDialogTest) 53 | runner = unittest.TextTestRunner(verbosity=2) 54 | runner.run(suite) 55 | 56 | -------------------------------------------------------------------------------- /test/test_translations.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Safe Translations Test. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | """ 10 | from .utilities import get_qgis_app 11 | 12 | __author__ = 'ismailsunni@yahoo.co.id' 13 | __date__ = '12/10/2011' 14 | __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 15 | 'Disaster Reduction') 16 | import unittest 17 | import os 18 | 19 | from qgis.PyQt.QtCore import QCoreApplication, QTranslator 20 | 21 | QGIS_APP = get_qgis_app() 22 | 23 | 24 | class SafeTranslationsTest(unittest.TestCase): 25 | """Test translations work.""" 26 | 27 | def setUp(self): 28 | """Runs before each test.""" 29 | if 'LANG' in iter(os.environ.keys()): 30 | os.environ.__delitem__('LANG') 31 | 32 | def tearDown(self): 33 | """Runs after each test.""" 34 | if 'LANG' in iter(os.environ.keys()): 35 | os.environ.__delitem__('LANG') 36 | 37 | def test_qgis_translations(self): 38 | """Test that translations work.""" 39 | parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir) 40 | dir_path = os.path.abspath(parent_path) 41 | file_path = os.path.join( 42 | dir_path, 'i18n', 'af.qm') 43 | translator = QTranslator() 44 | translator.load(file_path) 45 | QCoreApplication.installTranslator(translator) 46 | 47 | expected_message = 'Goeie more' 48 | real_message = QCoreApplication.translate("@default", 'Good morning') 49 | self.assertEqual(real_message, expected_message) 50 | 51 | 52 | if __name__ == "__main__": 53 | suite = unittest.makeSuite(SafeTranslationsTest) 54 | runner = unittest.TextTestRunner(verbosity=2) 55 | runner.run(suite) 56 | -------------------------------------------------------------------------------- /test/utilities.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Common functionality used by regression tests.""" 3 | 4 | import sys 5 | import logging 6 | 7 | 8 | LOGGER = logging.getLogger('QGIS') 9 | QGIS_APP = None # Static variable used to hold hand to running QGIS app 10 | CANVAS = None 11 | PARENT = None 12 | IFACE = None 13 | 14 | 15 | def get_qgis_app(): 16 | """ Start one QGIS application to test against. 17 | 18 | :returns: Handle to QGIS app, canvas, iface and parent. If there are any 19 | errors the tuple members will be returned as None. 20 | :rtype: (QgsApplication, CANVAS, IFACE, PARENT) 21 | 22 | If QGIS is already running the handle to that app will be returned. 23 | """ 24 | 25 | try: 26 | from qgis.PyQt import QtGui, QtCore 27 | from qgis.core import QgsApplication 28 | from qgis.gui import QgsMapCanvas 29 | from .qgis_interface import QgisInterface 30 | except ImportError: 31 | return None, None, None, None 32 | 33 | global QGIS_APP # pylint: disable=W0603 34 | 35 | if QGIS_APP is None: 36 | gui_flag = True # All test will run qgis in gui mode 37 | #noinspection PyPep8Naming 38 | QGIS_APP = QgsApplication(sys.argv, gui_flag) 39 | # Make sure QGIS_PREFIX_PATH is set in your env if needed! 40 | QGIS_APP.initQgis() 41 | s = QGIS_APP.showSettings() 42 | LOGGER.debug(s) 43 | 44 | global PARENT # pylint: disable=W0603 45 | if PARENT is None: 46 | #noinspection PyPep8Naming 47 | PARENT = QtGui.QWidget() 48 | 49 | global CANVAS # pylint: disable=W0603 50 | if CANVAS is None: 51 | #noinspection PyPep8Naming 52 | CANVAS = QgsMapCanvas(PARENT) 53 | CANVAS.resize(QtCore.QSize(400, 400)) 54 | 55 | global IFACE # pylint: disable=W0603 56 | if IFACE is None: 57 | # QgisInterface is a stub implementation of the QGIS plugin interface 58 | #noinspection PyPep8Naming 59 | IFACE = QgisInterface(CANVAS) 60 | 61 | return QGIS_APP, CANVAS, IFACE, PARENT 62 | -------------------------------------------------------------------------------- /test/test_init.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Tests QGIS plugin init.""" 3 | 4 | __author__ = 'Tim Sutton ' 5 | __revision__ = '$Format:%H$' 6 | __date__ = '17/10/2010' 7 | __license__ = "GPL" 8 | __copyright__ = 'Copyright 2012, Australia Indonesia Facility for ' 9 | __copyright__ += 'Disaster Reduction' 10 | 11 | import os 12 | import unittest 13 | import logging 14 | import configparser 15 | 16 | LOGGER = logging.getLogger('QGIS') 17 | 18 | 19 | class TestInit(unittest.TestCase): 20 | """Test that the plugin init is usable for QGIS. 21 | 22 | Based heavily on the validator class by Alessandro 23 | Passoti available here: 24 | 25 | http://github.com/qgis/qgis-django/blob/master/qgis-app/ 26 | plugins/validator.py 27 | 28 | """ 29 | 30 | def test_read_init(self): 31 | """Test that the plugin __init__ will validate on plugins.qgis.org.""" 32 | 33 | # You should update this list according to the latest in 34 | # https://github.com/qgis/qgis-django/blob/master/qgis-app/ 35 | # plugins/validator.py 36 | 37 | required_metadata = [ 38 | 'name', 39 | 'description', 40 | 'version', 41 | 'qgisMinimumVersion', 42 | 'email', 43 | 'author'] 44 | 45 | file_path = os.path.abspath(os.path.join( 46 | os.path.dirname(__file__), os.pardir, 47 | 'metadata.txt')) 48 | LOGGER.info(file_path) 49 | metadata = [] 50 | parser = configparser.ConfigParser() 51 | parser.optionxform = str 52 | parser.read(file_path) 53 | message = 'Cannot find a section named "general" in %s' % file_path 54 | assert parser.has_section('general'), message 55 | metadata.extend(parser.items('general')) 56 | 57 | for expectation in required_metadata: 58 | message = ('Cannot find metadata "%s" in metadata source (%s).' % ( 59 | expectation, file_path)) 60 | 61 | self.assertIn(expectation, dict(metadata), message) 62 | 63 | if __name__ == '__main__': 64 | unittest.main() 65 | -------------------------------------------------------------------------------- /test/test_qgis_environment.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """Tests for QGIS functionality. 3 | 4 | 5 | .. note:: This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | """ 11 | __author__ = 'tim@linfiniti.com' 12 | __date__ = '20/01/2011' 13 | __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 14 | 'Disaster Reduction') 15 | 16 | import os 17 | import unittest 18 | from qgis.core import ( 19 | QgsProviderRegistry, 20 | QgsCoordinateReferenceSystem, 21 | QgsRasterLayer) 22 | 23 | from .utilities import get_qgis_app 24 | QGIS_APP = get_qgis_app() 25 | 26 | 27 | class QGISTest(unittest.TestCase): 28 | """Test the QGIS Environment""" 29 | 30 | def test_qgis_environment(self): 31 | """QGIS environment has the expected providers""" 32 | 33 | r = QgsProviderRegistry.instance() 34 | self.assertIn('gdal', r.providerList()) 35 | self.assertIn('ogr', r.providerList()) 36 | self.assertIn('postgres', r.providerList()) 37 | 38 | def test_projection(self): 39 | """Test that QGIS properly parses a wkt string. 40 | """ 41 | crs = QgsCoordinateReferenceSystem() 42 | wkt = ( 43 | 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",' 44 | 'SPHEROID["WGS_1984",6378137.0,298.257223563]],' 45 | 'PRIMEM["Greenwich",0.0],UNIT["Degree",' 46 | '0.0174532925199433]]') 47 | crs.createFromWkt(wkt) 48 | auth_id = crs.authid() 49 | expected_auth_id = 'EPSG:4326' 50 | self.assertEqual(auth_id, expected_auth_id) 51 | 52 | # now test for a loaded layer 53 | path = os.path.join(os.path.dirname(__file__), 'tenbytenraster.asc') 54 | title = 'TestRaster' 55 | layer = QgsRasterLayer(path, title) 56 | auth_id = layer.crs().authid() 57 | self.assertEqual(auth_id, expected_auth_id) 58 | 59 | if __name__ == '__main__': 60 | unittest.main() 61 | -------------------------------------------------------------------------------- /china_transform_tool_dialog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | ChinaTransformToolDialog 5 | A QGIS plugin 6 | shp文件坐标系转换工具,支持WGS84\GCJ02\BD09坐标系转换 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2021-04-21 10 | git sha : $Format:%H$ 11 | copyright : (C) 2021 by wudaojian 12 | email : 827337743@qq.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | import os 26 | 27 | from qgis.PyQt import uic 28 | from qgis.PyQt import QtWidgets 29 | 30 | # This loads your .ui file so that PyQt can populate your plugin with the elements from Qt Designer 31 | FORM_CLASS, _ = uic.loadUiType(os.path.join( 32 | os.path.dirname(__file__), 'china_transform_tool_dialog_base.ui')) 33 | 34 | 35 | class ChinaTransformToolDialog(QtWidgets.QDialog, FORM_CLASS): 36 | def __init__(self, parent=None): 37 | """Constructor.""" 38 | super(ChinaTransformToolDialog, self).__init__(parent) 39 | # Set up the user interface from Designer through FORM_CLASS. 40 | # After self.setupUi() you can access any designer object by doing 41 | # self., and you can use autoconnect slots - see 42 | # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html 43 | # #widgets-and-dialogs-with-auto-connect 44 | self.setupUi(self) 45 | -------------------------------------------------------------------------------- /pb_tool.cfg: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # ChinaTransformTool 3 | # 4 | # Configuration file for plugin builder tool (pb_tool) 5 | # Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 6 | # ------------------- 7 | # begin : 2021-04-21 8 | # copyright : (C) 2021 by wudaojian 9 | # email : 827337743@qq.com 10 | # ***************************************************************************/ 11 | # 12 | #/*************************************************************************** 13 | # * * 14 | # * This program is free software; you can redistribute it and/or modify * 15 | # * it under the terms of the GNU General Public License as published by * 16 | # * the Free Software Foundation; either version 2 of the License, or * 17 | # * (at your option) any later version. * 18 | # * * 19 | # ***************************************************************************/ 20 | # 21 | # 22 | # You can install pb_tool using: 23 | # pip install http://geoapt.net/files/pb_tool.zip 24 | # 25 | # Consider doing your development (and install of pb_tool) in a virtualenv. 26 | # 27 | # For details on setting up and using pb_tool, see: 28 | # http://g-sherman.github.io/plugin_build_tool/ 29 | # 30 | # Issues and pull requests here: 31 | # https://github.com/g-sherman/plugin_build_tool: 32 | # 33 | # Sane defaults for your plugin generated by the Plugin Builder are 34 | # already set below. 35 | # 36 | # As you add Python source files and UI files to your plugin, add 37 | # them to the appropriate [files] section below. 38 | 39 | [plugin] 40 | # Name of the plugin. This is the name of the directory that will 41 | # be created in .qgis2/python/plugins 42 | name: china_transform_tool 43 | 44 | # Full path to where you want your plugin directory copied. If empty, 45 | # the QGIS default path will be used. Don't include the plugin name in 46 | # the path. 47 | plugin_path: 48 | 49 | [files] 50 | # Python files that should be deployed with the plugin 51 | python_files: __init__.py china_transform_tool.py china_transform_tool_dialog.py 52 | 53 | # The main dialog file that is loaded (not compiled) 54 | main_dialog: china_transform_tool_dialog_base.ui 55 | 56 | # Other ui files for dialogs you create (these will be compiled) 57 | compiled_ui_files: 58 | 59 | # Resource file(s) that will be compiled 60 | resource_files: resources.qrc 61 | 62 | # Other files required for the plugin 63 | extras: metadata.txt icon.png 64 | 65 | # Other directories to be deployed with the plugin. 66 | # These must be subdirectories under the plugin directory 67 | extra_dirs: 68 | 69 | # ISO code(s) for any locales (translations), separated by spaces. 70 | # Corresponding .ts files must exist in the i18n directory 71 | locales: 72 | 73 | [help] 74 | # the built help directory that should be deployed with the plugin 75 | dir: help/build/html 76 | # the name of the directory to target in the deployed plugin 77 | target: help 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /plugin_upload.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | """This script uploads a plugin package to the plugin repository. 4 | Authors: A. Pasotti, V. Picavet 5 | git sha : $TemplateVCSFormat 6 | """ 7 | 8 | import sys 9 | import getpass 10 | import xmlrpc.client 11 | from optparse import OptionParser 12 | 13 | standard_library.install_aliases() 14 | 15 | # Configuration 16 | PROTOCOL = 'https' 17 | SERVER = 'plugins.qgis.org' 18 | PORT = '443' 19 | ENDPOINT = '/plugins/RPC2/' 20 | VERBOSE = False 21 | 22 | 23 | def main(parameters, arguments): 24 | """Main entry point. 25 | 26 | :param parameters: Command line parameters. 27 | :param arguments: Command line arguments. 28 | """ 29 | address = "{protocol}://{username}:{password}@{server}:{port}{endpoint}".format( 30 | protocol=PROTOCOL, 31 | username=parameters.username, 32 | password=parameters.password, 33 | server=parameters.server, 34 | port=parameters.port, 35 | endpoint=ENDPOINT) 36 | print("Connecting to: %s" % hide_password(address)) 37 | 38 | server = xmlrpc.client.ServerProxy(address, verbose=VERBOSE) 39 | 40 | try: 41 | with open(arguments[0], 'rb') as handle: 42 | plugin_id, version_id = server.plugin.upload( 43 | xmlrpc.client.Binary(handle.read())) 44 | print("Plugin ID: %s" % plugin_id) 45 | print("Version ID: %s" % version_id) 46 | except xmlrpc.client.ProtocolError as err: 47 | print("A protocol error occurred") 48 | print("URL: %s" % hide_password(err.url, 0)) 49 | print("HTTP/HTTPS headers: %s" % err.headers) 50 | print("Error code: %d" % err.errcode) 51 | print("Error message: %s" % err.errmsg) 52 | except xmlrpc.client.Fault as err: 53 | print("A fault occurred") 54 | print("Fault code: %d" % err.faultCode) 55 | print("Fault string: %s" % err.faultString) 56 | 57 | 58 | def hide_password(url, start=6): 59 | """Returns the http url with password part replaced with '*'. 60 | 61 | :param url: URL to upload the plugin to. 62 | :type url: str 63 | 64 | :param start: Position of start of password. 65 | :type start: int 66 | """ 67 | start_position = url.find(':', start) + 1 68 | end_position = url.find('@') 69 | return "%s%s%s" % ( 70 | url[:start_position], 71 | '*' * (end_position - start_position), 72 | url[end_position:]) 73 | 74 | 75 | if __name__ == "__main__": 76 | parser = OptionParser(usage="%prog [options] plugin.zip") 77 | parser.add_option( 78 | "-w", "--password", dest="password", 79 | help="Password for plugin site", metavar="******") 80 | parser.add_option( 81 | "-u", "--username", dest="username", 82 | help="Username of plugin site", metavar="user") 83 | parser.add_option( 84 | "-p", "--port", dest="port", 85 | help="Server port to connect to", metavar="80") 86 | parser.add_option( 87 | "-s", "--server", dest="server", 88 | help="Specify server name", metavar="plugins.qgis.org") 89 | options, args = parser.parse_args() 90 | if len(args) != 1: 91 | print("Please specify zip file.\n") 92 | parser.print_help() 93 | sys.exit(1) 94 | if not options.server: 95 | options.server = SERVER 96 | if not options.port: 97 | options.port = PORT 98 | if not options.username: 99 | # interactive mode 100 | username = getpass.getuser() 101 | print("Please enter user name [%s] :" % username, end=' ') 102 | 103 | res = input() 104 | if res != "": 105 | options.username = res 106 | else: 107 | options.username = username 108 | if not options.password: 109 | # interactive mode 110 | options.password = getpass.getpass() 111 | main(options, args) 112 | -------------------------------------------------------------------------------- /resources.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Resource object code 4 | # 5 | # Created by: The Resource Compiler for PyQt5 (Qt v5.9.4) 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore 10 | 11 | qt_resource_data = b"\ 12 | \x00\x00\x02\x76\ 13 | \x89\ 14 | \x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ 15 | \x00\x00\x20\x00\x00\x00\x20\x08\x06\x00\x00\x00\x73\x7a\x7a\xf4\ 16 | \x00\x00\x02\x3d\x49\x44\x41\x54\x58\x47\xed\x96\x41\x68\x13\x41\ 17 | \x14\x86\xff\x37\x49\x3d\xc4\xa0\x75\xb5\x96\xf6\xa0\xc1\x6e\xda\ 18 | \x5c\x05\x45\x10\xaf\x7a\xf1\x68\x2f\xbd\x49\x55\x24\x9b\x7a\x10\ 19 | \x04\x11\x5c\x14\x52\x50\xf0\xa8\x69\x8c\x56\xd0\xa3\x20\xe8\xcd\ 20 | \x9b\xf4\x58\x04\x41\xa1\x22\x66\x6b\x2b\xe4\xa0\xad\xd9\x12\xe9\ 21 | \xa5\x24\xd9\x19\x99\x9a\x4d\xd6\x92\xb6\xbb\x9d\x8d\x15\xe9\x1e\ 22 | \x77\xe7\xbd\xef\xe3\xcd\x9b\x37\x4b\xd8\xe6\x87\xb6\x99\x8f\xff\ 23 | \x47\xe0\x40\xe1\x6b\x1f\x63\x9c\x2f\x5e\x3a\xb2\x10\xa4\xaa\xa1\ 24 | \x54\xe0\xe0\xe3\xb9\xde\x7a\xcd\xf9\x2e\xc1\x04\x61\xda\xc6\xe0\ 25 | \xb8\x5f\x89\x50\x04\xf6\x4c\x96\xb4\x68\x75\xc5\xf6\x40\x5f\x33\ 26 | \x90\x59\x36\xf4\x77\x9b\x89\x84\x22\x20\x21\xdd\x0f\xe6\x0e\x33\ 27 | \xe6\xcc\x00\x88\x37\xa0\x3f\x09\x64\xda\x86\x7e\x7f\x23\x89\xd0\ 28 | \x04\x5c\x88\x36\x61\x4d\x02\xb8\xe0\x81\x3e\x8f\x08\xba\xf9\x23\ 29 | \xa3\xcf\xb6\x13\x09\x5d\x40\x42\xb4\x7c\xf1\x1c\x04\xbd\xf0\x00\ 30 | \x4b\x04\x6e\xda\xc6\xd0\xb3\xb5\x12\x1d\x11\x90\x90\xbd\x05\x6b\ 31 | \x20\xe2\x88\xa7\x00\x9d\x6a\x41\xc5\xa3\x2e\x62\xe6\x42\x5a\x5f\ 32 | \x74\xdf\x35\x05\xba\xf3\x9f\x12\xa8\x47\x13\x9b\x35\x4d\xd0\xef\ 33 | \x2c\x42\x67\x01\x71\xcd\x13\x37\xd3\xe8\x8d\x57\xbf\x4f\x4d\xe3\ 34 | \xd1\x26\x2c\x11\x34\xb9\xc2\xfa\x0a\x5b\x76\x0e\x95\xaf\xa7\x96\ 35 | \x57\x05\x7a\xef\x7d\xd8\x5d\x8d\xc5\xe6\x89\xd0\xa3\x90\x34\x50\ 36 | \x28\xe3\x6c\xa8\x3c\x36\x50\x6c\x55\x20\x37\x7b\x12\x70\xce\x04\ 37 | \xca\xb2\xc5\xc5\x9c\xb3\xa9\xca\x95\xe4\xd4\x1f\x5b\xb0\xc5\x5c\ 38 | \xca\x61\x1d\x3b\x05\x7e\xcd\x76\x04\x9a\x15\xe8\xc9\x7d\x8c\xd7\ 39 | \xf8\xae\x63\x7e\x4b\xa7\xb2\xce\x6d\xc0\x35\x73\xa0\xf8\x16\xa0\ 40 | \xe3\x2a\x89\x83\xc4\xb2\x48\x57\x7f\xf9\x72\xe2\xdb\x6a\x05\xe4\ 41 | \x14\x64\x22\x3a\x1f\x24\x81\xea\x5a\x2e\xc4\xd1\x4a\x66\xf0\x7d\ 42 | \x6b\x0e\xe4\xad\x5b\x10\xb8\xdd\x4c\x4c\xa8\x82\xf3\x3b\xaa\xa0\ 43 | \x76\xf1\xeb\xce\x01\xed\x61\xf1\x34\x38\x65\x01\x9c\xf0\x04\x3e\ 44 | \x59\x32\x92\x17\x3b\x21\xd2\x76\x10\xc9\xb1\x5c\x8b\xc7\xb2\x10\ 45 | \xb8\xea\x81\x96\x88\xe8\xbc\x9d\xd6\xdf\x84\x2d\xb2\xee\x1c\xd0\ 46 | \x72\xd6\x30\x80\x2c\x08\x29\x17\x4a\x02\x77\xed\x4c\xf2\x46\x98\ 47 | \x12\x1b\x0e\x22\xf9\xa7\xcb\xeb\xb5\x71\x10\x46\x3d\x50\xf9\x9f\ 48 | \x37\xb6\x64\x24\xa7\xc3\x10\xf1\x35\x09\xb5\xbc\x35\x0a\x01\xd9\ 49 | \x1b\xfd\x0d\x68\xf3\x3a\x55\x95\xf0\x25\x20\x21\xfb\x0b\x9f\x53\ 50 | \x82\x33\xd9\x1b\x72\x6b\xe0\x5e\xa7\x7f\x4d\xc0\x05\xed\xcb\x7d\ 51 | \x19\x61\x4c\xac\xd8\x69\xfd\xa5\x2a\x7c\xe7\x3a\xfe\x27\x2a\xf0\ 52 | \x0b\x04\x3b\xaa\x21\x89\xf0\x0f\x50\x00\x00\x00\x00\x49\x45\x4e\ 53 | \x44\xae\x42\x60\x82\ 54 | " 55 | 56 | qt_resource_name = b"\ 57 | \x00\x07\ 58 | \x07\x3b\xe0\xb3\ 59 | \x00\x70\ 60 | \x00\x6c\x00\x75\x00\x67\x00\x69\x00\x6e\x00\x73\ 61 | \x00\x14\ 62 | \x04\x2c\x62\x9c\ 63 | \x00\x63\ 64 | \x00\x68\x00\x69\x00\x6e\x00\x61\x00\x5f\x00\x74\x00\x72\x00\x61\x00\x6e\x00\x73\x00\x66\x00\x6f\x00\x72\x00\x6d\x00\x5f\x00\x74\ 65 | \x00\x6f\x00\x6f\x00\x6c\ 66 | \x00\x08\ 67 | \x0a\x61\x5a\xa7\ 68 | \x00\x69\ 69 | \x00\x63\x00\x6f\x00\x6e\x00\x2e\x00\x70\x00\x6e\x00\x67\ 70 | " 71 | 72 | qt_resource_struct_v1 = b"\ 73 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ 74 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ 75 | \x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\ 76 | \x00\x00\x00\x42\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ 77 | " 78 | 79 | qt_resource_struct_v2 = b"\ 80 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ 81 | \x00\x00\x00\x00\x00\x00\x00\x00\ 82 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ 83 | \x00\x00\x00\x00\x00\x00\x00\x00\ 84 | \x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\ 85 | \x00\x00\x00\x00\x00\x00\x00\x00\ 86 | \x00\x00\x00\x42\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ 87 | \x00\x00\x01\x78\xf4\xc4\xec\x12\ 88 | " 89 | 90 | qt_version = QtCore.qVersion().split('.') 91 | if qt_version < ['5', '8', '0']: 92 | rcc_version = 1 93 | qt_resource_struct = qt_resource_struct_v1 94 | else: 95 | rcc_version = 2 96 | qt_resource_struct = qt_resource_struct_v2 97 | 98 | def qInitResources(): 99 | QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) 100 | 101 | def qCleanupResources(): 102 | QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) 103 | 104 | qInitResources() 105 | -------------------------------------------------------------------------------- /help/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source 10 | if NOT "%PAPER%" == "" ( 11 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 12 | ) 13 | 14 | if "%1" == "" goto help 15 | 16 | if "%1" == "help" ( 17 | :help 18 | echo.Please use `make ^` where ^ is one of 19 | echo. html to make standalone HTML files 20 | echo. dirhtml to make HTML files named index.html in directories 21 | echo. singlehtml to make a single large HTML file 22 | echo. pickle to make pickle files 23 | echo. json to make JSON files 24 | echo. htmlhelp to make HTML files and a HTML help project 25 | echo. qthelp to make HTML files and a qthelp project 26 | echo. devhelp to make HTML files and a Devhelp project 27 | echo. epub to make an epub 28 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 29 | echo. text to make text files 30 | echo. man to make manual pages 31 | echo. changes to make an overview over all changed/added/deprecated items 32 | echo. linkcheck to check all external links for integrity 33 | echo. doctest to run all doctests embedded in the documentation if enabled 34 | goto end 35 | ) 36 | 37 | if "%1" == "clean" ( 38 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 39 | del /q /s %BUILDDIR%\* 40 | goto end 41 | ) 42 | 43 | if "%1" == "html" ( 44 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 45 | echo. 46 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 47 | goto end 48 | ) 49 | 50 | if "%1" == "dirhtml" ( 51 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 52 | echo. 53 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 54 | goto end 55 | ) 56 | 57 | if "%1" == "singlehtml" ( 58 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 59 | echo. 60 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 61 | goto end 62 | ) 63 | 64 | if "%1" == "pickle" ( 65 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 66 | echo. 67 | echo.Build finished; now you can process the pickle files. 68 | goto end 69 | ) 70 | 71 | if "%1" == "json" ( 72 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 73 | echo. 74 | echo.Build finished; now you can process the JSON files. 75 | goto end 76 | ) 77 | 78 | if "%1" == "htmlhelp" ( 79 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 80 | echo. 81 | echo.Build finished; now you can run HTML Help Workshop with the ^ 82 | .hhp project file in %BUILDDIR%/htmlhelp. 83 | goto end 84 | ) 85 | 86 | if "%1" == "qthelp" ( 87 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 88 | echo. 89 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 90 | .qhcp project file in %BUILDDIR%/qthelp, like this: 91 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\template_class.qhcp 92 | echo.To view the help file: 93 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\template_class.ghc 94 | goto end 95 | ) 96 | 97 | if "%1" == "devhelp" ( 98 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 99 | echo. 100 | echo.Build finished. 101 | goto end 102 | ) 103 | 104 | if "%1" == "epub" ( 105 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 106 | echo. 107 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 108 | goto end 109 | ) 110 | 111 | if "%1" == "latex" ( 112 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 113 | echo. 114 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 115 | goto end 116 | ) 117 | 118 | if "%1" == "text" ( 119 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 120 | echo. 121 | echo.Build finished. The text files are in %BUILDDIR%/text. 122 | goto end 123 | ) 124 | 125 | if "%1" == "man" ( 126 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 127 | echo. 128 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 129 | goto end 130 | ) 131 | 132 | if "%1" == "changes" ( 133 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 134 | echo. 135 | echo.The overview file is in %BUILDDIR%/changes. 136 | goto end 137 | ) 138 | 139 | if "%1" == "linkcheck" ( 140 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 141 | echo. 142 | echo.Link check complete; look for any errors in the above output ^ 143 | or in %BUILDDIR%/linkcheck/output.txt. 144 | goto end 145 | ) 146 | 147 | if "%1" == "doctest" ( 148 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 149 | echo. 150 | echo.Testing of doctests in the sources finished, look at the ^ 151 | results in %BUILDDIR%/doctest/output.txt. 152 | goto end 153 | ) 154 | 155 | :end 156 | -------------------------------------------------------------------------------- /help/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | 15 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " singlehtml to make a single large HTML file" 22 | @echo " pickle to make pickle files" 23 | @echo " json to make JSON files" 24 | @echo " htmlhelp to make HTML files and a HTML help project" 25 | @echo " qthelp to make HTML files and a qthelp project" 26 | @echo " devhelp to make HTML files and a Devhelp project" 27 | @echo " epub to make an epub" 28 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 29 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 30 | @echo " text to make text files" 31 | @echo " man to make manual pages" 32 | @echo " changes to make an overview of all changed/added/deprecated items" 33 | @echo " linkcheck to check all external links for integrity" 34 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 35 | 36 | clean: 37 | -rm -rf $(BUILDDIR)/* 38 | 39 | html: 40 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 41 | @echo 42 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 43 | 44 | dirhtml: 45 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 48 | 49 | singlehtml: 50 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 51 | @echo 52 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 53 | 54 | pickle: 55 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 56 | @echo 57 | @echo "Build finished; now you can process the pickle files." 58 | 59 | json: 60 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 61 | @echo 62 | @echo "Build finished; now you can process the JSON files." 63 | 64 | htmlhelp: 65 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 66 | @echo 67 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 68 | ".hhp project file in $(BUILDDIR)/htmlhelp." 69 | 70 | qthelp: 71 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 72 | @echo 73 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 74 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 75 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/template_class.qhcp" 76 | @echo "To view the help file:" 77 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/template_class.qhc" 78 | 79 | devhelp: 80 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 81 | @echo 82 | @echo "Build finished." 83 | @echo "To view the help file:" 84 | @echo "# mkdir -p $$HOME/.local/share/devhelp/template_class" 85 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/template_class" 86 | @echo "# devhelp" 87 | 88 | epub: 89 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 90 | @echo 91 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 92 | 93 | latex: 94 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 95 | @echo 96 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 97 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 98 | "(use \`make latexpdf' here to do that automatically)." 99 | 100 | latexpdf: 101 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 102 | @echo "Running LaTeX files through pdflatex..." 103 | make -C $(BUILDDIR)/latex all-pdf 104 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 105 | 106 | text: 107 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 108 | @echo 109 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 110 | 111 | man: 112 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 113 | @echo 114 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 115 | 116 | changes: 117 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 118 | @echo 119 | @echo "The overview file is in $(BUILDDIR)/changes." 120 | 121 | linkcheck: 122 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 123 | @echo 124 | @echo "Link check complete; look for any errors in the above output " \ 125 | "or in $(BUILDDIR)/linkcheck/output.txt." 126 | 127 | doctest: 128 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 129 | @echo "Testing of doctests in the sources finished, look at the " \ 130 | "results in $(BUILDDIR)/doctest/output.txt." 131 | -------------------------------------------------------------------------------- /ImgTransform.py: -------------------------------------------------------------------------------- 1 | from .CoordTransform import gcj02tobd09,bd09togcj02,wgs84togcj02,gcj02towgs84,wgs84tomercator,mercatortowgs84,bd09tomercator,mercatortobd09 2 | import numpy as np 3 | import math 4 | import matplotlib.image as mpimg 5 | class Point(object): 6 | def __init__(self, x, y): 7 | self.x = x 8 | self.y = y 9 | def affine_abc(pixel_points,geo_points): 10 | n = len(pixel_points) 11 | pixelX_square = 0.0 12 | pixelX_pixelY = 0.0 13 | pixelY_square = 0.0 14 | pixelX = 0.0 15 | pixelY = 0.0 16 | pixelX_geoX = 0.0 17 | pixelY_geoX = 0.0 18 | geoX = 0.0 19 | for i in range(0,n): 20 | pixelX_square += math.pow(pixel_points[i].x,2) 21 | pixelX_pixelY += pixel_points[i].x*pixel_points[i].y 22 | pixelY_square += math.pow(pixel_points[i].y,2) 23 | pixelX += pixel_points[i].x 24 | pixelY += pixel_points[i].y 25 | pixelX_geoX += pixel_points[i].x*geo_points[i].x 26 | pixelY_geoX += pixel_points[i].y*geo_points[i].x 27 | geoX += geo_points[i].x 28 | a = np.array([[pixelX_square,pixelX_pixelY,pixelX],[pixelX_pixelY,pixelY_square,pixelY],[pixelX,pixelY,n]]) 29 | b = np.array([[pixelX_geoX],[pixelY_geoX],[geoX]]) 30 | at = np.linalg.inv(a) 31 | result = at.dot(b) 32 | return result[0,0],result[1,0],result[2,0] 33 | def affine_def(pixel_points,geo_points): 34 | n = len(pixel_points) 35 | pixelX_square = 0.0 36 | pixelX_pixelY = 0.0 37 | pixelY_square = 0.0 38 | pixelX = 0.0 39 | pixelY = 0.0 40 | pixelX_geoY = 0.0 41 | pixelY_geoY = 0.0 42 | geoY = 0.0 43 | for i in range(0,n): 44 | pixelX_square += math.pow(pixel_points[i].x,2) 45 | pixelX_pixelY += pixel_points[i].x*pixel_points[i].y 46 | pixelY_square += math.pow(pixel_points[i].y,2) 47 | pixelX += pixel_points[i].x 48 | pixelY += pixel_points[i].y 49 | pixelX_geoY += pixel_points[i].x*geo_points[i].y 50 | pixelY_geoY += pixel_points[i].y*geo_points[i].y 51 | geoY += geo_points[i].y 52 | a = np.array([[pixelX_square,pixelX_pixelY,pixelX],[pixelX_pixelY,pixelY_square,pixelY],[pixelX,pixelY,n]]) 53 | b = np.array([[pixelX_geoY],[pixelY_geoY],[geoY]]) 54 | at = np.linalg.inv(a) 55 | result = at.dot(b) 56 | return result[0,0],result[1,0],result[2,0] 57 | 58 | def width_height(path_str): 59 | img = mpimg.imread(path_str) 60 | return len(img[0]),len(img) 61 | def abc_def(path_str): 62 | pfw = open(path_str, 'r') 63 | affineOption = pfw.readlines() 64 | pfw.close() 65 | a = float(affineOption[0].strip('\n')) 66 | d = float(affineOption[1].strip('\n')) 67 | b = float(affineOption[2].strip('\n')) 68 | e = float(affineOption[3].strip('\n')) 69 | c = float(affineOption[4].strip('\n')) 70 | f = float(affineOption[5].strip('\n')) 71 | return a,b,c,d,e,f 72 | def transform_imgfile(read_path_str,write_path_str,coord_original,coord_target): 73 | file_suffix = read_path_str.split('.')[1] 74 | read_path_str_world = read_path_str.split('.')[0] + '.' + file_suffix[0]+file_suffix[len(file_suffix)-1]+'w' 75 | img = mpimg.imread(read_path_str) 76 | width = len(img[0]) 77 | heigth = len(img) 78 | mpimg.imsave(write_path_str,img) 79 | a,b,c,d,e,f = abc_def(read_path_str_world) 80 | p0 = [width/4,heigth/4] 81 | p1 = [width/4+width/2,heigth/4] 82 | p2 = [width/4+width/2,heigth/4+heigth/2] 83 | p3 = [width/4,heigth/4+heigth/2] 84 | go0 = [a*p0[0]+b*p0[1]+c,d*p0[0]+e*p0[1]+f] 85 | go1 = [a*p1[0]+b*p1[1]+c,d*p1[0]+e*p1[1]+f] 86 | go2 = [a*p2[0]+b*p2[1]+c,d*p2[0]+e*p2[1]+f] 87 | go3 = [a*p3[0]+b*p3[1]+c,d*p3[0]+e*p3[1]+f] 88 | # 坐标系转换 89 | if coord_original == 'gcj02' and coord_target == 'wgs84': 90 | gt0 = gcj02towgs84(go0[0], go0[1]) 91 | gt1 = gcj02towgs84(go1[0], go1[1]) 92 | gt2 = gcj02towgs84(go2[0], go2[1]) 93 | gt3 = gcj02towgs84(go3[0], go3[1]) 94 | elif coord_original == 'wgs84' and coord_target == 'gcj02': 95 | gt0 = wgs84togcj02(go0[0], go0[1]) 96 | gt1 = wgs84togcj02(go1[0], go1[1]) 97 | gt2 = wgs84togcj02(go2[0], go2[1]) 98 | gt3 = wgs84togcj02(go3[0], go3[1]) 99 | elif coord_original == 'gcj02' and coord_target == 'bd09': 100 | gt0 = gcj02tobd09(go0[0], go0[1]) 101 | gt1 = gcj02tobd09(go1[0], go1[1]) 102 | gt2 = gcj02tobd09(go2[0], go2[1]) 103 | gt3 = gcj02tobd09(go3[0], go3[1]) 104 | elif coord_original == 'bd09' and coord_target == 'gcj02': 105 | gt0 = bd09togcj02(go0[0], go0[1]) 106 | gt1 = bd09togcj02(go1[0], go1[1]) 107 | gt2 = bd09togcj02(go2[0], go2[1]) 108 | gt3 = bd09togcj02(go3[0], go3[1]) 109 | elif coord_original == 'wgs84' and coord_target == 'bd09': 110 | gtm0 = wgs84togcj02(go0[0], go0[1]) 111 | gtm1 = wgs84togcj02(go1[0], go1[1]) 112 | gtm2 = wgs84togcj02(go2[0], go2[1]) 113 | gtm3 = wgs84togcj02(go3[0], go3[1]) 114 | gt0 = gcj02tobd09(gtm0[0], gtm0[1]) 115 | gt1 = gcj02tobd09(gtm1[0], gtm1[1]) 116 | gt2 = gcj02tobd09(gtm2[0], gtm2[1]) 117 | gt3 = gcj02tobd09(gtm3[0], gtm3[1]) 118 | elif coord_original == 'bd09' and coord_target == 'wgs84': 119 | gtm0 = bd09togcj02(go0[0], go0[1]) 120 | gtm1 = bd09togcj02(go1[0], go1[1]) 121 | gtm2 = bd09togcj02(go2[0], go2[1]) 122 | gtm3 = bd09togcj02(go3[0], go3[1]) 123 | gt0 = gcj02towgs84(gtm0[0], gtm0[1]) 124 | gt1 = gcj02towgs84(gtm1[0], gtm1[1]) 125 | gt2 = gcj02towgs84(gtm2[0], gtm2[1]) 126 | gt3 = gcj02towgs84(gtm3[0], gtm3[1]) 127 | else: 128 | gt0 = [go0[0], go0[1]] 129 | gt1 = [go1[0], go1[1]] 130 | gt2 = [go2[0], go2[1]] 131 | gt3 = [go3[0], go3[1]] 132 | pl = [Point(p0[0],p0[1]),Point(p1[0],p1[1]),Point(p2[0],p2[1]),Point(p3[0],p3[1])] 133 | gl = [Point(gt0[0],gt0[1]),Point(gt1[0],gt1[1]),Point(gt2[0],gt2[1]),Point(gt3[0],gt3[1])] 134 | ar,br,cr = affine_abc(pl,gl) 135 | dr,er,fr = affine_def(pl,gl) 136 | write_path_str_world = write_path_str.split('.')[0] + '.' + file_suffix[0]+file_suffix[len(file_suffix)-1]+'w' 137 | fnew = open(write_path_str_world,'a') 138 | fnew.write('\n'.join([str(ar),str(dr),str(br),str(er),str(cr),str(fr)])+'\n') 139 | fnew.close() 140 | 141 | 142 | -------------------------------------------------------------------------------- /test/qgis_interface.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """QGIS plugin implementation. 3 | 4 | .. note:: This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | .. note:: This source code was copied from the 'postgis viewer' application 10 | with original authors: 11 | Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk 12 | Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org 13 | Copyright (c) 2014 Tim Sutton, tim@linfiniti.com 14 | 15 | """ 16 | 17 | __author__ = 'tim@linfiniti.com' 18 | __revision__ = '$Format:%H$' 19 | __date__ = '10/01/2011' 20 | __copyright__ = ( 21 | 'Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk and ' 22 | 'Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org' 23 | 'Copyright (c) 2014 Tim Sutton, tim@linfiniti.com' 24 | ) 25 | 26 | import logging 27 | from qgis.PyQt.QtCore import QObject, pyqtSlot, pyqtSignal 28 | from qgis.core import QgsMapLayerRegistry 29 | from qgis.gui import QgsMapCanvasLayer 30 | LOGGER = logging.getLogger('QGIS') 31 | 32 | 33 | #noinspection PyMethodMayBeStatic,PyPep8Naming 34 | class QgisInterface(QObject): 35 | """Class to expose QGIS objects and functions to plugins. 36 | 37 | This class is here for enabling us to run unit tests only, 38 | so most methods are simply stubs. 39 | """ 40 | currentLayerChanged = pyqtSignal(QgsMapCanvasLayer) 41 | 42 | def __init__(self, canvas): 43 | """Constructor 44 | :param canvas: 45 | """ 46 | QObject.__init__(self) 47 | self.canvas = canvas 48 | # Set up slots so we can mimic the behaviour of QGIS when layers 49 | # are added. 50 | LOGGER.debug('Initialising canvas...') 51 | # noinspection PyArgumentList 52 | QgsMapLayerRegistry.instance().layersAdded.connect(self.addLayers) 53 | # noinspection PyArgumentList 54 | QgsMapLayerRegistry.instance().layerWasAdded.connect(self.addLayer) 55 | # noinspection PyArgumentList 56 | QgsMapLayerRegistry.instance().removeAll.connect(self.removeAllLayers) 57 | 58 | # For processing module 59 | self.destCrs = None 60 | 61 | @pyqtSlot('QStringList') 62 | def addLayers(self, layers): 63 | """Handle layers being added to the registry so they show up in canvas. 64 | 65 | :param layers: list list of map layers that were added 66 | 67 | .. note:: The QgsInterface api does not include this method, 68 | it is added here as a helper to facilitate testing. 69 | """ 70 | #LOGGER.debug('addLayers called on qgis_interface') 71 | #LOGGER.debug('Number of layers being added: %s' % len(layers)) 72 | #LOGGER.debug('Layer Count Before: %s' % len(self.canvas.layers())) 73 | current_layers = self.canvas.layers() 74 | final_layers = [] 75 | for layer in current_layers: 76 | final_layers.append(QgsMapCanvasLayer(layer)) 77 | for layer in layers: 78 | final_layers.append(QgsMapCanvasLayer(layer)) 79 | 80 | self.canvas.setLayerSet(final_layers) 81 | #LOGGER.debug('Layer Count After: %s' % len(self.canvas.layers())) 82 | 83 | @pyqtSlot('QgsMapLayer') 84 | def addLayer(self, layer): 85 | """Handle a layer being added to the registry so it shows up in canvas. 86 | 87 | :param layer: list list of map layers that were added 88 | 89 | .. note: The QgsInterface api does not include this method, it is added 90 | here as a helper to facilitate testing. 91 | 92 | .. note: The addLayer method was deprecated in QGIS 1.8 so you should 93 | not need this method much. 94 | """ 95 | pass 96 | 97 | @pyqtSlot() 98 | def removeAllLayers(self): 99 | """Remove layers from the canvas before they get deleted.""" 100 | self.canvas.setLayerSet([]) 101 | 102 | def newProject(self): 103 | """Create new project.""" 104 | # noinspection PyArgumentList 105 | QgsMapLayerRegistry.instance().removeAllMapLayers() 106 | 107 | # ---------------- API Mock for QgsInterface follows ------------------- 108 | 109 | def zoomFull(self): 110 | """Zoom to the map full extent.""" 111 | pass 112 | 113 | def zoomToPrevious(self): 114 | """Zoom to previous view extent.""" 115 | pass 116 | 117 | def zoomToNext(self): 118 | """Zoom to next view extent.""" 119 | pass 120 | 121 | def zoomToActiveLayer(self): 122 | """Zoom to extent of active layer.""" 123 | pass 124 | 125 | def addVectorLayer(self, path, base_name, provider_key): 126 | """Add a vector layer. 127 | 128 | :param path: Path to layer. 129 | :type path: str 130 | 131 | :param base_name: Base name for layer. 132 | :type base_name: str 133 | 134 | :param provider_key: Provider key e.g. 'ogr' 135 | :type provider_key: str 136 | """ 137 | pass 138 | 139 | def addRasterLayer(self, path, base_name): 140 | """Add a raster layer given a raster layer file name 141 | 142 | :param path: Path to layer. 143 | :type path: str 144 | 145 | :param base_name: Base name for layer. 146 | :type base_name: str 147 | """ 148 | pass 149 | 150 | def activeLayer(self): 151 | """Get pointer to the active layer (layer selected in the legend).""" 152 | # noinspection PyArgumentList 153 | layers = QgsMapLayerRegistry.instance().mapLayers() 154 | for item in layers: 155 | return layers[item] 156 | 157 | def addToolBarIcon(self, action): 158 | """Add an icon to the plugins toolbar. 159 | 160 | :param action: Action to add to the toolbar. 161 | :type action: QAction 162 | """ 163 | pass 164 | 165 | def removeToolBarIcon(self, action): 166 | """Remove an action (icon) from the plugin toolbar. 167 | 168 | :param action: Action to add to the toolbar. 169 | :type action: QAction 170 | """ 171 | pass 172 | 173 | def addToolBar(self, name): 174 | """Add toolbar with specified name. 175 | 176 | :param name: Name for the toolbar. 177 | :type name: str 178 | """ 179 | pass 180 | 181 | def mapCanvas(self): 182 | """Return a pointer to the map canvas.""" 183 | return self.canvas 184 | 185 | def mainWindow(self): 186 | """Return a pointer to the main window. 187 | 188 | In case of QGIS it returns an instance of QgisApp. 189 | """ 190 | pass 191 | 192 | def addDockWidget(self, area, dock_widget): 193 | """Add a dock widget to the main window. 194 | 195 | :param area: Where in the ui the dock should be placed. 196 | :type area: 197 | 198 | :param dock_widget: A dock widget to add to the UI. 199 | :type dock_widget: QDockWidget 200 | """ 201 | pass 202 | 203 | def legendInterface(self): 204 | """Get the legend.""" 205 | return self.canvas 206 | -------------------------------------------------------------------------------- /help/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # ChinaTransformTool documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Feb 12 17:11:03 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = ['sphinx.ext.todo', 'sphinx.ext.imgmath', 'sphinx.ext.viewcode'] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'ChinaTransformTool' 44 | copyright = u'2013, wudaojian' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '0.1' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '0.1' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = [] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_TemplateModuleNames = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. See the documentation for 93 | # a list of builtin themes. 94 | html_theme = 'default' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | #html_theme_path = [] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | #html_title = None 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | #html_sidebars = {} 135 | 136 | # Additional templates that should be rendered to pages, maps page names to 137 | # template names. 138 | #html_additional_pages = {} 139 | 140 | # If false, no module index is generated. 141 | #html_domain_indices = True 142 | 143 | # If false, no index is generated. 144 | #html_use_index = True 145 | 146 | # If true, the index is split into individual pages for each letter. 147 | #html_split_index = False 148 | 149 | # If true, links to the reST sources are added to the pages. 150 | #html_show_sourcelink = True 151 | 152 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 153 | #html_show_sphinx = True 154 | 155 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 156 | #html_show_copyright = True 157 | 158 | # If true, an OpenSearch description file will be output, and all pages will 159 | # contain a tag referring to it. The value of this option must be the 160 | # base URL from which the finished HTML is served. 161 | #html_use_opensearch = '' 162 | 163 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 164 | #html_file_suffix = None 165 | 166 | # Output file base name for HTML help builder. 167 | htmlhelp_basename = 'TemplateClassdoc' 168 | 169 | 170 | # -- Options for LaTeX output -------------------------------------------------- 171 | 172 | # The paper size ('letter' or 'a4'). 173 | #latex_paper_size = 'letter' 174 | 175 | # The font size ('10pt', '11pt' or '12pt'). 176 | #latex_font_size = '10pt' 177 | 178 | # Grouping the document tree into LaTeX files. List of tuples 179 | # (source start file, target name, title, author, documentclass [howto/manual]). 180 | latex_documents = [ 181 | ('index', 'ChinaTransformTool.tex', u'ChinaTransformTool Documentation', 182 | u'wudaojian', 'manual'), 183 | ] 184 | 185 | # The name of an image file (relative to this directory) to place at the top of 186 | # the title page. 187 | #latex_logo = None 188 | 189 | # For "manual" documents, if this is true, then toplevel headings are parts, 190 | # not chapters. 191 | #latex_use_parts = False 192 | 193 | # If true, show page references after internal links. 194 | #latex_show_pagerefs = False 195 | 196 | # If true, show URL addresses after external links. 197 | #latex_show_urls = False 198 | 199 | # Additional stuff for the LaTeX preamble. 200 | #latex_preamble = '' 201 | 202 | # Documents to append as an appendix to all manuals. 203 | #latex_appendices = [] 204 | 205 | # If false, no module index is generated. 206 | #latex_domain_indices = True 207 | 208 | 209 | # -- Options for manual page output -------------------------------------------- 210 | 211 | # One entry per manual page. List of tuples 212 | # (source start file, name, description, authors, manual section). 213 | man_pages = [ 214 | ('index', 'TemplateClass', u'ChinaTransformTool Documentation', 215 | [u'wudaojian'], 1) 216 | ] 217 | -------------------------------------------------------------------------------- /china_transform_tool_dialog_base.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ChinaTransformToolDialogBase 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | China Transform Tool 15 | 16 | 17 | 18 | 19 | 30 20 | 240 21 | 341 22 | 32 23 | 24 | 25 | 26 | Qt::Horizontal 27 | 28 | 29 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 30 | 31 | 32 | 33 | 34 | 35 | 40 36 | 30 37 | 81 38 | 21 39 | 40 | 41 | 42 | 43 | 8 44 | 45 | 46 | 47 | 输入文件: 48 | 49 | 50 | 51 | 52 | 53 | 40 54 | 60 55 | 81 56 | 21 57 | 58 | 59 | 60 | 61 | 8 62 | 63 | 64 | 65 | 输出文件: 66 | 67 | 68 | 69 | 70 | 71 | 40 72 | 100 73 | 91 74 | 21 75 | 76 | 77 | 78 | 79 | 8 80 | 81 | 82 | 83 | 输入坐标: 84 | 85 | 86 | 87 | 88 | 89 | 219 90 | 100 91 | 111 92 | 21 93 | 94 | 95 | 96 | 97 | 8 98 | 99 | 100 | 101 | 输出坐标: 102 | 103 | 104 | 105 | 106 | 107 | 112 108 | 30 109 | 191 110 | 20 111 | 112 | 113 | 114 | 115 | 116 | 117 | 112 118 | 60 119 | 191 120 | 20 121 | 122 | 123 | 124 | 125 | 126 | 127 | 320 128 | 30 129 | 31 130 | 20 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 320 141 | 60 142 | 31 143 | 20 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 41 154 | 138 155 | 81 156 | 17 157 | 158 | 159 | 160 | 161 | 8 162 | 163 | 164 | 165 | WGS84 166 | 167 | 168 | buttonGroup 169 | 170 | 171 | 172 | 173 | 174 | 41 175 | 161 176 | 81 177 | 17 178 | 179 | 180 | 181 | 182 | 8 183 | 184 | 185 | 186 | GCJ02 187 | 188 | 189 | buttonGroup 190 | 191 | 192 | 193 | 194 | 195 | 41 196 | 186 197 | 81 198 | 17 199 | 200 | 201 | 202 | 203 | 8 204 | 205 | 206 | 207 | BD09 208 | 209 | 210 | buttonGroup 211 | 212 | 213 | 214 | 215 | 216 | 220 217 | 138 218 | 101 219 | 17 220 | 221 | 222 | 223 | 224 | 8 225 | 226 | 227 | 228 | WGS84 229 | 230 | 231 | buttonGroup_2 232 | 233 | 234 | 235 | 236 | 237 | 220 238 | 163 239 | 91 240 | 17 241 | 242 | 243 | 244 | 245 | 8 246 | 247 | 248 | 249 | GCJ02 250 | 251 | 252 | buttonGroup_2 253 | 254 | 255 | 256 | 257 | 258 | 220 259 | 188 260 | 101 261 | 17 262 | 263 | 264 | 265 | 266 | 8 267 | 268 | 269 | 270 | BD09 271 | 272 | 273 | buttonGroup_2 274 | 275 | 276 | 277 | 278 | 279 | 280 | button_box 281 | accepted() 282 | ChinaTransformToolDialogBase 283 | accept() 284 | 285 | 286 | 20 287 | 20 288 | 289 | 290 | 20 291 | 20 292 | 293 | 294 | 295 | 296 | button_box 297 | rejected() 298 | ChinaTransformToolDialogBase 299 | reject() 300 | 301 | 302 | 20 303 | 20 304 | 305 | 306 | 20 307 | 20 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # ChinaTransformTool 3 | # 4 | # shp文件坐标系转换工具,支持WGS84\GCJ02\BD09坐标系转换 5 | # ------------------- 6 | # begin : 2021-04-21 7 | # git sha : $Format:%H$ 8 | # copyright : (C) 2021 by wudaojian 9 | # email : 827337743@qq.com 10 | # ***************************************************************************/ 11 | # 12 | #/*************************************************************************** 13 | # * * 14 | # * This program is free software; you can redistribute it and/or modify * 15 | # * it under the terms of the GNU General Public License as published by * 16 | # * the Free Software Foundation; either version 2 of the License, or * 17 | # * (at your option) any later version. * 18 | # * * 19 | # ***************************************************************************/ 20 | 21 | ################################################# 22 | # Edit the following to match your sources lists 23 | ################################################# 24 | 25 | 26 | #Add iso code for any locales you want to support here (space separated) 27 | # default is no locales 28 | # LOCALES = af 29 | LOCALES = 30 | 31 | # If locales are enabled, set the name of the lrelease binary on your system. If 32 | # you have trouble compiling the translations, you may have to specify the full path to 33 | # lrelease 34 | #LRELEASE = lrelease 35 | #LRELEASE = lrelease-qt4 36 | 37 | 38 | # translation 39 | SOURCES = \ 40 | __init__.py \ 41 | china_transform_tool.py china_transform_tool_dialog.py 42 | 43 | PLUGINNAME = china_transform_tool 44 | 45 | PY_FILES = \ 46 | __init__.py \ 47 | china_transform_tool.py china_transform_tool_dialog.py 48 | 49 | UI_FILES = china_transform_tool_dialog_base.ui 50 | 51 | EXTRAS = metadata.txt icon.png 52 | 53 | EXTRA_DIRS = 54 | 55 | COMPILED_RESOURCE_FILES = resources.py 56 | 57 | PEP8EXCLUDE=pydev,resources.py,conf.py,third_party,ui 58 | 59 | # QGISDIR points to the location where your plugin should be installed. 60 | # This varies by platform, relative to your HOME directory: 61 | # * Linux: 62 | # .local/share/QGIS/QGIS3/profiles/default/python/plugins/ 63 | # * Mac OS X: 64 | # Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins 65 | # * Windows: 66 | # AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins' 67 | 68 | QGISDIR=C:\Users\wujin\AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins 69 | 70 | ################################################# 71 | # Normally you would not need to edit below here 72 | ################################################# 73 | 74 | HELP = help/build/html 75 | 76 | PLUGIN_UPLOAD = $(c)/plugin_upload.py 77 | 78 | RESOURCE_SRC=$(shell grep '^ *@@g;s/.*>//g' | tr '\n' ' ') 79 | 80 | .PHONY: default 81 | default: 82 | @echo While you can use make to build and deploy your plugin, pb_tool 83 | @echo is a much better solution. 84 | @echo A Python script, pb_tool provides platform independent management of 85 | @echo your plugins and runs anywhere. 86 | @echo You can install pb_tool using: pip install pb_tool 87 | @echo See https://g-sherman.github.io/plugin_build_tool/ for info. 88 | 89 | compile: $(COMPILED_RESOURCE_FILES) 90 | 91 | %.py : %.qrc $(RESOURCES_SRC) 92 | pyrcc5 -o $*.py $< 93 | 94 | %.qm : %.ts 95 | $(LRELEASE) $< 96 | 97 | test: compile transcompile 98 | @echo 99 | @echo "----------------------" 100 | @echo "Regression Test Suite" 101 | @echo "----------------------" 102 | 103 | @# Preceding dash means that make will continue in case of errors 104 | @-export PYTHONPATH=`pwd`:$(PYTHONPATH); \ 105 | export QGIS_DEBUG=0; \ 106 | export QGIS_LOG_FILE=/dev/null; \ 107 | nosetests -v --with-id --with-coverage --cover-package=. \ 108 | 3>&1 1>&2 2>&3 3>&- || true 109 | @echo "----------------------" 110 | @echo "If you get a 'no module named qgis.core error, try sourcing" 111 | @echo "the helper script we have provided first then run make test." 112 | @echo "e.g. source run-env-linux.sh ; make test" 113 | @echo "----------------------" 114 | 115 | deploy: compile doc transcompile 116 | @echo 117 | @echo "------------------------------------------" 118 | @echo "Deploying plugin to your .qgis2 directory." 119 | @echo "------------------------------------------" 120 | # The deploy target only works on unix like operating system where 121 | # the Python plugin directory is located at: 122 | # $HOME/$(QGISDIR)/python/plugins 123 | mkdir -p $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 124 | cp -vf $(PY_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 125 | cp -vf $(UI_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 126 | cp -vf $(COMPILED_RESOURCE_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 127 | cp -vf $(EXTRAS) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 128 | cp -vfr i18n $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 129 | cp -vfr $(HELP) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/help 130 | # Copy extra directories if any 131 | (foreach EXTRA_DIR,(EXTRA_DIRS), cp -R (EXTRA_DIR) (HOME)/(QGISDIR)/python/plugins/(PLUGINNAME)/;) 132 | 133 | 134 | # The dclean target removes compiled python files from plugin directory 135 | # also deletes any .git entry 136 | dclean: 137 | @echo 138 | @echo "-----------------------------------" 139 | @echo "Removing any compiled python files." 140 | @echo "-----------------------------------" 141 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "*.pyc" -delete 142 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".git" -prune -exec rm -Rf {} \; 143 | 144 | 145 | derase: 146 | @echo 147 | @echo "-------------------------" 148 | @echo "Removing deployed plugin." 149 | @echo "-------------------------" 150 | rm -Rf $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 151 | 152 | zip: deploy dclean 153 | @echo 154 | @echo "---------------------------" 155 | @echo "Creating plugin zip bundle." 156 | @echo "---------------------------" 157 | # The zip target deploys the plugin and creates a zip file with the deployed 158 | # content. You can then upload the zip file on http://plugins.qgis.org 159 | rm -f $(PLUGINNAME).zip 160 | cd $(HOME)/$(QGISDIR)/python/plugins; zip -9r $(CURDIR)/$(PLUGINNAME).zip $(PLUGINNAME) 161 | 162 | package: compile 163 | # Create a zip package of the plugin named $(PLUGINNAME).zip. 164 | # This requires use of git (your plugin development directory must be a 165 | # git repository). 166 | # To use, pass a valid commit or tag as follows: 167 | # make package VERSION=Version_0.3.2 168 | @echo 169 | @echo "------------------------------------" 170 | @echo "Exporting plugin to zip package. " 171 | @echo "------------------------------------" 172 | rm -f $(PLUGINNAME).zip 173 | git archive --prefix=$(PLUGINNAME)/ -o $(PLUGINNAME).zip $(VERSION) 174 | echo "Created package: $(PLUGINNAME).zip" 175 | 176 | upload: zip 177 | @echo 178 | @echo "-------------------------------------" 179 | @echo "Uploading plugin to QGIS Plugin repo." 180 | @echo "-------------------------------------" 181 | $(PLUGIN_UPLOAD) $(PLUGINNAME).zip 182 | 183 | transup: 184 | @echo 185 | @echo "------------------------------------------------" 186 | @echo "Updating translation files with any new strings." 187 | @echo "------------------------------------------------" 188 | @chmod +x scripts/update-strings.sh 189 | @scripts/update-strings.sh $(LOCALES) 190 | 191 | transcompile: 192 | @echo 193 | @echo "----------------------------------------" 194 | @echo "Compiled translation files to .qm files." 195 | @echo "----------------------------------------" 196 | @chmod +x scripts/compile-strings.sh 197 | @scripts/compile-strings.sh $(LRELEASE) $(LOCALES) 198 | 199 | transclean: 200 | @echo 201 | @echo "------------------------------------" 202 | @echo "Removing compiled translation files." 203 | @echo "------------------------------------" 204 | rm -f i18n/*.qm 205 | 206 | clean: 207 | @echo 208 | @echo "------------------------------------" 209 | @echo "Removing uic and rcc generated files" 210 | @echo "------------------------------------" 211 | rm $(COMPILED_UI_FILES) $(COMPILED_RESOURCE_FILES) 212 | 213 | doc: 214 | @echo 215 | @echo "------------------------------------" 216 | @echo "Building documentation using sphinx." 217 | @echo "------------------------------------" 218 | cd help; make html 219 | 220 | pylint: 221 | @echo 222 | @echo "-----------------" 223 | @echo "Pylint violations" 224 | @echo "-----------------" 225 | @pylint --reports=n --rcfile=pylintrc . || true 226 | @echo 227 | @echo "----------------------" 228 | @echo "If you get a 'no module named qgis.core' error, try sourcing" 229 | @echo "the helper script we have provided first then run make pylint." 230 | @echo "e.g. source run-env-linux.sh ; make pylint" 231 | @echo "----------------------" 232 | 233 | 234 | # Run pep8 style checking 235 | #http://pypi.python.org/pypi/pep8 236 | pep8: 237 | @echo 238 | @echo "-----------" 239 | @echo "PEP8 issues" 240 | @echo "-----------" 241 | @pep8 --repeat --ignore=E203,E121,E122,E123,E124,E125,E126,E127,E128 --exclude $(PEP8EXCLUDE) . || true 242 | @echo "-----------" 243 | @echo "Ignored in PEP8 check:" 244 | @echo $(PEP8EXCLUDE) 245 | -------------------------------------------------------------------------------- /CoordTransform.py: -------------------------------------------------------------------------------- 1 | """ 2 | # wgs84\gcj02\bd09坐标系转换 3 | # wgs84\Pseudo-Mercator投影转换 4 | # bd09\bd09mc投影转换 5 | """ 6 | import math 7 | 8 | x_pi = 3.14159265358979324 * 3000.0 / 180.0 9 | pi = 3.1415926535897932384626 # π 10 | a = 6378245.0 # 长半轴 11 | ee = 0.00669342162296594323 # 扁率 12 | # 百度墨卡托投影纠正矩阵 13 | LLBAND = [75, 60, 45, 30, 15, 0] 14 | LL2MC = [ 15 | [-0.0015702102444, 111320.7020616939, 1704480524535203, -10338987376042340, 26112667856603880, -35149669176653700, 16 | 26595700718403920, -10725012454188240, 1800819912950474, 82.5], 17 | [0.0008277824516172526, 111320.7020463578, 647795574.6671607, -4082003173.641316, 10774905663.51142, 18 | -15171875531.51559, 12053065338.62167, -5124939663.577472, 913311935.9512032, 67.5], 19 | [0.00337398766765, 111320.7020202162, 4481351.045890365, -23393751.19931662, 79682215.47186455, -115964993.2797253, 20 | 97236711.15602145, -43661946.33752821, 8477230.501135234, 52.5], 21 | [0.00220636496208, 111320.7020209128, 51751.86112841131, 3796837.749470245, 992013.7397791013, -1221952.21711287, 22 | 1340652.697009075, -620943.6990984312, 144416.9293806241, 37.5], 23 | [-0.0003441963504368392, 111320.7020576856, 278.2353980772752, 2485758.690035394, 6070.750963243378, 24 | 54821.18345352118, 9540.606633304236, -2710.55326746645, 1405.483844121726, 22.5], 25 | [-0.0003218135878613132, 111320.7020701615, 0.00369383431289, 823725.6402795718, 0.46104986909093, 26 | 2351.343141331292, 1.58060784298199, 8.77738589078284, 0.37238884252424, 7.45]] 27 | # 百度墨卡托转回到百度经纬度纠正矩阵 28 | MCBAND = [12890594.86, 8362377.87, 5591021, 3481989.83, 1678043.12, 0] 29 | MC2LL = [[1.410526172116255e-8, 0.00000898305509648872, -1.9939833816331, 200.9824383106796, -187.2403703815547, 30 | 91.6087516669843, -23.38765649603339, 2.57121317296198, -0.03801003308653, 17337981.2], 31 | [-7.435856389565537e-9, 0.000008983055097726239, -0.78625201886289, 96.32687599759846, -1.85204757529826, 32 | -59.36935905485877, 47.40033549296737, -16.50741931063887, 2.28786674699375, 10260144.86], 33 | [-3.030883460898826e-8, 0.00000898305509983578, 0.30071316287616, 59.74293618442277, 7.357984074871, 34 | -25.38371002664745, 13.45380521110908, -3.29883767235584, 0.32710905363475, 6856817.37], 35 | [-1.981981304930552e-8, 0.000008983055099779535, 0.03278182852591, 40.31678527705744, 0.65659298677277, 36 | -4.44255534477492, 0.85341911805263, 0.12923347998204, -0.04625736007561, 4482777.06], 37 | [3.09191371068437e-9, 0.000008983055096812155, 0.00006995724062, 23.10934304144901, -0.00023663490511, 38 | -0.6321817810242, -0.00663494467273, 0.03430082397953, -0.00466043876332, 2555164.4], 39 | [2.890871144776878e-9, 0.000008983055095805407, -3.068298e-8, 7.47137025468032, -0.00000353937994, 40 | -0.02145144861037, -0.00001234426596, 0.00010322952773, -0.00000323890364, 826088.5]] 41 | 42 | 43 | def gcj02tobd09(lng, lat): 44 | """ 45 | 火星坐标系(GCJ02)转百度坐标系(BD09) 46 | :param lng:火星坐标经度 47 | :param lat:火星坐标纬度 48 | :return: 49 | """ 50 | z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi) 51 | theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi) 52 | bd_lng = z * math.cos(theta) + 0.0065 53 | bd_lat = z * math.sin(theta) + 0.006 54 | return [bd_lng, bd_lat] 55 | 56 | 57 | def bd09togcj02(bd_lon, bd_lat): 58 | """ 59 | 百度坐标系(BD09)转火星坐标系(GCJ02) 60 | :param bd_lat:百度坐标纬度 61 | :param bd_lon:百度坐标经度 62 | :return:转换后的坐标列表形式 63 | """ 64 | x = bd_lon - 0.0065 65 | y = bd_lat - 0.006 66 | z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * x_pi) 67 | theta = math.atan2(y, x) - 0.000003 * math.cos(x * x_pi) 68 | gg_lng = z * math.cos(theta) 69 | gg_lat = z * math.sin(theta) 70 | return [gg_lng, gg_lat] 71 | 72 | 73 | def wgs84togcj02(lng, lat): 74 | """ 75 | WGS84转GCJ02(火星坐标系) 76 | :param lng:WGS84坐标系的经度 77 | :param lat:WGS84坐标系的纬度 78 | :return: 79 | """ 80 | if out_of_china(lng, lat): # 判断是否在国内 81 | return lng, lat 82 | dlat = transformlat(lng - 105.0, lat - 35.0) 83 | dlng = transformlng(lng - 105.0, lat - 35.0) 84 | radlat = lat / 180.0 * pi 85 | magic = math.sin(radlat) 86 | magic = 1 - ee * magic * magic 87 | sqrtmagic = math.sqrt(magic) 88 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 89 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 90 | mglat = lat + dlat 91 | mglng = lng + dlng 92 | return [mglng, mglat] 93 | 94 | 95 | def gcj02towgs84(lng, lat): 96 | """ 97 | GCJ02(火星坐标系)转GPS84 98 | :param lng:火星坐标系的经度 99 | :param lat:火星坐标系纬度 100 | :return: 101 | """ 102 | if out_of_china(lng, lat): 103 | return lng, lat 104 | dlat = transformlat(lng - 105.0, lat - 35.0) 105 | dlng = transformlng(lng - 105.0, lat - 35.0) 106 | radlat = lat / 180.0 * pi 107 | magic = math.sin(radlat) 108 | magic = 1 - ee * magic * magic 109 | sqrtmagic = math.sqrt(magic) 110 | dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi) 111 | dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi) 112 | mglat = lat + dlat 113 | mglng = lng + dlng 114 | return [lng * 2 - mglng, lat * 2 - mglat] 115 | 116 | 117 | def transformlat(lng, lat): 118 | ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng)) 119 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * math.sin(2.0 * lng * pi)) * 2.0 / 3.0 120 | ret += (20.0 * math.sin(lat * pi) + 40.0 * 121 | math.sin(lat / 3.0 * pi)) * 2.0 / 3.0 122 | ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 * 123 | math.sin(lat * pi / 30.0)) * 2.0 / 3.0 124 | return ret 125 | 126 | 127 | def transformlng(lng, lat): 128 | ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng)) 129 | ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 * math.sin(2.0 * lng * pi)) * 2.0 / 3.0 130 | ret += (20.0 * math.sin(lng * pi) + 40.0 * math.sin(lng / 3.0 * pi)) * 2.0 / 3.0 131 | ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 * math.sin(lng / 30.0 * pi)) * 2.0 / 3.0 132 | return ret 133 | 134 | 135 | def out_of_china(lng, lat): 136 | """ 137 | 判断是否在国内,不在国内不做偏移 138 | :param lng: 139 | :param lat: 140 | :return: 141 | """ 142 | if lng < 72.004 or lng > 137.8347: 143 | return True 144 | if lat < 0.8293 or lat > 55.8271: 145 | return True 146 | return False 147 | 148 | 149 | def wgs84tomercator(lng, lat): 150 | """ 151 | wgs84投影到墨卡托 152 | :param lng: 153 | :param lat: 154 | :return: 155 | """ 156 | x = lng * 20037508.34 / 180 157 | y = math.log(math.tan((90 + lat) * math.pi / 360)) / (math.pi / 180) * 20037508.34 / 180 158 | return x, y 159 | 160 | 161 | def mercatortowgs84(x, y): 162 | """ 163 | 墨卡托投影坐标转回wgs84 164 | :param x: 165 | :param y: 166 | :return: 167 | """ 168 | lng = x / 20037508.34 * 180 169 | lat = 180 / math.pi * (2 * math.atan(math.exp(y / 20037508.34 * 180 * math.pi / 180)) - math.pi / 2) 170 | return lng, lat 171 | 172 | 173 | def getRange(cC, cB, T): 174 | if (cB != None): 175 | cC = max(cC, cB) 176 | if (T != None): 177 | cC = min(cC, T) 178 | return cC 179 | 180 | 181 | def getLoop(cC, cB, T): 182 | while (cC > T): 183 | cC -= T - cB 184 | while (cC < cB): 185 | cC += T - cB 186 | return cC 187 | 188 | 189 | def convertor(cC, cD): 190 | if (cC == None or cD == None): 191 | print('null') 192 | return None 193 | T = cD[0] + cD[1] * abs(cC.x) 194 | cB = abs(cC.y) / cD[9] 195 | cE = cD[2] + cD[3] * cB + cD[4] * cB * cB + cD[5] * cB * cB * cB + cD[6] * cB * cB * cB * cB + cD[ 196 | 7] * cB * cB * cB * cB * cB + cD[8] * cB * cB * cB * cB * cB * cB 197 | if (cC.x < 0): 198 | T = T * -1 199 | else: 200 | T = T 201 | if (cC.y < 0): 202 | cE = cE * -1 203 | else: 204 | cE = cE 205 | return [T, cE] 206 | 207 | 208 | def convertLL2MC(T): 209 | cD = None 210 | T.x = getLoop(T.x, -180, 180) 211 | T.y = getRange(T.y, -74, 74) 212 | cB = T 213 | for cC in range(0, len(LLBAND), 1): 214 | if (cB.y >= LLBAND[cC]): 215 | cD = LL2MC[cC] 216 | break 217 | if (cD != None): 218 | for cC in range(len(LLBAND) - 1, -1, -1): 219 | if (cB.y <= -LLBAND[cC]): 220 | cD = LL2MC[cC] 221 | break 222 | cE = convertor(T, cD) 223 | return cE 224 | 225 | 226 | def convertMC2LL(cB): 227 | cC = LLT(abs(cB.x), abs(cB.y)) 228 | cE = None 229 | for cD in range(0, len(MCBAND), 1): 230 | if (cC.y >= MCBAND[cD]): 231 | cE = MC2LL[cD] 232 | break 233 | T = convertor(cB, cE) 234 | return T 235 | 236 | 237 | def bd09tomercator(lng, lat): 238 | """ 239 | bd09投影到百度墨卡托 240 | :param lng: 241 | :param lat: 242 | :return: 243 | """ 244 | baidut = LLT(lng, lat) 245 | return convertLL2MC(baidut) 246 | 247 | 248 | def mercatortobd09(x, y): 249 | """ 250 | 墨卡托投影坐标转回bd09 251 | :param x: 252 | :param y: 253 | :return: 254 | """ 255 | baidut = LLT(x, y) 256 | return convertMC2LL(baidut) 257 | 258 | 259 | class LLT: 260 | def __init__(self, x, y): 261 | self.x = x 262 | self.y = y 263 | 264 | -------------------------------------------------------------------------------- /china_transform_tool.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | ChinaTransformTool 5 | A QGIS plugin 6 | shp文件坐标系转换工具,支持WGS84\GCJ02\BD09坐标系转换 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2021-04-21 10 | git sha : $Format:%H$ 11 | copyright : (C) 2021 by wudaojian 12 | email : 827337743@qq.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication 25 | from qgis.PyQt.QtGui import QIcon 26 | from qgis.PyQt.QtWidgets import QAction,QFileDialog 27 | from .ImgTransform import transform_imgfile 28 | from .ShpTransform import transform_shpfile 29 | # Initialize Qt resources from file resources.py 30 | from .resources import * 31 | # Import the code for the dialog 32 | from .china_transform_tool_dialog import ChinaTransformToolDialog 33 | import os.path 34 | 35 | 36 | class ChinaTransformTool: 37 | """QGIS Plugin Implementation.""" 38 | 39 | def __init__(self, iface): 40 | """Constructor. 41 | 42 | :param iface: An interface instance that will be passed to this class 43 | which provides the hook by which you can manipulate the QGIS 44 | application at run time. 45 | :type iface: QgsInterface 46 | """ 47 | # Save reference to the QGIS interface 48 | self.iface = iface 49 | # initialize plugin directory 50 | self.plugin_dir = os.path.dirname(__file__) 51 | # initialize locale 52 | locale = QSettings().value('locale/userLocale')[0:2] 53 | locale_path = os.path.join( 54 | self.plugin_dir, 55 | 'i18n', 56 | 'ChinaTransformTool_{}.qm'.format(locale)) 57 | 58 | if os.path.exists(locale_path): 59 | self.translator = QTranslator() 60 | self.translator.load(locale_path) 61 | QCoreApplication.installTranslator(self.translator) 62 | 63 | # Declare instance attributes 64 | self.actions = [] 65 | self.menu = self.tr(u'&China Transform Tool') 66 | 67 | # Check if plugin was started the first time in current QGIS session 68 | # Must be set in initGui() to survive plugin reloads 69 | self.first_start = None 70 | 71 | # noinspection PyMethodMayBeStatic 72 | def tr(self, message): 73 | """Get the translation for a string using Qt translation API. 74 | 75 | We implement this ourselves since we do not inherit QObject. 76 | 77 | :param message: String for translation. 78 | :type message: str, QString 79 | 80 | :returns: Translated version of message. 81 | :rtype: QString 82 | """ 83 | # noinspection PyTypeChecker,PyArgumentList,PyCallByClass 84 | return QCoreApplication.translate('ChinaTransformTool', message) 85 | 86 | 87 | def add_action( 88 | self, 89 | icon_path, 90 | text, 91 | callback, 92 | enabled_flag=True, 93 | add_to_menu=True, 94 | add_to_toolbar=True, 95 | status_tip=None, 96 | whats_this=None, 97 | parent=None): 98 | """Add a toolbar icon to the toolbar. 99 | 100 | :param icon_path: Path to the icon for this action. Can be a resource 101 | path (e.g. ':/plugins/foo/bar.png') or a normal file system path. 102 | :type icon_path: str 103 | 104 | :param text: Text that should be shown in menu items for this action. 105 | :type text: str 106 | 107 | :param callback: Function to be called when the action is triggered. 108 | :type callback: function 109 | 110 | :param enabled_flag: A flag indicating if the action should be enabled 111 | by default. Defaults to True. 112 | :type enabled_flag: bool 113 | 114 | :param add_to_menu: Flag indicating whether the action should also 115 | be added to the menu. Defaults to True. 116 | :type add_to_menu: bool 117 | 118 | :param add_to_toolbar: Flag indicating whether the action should also 119 | be added to the toolbar. Defaults to True. 120 | :type add_to_toolbar: bool 121 | 122 | :param status_tip: Optional text to show in a popup when mouse pointer 123 | hovers over the action. 124 | :type status_tip: str 125 | 126 | :param parent: Parent widget for the new action. Defaults None. 127 | :type parent: QWidget 128 | 129 | :param whats_this: Optional text to show in the status bar when the 130 | mouse pointer hovers over the action. 131 | 132 | :returns: The action that was created. Note that the action is also 133 | added to self.actions list. 134 | :rtype: QAction 135 | """ 136 | 137 | icon = QIcon(icon_path) 138 | action = QAction(icon, text, parent) 139 | action.triggered.connect(callback) 140 | action.setEnabled(enabled_flag) 141 | 142 | if status_tip is not None: 143 | action.setStatusTip(status_tip) 144 | 145 | if whats_this is not None: 146 | action.setWhatsThis(whats_this) 147 | 148 | if add_to_toolbar: 149 | # Adds plugin icon to Plugins toolbar 150 | self.iface.addToolBarIcon(action) 151 | 152 | if add_to_menu: 153 | self.iface.addPluginToMenu( 154 | self.menu, 155 | action) 156 | 157 | self.actions.append(action) 158 | 159 | return action 160 | 161 | def initGui(self): 162 | """Create the menu entries and toolbar icons inside the QGIS GUI.""" 163 | 164 | icon_path = ':/plugins/china_transform_tool/icon.png' 165 | self.add_action( 166 | icon_path, 167 | text=self.tr(u'china transform tool bar'), 168 | callback=self.run, 169 | parent=self.iface.mainWindow()) 170 | 171 | # will be set False in run() 172 | self.first_start = True 173 | 174 | 175 | def unload(self): 176 | """Removes the plugin menu item and icon from QGIS GUI.""" 177 | for action in self.actions: 178 | self.iface.removePluginMenu( 179 | self.tr(u'&China Transform Tool'), 180 | action) 181 | self.iface.removeToolBarIcon(action) 182 | # 加载文件的路径 183 | def select_input_file(self): 184 | filename,_filter = QFileDialog.getOpenFileName( 185 | self.dlg,"Select input file","","*.shp;;*.jpeg;;*.jpg;;*.png;;*.tif;;*.tiff" 186 | ) 187 | self.dlg.lineEdit_InPut.setText(filename) 188 | # 导出文件的路径 189 | def select_output_file(self): 190 | filename,_filter = QFileDialog.getSaveFileName( 191 | self.dlg,"Select output file","",self.dlg.lineEdit_InPut.text().split(".")[1] 192 | ) 193 | self.dlg.lineEdit_OutPut.setText(".".join([filename.split(".")[0],self.dlg.lineEdit_InPut.text().split(".")[1]])) 194 | def run(self): 195 | """Run method that performs all the real work""" 196 | 197 | # Create the dialog with elements (after translation) and keep reference 198 | # Only create GUI ONCE in callback, so that it will only load when the plugin is started 199 | if self.first_start == True: 200 | self.first_start = False 201 | self.dlg = ChinaTransformToolDialog() 202 | # 点击按钮,确定路径 203 | self.dlg.pushButton_InPut.clicked.connect(self.select_input_file) 204 | self.dlg.pushButton_OutPut.clicked.connect(self.select_output_file) 205 | # show the dialog 206 | self.dlg.show() 207 | # Run the dialog event loop 208 | result = self.dlg.exec_() 209 | # See if OK was pressed 210 | if result: 211 | # Do something useful here - delete the line containing pass and 212 | # substitute with your code. 213 | # 获取txt文件路径,shp文件路径,腾讯key 214 | input_filepath = self.dlg.lineEdit_InPut.text() 215 | output_filepath = self.dlg.lineEdit_OutPut.text() 216 | coord_original = "" 217 | coord_target = "" 218 | if self.dlg.radioButton_InWGS84.isChecked(): 219 | coord_original = "wgs84" 220 | if self.dlg.radioButton_InGCJ02.isChecked(): 221 | coord_original = "gcj02" 222 | if self.dlg.radioButton_InBD09.isChecked(): 223 | coord_original = "bd09" 224 | if self.dlg.radioButton_OutWGS84.isChecked(): 225 | coord_target = "wgs84" 226 | if self.dlg.radioButton_OutGCJ02.isChecked(): 227 | coord_target = "gcj02" 228 | if self.dlg.radioButton_OutBD09.isChecked(): 229 | coord_target = "bd09" 230 | if input_filepath.split(".")[1] == "shp": 231 | transform_shpfile(input_filepath,output_filepath,coord_original,coord_target) 232 | else: 233 | transform_imgfile(input_filepath,output_filepath,coord_original,coord_target) 234 | pass 235 | # 在QGIS界面上打印结果 236 | self.iface.messageBar().pushMessage("成功", "文件路径:" +output_filepath) -------------------------------------------------------------------------------- /pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | 3 | # Specify a configuration file. 4 | #rcfile= 5 | 6 | # Python code to execute, usually for sys.path manipulation such as 7 | # pygtk.require(). 8 | #init-hook= 9 | 10 | # Profiled execution. 11 | profile=no 12 | 13 | # Add files or directories to the blacklist. They should be base names, not 14 | # paths. 15 | ignore=CVS 16 | 17 | # Pickle collected data for later comparisons. 18 | persistent=yes 19 | 20 | # List of plugins (as comma separated values of python modules names) to load, 21 | # usually to register additional checkers. 22 | load-plugins= 23 | 24 | 25 | [MESSAGES CONTROL] 26 | 27 | # Enable the message, report, category or checker with the given id(s). You can 28 | # either give multiple identifier separated by comma (,) or put this option 29 | # multiple time. See also the "--disable" option for examples. 30 | #enable= 31 | 32 | # Disable the message, report, category or checker with the given id(s). You 33 | # can either give multiple identifiers separated by comma (,) or put this 34 | # option multiple times (only on the command line, not in the configuration 35 | # file where it should appear only once).You can also use "--disable=all" to 36 | # disable everything first and then reenable specific checks. For example, if 37 | # you want to run only the similarities checker, you can use "--disable=all 38 | # --enable=similarities". If you want to run only the classes checker, but have 39 | # no Warning level messages displayed, use"--disable=all --enable=classes 40 | # --disable=W" 41 | # see http://stackoverflow.com/questions/21487025/pylint-locally-defined-disables-still-give-warnings-how-to-suppress-them 42 | disable=locally-disabled,C0103 43 | 44 | 45 | [REPORTS] 46 | 47 | # Set the output format. Available formats are text, parseable, colorized, msvs 48 | # (visual studio) and html. You can also give a reporter class, eg 49 | # mypackage.mymodule.MyReporterClass. 50 | output-format=text 51 | 52 | # Put messages in a separate file for each module / package specified on the 53 | # command line instead of printing them on stdout. Reports (if any) will be 54 | # written in a file name "pylint_global.[txt|html]". 55 | files-output=no 56 | 57 | # Tells whether to display a full report or only the messages 58 | reports=yes 59 | 60 | # Python expression which should return a note less than 10 (10 is the highest 61 | # note). You have access to the variables errors warning, statement which 62 | # respectively contain the number of errors / warnings messages and the total 63 | # number of statements analyzed. This is used by the global evaluation report 64 | # (RP0004). 65 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 66 | 67 | # Add a comment according to your evaluation note. This is used by the global 68 | # evaluation report (RP0004). 69 | comment=no 70 | 71 | # Template used to display messages. This is a python new-style format string 72 | # used to format the message information. See doc for all details 73 | #msg-template= 74 | 75 | 76 | [BASIC] 77 | 78 | # Required attributes for module, separated by a comma 79 | required-attributes= 80 | 81 | # List of builtins function names that should not be used, separated by a comma 82 | bad-functions=map,filter,apply,input 83 | 84 | # Regular expression which should only match correct module names 85 | module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 86 | 87 | # Regular expression which should only match correct module level names 88 | const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 89 | 90 | # Regular expression which should only match correct class names 91 | class-rgx=[A-Z_][a-zA-Z0-9]+$ 92 | 93 | # Regular expression which should only match correct function names 94 | function-rgx=[a-z_][a-z0-9_]{2,30}$ 95 | 96 | # Regular expression which should only match correct method names 97 | method-rgx=[a-z_][a-z0-9_]{2,30}$ 98 | 99 | # Regular expression which should only match correct instance attribute names 100 | attr-rgx=[a-z_][a-z0-9_]{2,30}$ 101 | 102 | # Regular expression which should only match correct argument names 103 | argument-rgx=[a-z_][a-z0-9_]{2,30}$ 104 | 105 | # Regular expression which should only match correct variable names 106 | variable-rgx=[a-z_][a-z0-9_]{2,30}$ 107 | 108 | # Regular expression which should only match correct attribute names in class 109 | # bodies 110 | class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 111 | 112 | # Regular expression which should only match correct list comprehension / 113 | # generator expression variable names 114 | inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ 115 | 116 | # Good variable names which should always be accepted, separated by a comma 117 | good-names=i,j,k,ex,Run,_ 118 | 119 | # Bad variable names which should always be refused, separated by a comma 120 | bad-names=foo,bar,baz,toto,tutu,tata 121 | 122 | # Regular expression which should only match function or class names that do 123 | # not require a docstring. 124 | no-docstring-rgx=__.*__ 125 | 126 | # Minimum line length for functions/classes that require docstrings, shorter 127 | # ones are exempt. 128 | docstring-min-length=-1 129 | 130 | 131 | [MISCELLANEOUS] 132 | 133 | # List of note tags to take in consideration, separated by a comma. 134 | notes=FIXME,XXX,TODO 135 | 136 | 137 | [TYPECHECK] 138 | 139 | # Tells whether missing members accessed in mixin class should be ignored. A 140 | # mixin class is detected if its name ends with "mixin" (case insensitive). 141 | ignore-mixin-members=yes 142 | 143 | # List of classes names for which member attributes should not be checked 144 | # (useful for classes with attributes dynamically set). 145 | ignored-classes=SQLObject 146 | 147 | # When zope mode is activated, add a predefined set of Zope acquired attributes 148 | # to generated-members. 149 | zope=no 150 | 151 | # List of members which are set dynamically and missed by pylint inference 152 | # system, and so shouldn't trigger E0201 when accessed. Python regular 153 | # expressions are accepted. 154 | generated-members=REQUEST,acl_users,aq_parent 155 | 156 | 157 | [VARIABLES] 158 | 159 | # Tells whether we should check for unused import in __init__ files. 160 | init-import=no 161 | 162 | # A regular expression matching the beginning of the name of dummy variables 163 | # (i.e. not used). 164 | dummy-variables-rgx=_$|dummy 165 | 166 | # List of additional names supposed to be defined in builtins. Remember that 167 | # you should avoid to define new builtins when possible. 168 | additional-builtins= 169 | 170 | 171 | [FORMAT] 172 | 173 | # Maximum number of characters on a single line. 174 | max-line-length=80 175 | 176 | # Regexp for a line that is allowed to be longer than the limit. 177 | ignore-long-lines=^\s*(# )??$ 178 | 179 | # Allow the body of an if to be on the same line as the test if there is no 180 | # else. 181 | single-line-if-stmt=no 182 | 183 | # List of optional constructs for which whitespace checking is disabled 184 | no-space-check=trailing-comma,dict-separator 185 | 186 | # Maximum number of lines in a module 187 | max-module-lines=1000 188 | 189 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 190 | # tab). 191 | indent-string=' ' 192 | 193 | 194 | [SIMILARITIES] 195 | 196 | # Minimum lines number of a similarity. 197 | min-similarity-lines=4 198 | 199 | # Ignore comments when computing similarities. 200 | ignore-comments=yes 201 | 202 | # Ignore docstrings when computing similarities. 203 | ignore-docstrings=yes 204 | 205 | # Ignore imports when computing similarities. 206 | ignore-imports=no 207 | 208 | 209 | [IMPORTS] 210 | 211 | # Deprecated modules which should not be used, separated by a comma 212 | deprecated-modules=regsub,TERMIOS,Bastion,rexec 213 | 214 | # Create a graph of every (i.e. internal and external) dependencies in the 215 | # given file (report RP0402 must not be disabled) 216 | import-graph= 217 | 218 | # Create a graph of external dependencies in the given file (report RP0402 must 219 | # not be disabled) 220 | ext-import-graph= 221 | 222 | # Create a graph of internal dependencies in the given file (report RP0402 must 223 | # not be disabled) 224 | int-import-graph= 225 | 226 | 227 | [DESIGN] 228 | 229 | # Maximum number of arguments for function / method 230 | max-args=5 231 | 232 | # Argument names that match this expression will be ignored. Default to name 233 | # with leading underscore 234 | ignored-argument-names=_.* 235 | 236 | # Maximum number of locals for function / method body 237 | max-locals=15 238 | 239 | # Maximum number of return / yield for function / method body 240 | max-returns=6 241 | 242 | # Maximum number of branch for function / method body 243 | max-branches=12 244 | 245 | # Maximum number of statements in function / method body 246 | max-statements=50 247 | 248 | # Maximum number of parents for a class (see R0901). 249 | max-parents=7 250 | 251 | # Maximum number of attributes for a class (see R0902). 252 | max-attributes=7 253 | 254 | # Minimum number of public methods for a class (see R0903). 255 | min-public-methods=2 256 | 257 | # Maximum number of public methods for a class (see R0904). 258 | max-public-methods=20 259 | 260 | 261 | [CLASSES] 262 | 263 | # List of interface methods to ignore, separated by a comma. This is used for 264 | # instance to not check methods defines in Zope's Interface base class. 265 | ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by 266 | 267 | # List of method names used to declare (i.e. assign) instance attributes. 268 | defining-attr-methods=__init__,__new__,setUp 269 | 270 | # List of valid names for the first argument in a class method. 271 | valid-classmethod-first-arg=cls 272 | 273 | # List of valid names for the first argument in a metaclass class method. 274 | valid-metaclass-classmethod-first-arg=mcs 275 | 276 | 277 | [EXCEPTIONS] 278 | 279 | # Exceptions that will emit a warning when being caught. Defaults to 280 | # "Exception" 281 | overgeneral-exceptions=Exception 282 | -------------------------------------------------------------------------------- /ShpTransform.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | try: 3 | from osgeo import gdal 4 | from osgeo import ogr 5 | from osgeo import osr 6 | except ImportError: 7 | import gdal 8 | import ogr 9 | import osr 10 | from shutil import copyfile 11 | import os 12 | from .CoordTransform import gcj02tobd09,bd09togcj02,wgs84togcj02,gcj02towgs84,wgs84tomercator,mercatortowgs84,bd09tomercator,mercatortobd09 13 | # 写入shp文件,polygon 14 | # coord_type,code_name, field_list, result_list 15 | 16 | def polygon_transform(geom_polygon,coord_original,coord_target): 17 | geom_type = geom_polygon.GetGeometryType() 18 | z_value = ogr.GT_HasZ(geom_type) 19 | # print(z_value) 20 | geom_col_polygon = ogr.Geometry(ogr.wkbGeometryCollection) 21 | geom_col_polygon.AddGeometry(geom_polygon) 22 | geom_poly = geom_polygon 23 | # print(geom_poly.GetGeometryCount()) 24 | geom_poly_o_count = geom_poly.GetGeometryCount() 25 | for m in range(0,geom_poly_o_count): 26 | geom_poly.RemoveGeometry(geom_poly_o_count-m-1) 27 | # print('geom_poly') 28 | # print(geom_poly) 29 | # 获取polygon对象的边界 30 | boundary_polygon = geom_col_polygon.GetGeometryRef(0).GetBoundary() 31 | # print('boundary_polygon') 32 | # print(boundary_polygon) 33 | # 获取边界的数量,如果大于1,说明有孔洞 34 | boundary_polygon_count = boundary_polygon.GetGeometryCount() 35 | # print('boundary_polygon_count') 36 | # print(boundary_polygon_count) 37 | if boundary_polygon_count == 0: 38 | boundary_polygon_point_count = boundary_polygon.GetPointCount() 39 | ring = ogr.Geometry(ogr.wkbLinearRing) 40 | for j in range(boundary_polygon_point_count): 41 | point_polygon = boundary_polygon.GetPoint(j) 42 | # 坐标系转换 43 | if coord_original == 'gcj02' and coord_target == 'wgs84': 44 | point_polygon_trans = gcj02towgs84(point_polygon[0], point_polygon[1]) 45 | elif coord_original == 'wgs84' and coord_target == 'gcj02': 46 | point_polygon_trans = wgs84togcj02(point_polygon[0], point_polygon[1]) 47 | elif coord_original == 'gcj02' and coord_target == 'bd09': 48 | point_polygon_trans = gcj02tobd09(point_polygon[0], point_polygon[1]) 49 | elif coord_original == 'bd09' and coord_target == 'gcj02': 50 | point_polygon_trans = bd09togcj02(point_polygon[0], point_polygon[1]) 51 | elif coord_original == 'wgs84' and coord_target == 'bd09': 52 | point_polygon_trans_gcj02 = wgs84togcj02(point_polygon[0], point_polygon[1]) 53 | point_polygon_trans = gcj02tobd09(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 54 | elif coord_original == 'bd09' and coord_target == 'wgs84': 55 | point_polygon_trans_gcj02 = bd09togcj02(point_polygon[0], point_polygon[1]) 56 | point_polygon_trans = gcj02towgs84(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 57 | else: 58 | point_polygon_trans = [point_polygon[0], point_polygon[1]] 59 | # 添加坐标点 60 | if z_value == 1: 61 | ring.AddPoint(point_polygon_trans[0],point_polygon_trans[1],point_polygon[2]) 62 | else: 63 | ring.AddPoint_2D(point_polygon_trans[0],point_polygon_trans[1]) 64 | geom_poly.AddGeometry(ring) 65 | else: 66 | for i in range(boundary_polygon_count): 67 | boundary_polygon_ring = boundary_polygon.GetGeometryRef(i) 68 | boundary_polygon_ring_point_count = boundary_polygon_ring.GetPointCount() 69 | ring = ogr.Geometry(ogr.wkbLinearRing) 70 | for j in range(0,boundary_polygon_ring_point_count): 71 | point_polygon = boundary_polygon_ring.GetPoint(j) 72 | # print('point_polygon') 73 | # print(point_polygon) 74 | # 坐标系转换 75 | if coord_original == 'gcj02' and coord_target == 'wgs84': 76 | point_polygon_trans = gcj02towgs84(point_polygon[0], point_polygon[1]) 77 | elif coord_original == 'wgs84' and coord_target == 'gcj02': 78 | point_polygon_trans = wgs84togcj02(point_polygon[0], point_polygon[1]) 79 | elif coord_original == 'gcj02' and coord_target == 'bd09': 80 | point_polygon_trans = gcj02tobd09(point_polygon[0], point_polygon[1]) 81 | elif coord_original == 'bd09' and coord_target == 'gcj02': 82 | point_polygon_trans = bd09togcj02(point_polygon[0], point_polygon[1]) 83 | elif coord_original == 'wgs84' and coord_target == 'bd09': 84 | point_polygon_trans_gcj02 = wgs84togcj02(point_polygon[0], point_polygon[1]) 85 | point_polygon_trans = gcj02tobd09(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 86 | elif coord_original == 'bd09' and coord_target == 'wgs84': 87 | point_polygon_trans_gcj02 = bd09togcj02(point_polygon[0], point_polygon[1]) 88 | point_polygon_trans = gcj02towgs84(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 89 | else: 90 | point_polygon_trans = [point_polygon[0], point_polygon[1]] 91 | # 添加坐标点 92 | if z_value == 1: 93 | ring.AddPoint(point_polygon_trans[0], point_polygon_trans[1], point_polygon[2]) 94 | else: 95 | ring.AddPoint_2D(point_polygon_trans[0], point_polygon_trans[1]) 96 | geom_poly.AddGeometry(ring) 97 | return geom_poly 98 | 99 | def multi_polygon_transform(geom_polygon,coord_original,coord_target): 100 | geom_col = ogr.Geometry(ogr.wkbGeometryCollection) 101 | for g in geom_polygon: 102 | geom_col.AddGeometry(g) 103 | geom_polygon_count = geom_polygon.GetGeometryCount() 104 | for m in range(0,geom_polygon_count): 105 | geom_polygon.RemoveGeometry(geom_polygon_count-m-1) 106 | for g in geom_col: 107 | g_trans = polygon_transform(g,coord_original,coord_target) 108 | geom_polygon.AddGeometry(g_trans) 109 | return geom_polygon 110 | def polyline_transform(geom_polyline,coord_original,coord_target): 111 | geom_type = geom_polyline.GetGeometryType() 112 | z_value = ogr.GT_HasZ(geom_type) 113 | # print(z_value) 114 | geom_polyline_count = geom_polyline.GetPointCount() 115 | for i in range(0,geom_polyline_count): 116 | point_orginal = geom_polyline.GetPoint(i) 117 | # 坐标系转换 118 | if coord_original == 'gcj02' and coord_target == 'wgs84': 119 | point_polygon_trans = gcj02towgs84(point_orginal[0], point_orginal[1]) 120 | elif coord_original == 'wgs84' and coord_target == 'gcj02': 121 | point_polygon_trans = wgs84togcj02(point_orginal[0], point_orginal[1]) 122 | elif coord_original == 'gcj02' and coord_target == 'bd09': 123 | point_polygon_trans = gcj02tobd09(point_orginal[0], point_orginal[1]) 124 | elif coord_original == 'bd09' and coord_target == 'gcj02': 125 | point_polygon_trans = bd09togcj02(point_orginal[0], point_orginal[1]) 126 | elif coord_original == 'wgs84' and coord_target == 'bd09': 127 | point_polygon_trans_gcj02 = wgs84togcj02(point_orginal[0], point_orginal[1]) 128 | point_polygon_trans = gcj02tobd09(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 129 | elif coord_original == 'bd09' and coord_target == 'wgs84': 130 | point_polygon_trans_gcj02 = bd09togcj02(point_orginal[0], point_orginal[1]) 131 | point_polygon_trans = gcj02towgs84(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 132 | else: 133 | point_polygon_trans = [point_orginal[0], point_orginal[1]] 134 | if z_value == 1: 135 | geom_polyline.SetPoint(i,point_polygon_trans[0],point_polygon_trans[1],point_orginal[2]) 136 | else: 137 | geom_polyline.SetPoint_2D(i,point_polygon_trans[0],point_polygon_trans[1]) 138 | return geom_polyline 139 | def multi_polyline_transform(geom_polyline,coord_original,coord_target): 140 | geom_col = ogr.Geometry(ogr.wkbGeometryCollection) 141 | for g in geom_polyline: 142 | geom_col.AddGeometry(g) 143 | geom_polyline_count = geom_polyline.GetGeometryCount() 144 | for m in range(0,geom_polyline_count): 145 | geom_polyline.RemoveGeometry(geom_polyline_count-m-1) 146 | for g in geom_col: 147 | g_trans = polyline_transform(g,coord_original,coord_target) 148 | geom_polyline.AddGeometry(g_trans) 149 | return geom_polyline 150 | def point_transform(geom_point,coord_original,coord_target): 151 | geom_type = geom_point.GetGeometryType() 152 | z_value = ogr.GT_HasZ(geom_type) 153 | # print(z_value) 154 | # 坐标系转换 155 | if coord_original == 'gcj02' and coord_target == 'wgs84': 156 | point_polygon_trans = gcj02towgs84(geom_point.GetX(), geom_point.GetY()) 157 | elif coord_original == 'wgs84' and coord_target == 'gcj02': 158 | point_polygon_trans = wgs84togcj02(geom_point.GetX(), geom_point.GetY()) 159 | elif coord_original == 'gcj02' and coord_target == 'bd09': 160 | point_polygon_trans = gcj02tobd09(geom_point.GetX(), geom_point.GetY()) 161 | elif coord_original == 'bd09' and coord_target == 'gcj02': 162 | point_polygon_trans = bd09togcj02(geom_point.GetX(), geom_point.GetY()) 163 | elif coord_original == 'wgs84' and coord_target == 'bd09': 164 | point_polygon_trans_gcj02 = wgs84togcj02(geom_point.GetX(), geom_point.GetY()) 165 | point_polygon_trans = gcj02tobd09(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 166 | elif coord_original == 'bd09' and coord_target == 'wgs84': 167 | point_polygon_trans_gcj02 = bd09togcj02(geom_point.GetX(), geom_point.GetY()) 168 | point_polygon_trans = gcj02towgs84(point_polygon_trans_gcj02[0], point_polygon_trans_gcj02[1]) 169 | else: 170 | point_polygon_trans = [geom_point.GetX(), geom_point.GetY()] 171 | if z_value == 1: 172 | geom_point.SetPoint(0,point_polygon_trans[0],point_polygon_trans[1], geom_point.GetZ()) 173 | else: 174 | geom_point.SetPoint_2D(0,point_polygon_trans[0],point_polygon_trans[1]) 175 | return geom_point 176 | def multi_point_transform(geom_point,coord_original,coord_target): 177 | # print(geom_point) 178 | geom_col = ogr.Geometry(ogr.wkbGeometryCollection) 179 | for g in geom_point: 180 | geom_col.AddGeometry(g) 181 | geom_point_count = geom_point.GetGeometryCount() 182 | for m in range(0,geom_point_count): 183 | geom_point.RemoveGeometry(geom_point_count-m-1) 184 | for g in geom_col: 185 | g_trans = point_transform(g,coord_original,coord_target) 186 | geom_point.AddGeometry(g_trans) 187 | # print(geom_point) 188 | return geom_point 189 | def transform_shpfile(read_path_str,write_path_str,coord_original,coord_target): 190 | write_file_name = write_path_str.split('.')[0] 191 | read_file_name = read_path_str.split('.')[0] 192 | if os.path.exists(read_file_name+'.cpg'): 193 | copyfile(read_file_name+'.cpg',write_file_name+'.cpg') 194 | if os.path.exists(read_file_name+'.dbf'): 195 | copyfile(read_file_name+'.dbf',write_file_name+'.dbf') 196 | if os.path.exists(read_file_name+'.prj'): 197 | copyfile(read_file_name+'.prj',write_file_name+'.prj') 198 | if os.path.exists(read_file_name+'.qpj'): 199 | copyfile(read_file_name+'.qpj',write_file_name+'.qpj') 200 | if os.path.exists(read_file_name+'.shp'): 201 | copyfile(read_file_name+'.shp',write_file_name+'.shp') 202 | if os.path.exists(read_file_name+'.shx'): 203 | copyfile(read_file_name+'.shx',write_file_name+'.shx') 204 | # 支持中文路径 205 | gdal.SetConfigOption('GDAL_FILENAME_IS_UTF8', 'YES') 206 | fcode = open(write_file_name+'.cpg','r') 207 | fcodelines = fcode.readlines() 208 | code_name = fcodelines[0].strip('\n') 209 | fcode.close() 210 | # 支持中文编码 211 | gdal.SetConfigOption('SHAPE_ENCODING', code_name) 212 | # 注册所有的驱动 213 | ogr.RegisterAll() 214 | # 打开数据 215 | ds = ogr.Open(write_file_name+'.shp', 1) 216 | if ds == None: 217 | print('打开文件失败!') 218 | # 获取数据源中的图层个数,shp数据图层只有一个,gdb、dxf会有多个 219 | iLayerCount = ds.GetLayerCount() 220 | print('图层个数 = ', iLayerCount) 221 | # 获取第一个图层 222 | oLayer = ds.GetLayerByIndex(0) 223 | if oLayer == None: 224 | print('获取图层失败!') 225 | # 对图层进行初始化 226 | oLayer.ResetReading() 227 | # 输出图层中的要素个数 228 | num = oLayer.GetFeatureCount(0) 229 | oFid = oLayer.GetFIDColumn() 230 | print(oFid) 231 | oDefn = oLayer.GetLayerDefn() 232 | # 获取要素 233 | for i in range(0, num): 234 | ofeature = oLayer.GetFeature(i) 235 | oLayer.DeleteFeature(i) 236 | geom = ofeature.GetGeometryRef() 237 | geom_type = geom.GetGeometryName() 238 | # print(geom_type) 239 | if 'MULTIPOLYGON' in geom_type: 240 | ofeature.SetGeometry(multi_polygon_transform(geom, coord_original, coord_target)) 241 | elif 'MULTILINESTRING' in geom_type: 242 | ofeature.SetGeometry(multi_polyline_transform(geom, coord_original, coord_target)) 243 | elif 'MULTIPOINT' in geom_type: 244 | ofeature.SetGeometry(multi_point_transform(geom, coord_original, coord_target)) 245 | elif 'POLYGON' in geom_type and 'MULTI' not in geom_type: 246 | ofeature.SetGeometry(polygon_transform(geom, coord_original, coord_target)) 247 | elif 'LINESTRING' in geom_type and 'MULTI' not in geom_type: 248 | ofeature.SetGeometry(polyline_transform(geom, coord_original, coord_target)) 249 | elif 'POINT' in geom_type and 'MULTI' not in geom_type: 250 | ofeature.SetGeometry(point_transform(geom, coord_original, coord_target)) 251 | oLayer.CreateFeature(ofeature) 252 | ds.Destroy() 253 | del ds 254 | 255 | --------------------------------------------------------------------------------