├── .gitignore ├── CHANGES.txt ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── examples ├── multiple_layers.gpkg ├── owc.xml └── small_world.gpkg ├── owc_geopackage_extension.md ├── qgis_geopackage_extension.md ├── qgis_plugin └── qgpkg │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── __init__.py │ ├── i18n │ ├── qgpkg.pro │ ├── qgpkg_de.qm │ └── qgpkg_de.ts │ ├── metadata.txt │ ├── plugin_upload.py │ ├── qgis_geopackage.py │ ├── qgpkg.py │ ├── qgpkgAbout.py │ ├── qgpkg_owc.py │ ├── qgpkg_qgis.py │ ├── read.png │ ├── resources.py │ ├── resources.qrc │ ├── test │ └── __init__.py │ ├── ui_about_dialog.py │ ├── ui_about_dialog.ui │ └── write.png ├── qgisgpkg ├── __init__.py ├── qgpkg.py ├── qgpkg_owc.py └── qgpkg_qgis.py ├── qgpkg_cli ├── __init__.py └── qgpkg.py ├── setup.py ├── tests ├── __init__.py ├── data │ ├── qgis.png │ ├── small_world.gpkg │ └── small_world.qgs ├── test_info.py └── test_readwrite.py ├── workflow-owc.png └── workflow-qgis.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.gpkg-shm 2 | *.gpkg-wal 3 | 4 | -------------------------------------------------------------------------------- /CHANGES.txt: -------------------------------------------------------------------------------- 1 | v0.0.0, 2016-12-31 -- Initial PyPI release. 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Sourcepole AG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | exclude *.txt 2 | recursive-exclude qgis * 3 | include CHANGES.txt LICENSE.txt README.rst 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | qgpkg 2 | ======== 3 | 4 | Introduction 5 | ------------ 6 | 7 | qgpkg implements a `GeoPackage `_ extension to store 8 | QGIS mapping information in a GeoPackage database file. 9 | The OGC geopackage format was designed with the goal of being interoperable across a range of environments, in particular mobile devices operating in offline and near offline scenarios. 10 | 11 | This plugin introduces two approaches for storing mapping projects, based on two different geopackage extensions: 12 | the `QGIS extension `_ and the `OWC context extension `_. 13 | 14 | The goal of the ``qgis geopackage extension`` is to enable users to share their QGIS projects, including style and resources. 15 | This extension stores a QGIS project file in one of the extension tables, which works for the described use case, but does not allow interoperability with other GIS software. 16 | 17 | .. image:: workflow-qgis.png 18 | 19 | The ``owc geopackage extension`` was designed with the specific goal of enabling interoperability with other GIS software, being completely based on OGC standards. 20 | The idea is to store styling using OGC:SLD, and the project context using OGC:OWS_Context, so that other software can encode/decode this information. 21 | 22 | .. image:: workflow-owc.png 23 | 24 | In both extensions, data, resources and style are packed along with project information (e.g.: layer order or visibility, bounding box), enabling a self-contained, portable mapping project. 25 | 26 | 27 | QGIS plugin 28 | ----------- 29 | 30 | The QGIS plugin adds a toolbar button for saving the current 31 | project in a GeoPackage file and another one for loading a QGIS project from a 32 | GeoPackage file. 33 | 34 | Support is given for loading multiple layers and styles from the geopackage. In the `examples <./examples>`_ folder you may find examples of 35 | geopackages using the `qgis <./examples/small_world.gpkg>`_ and `owc <./examples/multiple_layers.gpkg>`_ extensions. 36 | 37 | Although the user can read from either extension, using a detection mechanism, currently the writing operation is only supported for the ``qgis extension``. 38 | If you are interested in writing geopackages using the ``owc extension``, please have a look at `ArcGIS GeoCat Bridge `_. 39 | 40 | 41 | qgpkg library and cli 42 | --------------------- 43 | 44 | In addition, gpkg is implemented as a Python library with a command line interface. 45 | 46 | Commands:: 47 | 48 | usage: qgpkg.py [-h] {info,write,read} ... 49 | 50 | Store QGIS map information in GeoPackages 51 | 52 | optional arguments: 53 | -h, --help show this help message and exit 54 | 55 | commands: 56 | valid commands 57 | 58 | {info,write,read} 59 | info GeoPackage content information 60 | write Save QGIS project in GeoPackage 61 | read Read QGIS project from GeoPackage 62 | 63 | Please note that the cli supports **only** for the ``qgis extension``. 64 | 65 | 66 | History 67 | ------- 68 | 69 | This plugin was initially created by Cédric Christen and Pirmin Kalberer (Sourcepole) using the ``qgis_extension`` approach. 70 | Later it was forked by Joana Simoes and Paul van Genuchten (GeoCat), who added support to the ``owc_extension``. 71 | The fork was merged into the master branch, to create this version: a plugin which enables users to read projects using either geopackage extension. 72 | Support to writing in both extensions, is also envisioned for the near future. 73 | 74 | 75 | Compatibility 76 | ------------- 77 | 78 | This plugin requires ``QGIS`` 2.18 and ``GDAL`` 2.0 or newer. 79 | 80 | On Ubuntu Linux you can install GDAL 2 from the UbuntuGIS repository and on OS X, you can use the package compiled by `King Chaos `_. 81 | 82 | 83 | Development 84 | ----------- 85 | 86 | :: 87 | 88 | git clone https://github.com/pka/qgpkg.git 89 | 90 | Running tests: 91 | 92 | :: 93 | 94 | apt-get install python-nose 95 | 96 | :: 97 | 98 | nosetests 99 | 100 | For running qgpkg commands from source tree: 101 | 102 | :: 103 | 104 | alias qgpkg="PYTHONPATH=$(pwd) $(pwd)/qgpkg_cli/qgpkg.py" 105 | 106 | 107 | Issues 108 | ------ 109 | 110 | You are welcome to report any issues using the `github track `_. 111 | 112 | 113 | License 114 | ------- 115 | 116 | qgpkg is Copyright © 2016-2017 Sourcepole AG. It is free software, 117 | and may be redistributed under the terms specified in the `LICENSE.txt `_ (Library - MIT) 118 | and `LICENSE `_ (Plugin - GPL V2) files. 119 | -------------------------------------------------------------------------------- /examples/multiple_layers.gpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/examples/multiple_layers.gpkg -------------------------------------------------------------------------------- /examples/owc.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | a mapping project to test geopackage in qgis 8 | 11 | 2012-02-21T11:58:23Z 12 | 13 | Paul 14 | paul@geocat.net 15 | http://geocat.net/~paul 16 | 17 | 18 | Copyright (c) 2012. Some rights reserved. This feed 19 | licensed under a Creative Commons Attribution 3.0 License. 20 | 21 | 22 | 23 | 24 | 25 | -4483330.00 1404270.00 4604460.00 1404270.00 4604460.00 6635460.00 -4483330.00 26 | 6635460.00 -4483330.00 1404270.00 27 | 28 | 29 | 30 | 31 | 32 | popp 33 | population 34 | 35 | Paul 36 | paul@geocat.net 37 | 38 | 39 | 40 | 41 | simple_point 42 | Simple point 43 | 44 | 45 | 46 | 47 | 2000 48 | 10000 49 | 50 | 51 | 52 | grassland 53 | Grassland region 54 | 55 | Joana 56 | joana@nowhere.com 57 | 58 | 59 | 60 | 61 | simple_area 62 | Simple area 63 | 64 | 65 | 66 | 67 | 2000 68 | 10000 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /examples/small_world.gpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/examples/small_world.gpkg -------------------------------------------------------------------------------- /owc_geopackage_extension.md: -------------------------------------------------------------------------------- 1 | # GeoPackage-OWC 2 | 3 | QGPKG offers read support for the GeoPackage-OWC extension. Goal of the extension is to store context and styling of a mapping project in a standardised way as part of a GeoPackage file. The specification is maintained at [this repository](https://github.com/GeoCat/geopackage-owc-spec). 4 | 5 | The extension introduces 3 tables; 6 | - owc_context; which stores the project context (layer order) 7 | - owc_style; which store the layer styling 8 | - owc_resource; stores additional resources (thumbnails, fonts, documentation) 9 | 10 | A GeoPackage-OWC example is provided [here](examples/multiple_layers.gpkg) 11 | -------------------------------------------------------------------------------- /qgis_geopackage_extension.md: -------------------------------------------------------------------------------- 1 | # GeoPackage 1.0 Extension 2 | 3 | **DRAFT** 4 | 5 | Extension follows template from Annex I of the OGC [GeoPackage 1.0 Specification](http://www.geopackage.org/). 6 | 7 | ## Extension Title 8 | 9 | **QGIS map styling information** 10 | 11 | ## Introduction 12 | 13 | Store QGIS projects with their resources like images in print templates in a GeoPackage file. 14 | 15 | ## Extension Author 16 | 17 | Pirmin Kalberer, author_name `pka`. 18 | 19 | ## Extension Name or Template 20 | 21 | `qgis` 22 | 23 | ## Extension Type 24 | 25 | Extension of Existing Requirement in Clause 2. 26 | 27 | ## Applicability 28 | 29 | This extension applies to additional tables `qgis_projects`, `qgis_resources` 30 | and `layer_styles`. 31 | 32 | ## Scope 33 | 34 | Read-write 35 | 36 | ## Requirements 37 | 38 | Definition of extension and interdependencies with other extensions if 39 | any. 40 | 41 | ### GeoPackage 42 | 43 | #### Extension tables 44 | 45 | An Extended GeoPackage with QGIS support MAY contain the following tables or views: 46 | 47 | **qgis_projects** 48 | 49 | | Column | type | Desctiption | 50 | | --- | --- | --- | 51 | | name | text NOT NULL UNIQUE | Project name (file name) | 52 | | xml | text NOT NULL | Project file content (.qgs) in XML format | 53 | 54 | **qgis_resources** 55 | 56 | | Column | type | Desctiption | 57 | | --- | --- | --- | 58 | | name | text NOT NULL UNIQUE | Name of resource (file name) | 59 | | mime_type | text NOT NULL | [Mime type](http://www.iana.org/assignments/media-types/media-types.xhtml) of resource (`image/png`, `image/svg+xml`, ...) 60 | | content | blob NOT NULL | Binary content of resource | 61 | 62 | **layer_styles** 63 | 64 | QGIS style library. Used styles are included in project XML. 65 | 66 | | Column | type | Desctiption | 67 | | --- | --- | --- | 68 | | id | INTEGER | PRIMARY KEY | 69 | | f_table_catalog | varchar(256) | | 70 | | f_table_schema | varchar(256) | | 71 | | f_table_name | varchar(256) | | 72 | | f_geometry_column | varchar(256) | | 73 | | styleName | varchar(30) | | 74 | | styleQML | text | | 75 | | styleSLD | text | | 76 | | useAsDefault | boolean | | 77 | | description | text | | 78 | | owner | varchar(30) | | 79 | | ui | text | | 80 | | update_time | timestamp | | 81 | 82 | 83 | Additional metadata (authorship, licensing, ...) can be stored in the 84 | [GeoPackage metadata tables](http://www.geopackage.org/spec/#extension_metadata). 85 | 86 | ### GeoPackage SQLite Configuration 87 | 88 | None 89 | 90 | ### GeoPackage SQLite Extension 91 | 92 | None 93 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/.gitignore: -------------------------------------------------------------------------------- 1 | QgisGeopackage.zip 2 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/Makefile: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # QgisGeopackage 3 | # 4 | # This Plugin writes and reads Project files in Geopackages. 5 | # ------------------- 6 | # begin : 2016-04-06 7 | # git sha : $Format:%H$ 8 | # copyright : (C) 2016 by Sourcepole 9 | # email : pka@sourcepole.ch 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 | LOCALES = de 22 | 23 | # If locales are enabled, set the name of the lrelease binary on your system. If 24 | # you have trouble compiling the translations, you may have to specify the full path to 25 | # lrelease 26 | #LRELEASE = lrelease 27 | #LRELEASE = lrelease-qt4 28 | 29 | 30 | # translation 31 | SOURCES = \ 32 | __init__.py \ 33 | qgis_geopackage.py 34 | 35 | PLUGINNAME = QgisGeopackage 36 | 37 | PY_FILES = \ 38 | __init__.py \ 39 | qgis_geopackage.py 40 | 41 | UI_FILES = 42 | 43 | EXTRAS = metadata.txt read.png write.png 44 | 45 | EXTRA_DIRS = 46 | 47 | COMPILED_RESOURCE_FILES = resources.py qgpkg.py 48 | 49 | PEP8EXCLUDE=pydev,resources.py,conf.py,third_party,ui 50 | 51 | 52 | ################################################# 53 | # Normally you would not need to edit below here 54 | ################################################# 55 | 56 | HELP = help/build/html 57 | 58 | PLUGIN_UPLOAD = ./plugin_upload.py 59 | 60 | RESOURCE_SRC=$(shell grep '^ *@@g;s/.*>//g' | tr '\n' ' ') 61 | 62 | QGISDIR=.qgis2 63 | 64 | default: compile qgpkg.py qgpkg_qgis.py qgpkg_owc.py 65 | 66 | compile: $(COMPILED_RESOURCE_FILES) 67 | 68 | %.py : %.qrc $(RESOURCES_SRC) 69 | pyrcc4 -o $*.py $< 70 | 71 | %.qm : %.ts 72 | $(LRELEASE) $< 73 | 74 | qgpkg.py: ../../qgisgpkg/qgpkg.py 75 | cp $< $@ 76 | 77 | qgpkg_qgis.py: ../../qgisgpkg/qgpkg_qgis.py 78 | cp $< $@ 79 | 80 | qgpkg_owc.py: ../../qgisgpkg/qgpkg_owc.py 81 | cp $< $@ 82 | 83 | test: compile transcompile 84 | @echo 85 | @echo "----------------------" 86 | @echo "Regression Test Suite" 87 | @echo "----------------------" 88 | 89 | @# Preceding dash means that make will continue in case of errors 90 | @-export PYTHONPATH=`pwd`:$(PYTHONPATH); \ 91 | export QGIS_DEBUG=0; \ 92 | export QGIS_LOG_FILE=/dev/null; \ 93 | nosetests -v --with-id --with-coverage --cover-package=. \ 94 | 3>&1 1>&2 2>&3 3>&- || true 95 | @echo "----------------------" 96 | @echo "If you get a 'no module named qgis.core error, try sourcing" 97 | @echo "the helper script we have provided first then run make test." 98 | @echo "e.g. source run-env-linux.sh ; make test" 99 | @echo "----------------------" 100 | 101 | deploy: compile doc transcompile 102 | @echo 103 | @echo "------------------------------------------" 104 | @echo "Deploying plugin to your .qgis2 directory." 105 | @echo "------------------------------------------" 106 | # The deploy target only works on unix like operating system where 107 | # the Python plugin directory is located at: 108 | # $HOME/$(QGISDIR)/python/plugins 109 | mkdir -p $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 110 | cp -vf $(PY_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 111 | cp -vf $(UI_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 112 | cp -vf $(COMPILED_RESOURCE_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 113 | cp -vf $(EXTRAS) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 114 | cp -vfr i18n $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 115 | cp -vfr $(HELP) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/help 116 | # Copy extra directories if any 117 | $(foreach EXTRA_DIR,$(EXTRA_DIRS), cp -R $(EXTRA_DIR) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/;) 118 | 119 | 120 | # The dclean target removes compiled python files from plugin directory 121 | # also deletes any .git entry 122 | dclean: 123 | @echo 124 | @echo "-----------------------------------" 125 | @echo "Removing any compiled python files." 126 | @echo "-----------------------------------" 127 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "*.pyc" -delete 128 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".git" -prune -exec rm -Rf {} \; 129 | 130 | 131 | derase: 132 | @echo 133 | @echo "-------------------------" 134 | @echo "Removing deployed plugin." 135 | @echo "-------------------------" 136 | rm -Rf $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 137 | 138 | zip: deploy dclean 139 | @echo 140 | @echo "---------------------------" 141 | @echo "Creating plugin zip bundle." 142 | @echo "---------------------------" 143 | # The zip target deploys the plugin and creates a zip file with the deployed 144 | # content. You can then upload the zip file on http://plugins.qgis.org 145 | rm -f $(PLUGINNAME).zip 146 | cd $(HOME)/$(QGISDIR)/python/plugins; zip -9r $(CURDIR)/$(PLUGINNAME).zip $(PLUGINNAME) 147 | 148 | package: compile 149 | # Create a zip package of the plugin named $(PLUGINNAME).zip. 150 | # This requires use of git (your plugin development directory must be a 151 | # git repository). 152 | # To use, pass a valid commit or tag as follows: 153 | # make package VERSION=Version_0.3.2 154 | @echo 155 | @echo "------------------------------------" 156 | @echo "Exporting plugin to zip package. " 157 | @echo "------------------------------------" 158 | rm -f $(PLUGINNAME).zip 159 | git archive --prefix=$(PLUGINNAME)/ -o $(PLUGINNAME).zip $(VERSION) 160 | echo "Created package: $(PLUGINNAME).zip" 161 | 162 | upload: # zip 163 | @echo 164 | @echo "-------------------------------------" 165 | @echo "Uploading plugin to QGIS Plugin repo." 166 | @echo "-------------------------------------" 167 | $(PLUGIN_UPLOAD) $(PLUGINNAME).zip 168 | 169 | transup: 170 | @echo 171 | @echo "------------------------------------------------" 172 | @echo "Updating translation files with any new strings." 173 | @echo "------------------------------------------------" 174 | @chmod +x scripts/update-strings.sh 175 | @scripts/update-strings.sh $(LOCALES) 176 | 177 | transcompile: 178 | @echo 179 | @echo "----------------------------------------" 180 | @echo "Compiled translation files to .qm files." 181 | @echo "----------------------------------------" 182 | @chmod +x scripts/compile-strings.sh 183 | @scripts/compile-strings.sh $(LRELEASE) $(LOCALES) 184 | 185 | transclean: 186 | @echo 187 | @echo "------------------------------------" 188 | @echo "Removing compiled translation files." 189 | @echo "------------------------------------" 190 | rm -f i18n/*.qm 191 | 192 | clean: 193 | @echo 194 | @echo "------------------------------------" 195 | @echo "Removing uic and rcc generated files" 196 | @echo "------------------------------------" 197 | rm $(COMPILED_UI_FILES) $(COMPILED_RESOURCE_FILES) 198 | 199 | doc: 200 | @echo 201 | @echo "------------------------------------" 202 | @echo "Building documentation using sphinx." 203 | @echo "------------------------------------" 204 | cd help; make html 205 | 206 | pylint: 207 | @echo 208 | @echo "-----------------" 209 | @echo "Pylint violations" 210 | @echo "-----------------" 211 | @pylint --reports=n --rcfile=pylintrc . || true 212 | @echo 213 | @echo "----------------------" 214 | @echo "If you get a 'no module named qgis.core' error, try sourcing" 215 | @echo "the helper script we have provided first then run make pylint." 216 | @echo "e.g. source run-env-linux.sh ; make pylint" 217 | @echo "----------------------" 218 | 219 | 220 | # Run pep8 style checking 221 | #http://pypi.python.org/pypi/pep8 222 | pep8: 223 | @echo 224 | @echo "-----------" 225 | @echo "PEP8 issues" 226 | @echo "-----------" 227 | @pep8 --repeat --ignore=E203,E121,E122,E123,E124,E125,E126,E127,E128 --exclude $(PEP8EXCLUDE) . || true 228 | @echo "-----------" 229 | @echo "Ignored in PEP8 check:" 230 | @echo $(PEP8EXCLUDE) 231 | 232 | # Upload to plugins.qgis.org: 233 | # make package VERSION=master 234 | # make upload 235 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | QgisGeopackage 5 | A QGIS plugin 6 | This Plugin writes and reads Project files in Geopackages. 7 | ------------------- 8 | begin : 2016-03-31 9 | copyright : (C) 2016 by Cédric Christen 10 | email : cch@sourcepole.ch 11 | git sha : $Format:%H$ 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | This script initializes the plugin, making it known to QGIS. 23 | """ 24 | 25 | 26 | # noinspection PyPep8Naming 27 | def classFactory(iface): # pylint: disable=invalid-name 28 | """Load QgisGeopackage class from file QgisGeopackage. 29 | 30 | :param iface: A QGIS interface instance. 31 | :type iface: QgsInterface 32 | """ 33 | # 34 | from .qgis_geopackage import QgisGeopackage 35 | return QgisGeopackage(iface) 36 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/i18n/qgpkg.pro: -------------------------------------------------------------------------------- 1 | FORMS = ../ui_about_dialog.ui 2 | 3 | SOURCES = ../qgis_geopackage.py \ 4 | ../__init__.py \ 5 | ../plugin_upload.py \ 6 | ../qgpkg_owc.py \ 7 | ../qgpkg.py \ 8 | ../qgpkg_qgis.py \ 9 | ../resources.py 10 | 11 | 12 | 13 | 14 | TRANSLATIONS = qgpkg_de.ts 15 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/i18n/qgpkg_de.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/qgis_plugin/qgpkg/i18n/qgpkg_de.qm -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/i18n/qgpkg_de.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QgisGeopackage 5 | 6 | 7 | Write project in GeoPackage 8 | Schreibe Projekt ins GeoPackage 9 | 10 | 11 | 12 | Read project from GeoPackage 13 | Lese Projekt aus GeoPackage 14 | 15 | 16 | 17 | Choose GeoPackage... 18 | Wähle GeoPackage... 19 | 20 | 21 | 22 | Read 23 | 24 | 25 | No GeoPackage selected. 26 | Kein GeoPackage ausgewählt. 27 | 28 | 29 | 30 | Please choose a GeoPackage. 31 | Bitte wählen Sie ein GeoPackage. 32 | 33 | 34 | 35 | There is no Project file in the database. 36 | Es gibt kein Projekt in der Datenbank. 37 | 38 | 39 | 40 | The xml code is corrupted. 41 | Der XML-Code ist korrumpiert. 42 | 43 | 44 | 45 | The xml code is corrupted, please check the database. 46 | Der XML-Code ist korrumpiert, bitte überprüfen Sie die Datenbank. 47 | 48 | 49 | 50 | Xml successfully read. 51 | XML erfolgreich eingelesen. 52 | 53 | 54 | 55 | Layerpath from layer 56 | Layerpfad vom Layer 57 | 58 | 59 | 60 | was adjusted. 61 | wurde angepasst. 62 | 63 | 64 | 65 | External image 66 | Externes Bild 67 | 68 | 69 | 70 | found. 71 | gefunden. 72 | 73 | 74 | 75 | Image saved: 76 | Bild gespeichert: 77 | 78 | 79 | 80 | Project started. 81 | Projekt gestarted. 82 | 83 | 84 | 85 | Write 86 | 87 | 88 | Corrupted project 89 | Korrumpiertes Projekt 90 | 91 | 92 | 93 | There are problems with the project file, please check if everything is working. 94 | Es gibt Probleme mit dem Projekt, bitte überprüfen Sie ob alles funktioniert. 95 | 96 | 97 | 98 | Xml successfully read 99 | XML erfolgreich eingelesen 100 | 101 | 102 | 103 | Found datasource: 104 | Datenquelle gefunden: 105 | 106 | 107 | 108 | The project uses layers from different GeoPackage databases. 109 | Das Projekt benutzt Layer von verschiedenen GeoPackage Datenbanken. 110 | 111 | 112 | 113 | Some layers aren't in the GeoPackage. It can't be garanteed that all layers will be shown properly. 114 | Einige Layer sind nicht im GeoPackage vorhanden. Es kann nicht garantiert werden, dass alle Layer richtig angezeigt werden. 115 | 116 | 117 | 118 | Warning 119 | Warnung 120 | 121 | 122 | 123 | There is no GeoPackage layer in the project. 124 | Es gibt kein GeoPackage Layer im Projekt. 125 | 126 | 127 | 128 | Image found: 129 | Bild gefunden: 130 | 131 | 132 | 133 | Ther is already a project in the GeoPackage, 134 | Do you want to overwrite it? 135 | Es gibt bereits ein Projekt im GeoPackage, 136 | Wollen Sie dieses überschrieben? 137 | 138 | 139 | 140 | Project overwritten. 141 | Projekt überschrieben. 142 | 143 | 144 | 145 | Aborted. 146 | Abgebrochen. 147 | 148 | 149 | 150 | Project 151 | Projekt 152 | 153 | 154 | 155 | was saved. 156 | wurde gespeichert. 157 | 158 | 159 | 160 | Image 161 | Bild 162 | 163 | 164 | 165 | was saved 166 | wurde gespeichert 167 | 168 | 169 | 170 | There is already a project in the GeoPackage, 171 | Do you want to overwrite it? 172 | Es gibt bereits ein Projekt im GeoPackage, 173 | Wollen Sie dieses überschrieben? 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/metadata.txt: -------------------------------------------------------------------------------- 1 | [general] 2 | name=QGIS map styling GeoPackage extension 3 | version=0.3.2 4 | qgisMinimumVersion=2.18 5 | author=Cédric Christen, Pirmin Kalberer, Joana Simoes, Paul van Genuchten 6 | email=pka@sourcepole.ch, joana.simoes@geocat.net 7 | description=Read and write QGIS project information in GeoPackages, using the QGIS or OWC geopackage extensions. 8 | about=This plugin reads and writes QGIS projects with related resources (e.g. images used in a print layout) and style in a GeoPackage file. 9 | 10 | tracker=https://github.com/pka/qgpkg/issues 11 | repository=https://github.com/pka/qgpkg 12 | homepage=https://github.com/pka/qgpkg 13 | 14 | changelog= 15 | 0.3.2 16 | - Show a message after saving project 17 | - Support print composers with images <> 1 18 | 0.3.1 19 | - Fix overwriting of projects and resources 20 | 0.3.0 21 | - Added support for reading OWC GeoPackage extension 22 | - Updated schema for storing QGIS resources 23 | 0.2.0 24 | - Bug fixes 25 | 0.1.2-0.1.4 26 | - Minor changes in metadata.txt 27 | 0.1.0 28 | - Initial release 29 | 30 | tags=GeoPackage,gpkg 31 | category=Plugins 32 | icon=write.png 33 | 34 | experimental=True 35 | deprecated=False 36 | 37 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/plugin_upload.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | """This script uploads a plugin package on the server. 4 | Authors: A. Pasotti, V. Picavet 5 | git sha : $TemplateVCSFormat 6 | """ 7 | 8 | import sys 9 | import getpass 10 | import xmlrpclib 11 | from optparse import OptionParser 12 | 13 | # Configuration 14 | PROTOCOL = 'http' 15 | SERVER = 'plugins.qgis.org' 16 | PORT = '80' 17 | ENDPOINT = '/plugins/RPC2/' 18 | VERBOSE = False 19 | 20 | 21 | def main(parameters, arguments): 22 | """Main entry point. 23 | 24 | :param parameters: Command line parameters. 25 | :param arguments: Command line arguments. 26 | """ 27 | address = "%s://%s:%s@%s:%s%s" % ( 28 | PROTOCOL, 29 | parameters.username, 30 | parameters.password, 31 | parameters.server, 32 | parameters.port, 33 | ENDPOINT) 34 | print "Connecting to: %s" % hide_password(address) 35 | 36 | server = xmlrpclib.ServerProxy(address, verbose=VERBOSE) 37 | 38 | try: 39 | plugin_id, version_id = server.plugin.upload( 40 | xmlrpclib.Binary(open(arguments[0]).read())) 41 | print "Plugin ID: %s" % plugin_id 42 | print "Version ID: %s" % version_id 43 | except xmlrpclib.ProtocolError, err: 44 | print "A protocol error occurred" 45 | print "URL: %s" % hide_password(err.url, 0) 46 | print "HTTP/HTTPS headers: %s" % err.headers 47 | print "Error code: %d" % err.errcode 48 | print "Error message: %s" % err.errmsg 49 | except xmlrpclib.Fault, err: 50 | print "A fault occurred" 51 | print "Fault code: %d" % err.faultCode 52 | print "Fault string: %s" % err.faultString 53 | 54 | 55 | def hide_password(url, start=6): 56 | """Returns the http url with password part replaced with '*'. 57 | 58 | :param url: URL to upload the plugin to. 59 | :type url: str 60 | 61 | :param start: Position of start of password. 62 | :type start: int 63 | """ 64 | start_position = url.find(':', start) + 1 65 | end_position = url.find('@') 66 | return "%s%s%s" % ( 67 | url[:start_position], 68 | '*' * (end_position - start_position), 69 | url[end_position:]) 70 | 71 | 72 | if __name__ == "__main__": 73 | parser = OptionParser(usage="%prog [options] plugin.zip") 74 | parser.add_option( 75 | "-w", "--password", dest="password", 76 | help="Password for plugin site", metavar="******") 77 | parser.add_option( 78 | "-u", "--username", dest="username", 79 | help="Username of plugin site", metavar="user") 80 | parser.add_option( 81 | "-p", "--port", dest="port", 82 | help="Server port to connect to", metavar="80") 83 | parser.add_option( 84 | "-s", "--server", dest="server", 85 | help="Specify server name", metavar="plugins.qgis.org") 86 | options, args = parser.parse_args() 87 | if len(args) != 1: 88 | print "Please specify zip file.\n" 89 | parser.print_help() 90 | sys.exit(1) 91 | if not options.server: 92 | options.server = SERVER 93 | if not options.port: 94 | options.port = PORT 95 | if not options.username: 96 | # interactive mode 97 | username = getpass.getuser() 98 | print "Please enter user name [%s] :" % username, 99 | res = raw_input() 100 | if res != "": 101 | options.username = res 102 | else: 103 | options.username = username 104 | if not options.password: 105 | # interactive mode 106 | options.password = getpass.getpass() 107 | main(options, args) 108 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/qgis_geopackage.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """ 3 | /*************************************************************************** 4 | QgisGeopackage 5 | A QGIS plugin 6 | This Plugin writes and reads Project files in Geopackages. 7 | ------------------- 8 | begin : 2016-03-31 9 | git sha : $Format:%H$ 10 | copyright : (C) 2016 by Cédric Christen 11 | email : cch@sourcepole.ch 12 | ***************************************************************************/ 13 | 14 | /*************************************************************************** 15 | * * 16 | * This program is free software; you can redistribute it and/or modify * 17 | * it under the terms of the GNU General Public License as published by * 18 | * the Free Software Foundation; either version 2 of the License, or * 19 | * (at your option) any later version. * 20 | * * 21 | ***************************************************************************/ 22 | """ 23 | from qgis.core import QgsProject, QgsMessageLog 24 | from PyQt4.QtGui import * 25 | from PyQt4.QtCore import * 26 | import resources 27 | import os 28 | import tempfile 29 | import logging 30 | import sqlite3 31 | 32 | from qgpkg import QGpkg 33 | from qgpkg_owc import QGpkg_owc 34 | from qgpkg_qgis import QGpkg_qgis 35 | 36 | from qgpkgAbout import qgpkgAbout 37 | 38 | message_bar = None 39 | 40 | 41 | def qlog(lvl, msg, *args, **kwargs): 42 | msg_level = 2 # TODO: 43 | # QgsMessageBar.INFO = 0 44 | # QgsMessageBar.WARNING = 1 45 | # QgsMessageBar.CRITICAL = 2 46 | # QgsMessageBar.SUCCESS = 3 47 | QgsMessageLog.logMessage( 48 | msg, 'QGIS Geopackage', msg_level) 49 | if lvl >= logging.WARNING: 50 | message_bar.pushMessage( 51 | msg, level=msg_level) 52 | 53 | class QgisGeopackage(QObject): 54 | """QGIS Plugin Implementation.""" 55 | 56 | def __init__(self, iface): 57 | global message_bar 58 | QObject.__init__(self) 59 | self.iface = iface 60 | self.toolbar = self.iface.addToolBar(u'Qgis Geopackage') 61 | self.toolbar.setObjectName(u'Qgis Geopackage') 62 | message_bar = self.iface.messageBar() 63 | self._log = qlog 64 | 65 | def log(self, lvl, msg, *args, **kwargs): 66 | self._log(lvl, msg, *args, **kwargs) 67 | 68 | def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, status_tip=None, parent=None): 69 | icon = QIcon(icon_path) 70 | action = QAction(icon, text, parent) 71 | action.triggered.connect(callback) 72 | action.setEnabled(enabled_flag) 73 | 74 | if status_tip is not None: 75 | action.setStatusTip(status_tip) 76 | 77 | if add_to_toolbar: 78 | self.toolbar.addAction(action) 79 | 80 | return action 81 | 82 | def initGui(self): 83 | pluginPath = QFileInfo(os.path.realpath(__file__)).path() 84 | locale = QSettings().value("locale/userLocale", type=str)[0:2] 85 | if QFileInfo(pluginPath).exists(): 86 | localePath = pluginPath + "/i18n/qgis_geopackage" + locale + ".qm" 87 | if QFileInfo(localePath).exists(): 88 | self.translator = QTranslator() 89 | self.translator.load(localePath) 90 | 91 | if qVersion() > '4.3.3': 92 | QCoreApplication.installTranslator(self.translator) 93 | 94 | # Create the dialogs (after translation) and keep reference 95 | self.aboutDlg = qgpkgAbout() 96 | 97 | self.actionWrite = QAction( 98 | QIcon(":/plugins/QgisGeopackage/write.png"), 99 | self.tr(u"Write project in GeoPackage"), 100 | self.iface.mainWindow() 101 | ) 102 | self.actionWrite.setWhatsThis(self.tr(u"Write project in GeoPackage")) 103 | self.iface.addPluginToMenu("&Qgis Geopackage", self.actionWrite) 104 | self.toolbar.addAction(self.actionWrite) 105 | # self.actionWrite.setEnabled(False) 106 | QObject.connect(self.actionWrite, SIGNAL("triggered()"), self.write) 107 | 108 | self.actionRead = QAction( 109 | QIcon(":/plugins/QgisGeopackage/read.png"), 110 | self.tr(u"Read project from GeoPackage"), 111 | self.iface.mainWindow() 112 | ) 113 | self.actionRead.setWhatsThis(self.tr(u"Read project from GeoPackage")) 114 | self.iface.addPluginToMenu("&Qgis Geopackage", self.actionRead) 115 | self.toolbar.addAction(self.actionRead) 116 | QObject.connect(self.actionRead, SIGNAL("triggered()"), self.read) 117 | 118 | 119 | self.actionAbout = QAction( 120 | QIcon(":/plugins/QgisGeopackage/about.png"), 121 | self.tr(u"About"), 122 | self.iface.mainWindow() 123 | ) 124 | self.actionAbout.setWhatsThis(self.tr(u"About the Geopackage plugin")) 125 | self.iface.addPluginToMenu("&Qgis Geopackage", self.actionAbout) 126 | QObject.connect(self.actionAbout, SIGNAL("triggered()"), self.runAbout) 127 | 128 | 129 | def unload(self): 130 | self.iface.removePluginMenu("&Qgis Geopackage", self.actionWrite) 131 | self.iface.removePluginMenu("&Qgis Geopackage", self.actionRead) 132 | self.iface.removeToolBarIcon(self.actionWrite) 133 | self.iface.removeToolBarIcon(self.actionRead) 134 | 135 | def runAbout(self): 136 | ' show the dialog' 137 | self.aboutDlg.show() 138 | # Run the dialog event loop and See if OK was pressed 139 | result = self.aboutDlg.exec_() 140 | 141 | def write(self): 142 | project = QgsProject.instance() 143 | tmpfile = None 144 | if project.isDirty(): 145 | # If the project is dirty 146 | # create a temporary file and delete it afterwards 147 | tmpfile = os.path.join(tempfile.gettempdir(), "qgpkg.qgs") 148 | file_info = QFileInfo(tmpfile) 149 | project.write(file_info) 150 | project_path = project.fileName() 151 | project.dirty(True) 152 | else: 153 | project_path = project.fileName() 154 | 155 | gpkg = QGpkg_qgis(project_path, qlog) 156 | gpkg_path = gpkg.write(project_path) 157 | 158 | if tmpfile: 159 | os.remove(tmpfile) 160 | 161 | if gpkg_path is not None: 162 | message_bar.pushMessage("Project saved in %s" % gpkg_path) 163 | 164 | def read(self): 165 | """Reads a geopackage file polymorphically, according to the auto-detected extension """ 166 | 167 | gpkg_path = QFileDialog.getOpenFileName( 168 | self.iface.mainWindow(), self.tr(u"Choose GeoPackage..."), 169 | None, "GeoPackage (*.gpkg)") 170 | if gpkg_path: 171 | gpkg = self.detect_gpkg_extension(gpkg_path, qlog) 172 | if gpkg is not None: 173 | project_path = gpkg.read(gpkg_path) 174 | QgsProject.instance().read(QFileInfo(project_path)) 175 | else: 176 | self.log(logging.ERROR, 177 | u"We were unable to read this geopackage file") 178 | return 179 | 180 | def detect_gpkg_extension(self, gpkg_path, qlog): 181 | """Detects which geopackage extension we need to load (if any) 182 | and instantiates the subclass of qgpkg, according to it. 183 | 184 | Args: 185 | gpkg_path: The path of the gpkg file. 186 | qlog: log function 187 | Returns: 188 | An handle to the instantiated subclass 189 | """ 190 | 191 | if self.checkIfTableExists("qgis_projects", gpkg_path) is True: 192 | gpkg = QGpkg_qgis(gpkg_path, qlog) 193 | elif self.checkIfTableExists("owc_context", gpkg_path) is True: 194 | gpkg = QGpkg_owc(gpkg_path, qlog) 195 | else: 196 | self.log(logging.ERROR, 197 | u"Sorry: we did not find a valid geopackage extension whithin this geopackage." + 198 | u"\n Supported extensions include owc_geopackage and qgis_geopackage") 199 | return 200 | 201 | return gpkg 202 | 203 | def checkIfTableExists(self, table_name, gpkg_path): 204 | """Check if a table with a given name, 205 | exists in a sqlite3 database 206 | 207 | Args: 208 | table_name: The table we are looking for. 209 | gpkg_path: The path of the gpkg file. 210 | """ 211 | 212 | conn = sqlite3.connect(gpkg_path) 213 | c = conn.cursor() 214 | 215 | try: 216 | c.execute(""" 217 | SELECT name 218 | FROM sqlite_master 219 | WHERE type='table' AND name=?; 220 | """, (table_name,)) 221 | ret = bool(c.fetchone()) 222 | conn.close() 223 | return ret 224 | 225 | except sqlite3.OperationalError: 226 | conn.close() 227 | self.log(logging.ERROR, u"Table '" + table_name + u"' does not seem to exist in the database.") 228 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/qgpkg.py: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE in the QGIS plugin directory. 2 | # Edit the original library file in the qgpkg directory and 3 | # execute `make` to update the QGIS plugin files. 4 | import os 5 | import sqlite3 6 | import logging 7 | 8 | logger = logging.getLogger('qgpkg') 9 | 10 | class QGpkg: 11 | """Base class for handling data and style information within a GeoPackage database file""" 12 | 13 | def read(self, gpkg_path): pass 14 | """Abstract method to read a QGIS project from geopackage. 15 | 16 | Args: 17 | gpkg_path: The geopackage path on disk. 18 | """ 19 | 20 | def write(self, project_path): pass 21 | """Abstract method to write a QGIS project into a geopackage. 22 | 23 | Args: 24 | gpkg_path: The geopackage path on disk. 25 | """ 26 | 27 | def __init__(self, gpkg, logfunc): 28 | self._gpkg = gpkg 29 | self._log = logfunc 30 | 31 | def log(self, lvl, msg, *args, **kwargs): 32 | self._log(lvl, msg, *args, **kwargs) 33 | 34 | def _connect_read_only(self): 35 | ''' Connect database with sqlite3 ''' 36 | try: 37 | conn = sqlite3.connect(self._gpkg) 38 | # Open in read-only mode needs Python 3.4+ 39 | # conn = sqlite3.connect('file:%s?mode=ro' % self._gpkg, uri=True) 40 | # Workaround: 41 | if os.stat(self._gpkg).st_size == 0: 42 | os.remove(self._gpkg) 43 | self.log(logging.ERROR, 44 | "Couldn't find GeoPackage '%s'" % self._gpkg) 45 | return None 46 | conn.row_factory = sqlite3.Row 47 | return conn.cursor() 48 | except sqlite3.Error as e: 49 | self.log(logging.ERROR, 50 | "Couldn't connect to GeoPackage: %s" % e.args[0]) 51 | return None 52 | 53 | def info(self): 54 | ''' Show information about GeoPackage ''' 55 | cur = self._connect_read_only() 56 | if not cur: 57 | return 58 | data_type = None 59 | try: 60 | for row in cur.execute('''SELECT * FROM gpkg_contents 61 | ORDER BY data_type'''): 62 | if row['data_type'] != data_type: 63 | data_type = row['data_type'] 64 | print("gpkg_contents %s:" % data_type) 65 | print(row['table_name']) 66 | except sqlite3.Error as e: 67 | self.log(logging.ERROR, "GeoPackage access error: ", e.args[0]) 68 | 69 | try: 70 | rows = list(cur.execute('''SELECT extension_name FROM gpkg_extensions''')) 71 | if len(rows) > 0: 72 | print("GPKG extensions:") 73 | for row in rows: 74 | print(row['extension_name']) 75 | except sqlite3.Error: 76 | pass 77 | 78 | try: 79 | rows = list(cur.execute('''SELECT name FROM qgis_projects''')) 80 | if len(rows) > 0: 81 | print("QGIS projects:") 82 | for row in rows: 83 | print(row['name']) 84 | except sqlite3.Error: 85 | pass 86 | 87 | try: 88 | rows = list(cur.execute('''SELECT name, mime_type FROM qgis_resources''')) 89 | if len(rows) > 0: 90 | print("QGIS recources:") 91 | for row in rows: 92 | print(row['name'] + ' (%s)' % row['mime_type']) 93 | except sqlite3.Error: 94 | pass 95 | 96 | def database_connect(self, path): 97 | ''' Connect database with sqlite3 ''' 98 | try: 99 | self.conn = sqlite3.connect(path) 100 | self.c = self.conn.cursor() 101 | return True 102 | except sqlite3.Error as e: 103 | self.log(logging.ERROR, 104 | "Couldn't connect to GeoPackage: %s" % e.args[0]) 105 | return False 106 | 107 | def check_gpkg(self, path): 108 | ''' Check if file is GeoPackage ''' 109 | try: 110 | self.c.execute('SELECT * FROM gpkg_contents') 111 | self.c.fetchone() 112 | return True 113 | except: 114 | return False 115 | 116 | def make_path_absolute(self, path, project_path): 117 | ''' Make path absolut and handle multiplatform issues ''' 118 | if not os.path.isabs(path): 119 | path = os.path.join(os.path.dirname(project_path), path) 120 | return os.path.normpath(path) 121 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/qgpkgAbout.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import os 4 | 5 | from PyQt4 import QtGui, QtCore 6 | from ui_about_dialog import Ui_qgpkgDlg 7 | 8 | class qgpkgAbout(QtGui.QDialog): 9 | def __init__(self, parent=None): 10 | QtGui.QDialog.__init__(self, None) 11 | self.setWindowFlags( self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint ) 12 | 13 | # Todo: add support for translation 14 | self._initGui(parent) 15 | 16 | def _initGui(self, parent): 17 | self.ui = Ui_qgpkgDlg() 18 | self.ui.setupUi(self) -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/qgpkg_owc.py: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE in the QGIS plugin directory. 2 | # Edit the original library file in the qgpkg directory and 3 | # execute `make` to update the QGIS plugin files. 4 | from __future__ import print_function 5 | import sys 6 | import os 7 | import sqlite3 8 | import tempfile 9 | import logging 10 | from xml.etree import ElementTree as ET 11 | from qgis.core import * 12 | from qgis.utils import * 13 | from PyQt4.QtXml import * 14 | from PyQt4.QtCore import * 15 | from StringIO import StringIO 16 | from urlparse import urlparse 17 | import sys 18 | 19 | from qgpkg import QGpkg 20 | 21 | logger = logging.getLogger('qgpkg') 22 | 23 | # Debug code for Pycharm 24 | #sys.path.append('/home/joana/Downloads/pycharm-2016.3.3/debug-eggs/pycharm-debug.egg') 25 | #import pydevd 26 | 27 | #pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True) 28 | 29 | 30 | class QGpkg_owc (QGpkg): 31 | """Read and write QGIS mapping information in a GeoPackage database file, using this spec: 32 | https://github.com/pka/qgpkg/blob/master/ows_geopackage_extension.md 33 | """ 34 | 35 | def write(self, project_path): 36 | self.log(logging.ERROR, u"Sorry, but it appears that writing into this geopackage extension was not implemented yet!") 37 | return 38 | 39 | def read(self, gpkg_path): 40 | 41 | iface.newProject(True) # Clear project, before opening 42 | 43 | ''' Read QGIS project from GeoPackage ''' 44 | # Check if it's a GeoPackage Database 45 | self.database_connect(gpkg_path) 46 | if not self.check_gpkg(gpkg_path): 47 | self.log(logging.ERROR, u"No valid GeoPackage selected.") 48 | return 49 | 50 | try: 51 | self.c.execute('SELECT table_name FROM gpkg_contents') 52 | except sqlite3.OperationalError: 53 | self.log(logging.ERROR, u"Unable to read table Name.") 54 | return 55 | 56 | table_names = self.c.fetchall() 57 | 58 | db_name = QFileInfo(gpkg_path).baseName() 59 | 60 | # Load OWS Context 61 | try: 62 | self.c.execute('SELECT content FROM owc_context') 63 | except sqlite3.OperationalError: 64 | self.log(logging.ERROR, u"Unable to read table owc_context.") 65 | return 66 | 67 | context = self.c.fetchone() 68 | 69 | if context is None: 70 | self.log(logging.ERROR, u"No record found on table owc_context!") 71 | return 72 | 73 | # Everything is read from the context 74 | self.loadContext(context[0], gpkg_path) 75 | 76 | # TODO: read resources 77 | 78 | def loadContext(self, context, gpkg_path): 79 | """Parses and applies the information on OWC_context. 80 | 81 | Args: 82 | context: The contents of owc_context table. 83 | gpkg_path: The path of the gpkg file. 84 | """ 85 | it = ET.iterparse(StringIO(context)) 86 | for _, el in it: 87 | if '}' in el.tag: 88 | el.tag = el.tag.split('}', 1)[1] # strip all namespaces 89 | root = it.root 90 | 91 | # Missing mandatory elements 92 | # spec reference 93 | spec_elem = root.find("specReference") 94 | # if spec_elem is None: 95 | # self.log(logging.ERROR, u"Could not parse project spec feference.") 96 | # return 97 | # Language 98 | lang_elem = root.find("language") 99 | # if lang_elem is None: 100 | # self.log(logging.ERROR, u"Could not parse project language.") 101 | # return 102 | 103 | # Parse project id (mandatory) 104 | id_elem = root.find("id") 105 | if id_elem is None: 106 | self.log(logging.ERROR, u"Could not parse project id.") 107 | return 108 | 109 | # Parse project title (mandatory) 110 | title_elem = root.find("title") 111 | if title_elem is None: 112 | self.log(logging.ERROR, u"Could not parse project title.") 113 | return 114 | 115 | QgsProject.instance().setTitle(title_elem.text) 116 | 117 | # Parse bbox, if it exists (not owc) 118 | where_elem = root.find("where") 119 | if where_elem is not None: 120 | self.loadBBbox(where_elem) 121 | 122 | # OWC (optional) elements 123 | # Parse abstract (optional) 124 | abstract_elem = root.find("abstract") 125 | 126 | # Parse update date (updateDate?) (optional) 127 | update_elem = root.find("update") 128 | 129 | # Parse author (optional) 130 | author_elem = root.find("author") 131 | # TODO: parse comma separated list 132 | 133 | # Parse publisher (optional) 134 | publisher_elem = root.find("publisher") 135 | 136 | # Parse creator (optional) 137 | creator_elem = root.find("creator") 138 | 139 | # Parse rights (optional) 140 | rights_elem = root.find("rights") 141 | 142 | # Parse area of interest (optional) 143 | aio_elem = root.find("areaOfInterest") 144 | # TODO: parse GM_Envelope 145 | 146 | # Parse time interval of interest (optional) 147 | time_elem = root.find("timeIntervalOfInterest") 148 | 149 | # Parse keyword (optional) 150 | keyword_elem = root.find("keyword") 151 | 152 | # Parse context metadata (optional) 153 | metadata_elem = root.find("contextMetadata") 154 | 155 | entry_elems = root.findall("entry") # owc:resource? 156 | if entry_elems is not None: 157 | 158 | entry_elems.reverse() 159 | # Load every entry 160 | for entry_elem in entry_elems: 161 | self.loadOWCLayer(gpkg_path, entry_elem) 162 | 163 | def loadOWCLayer(self, gpkg_path, entry_elem): 164 | """Parses layer information from an entry, on OWC_context, and uses it to load and style the layer. 165 | 166 | Args: 167 | gpkg_path: The geopackage path. 168 | entry_elem: The entry xml node. 169 | """ 170 | 171 | # Id: is it called code? 172 | id_elem = entry_elem.find("id") 173 | if id_elem is None: 174 | self.log(logging.ERROR, u"Could not parse layer uri.") 175 | return 176 | 177 | # Parse RFC and check if there is a valid schema 178 | parsed_url = urlparse(id_elem.text) 179 | if (parsed_url.scheme) is None: 180 | self.log(logging.ERROR, u"Invalid layer uri.") 181 | return 182 | 183 | # Mandatory 184 | title_elem = entry_elem.find("title") 185 | if title_elem is None: 186 | self.log(logging.ERROR, u"Could not parse layer title.") 187 | return 188 | 189 | # TODO: make offering more general, to support other types of data formats (e.g.: wms) 190 | offering_elem = entry_elem.find("offering") 191 | if offering_elem is not None: 192 | # Mandatory 193 | content_elem = offering_elem.find("content") 194 | if content_elem is None: 195 | self.log(logging.ERROR, u"Failed to content '" + name + "' layer!") 196 | return; 197 | href = content_elem.get("href") 198 | name = self.find_between(href, "#table=") 199 | if name is None: 200 | self._log(logging.ERROR, u"Could not parse table name.") 201 | return 202 | 203 | layer = self.loadLayer(gpkg_path, name, title_elem.text) 204 | if layer is None or not layer.isValid(): 205 | self.log(logging.ERROR, u"Layer '" + name + "' failed to load!") 206 | return; 207 | 208 | # layer.setShortName(name) 209 | 210 | # Check visibility (mandatory) 211 | visibility = entry_elem.find("category").get("term") 212 | if visibility is None: 213 | self.log(logging.ERROR, u"Failed to read visibility for '" + name + "' layer!") 214 | return; 215 | 216 | iface.legendInterface().setLayerVisible(layer, visibility.lower() == 'true') 217 | 218 | # Read style (optional) 219 | style_elem = offering_elem.find("styleSet") 220 | if style_elem is not None: 221 | self.loadOWCStyle(style_elem, title_elem.text) 222 | 223 | # Read other OWC (optional) elements ################## 224 | 225 | # Parse abstract (optional) 226 | abstract_elem = entry_elem.find("abstract") 227 | if abstract_elem is not None: 228 | layer.setAbstract(abstract_elem.text) 229 | 230 | # Parse update date (optional): shouldn't this be OWC:updateDate ? 231 | date_elem = entry_elem.find("updated") 232 | 233 | # Parse author (optional) 234 | author_elem = entry_elem.find("author") 235 | if author_elem is not None: 236 | layer.setAttribution(author_elem.text) 237 | 238 | # Parse publisher (optional) 239 | publisher_elem = entry_elem.find("publisher") 240 | 241 | # Parse rights (optional) 242 | rights_elem = entry_elem.find("rights") 243 | 244 | # Parse geospatial extent (optional) 245 | ext_elem = entry_elem.find("geospatialExtent") 246 | # TODO: parse GM_envelope 247 | 248 | # Parse temporal extent (optional) 249 | temp_elem = entry_elem.find("temporalExtent") 250 | # TODO: parse TM_GeometricPrimitive 251 | 252 | # Parse content description (optional) 253 | desc_elem = entry_elem.find("contentDescription") 254 | 255 | # Parse preview (optional) 256 | prev_elem = entry_elem.find("preview") 257 | # TODO: validate uri 258 | 259 | # Parse content reference (optional) 260 | ref_elem = entry_elem.find("contentByRef") 261 | # TODO: validate uri 262 | 263 | # Parse status (optional) 264 | active_elem = entry_elem.find("active") 265 | # TODO: validate boolean 266 | 267 | # Parse keyword (optional) 268 | keyword_elem = entry_elem.find("keyword") 269 | if keyword_elem is not None: 270 | keywords = [keyword_elem.text] 271 | layer.setKeywordList(keywords) 272 | 273 | # Parse minimum scale denominator (optional) 274 | minScale_elem = entry_elem.find("minScaleDenominator") 275 | if minScale_elem is not None: 276 | layer.setMinimumScale(float(minScale_elem.text)) 277 | 278 | # Parse maximum scale denominator (optional) 279 | maxScale_elem = entry_elem.find("maxScaleDenominator") 280 | if maxScale_elem is not None: 281 | layer.setMaximumScale(float(maxScale_elem.text)) 282 | 283 | # Parse resource metadata (optional) 284 | metadata_elem = entry_elem.find("resourceMetadata") 285 | 286 | # Parse folder (optional) 287 | folder_elem = entry_elem.find("folder") 288 | 289 | def loadOWCStyle(self, style_elem, layer_title): 290 | """Parses and applies style information from a styleSet, on OWC_context. 291 | 292 | Args: 293 | style_elem: The styleSet xml node. 294 | layer_title: The title of the layer to which we want to apply the style. 295 | """ 296 | 297 | # Mandatory: given name 298 | stylename_elem = style_elem.find("name") 299 | if stylename_elem is None: 300 | self.log(logging.ERROR, u"Could not parse style name.") 301 | return 302 | 303 | # parse title (optional) 304 | title_elem = style_elem.find("title") 305 | 306 | # parse content (mandatory) 307 | href = style_elem.find("content").get("href") 308 | pref1 = "#table=" 309 | pref2 = "&name=" 310 | style_table = self.find_between(href, pref1, pref2) 311 | 312 | stylename = self.find_between(href, pref2) 313 | if stylename is None or stylename != stylename_elem.text: 314 | self._log(logging.ERROR, u"Could not parse style name.") 315 | return 316 | 317 | type = style_elem.find("content").get("type") 318 | if type != "application/sld+xml": 319 | self._log(logging.ERROR, u"Currently we only support styles in sld/xml format.") 320 | return 321 | 322 | self.loadStyle(stylename, style_table, layer_title) 323 | 324 | # Load layers from gpkg 325 | def loadLayer(self, gpkg_path, layername, title): 326 | """Loads a layer from a geopackage, and it sets its title. 327 | 328 | Args: 329 | gpkg_path: The gpkg path. 330 | layername: The layer name, within the geopackage. 331 | title: The title to be given to the layer. 332 | 333 | Returns: 334 | An handle to the loaded layer. 335 | """ 336 | return iface.addVectorLayer(gpkg_path + "|layername=" + layername, title, "ogr") 337 | 338 | def loadStyle(self, style_name, table_name, given_name): 339 | """Load named style from a table. 340 | 341 | Args: 342 | style_name: The style name, as it is referenced in the style table. 343 | table_name: The name of the table where the style is stored (shouldn't it be a convention?). 344 | given_name: The layer title. 345 | """ 346 | try: 347 | self.c.execute("SELECT content FROM owc_style where name like'" + style_name + "'") 348 | except sqlite3.OperationalError: 349 | self.log(logging.ERROR, u"Could not find style " 350 | + style_name) 351 | return 352 | styles = self.c.fetchone() 353 | 354 | if styles is None: 355 | self.log(logging.ERROR, u"Could not find any styles " 356 | u"named " + style_name) 357 | return 358 | 359 | style = styles[0] 360 | 361 | layerList = QgsMapLayerRegistry.instance().mapLayersByName(given_name) 362 | 363 | if layerList is None: 364 | self.log(logging.ERROR, u"We could not find a loaded layer " 365 | "called " + given_name + ". Something is not right!") 366 | 367 | layer = layerList[0] 368 | 369 | f = QTemporaryFile() 370 | if f.open(): 371 | f.write(style) 372 | f.close() 373 | ret = layer.loadSldStyle(f.fileName()) 374 | # TODO: add style to default styles? 375 | 376 | if ret[1] is True: 377 | self.log(logging.DEBUG, "Style '" + style_name + "' loaded") 378 | else: 379 | self.log(logging.ERROR, "Style '" + style_name + "' not loaded: " + ret[0]) 380 | 381 | f.remove() 382 | 383 | else: 384 | self.log(logging.ERROR, u"Although there was a reference to style " 385 | + style_name + ", we could not find it in table owc_style. Something is not right!") 386 | return 387 | 388 | def loadBBbox(self, where_elem): 389 | """Parses and applies bbox. 390 | 391 | Args: 392 | where_elem: The where xml node. 393 | """ 394 | env_elem = where_elem.find("Envelope") 395 | if env_elem is None: 396 | self.log(logging.ERROR, u"Could not parse envelope.") 397 | return 398 | 399 | lower_elem = env_elem.find("lowerCorner") 400 | if lower_elem is None: 401 | self.log(logging.ERROR, u"Could not parse lower corner.") 402 | return 403 | lc = lower_elem.text.split() 404 | if (len(lc) != 2): 405 | self.log(logging.ERROR, u"Wrong number of entries in lower corner.") 406 | return 407 | 408 | upper_elem = env_elem.find("upperCorner") 409 | if upper_elem is None: 410 | self.log(logging.ERROR, u"Could not parse lower corner.") 411 | return 412 | uc = upper_elem.text.split() 413 | if (len(uc) != 2): 414 | self.log(logging.ERROR, u"Wrong number of entries in upper corner.") 415 | return 416 | 417 | # TODO: review this implementation 418 | # str = (self.find_between(context, "", "")).replace('\n', '').encode('ascii', 419 | # 'ignore') 420 | # d = QDomDocument() 421 | # d.setContent("< ?xml version = \"1.0\" encoding = \"utf-8\"? >" + str.) 422 | # docElem = d.documentElement() 423 | # extent = QgsOgcUtils.rectangleFromGMLEnvelope(docElem.firstChild()) 424 | 425 | # TODO: what happens to srs and dimension? 426 | extent = QgsRectangle(float(lc[0]), float(lc[1]), float(uc[0]), float(uc[1])) 427 | 428 | iface.mapCanvas().setExtent(extent) 429 | iface.mapCanvas().refresh() 430 | 431 | def find_between(self, s, first, last=None): 432 | """Extracts a substring from a string, between one, or two substrings. 433 | If the last parameter is empty, it will extract everything after the first substring. 434 | 435 | Args: 436 | s: The string we want to parse. 437 | first: The first substring. 438 | last: The last substring (optional). 439 | 440 | Returns: 441 | The extracted substring. 442 | """ 443 | try: 444 | start = s.index(first) + len(first) 445 | if last is None: 446 | end = len(s) 447 | else: 448 | end = s.index(last, start) 449 | 450 | return s[start:end] 451 | 452 | except ValueError: 453 | return "" 454 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/qgpkg_qgis.py: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE in the QGIS plugin directory. 2 | # Edit the original library file in the qgpkg directory and 3 | # execute `make` to update the QGIS plugin files. 4 | from __future__ import print_function 5 | import os 6 | import sqlite3 7 | import tempfile 8 | import mimetypes 9 | import logging 10 | 11 | from xml.etree import ElementTree as ET 12 | 13 | from qgpkg import QGpkg 14 | 15 | logger = logging.getLogger('qgpkg_qgis') 16 | 17 | # Debug code for Pycharm 18 | #sys.path.append('/home/joana/Downloads/pycharm-2016.3.3/debug-eggs/pycharm-debug.egg') 19 | #import pydevd 20 | 21 | #pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True) 22 | 23 | class QGpkg_qgis(QGpkg): 24 | """Read and write QGIS mapping information in a GeoPackage database file, using this spec: 25 | https://github.com/pka/qgpkg/blob/master/qgis_geopackage_extension.md 26 | """ 27 | 28 | def write(self, project_path): 29 | ''' Store QGIS project ''' 30 | xmltree = self.read_project(project_path) 31 | # If something is messed up with the file, the Method will stop 32 | if not xmltree: 33 | self.log(logging.ERROR, u"Couldn't read project (wrong file format)") 34 | return None 35 | 36 | root = xmltree.getroot() 37 | projectlayers = root.find("projectlayers") 38 | 39 | # Search for layersources 40 | sources = [] 41 | for layer in projectlayers: 42 | layer_path = self.make_path_absolute(layer.find( 43 | "datasource").text.split("|")[0], project_path) 44 | if layer_path not in sources: 45 | self.log(logging.DEBUG, u"Found datasource: %s" % layer_path) 46 | sources.append(layer_path) 47 | 48 | # If there are more than just one different datasource check from where 49 | # they are from 50 | gpkg_found = False 51 | if len(sources) >= 1: 52 | for path in sources: 53 | if self.database_connect(path): 54 | if self.check_gpkg(path) and not gpkg_found: 55 | gpkg_found = True 56 | gpkg_path = path 57 | elif self.check_gpkg(path) and gpkg_found: 58 | # If a project has layer from more than just one 59 | # GeoPackage it can't be written 60 | self.log(logging.ERROR, u"The project uses layers " 61 | "from different GeoPackage databases.") 62 | return None 63 | if gpkg_found and len(sources) > 1: 64 | self.log( 65 | logging.WARNING, 66 | u"Some layers aren't in the GeoPackage. It can't be " 67 | "garanteed that all layers will be shown properly.") 68 | 69 | if not gpkg_found: 70 | self.log(logging.ERROR, u"There is no GeoPackage layer " 71 | "in the project.") 72 | return None 73 | 74 | # Check for images in the composer of the project 75 | images = [] 76 | for composer in root.findall("Composer"): 77 | for comp in composer: 78 | for composer_picture in comp.findall("ComposerPicture"): 79 | img = composer_picture.attrib['file'] 80 | if img not in images: 81 | self.log(logging.DEBUG, u"Image found: %s" % img) 82 | images.append(img) 83 | 84 | # Write data in database 85 | project_name = os.path.basename(project_path) 86 | project_xml = ET.tostring(root) 87 | 88 | self.database_connect(gpkg_path) 89 | 90 | # Create tables 91 | self.c.execute('CREATE TABLE IF NOT EXISTS qgis_projects (name TEXT PRIMARY KEY, xml TEXT NOT NULL)') 92 | self.c.execute( 93 | """CREATE TABLE IF NOT EXISTS qgis_resources 94 | (name TEXT PRIMARY KEY, mime_type TEXT NOT NULL, content BLOB NOT NULL)""") 95 | self.c.execute( 96 | 'CREATE TABLE IF NOT EXISTS gpkg_extensions (table_name TEXT,column_name TEXT,extension_name TEXT NOT NULL,definition TEXT NOT NULL,scope TEXT NOT NULL,CONSTRAINT ge_tce UNIQUE (table_name, column_name, extension_name))') 97 | extension_record = (None, None, 'qgis', 98 | 'http://github.com/pka/qgpkg/blob/master/' 99 | 'qgis_geopackage_extension.md', 100 | 'read-write') 101 | self.c.execute('SELECT count(1) FROM gpkg_extensions WHERE extension_name=?', (extension_record[2],)) 102 | if self.c.fetchone()[0] == 0: 103 | self.c.execute( 104 | 'INSERT INTO gpkg_extensions VALUES (?,?,?,?,?)', extension_record) 105 | 106 | self.c.execute('SELECT count(1) FROM qgis_projects WHERE name=?', (project_name,)) 107 | if self.c.fetchone()[0] == 0: 108 | self.c.execute('INSERT INTO qgis_projects VALUES (?,?)', (project_name, project_xml)) 109 | self.log(logging.DEBUG, u"Project %s saved." % project_name) 110 | else: 111 | # Overwrite existing project (DELETE gives locking problems) 112 | self.c.execute('UPDATE qgis_projects SET xml=? WHERE name=?', 113 | (project_xml, project_name)) 114 | self.log(logging.INFO, u"Project overwritten.") 115 | 116 | if images: 117 | for image in images: 118 | img = self.make_path_absolute(image, project_path) 119 | with open(img, 'rb') as input_file: 120 | blob = input_file.read() 121 | mime_type = mimetypes.MimeTypes().guess_type(image)[0] 122 | self.c.execute('SELECT count(1) FROM qgis_resources WHERE name=?', (image,)) 123 | if self.c.fetchone()[0] == 0: 124 | self.conn.execute( 125 | """INSERT INTO qgis_resources \ 126 | VALUES(?, ?, ?)""", (image, mime_type, sqlite3.Binary(blob))) 127 | self.log(logging.DEBUG, u"Image %s was saved" % image) 128 | else: 129 | # TODO: forced overwrite 130 | self.log(logging.DEBUG, u"Skipping existing image %s" % image) 131 | self.conn.commit() 132 | 133 | return gpkg_path 134 | 135 | def read(self, gpkg_path): 136 | ''' Read QGIS project from GeoPackage ''' 137 | # Check if it's a GeoPackage Database 138 | self.database_connect(gpkg_path) 139 | if not self.check_gpkg(gpkg_path): 140 | self.log(logging.ERROR, u"No valid GeoPackage selected.") 141 | return None 142 | 143 | # Read xml from the project in the Database 144 | try: 145 | self.c.execute('SELECT name, xml FROM qgis_projects') 146 | except sqlite3.OperationalError: 147 | self.log(logging.ERROR, u"There is no Project file " 148 | "in the database.") 149 | return None 150 | file_name, xml = self.c.fetchone() 151 | try: 152 | xml_tree = ET.ElementTree() 153 | root = ET.fromstring(xml) 154 | except: 155 | self.log(logging.ERROR, u"The xml code is corrupted.") 156 | return None 157 | self.log(logging.DEBUG, u"Xml successfully read.") 158 | xml_tree._setroot(root) 159 | projectlayers = root.find("projectlayers") 160 | 161 | # Layerpath in xml adjusted 162 | tmp_folder = tempfile.mkdtemp() 163 | project_path = os.path.join(tmp_folder, file_name) 164 | for layer in projectlayers: 165 | layer_element = layer.find("datasource") 166 | layer_info = layer_element.text.split("|") 167 | layer_path = self.make_path_absolute(gpkg_path, layer_info[0]) 168 | if layer_path.endswith('.gpkg'): 169 | if len(layer_info) >= 2: 170 | for i in range(len(layer_info)): 171 | if i == 0: 172 | layer_element.text = layer_path 173 | else: 174 | layer_element.text += "|" + layer_info[i] 175 | elif len(layer_info) == 1: 176 | layer_element.text = layer_path 177 | self.log(logging.DEBUG, 178 | u"Layerpath from layer %s was adjusted." % 179 | layer.find("layername").text) 180 | 181 | # Check if an image is available 182 | images = [] 183 | for composer in root.findall("Composer"): 184 | for comp in composer: 185 | for composer_picture in comp.findall("ComposerPicture"): 186 | img = self.make_path_absolute( 187 | composer_picture.attrib['file'], project_path) 188 | # If yes, the path will be adjusted 189 | composer_picture.set('file', './' + os.path.basename(img)) 190 | self.log(logging.DEBUG, 191 | u"External image %s found." % os.path.basename(img)) 192 | images.append(img) 193 | 194 | # and the image will be saved in the same folder as the project 195 | if images: 196 | self.c.execute("SELECT name, mime_type, content FROM qgis_resources") 197 | images = self.c.fetchall() 198 | for img in images: 199 | img_name, mime_type, blob = img 200 | img_path = os.path.join(tmp_folder, img_name) 201 | with open(img_path, 'wb') as file: 202 | file.write(blob) 203 | self.log(logging.DEBUG, u"Image saved: %s" % img_name) 204 | 205 | # Project is saved and started 206 | xml_tree.write(project_path) 207 | self.log(logging.DEBUG, u"Temporary project written: %s" % project_path) 208 | return project_path 209 | 210 | def read_project(self, path): 211 | ''' Check if it's a file and give ElementTree object back ''' 212 | if not os.path.isfile(path): 213 | return False 214 | 215 | return ET.parse(path) -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/read.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/qgis_plugin/qgpkg/read.png -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/resources.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Resource object code 4 | # 5 | # Created by: The Resource Compiler for PyQt4 (Qt v4.8.7) 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt4 import QtCore 10 | 11 | qt_resource_data = "\ 12 | \x00\x00\x08\x84\ 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\x08\x4b\x49\x44\x41\x54\x78\x9c\xed\x97\x69\x6c\x5c\xd5\ 17 | \x15\xc7\x7f\x6f\x9b\xf1\x8c\xed\x19\xdb\x33\x63\x7b\xbc\xc6\xbb\ 18 | \x93\xd8\x4e\xe2\x04\x82\x03\x31\x4d\x02\x21\x14\x02\xc1\x84\xa5\ 19 | \x94\x45\x15\x55\xe9\x87\x6e\x94\x82\x10\x29\x91\x2a\x35\x5f\xba\ 20 | \xa8\x08\x4a\x45\xe9\x02\xa5\x14\x28\xb4\x46\x45\x15\x2d\x22\x09\ 21 | \x64\xa1\x49\x6a\x1c\x12\x3b\xb1\x1d\x3b\x13\x3b\xf1\xd8\x1e\xc7\ 22 | \xb3\x2f\x6f\xe6\xcd\x9b\x99\xd7\x0f\xd9\x80\x9a\x04\x68\xbf\xb5\ 23 | \x7f\xe9\xea\x3e\xdd\xfb\x74\xce\xff\x9c\x7b\xce\xb9\xe7\xc2\xff\ 24 | \x3a\xa4\x4f\xfb\xa3\xd3\x82\x6d\x5b\x37\xeb\x36\xd4\xb1\xa9\xdf\ 25 | \xc7\x70\xc1\x5a\x3a\xab\xbf\xcc\xf6\xfc\x06\xa2\x09\x0f\x43\x25\ 26 | \x22\xc6\xf2\x72\x6a\xac\x0a\x29\x7f\x92\xec\x7f\x95\xc0\x2d\xcd\ 27 | \x54\xdd\xb3\x98\xa7\x97\x35\xda\x1e\xaa\x28\xb5\xae\xab\x2c\x48\ 28 | \xa5\x3d\xab\xc4\xaf\x75\x34\x75\x2e\x8d\x18\x73\x6d\xe6\xca\x5c\ 29 | \xdf\x23\x85\xb4\xf6\xb4\xf0\x93\xe5\xe5\x74\x2d\x74\xe0\xd9\xe3\ 30 | \x65\xee\x3f\x22\xe0\xb4\x20\x2c\x2f\xa7\xe6\xd9\x0d\x6c\xbd\xb2\ 31 | \xa5\xf0\xd7\x9d\xd7\xad\xe8\x5c\xbc\xf9\x3a\x8b\xe2\x2e\x32\xbd\ 32 | \x91\x39\xb5\xb6\xa6\x73\x75\xed\x3d\x1b\x1f\x10\xec\x96\x22\xc7\ 33 | \x54\x68\x78\xfd\x46\x6b\xc1\x57\xdb\x6f\xed\x69\x2a\x6f\xa8\xea\ 34 | \x2c\xcf\x86\xef\xbf\xb3\x4e\x75\x5a\x65\xfc\xfd\xb3\xcc\x7c\x2e\ 35 | \x02\xdb\xba\xf9\x4a\x4f\x0b\xdb\x5c\x8b\x9b\xee\x68\xfe\x62\x77\ 36 | \x5e\x45\x47\x03\x92\xa1\xd1\x3b\x35\xca\x01\xc1\xe0\x9e\x9b\xbf\ 37 | \xce\xac\x30\x48\x53\x79\x07\xd1\x44\xd2\x3e\x55\x98\x93\xd7\x6f\ 38 | \xd8\x88\xbb\xb9\x81\x92\xfa\x2a\x59\x8f\xc5\x2e\x5f\x60\x84\xd6\ 39 | \x54\x17\x1a\xca\x5c\x92\x21\x7f\x12\xed\x92\x04\x5a\x1d\x48\x3d\ 40 | \xcd\xdc\xb8\x6d\x8d\xf0\x64\xf3\xe2\xea\x87\x5a\x6f\x5a\x53\x53\ 41 | \x7f\xf5\x32\xf2\xf2\x04\x72\x6a\x98\xbd\x93\x1e\x9e\xf1\x4e\x73\ 42 | \xdf\x4d\xdf\x26\x6c\x1d\xe1\xa4\xd6\x4f\xd4\x98\x61\xdd\xc2\x1e\ 43 | \x76\x0e\x1f\xe4\xa4\xef\x04\x57\xb9\xab\xc8\xcb\x13\x29\x6b\xa9\ 44 | \x16\x4a\x9b\xaa\x1c\xa5\x99\xe0\x75\xeb\xca\xb5\xbb\x97\x39\x73\ 45 | \x09\x55\x67\xea\x54\x94\xf8\xbc\x04\x5a\x1d\x54\x6d\xe9\x62\x4b\ 46 | \x57\xa3\x65\x6b\xdd\x17\x2e\x5f\xd2\xb0\x66\x05\x76\x97\x0d\x92\ 47 | \x51\x48\xc5\x38\xee\xf7\xf1\xc3\xa1\x41\xd6\xaf\xb9\x97\xe2\x2a\ 48 | \x99\xb1\xd4\x5e\x0c\x0c\x34\x23\x41\xc2\x08\x72\x45\xc5\x46\xfe\ 49 | \xda\xff\x36\x65\x32\xd4\x5b\x2c\x18\xa9\x38\x26\x39\x87\xb3\xd2\ 50 | \x4e\xa1\xdd\x64\xb7\x24\xa3\x6b\xaf\x70\x65\xae\xaa\xb1\x31\x36\ 51 | \x97\x64\xca\x9f\xc4\x00\x10\x00\x1e\xeb\xc2\xd5\x5d\xcd\x88\xb3\ 52 | \x65\x41\xc9\xc2\x9b\xae\xc6\x6c\x91\x41\x4b\x80\x96\xc4\xd0\x12\ 53 | \x04\xd5\x18\xdf\x3c\x36\x4a\x43\xc7\x06\x56\x5e\xb9\x84\xc1\xc4\ 54 | \x5b\xe8\x46\xf2\x43\x76\x08\xd4\x99\x97\x63\x9e\x5b\xc0\xef\xff\ 55 | \xf2\x23\x1e\x5e\xd4\x46\x77\x71\x31\x46\x5a\x85\xd4\x19\x39\x59\ 56 | \x35\xc6\xe9\xf1\x00\x13\xc7\x42\x19\x35\x9e\x79\x77\xc3\xab\x5c\ 57 | \x0b\x20\x02\xf4\x8e\x12\x05\x7a\xd3\x71\x35\x23\x68\x71\x88\x07\ 58 | \x31\xe2\x21\x8c\x44\x90\x64\x34\xc0\x73\x13\xe3\x58\x2a\xda\xb9\ 59 | \x6a\xc5\x6a\x86\xd4\xed\xe7\x95\x0b\x08\x48\x28\x28\x82\x99\x39\ 60 | \x7d\x9c\x42\xb7\x41\xd7\xd2\x4d\x3c\x3d\x3c\x48\x30\x1a\x84\x64\ 61 | \x1c\x52\x71\x8c\x54\x1c\x31\x93\xa4\xc4\x69\x42\x92\x45\x19\x2e\ 62 | \xa4\xa9\x04\xe0\x4f\x92\x7d\xdf\xc7\x8e\x36\x6b\xc2\x2e\x84\x02\ 63 | \x2b\xed\x76\x11\x49\x8f\x81\x1a\xe1\x57\x53\x53\xec\x12\x8b\xf8\ 64 | \xd6\xe6\xc7\x49\x9b\x42\x64\x8d\x2c\xb1\xac\x1f\x45\x30\x21\x8b\ 65 | \x66\x14\xc1\x8c\x22\xe6\x51\x24\xbb\x29\x92\xdd\xac\xac\xb9\x96\ 66 | \x59\x55\xe5\xef\x47\x76\xd1\x9e\x33\x28\xcc\x25\x21\x9d\x22\x16\ 67 | \xd6\x18\xea\x0f\x64\x4e\x4c\xa7\x7f\xba\x65\x37\xdf\xf3\x27\x51\ 68 | \x3f\x12\x03\xfe\x24\xfa\x70\x80\xfe\xab\x1d\x6a\x87\x1a\x8a\x35\ 69 | \x16\xdb\xe1\x80\x37\xc8\x8f\xa3\x61\x44\x53\x3e\x27\x66\xc6\x90\ 70 | \x34\x2b\xad\x95\x1d\xf8\xf4\x63\xc8\x82\x19\x45\x30\xa1\x88\x66\ 71 | \x64\xc1\x4c\x99\xd2\x88\xe2\xaf\xe0\x77\xdb\x7f\xce\x74\xe0\x14\ 72 | \xfd\x33\x27\xc0\x1b\xa5\x26\x99\x45\x51\x44\x86\x3f\x08\x66\xa2\ 73 | \xe1\xf4\xf3\x5b\x76\xf3\xe8\x48\x80\xc8\xbc\x59\xe0\xb4\x62\x56\ 74 | \xd3\x84\x6a\x4d\xda\xd2\xa9\x13\x51\x47\x91\x2c\xb2\xbc\xaa\x90\ 75 | \x55\xb2\x8e\x1e\xf4\x32\x9a\x93\x59\xb6\xb0\x93\xd3\x59\x0f\x8a\ 76 | \x90\x87\x22\x9a\xcf\xce\x79\x14\x4b\x6e\xc2\x3e\x8d\xc1\x0f\x5e\ 77 | \xe2\x3e\x57\x21\xd7\xb8\x5c\x74\x37\x54\x13\x1e\x0b\x33\x76\xf8\ 78 | \x34\x5a\x32\x7b\xa0\xf7\x18\x4f\x9d\x8c\xe2\xf5\x27\xd1\xcf\xe9\ 79 | \x94\x07\x76\xbc\x2a\xbd\xf2\xfd\xdb\x17\x03\x77\x2e\x74\x70\x99\ 80 | \xdb\x95\xdf\xe6\x5c\xd2\x5e\x2a\x08\x10\x39\x3a\x40\xcb\x6c\x86\ 81 | \xca\xda\x02\x00\xc6\xcf\x9e\xb9\x49\xb0\x20\x09\x32\x12\x32\xe2\ 82 | \xd9\x59\x16\xcc\x08\x08\x94\x29\x26\xd6\x97\x14\xa3\xc5\x53\x4c\ 83 | \x1e\x9d\x26\x11\x4d\x53\xbe\xf2\x32\xf4\x58\xec\xb2\xcd\x26\xcf\ 84 | \x73\xab\xab\xf5\xbe\xe1\x00\x7b\x87\x03\xbc\xf1\xfa\x28\x1e\xd9\ 85 | \x65\xa1\xbb\xbb\x9a\x97\xf3\x2b\xdd\x65\x0d\xb7\xdc\x8c\x7b\xf5\ 86 | \xaa\xf3\x1e\x89\x8e\x4f\x30\xf6\xca\x9f\x98\x3d\xe0\x21\xe1\x32\ 87 | \x28\xb0\x0b\x28\x82\x09\xb3\x98\x7f\x5e\xb9\x2c\x28\x88\x82\x84\ 88 | \x49\xb0\x20\x92\xc6\x50\x35\xbc\x03\x27\x99\x18\x9a\xc3\xde\xd4\ 89 | \xc4\xb2\xef\xde\x4d\x81\xab\x18\x43\x4b\xc8\x99\x58\xa4\xda\xd7\ 90 | \x77\xb8\xba\x76\xcf\xc1\x9e\xee\x60\x64\xeb\x2f\x9e\x7f\xf5\x76\ 91 | \xe9\x86\x4d\xb7\xf9\x8f\xec\x7c\xed\x68\x89\xa2\xaf\xc8\xa8\xc9\ 92 | \x12\x5b\x5d\x0d\x26\x9b\x0d\x00\x73\x71\x11\xce\xa5\xed\xe4\xb9\ 93 | \x2b\x89\xfe\x73\x04\xe7\x5c\x94\xfc\xc6\x06\x22\x85\xea\xd9\xb3\ 94 | \x37\x9d\x8d\x05\x33\x85\x38\x50\x46\x7c\x14\xbc\xf3\x36\x72\x5c\ 95 | \xa2\xe5\xae\xdb\xa8\x5d\xb7\x1a\x4b\x81\x19\x43\x53\x41\x4b\x90\ 96 | \x0e\x85\x98\xee\x1f\x22\x3e\x1b\x38\x7d\xd4\x97\x7d\x50\x5a\x72\ 97 | \xdb\x4e\xe1\x43\x85\xc8\xd6\xd3\xcc\xfd\x6b\x9b\x2d\xdf\x71\xaf\ 98 | \x5e\x55\xb5\xe0\xc6\xeb\x45\x8b\xcb\x89\x20\x8a\x00\x64\xd4\x24\ 99 | \xde\x9d\xbb\x98\xd8\xb1\x83\x68\xbd\x8b\xf4\xf5\x5d\xe0\x2e\x43\ 100 | \x42\x42\x9a\xf2\x63\x7e\x7d\x17\x96\x69\x3f\x55\xdd\x5d\x54\x75\ 101 | \x77\xa1\x28\x02\xa4\x53\x18\x5a\x82\x74\x38\xc4\xd4\xfe\x43\x9c\ 102 | \xda\x3f\x18\x9c\x3a\xad\xfe\x72\xdb\x3e\x9e\x1c\x09\xe0\xfb\x78\ 103 | \x16\x68\x7b\xbc\xec\xcf\x23\x73\xb0\x32\x32\x9e\x1f\x19\x3b\xde\ 104 | \x26\x48\x12\xb6\xba\x5a\x00\x44\x45\xa1\xa8\xb9\x11\x7b\xdd\x02\ 105 | \xa4\xf1\x69\x52\xdb\xf7\x21\x65\x40\x19\xf0\x20\xbf\xbe\x03\xb7\ 106 | \xab\x8c\xa6\xcd\x1b\x29\x5f\xde\x81\x24\x64\x31\x52\x09\xd0\x54\ 107 | \xc2\x9e\x71\xc6\xde\xdc\x8d\xb7\x6f\x68\xdf\x6b\x83\xfa\xa3\x2f\ 108 | \x0e\xf1\xcc\x48\x80\xd8\x85\x12\x36\x0f\x1e\xeb\x62\xd1\x35\x6d\ 109 | \xb6\xa3\x79\x8e\x12\xcc\xc5\xc5\x2c\xb8\x61\x03\xc5\xad\xcd\x08\ 110 | \x92\x44\x4e\xd7\x49\x78\x27\x19\x7b\xe1\x45\x42\x27\x26\x11\x64\ 111 | \x09\x5b\x7d\x3d\x2d\x77\x6c\xc2\x5a\x62\x47\xcc\x6a\x18\xe9\x24\ 112 | \x71\xaf\x97\xe9\x03\x87\x99\xe9\x3f\x42\x46\xcf\xb2\xfe\x65\x63\ 113 | \x5e\x5d\xf2\x7c\x8b\x00\xf9\x15\x6e\x5a\xee\xbd\x8b\x99\xbd\xfb\ 114 | \x18\xfe\xed\x0b\xb8\x57\xaf\xa2\xb8\xb5\x99\x99\xf7\xf6\x13\x3c\ 115 | \x3a\x8c\xad\x6e\x01\xed\xd7\xae\x03\x35\xc4\x4c\xdf\x00\x87\x9e\ 116 | \x7a\x16\x47\x73\x3d\xd5\x2b\xdb\x89\x4f\xcf\x30\xbe\x73\x3f\x16\ 117 | \x73\x8e\xa6\xe5\x15\x8c\x0f\xf8\x80\xf4\xbc\x7a\x3e\x91\x00\x82\ 118 | \x80\xc5\xe9\xa0\xf5\xde\xbb\x50\x7d\xb3\x8c\xbe\xf4\x47\x66\x0f\ 119 | \xf4\xe1\xe8\x68\xa3\xf3\x91\x07\xb1\x96\x97\x61\xa8\x51\x0c\xdf\ 120 | \x71\x9c\xd5\x25\xa8\xbe\x59\xbc\x7d\x43\x1c\xfe\xcd\xcb\x48\x92\ 121 | \x40\x63\x67\x15\xc5\x4e\x33\x09\x7f\x64\x7e\x37\x5f\x92\xc0\x87\ 122 | \x60\x2d\x2f\x63\xf1\x03\xf7\xa3\xc7\x13\x58\xcb\x4a\x2f\x6c\x18\ 123 | \x59\xc8\xa4\x21\x93\xc6\x52\x60\xa6\x71\x55\x2b\x15\x8d\x0e\x44\ 124 | \x43\x27\x4f\xc9\x61\xe8\x29\xc8\xea\x70\xe6\xe2\xfb\xfc\x04\x00\ 125 | \x94\xfc\x7c\x94\xfc\xfc\x8f\x2e\xe6\x72\x18\xba\x06\xe7\x46\x56\ 126 | \xc3\x5a\x20\x83\x9e\xc1\x48\x9d\x5b\xcb\x5c\x54\xae\xf8\x49\x1b\ 127 | \x7a\x3c\x81\x16\x0a\x5f\x9c\x55\x2e\x77\xc6\x03\x7a\x1a\x32\xda\ 128 | \x79\x6f\x5c\x18\x3a\x69\x2d\x4b\x46\xcf\x7d\xa2\x88\x79\x5b\x32\ 129 | \xa7\x95\xa8\x92\x88\x3a\x32\x07\xff\x51\x21\xca\xb2\xcd\x5c\x54\ 130 | \xf4\xef\xd6\x1b\xb9\x33\xd7\x76\x70\x1a\xf4\x14\x46\x3a\x75\xc6\ 131 | \xe2\xf4\x99\x6f\x35\x14\x67\xd2\x13\xe1\xd8\x40\x68\x62\x70\xc6\ 132 | \x78\xe2\xad\x71\x76\x7d\x6a\x02\x23\x01\xb2\xfd\x3e\x76\xb4\xd8\ 133 | \x32\x7d\xd2\xc4\x48\x73\x70\xe4\x58\xb5\xb5\xb4\x14\x8b\xd3\x71\ 134 | \xbe\x30\x19\x7a\x0a\x23\xea\x87\xb0\xef\xec\x11\xa4\x20\xa3\x91\ 135 | \xd3\x92\xcc\x9d\x0a\x31\x7a\xc8\x9f\x39\x3d\x93\xfc\xdb\xb6\xf7\ 136 | \xf8\x46\xef\x28\x7f\x56\x33\xf3\xb7\xea\x17\x0b\x50\x00\x5a\x1d\ 137 | \x98\x7b\x9a\xd9\xd8\x5d\x2b\x3e\x5e\xb2\xa8\x75\x51\xf3\x97\x6e\ 138 | \x97\x0b\x2b\xcb\x21\x15\x81\xc0\x24\xb9\x99\xe3\x90\x4e\x91\x4d\ 139 | \xc4\x89\xf8\x42\x78\x0e\x4d\xa5\xa2\x81\xd4\x07\xbb\x27\x79\xbc\ 140 | \x77\x94\x77\x47\x02\x17\x7f\x23\x5c\xf2\x5d\xe0\x4f\x92\xdd\xe3\ 141 | \x65\xe8\x64\xd8\x78\xa7\x20\x36\x17\x15\x3c\x47\x2e\xd7\x23\x21\ 142 | \xd9\x56\x5a\x88\x98\x8c\x60\xc4\x83\xa4\x63\x71\x3c\xef\x4f\x30\ 143 | \x71\x64\x36\xd2\x3f\x9e\xde\xfa\xec\x21\x7e\xf0\x87\x21\x0e\x9f\ 144 | \xeb\xfb\x2e\x86\x4b\x7a\xe0\xe3\x78\xac\x8b\x45\x0b\x1d\x3c\x5c\ 145 | \x53\x65\xbb\xa5\x66\x59\xbd\x5d\x0f\x87\x99\x3c\xea\x0d\x4e\x07\ 146 | \x33\xcf\x6f\xdb\xc7\xcf\x46\x02\x78\x3f\x8b\xbc\xcf\x4c\x00\xa0\ 147 | \xd5\x81\xb5\xbb\x8a\x9e\x5b\x17\x0a\x0f\x1a\x86\x11\xed\x1d\xe1\ 148 | \xc9\xdd\x5e\xde\x1c\x09\xcc\xdf\xfb\xff\x1f\x17\xc3\xbf\x00\xc5\ 149 | \xc9\xb8\xc4\xfe\x61\xca\xed\x00\x00\x00\x00\x49\x45\x4e\x44\xae\ 150 | \x42\x60\x82\ 151 | \x00\x00\x06\xd3\ 152 | \x89\ 153 | \x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ 154 | \x00\x00\x20\x00\x00\x00\x20\x08\x06\x00\x00\x00\x73\x7a\x7a\xf4\ 155 | \x00\x00\x00\x06\x62\x4b\x47\x44\x00\xff\x00\xff\x00\xff\xa0\xbd\ 156 | \xa7\x93\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\ 157 | \x0b\x13\x01\x00\x9a\x9c\x18\x00\x00\x00\x07\x74\x49\x4d\x45\x07\ 158 | \xe1\x07\x15\x09\x36\x39\x1d\xe3\x3b\xc8\x00\x00\x06\x60\x49\x44\ 159 | \x41\x54\x58\xc3\xed\x97\x6d\x4c\x5b\xe7\x15\xc7\x7f\xf7\x72\x5d\ 160 | \xa7\x40\x6c\x1a\xfc\x92\x80\x21\xc5\xb8\x84\x17\x87\x40\x44\x4d\ 161 | \x1b\x45\x91\x80\x22\x50\x9a\x29\x59\x5a\x6d\x53\x95\x2f\x53\xfb\ 162 | \xa5\xd2\xa4\xad\xda\x26\x45\xaa\x1a\x69\x95\xf6\x71\xeb\x94\x4f\ 163 | \x5d\x57\x75\xad\x34\x69\x51\xa5\x45\xd5\xaa\x0e\x55\x1d\xa3\x69\ 164 | \x51\x96\x94\x02\xb1\x63\x9c\x41\x70\x42\x6b\x43\x62\x6e\x42\xc0\ 165 | \xd8\x17\xbf\xe2\x7d\x38\xf1\xbc\x6c\x84\xd0\x6c\xdf\xb6\x47\x3a\ 166 | \xd2\x7d\x79\x74\xce\xff\x39\xff\x73\xfe\xf7\x5c\xf8\x5f\x5f\x65\ 167 | \x5b\xdd\x58\x5e\x8e\x65\x70\x90\xbe\x3d\x7b\x38\x16\x8d\x72\xa5\ 168 | \xb3\x93\xfd\x03\x03\xfc\xb9\xb6\x96\x78\x34\x4a\xc8\x64\xa2\x50\ 169 | \x5b\x4b\xbd\xc9\x44\xca\x30\xc8\x6f\xd5\xaf\xb6\x95\x4d\x5e\x2f\ 170 | \xae\x86\x06\x7e\xe9\xf1\xd0\xa7\x69\x98\x01\xb3\xdd\x4e\xff\x9e\ 171 | \x3d\x78\xca\xca\x78\xb5\xb7\x97\x59\x45\xa1\xc2\xe9\xe4\x64\x22\ 172 | \xc1\xb5\x58\x8c\x37\x46\x46\x08\x6d\xc5\xb7\xb2\xc9\x89\x15\x87\ 173 | \x83\xba\x67\x9e\xe1\x87\x95\x95\xbc\xd8\xd1\x81\x75\xff\x7e\x98\ 174 | \x9f\x87\x8f\x3e\x82\x96\x16\x38\x72\x04\xc6\xc7\xe1\xe3\x8f\x89\ 175 | \x54\x56\x62\xef\xed\x65\x5b\x3c\x0e\x93\x93\xa4\x96\x96\x78\x33\ 176 | \x10\xe0\x77\x5f\x7c\xc1\xf8\x43\x51\x30\x38\xc8\xf7\xdb\xdb\xf9\ 177 | \xf9\x13\x4f\xf0\xdd\xbe\x3e\xb6\x35\x37\xcb\xf3\xe9\x69\x48\x26\ 178 | \xe1\xb9\xe7\x20\x93\x81\xda\x5a\x48\x26\xb1\xaa\x2a\xda\xe0\x20\ 179 | \x34\x36\xc2\xee\xdd\x68\x89\x04\x3e\x93\x89\x1e\x8b\x05\x53\x32\ 180 | \x49\xc8\x30\x48\x3f\x10\x80\xdd\x4e\x99\xd7\xcb\x91\xc3\x87\x39\ 181 | \xdd\xdc\xcc\x8f\xfb\xfb\xa9\xef\xee\x06\xb3\x19\x52\x29\x98\x9d\ 182 | \x85\x60\x10\x9e\x7f\x1e\x54\x15\x56\x56\x04\x44\x67\x27\xf8\xfd\ 183 | \x70\xe3\x06\x34\x34\xc8\x7e\xb7\x1b\xc5\xed\xa6\x1a\x18\xa8\xaf\ 184 | \xe7\xc4\xae\x5d\x24\x33\x19\xe6\x97\x97\x49\x6c\x08\xc0\x6e\xc7\ 185 | \xd5\xd7\xc7\xab\x4d\x4d\x9c\x7a\xea\x29\xf6\x1d\x38\x00\xd5\xd5\ 186 | \x90\x4e\x8b\xc5\x62\xf0\xf9\xe7\xd0\xdf\x0f\x3b\x77\xc2\x9d\x3b\ 187 | \x50\x28\x40\x3e\x0f\xb9\x1c\x78\x3c\x70\xfe\xbc\x04\xb7\x58\x04\ 188 | \x98\xa6\xc1\xae\x5d\x60\xb1\x60\xcd\x64\xe8\x75\xb9\x38\x68\xb5\ 189 | \x72\x35\x99\x64\xde\x30\x28\xfc\xa3\x06\x7a\x7a\xb0\x37\x36\xf2\ 190 | \x37\xb7\x9b\x1d\xfd\xfd\xb0\x6d\x9b\x38\x28\x5a\x22\x21\xc1\xf7\ 191 | \xee\x85\xa7\x9f\x16\x30\x85\xc2\xbd\xa9\xb4\x5a\xc1\x30\xe0\xfd\ 192 | \xf7\xe1\xc0\x01\xa8\xa9\x11\x60\xe9\xb4\xf8\x58\x5b\x83\x48\x04\ 193 | \xc2\x61\x72\xc9\x24\x9f\xbe\xfd\x36\xfd\x00\x2a\x40\x30\x48\x1c\ 194 | \x38\x9b\x4c\x92\xcb\x64\xc4\xd1\xda\x9a\xd8\xea\x2a\x04\x02\x72\ 195 | \x6a\x9f\x0f\x74\xbd\x14\x5c\x51\x4a\x66\x18\x60\xb3\x41\x57\x17\ 196 | \x5c\xbc\x28\xf4\x14\x83\x67\x32\xb0\xbe\x0e\x3b\x76\x80\xaa\xa2\ 197 | \x41\xa9\x4d\xcb\x00\x0c\x83\x7c\x24\xc2\x70\x55\x15\xd6\xd5\x55\ 198 | \xba\xb7\x6f\x17\xf4\xa9\x14\x4c\x4d\x89\xf3\x13\x27\x84\xf7\x42\ 199 | \x01\xb2\x59\x09\xaa\xaa\x62\x9a\x26\x59\x33\x9b\xa1\xa9\x49\x40\ 200 | \x8f\x8f\xcb\xbd\xa2\x88\xaf\x95\x15\x08\x04\xc8\xdd\xb8\xc1\x2f\ 201 | \x86\x86\xf8\x89\x61\x60\xdc\x53\x03\x86\x41\x36\x16\x63\xbc\xa6\ 202 | \x86\xf6\x78\x1c\x8f\xc5\x02\xd7\xae\x49\xe1\x3d\xf2\x08\x44\xa3\ 203 | \xc2\xf7\xee\xdd\x12\xa0\xac\x4c\xac\x08\xa2\xb2\x52\xa8\xfa\xf0\ 204 | \x43\xb8\x75\x0b\xbe\xfa\x4a\xb2\x05\x02\xf0\xf2\x65\x72\xf1\x38\ 205 | \xef\x0e\x0d\x71\x52\xd7\x59\xb9\x9f\x10\xe5\xfc\x7e\x7e\x53\x28\ 206 | \xd0\x10\x8b\xd1\xb4\x73\xa7\xf0\x0e\x52\x74\xb3\xb3\xd0\xd1\x21\ 207 | \x0e\x15\x45\x00\x80\x00\x50\x14\x39\xe5\xc2\x02\xb4\xb5\x49\x7b\ 208 | \x6e\xdf\x2e\xdd\x71\xe5\x0a\x14\x0a\x8c\x05\x02\x9c\xf9\x37\x25\ 209 | \x1c\x19\xa1\xec\xf5\xd7\x69\x03\xbe\xe7\x74\xf2\xa4\xcd\x86\xb7\ 210 | \xb5\x15\x87\xa2\xc0\xcc\x0c\x54\x54\x40\x5d\x9d\x6c\x2e\x14\x24\ 211 | \x50\x11\x40\x91\x86\x22\x18\x45\x81\x47\x1f\x95\xfd\x89\x04\x5c\ 212 | \xbd\x2a\xd9\xea\xe8\x80\x44\x82\x27\x35\x8d\xdf\xba\xdd\x8c\xc5\ 213 | \x62\x8c\xea\x3a\x7f\x0c\x06\x09\x6b\x15\x15\x1c\x6a\x6c\xe4\xf7\ 214 | \x0e\x07\xce\x81\x01\x29\xb4\xe2\x8a\x44\x24\xa5\x5f\x7e\x29\x8e\ 215 | \x1d\x8e\x12\xe7\xca\x5d\x0d\x2d\x06\x56\x55\xb9\x4f\xa7\xe5\xc4\ 216 | \xd3\xd3\xf0\xf8\xe3\xf0\xd2\x4b\xd2\xce\x99\x0c\x5a\x22\x41\x5d\ 217 | \x20\x40\xdd\xd8\x18\xc7\x97\x97\x39\xf5\xce\x3b\x7c\xa7\xec\xe8\ 218 | \x51\x6e\x9d\x3b\xc7\x94\xd9\x4c\x57\x2a\xc5\x0e\x97\x4b\x52\x57\ 219 | \x6c\xad\x96\x16\xb0\xdb\x45\x80\x92\x49\xa8\xaf\x07\x93\xe9\x5e\ 220 | \xfe\x55\x55\x9e\x45\xa3\x30\x31\x21\xc5\x7b\xec\x98\xb4\x63\x45\ 221 | \x45\xa9\x13\xe2\x71\xb8\x7c\x19\x74\x9d\xc5\x85\x05\x5e\x69\x69\ 222 | \xe1\x2f\xca\x3f\x09\x91\xc5\xeb\xe5\xc5\x96\x16\x7e\xe4\xf3\xe1\ 223 | \xea\xeb\x43\xbd\xdb\x36\x80\x38\x3d\x7f\x1e\x46\x47\xc1\xe9\x84\ 224 | \xee\x6e\x39\x99\xa2\x48\xd1\x8d\x8e\xc2\xed\xdb\x92\x41\x9f\x4f\ 225 | \x0a\x37\x9b\x95\x8c\xac\xae\x0a\xb0\xc9\x49\x96\x16\x17\xf9\xf5\ 226 | \xf0\x30\xa7\x75\x9d\x9b\xff\xda\x05\xe9\xb9\x39\x2e\x28\x0a\x13\ 227 | \xe9\x34\x15\x73\x73\x78\x55\xb5\xc4\xbf\xa6\x89\xcc\xba\x5c\x22\ 228 | \xb9\x17\x2f\x4a\x4d\x84\xc3\xf0\xd9\x67\x42\xcf\xe1\xc3\x52\xb4\ 229 | \x8a\x22\x27\x4e\xa7\xe1\xeb\xaf\x61\x64\x04\x02\x01\xfe\x3a\x3e\ 230 | \xce\xc9\x89\x09\xde\xd4\x75\x56\x37\xfd\x1a\xf6\xf4\xd0\xda\xd1\ 231 | \xc1\x54\x55\x95\xc8\x6a\x6f\xaf\x48\xad\xaa\xca\xa9\x6e\xde\x84\ 232 | \xb3\x67\xc5\xb9\xa6\x09\x2d\xcf\x3e\x0b\x8f\x3d\x26\x82\x93\xc9\ 233 | \xc8\x9e\xc9\x49\xa1\x2e\x9b\x85\xb7\xde\xda\x38\xd6\x7d\xe7\x01\ 234 | \xbb\x5d\x3e\x3a\x63\x63\x22\xaf\x3e\x1f\xb8\xdd\x22\x30\x33\x33\ 235 | \x12\xf4\xe0\x41\xa1\xc6\xef\x87\xf7\xde\x93\xf7\x9d\x9d\x12\xbc\ 236 | \xf8\x5d\x68\x6f\x87\x50\xe8\x21\x06\x12\x45\x81\xaa\x2a\x38\x7e\ 237 | \x1c\x0e\x1d\x82\x0f\x3e\x80\x4b\x97\xa0\xb9\x19\x5e\x7e\x59\x64\ 238 | \x37\x95\x12\xfe\x6b\x6a\x44\x74\xfc\x7e\x38\x73\x46\x0a\x74\xef\ 239 | \x5e\xa9\x91\xa5\xa5\xff\xc2\x44\x64\xb3\xc1\x0b\x2f\x94\xf4\xbe\ 240 | \xb8\x0a\x05\x91\xd9\x7c\x5e\xaa\xbd\xab\x4b\xb2\xb0\xbe\x2e\x45\ 241 | \x98\xcb\xc9\xf5\x7f\x0c\xe0\xee\x84\x44\x79\xf9\xbd\xcf\x8a\x00\ 242 | \x8a\xb6\xbe\x2e\x7b\x72\x39\xa9\x83\x6c\x56\xae\x37\x5b\xea\xfd\ 243 | \x5e\x18\x86\xf4\xed\x66\x6b\x7d\xbd\x14\xbc\x38\x17\xe4\xf3\xa5\ 244 | \xeb\x62\x41\x6e\x06\x62\xc3\x91\xac\xb2\x92\x78\x3a\x4d\x75\x28\ 245 | \x44\x8d\xc9\x84\xc5\x62\xd9\xf8\xf4\x6b\x6b\xa2\xff\xd9\xac\x58\ 246 | \x3e\x5f\xba\x5e\x59\x81\xeb\xd7\x21\x14\x62\x6e\x7e\x9e\x5f\xcd\ 247 | \xcc\x70\x6e\xcb\x00\x16\x17\xc9\x47\xa3\x0c\x57\x57\x33\xb6\xb0\ 248 | \x40\x53\x38\x4c\x9d\xcd\x26\xdf\xf3\xa2\x04\xe7\xf3\x22\x30\xf1\ 249 | \x78\xe9\xc4\xc5\xd4\x47\xa3\x10\x0c\x92\x5b\x5c\x64\xe8\x93\x4f\ 250 | \xf8\x41\x30\xc8\x1f\xb2\xd9\x8d\x47\x75\xe5\x41\xdc\xdb\xed\x98\ 251 | \xbd\x5e\xbe\xe5\xf1\xf0\x9a\xc7\x43\xeb\xd1\xa3\x68\x0e\x87\x04\ 252 | \x5a\x5e\x96\x2e\xc8\x66\x85\x32\x5d\x87\xa9\x29\x52\x77\xee\x30\ 253 | \x19\x0e\xf3\x5a\x30\xc8\xa7\xba\xbe\xf9\x3f\xc2\x03\x7f\x4c\x0c\ 254 | \x83\xfc\xdc\x1c\xa1\xa5\x25\x46\xd2\x69\xe2\x91\x08\xbe\x44\x02\ 255 | \xcd\x66\x13\xa5\x4b\x26\xc5\xfc\x7e\x98\x9e\x66\x25\x1c\xe6\xd4\ 256 | \x85\x0b\xfc\xec\xd2\x25\xfc\xc5\xb9\xef\xa1\xfe\x0b\xee\xb7\x7a\ 257 | \x7a\x68\x75\x3a\xf9\xa9\xcb\xc5\xb7\xdb\xda\xb0\xc6\xe3\x30\x33\ 258 | \xc3\xd2\xed\xdb\xbc\x3b\x3c\xcc\x1b\xba\x4e\xf4\x9b\xf8\xfb\xc6\ 259 | \x00\xee\xd2\x52\xde\xd0\xc0\xf1\x7d\xfb\x78\x05\x88\xfb\xfd\x9c\ 260 | \xbe\x7e\x9d\x3f\xe9\xfa\xc6\xb3\xff\xff\xd7\x66\xeb\xef\x2f\x57\ 261 | \xd9\x36\x56\x08\xf3\x30\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\ 262 | \x60\x82\ 263 | \x00\x00\x08\x08\ 264 | \x89\ 265 | \x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ 266 | \x00\x00\x20\x00\x00\x00\x20\x08\x06\x00\x00\x00\x73\x7a\x7a\xf4\ 267 | \x00\x00\x07\xcf\x49\x44\x41\x54\x78\x5e\xed\x96\x6b\x6c\x14\xd7\ 268 | \x15\xc7\xff\xf7\xce\x9d\x99\x9d\x7d\x3f\xbd\xde\x5d\xb3\xf8\x01\ 269 | \xc6\x36\x18\x01\x8d\x4d\x54\x30\x09\x29\x04\x44\xd5\xaa\xa5\x55\ 270 | \x69\x50\x94\xd0\x54\x0d\x2a\x5f\xa2\x48\xad\xa2\xa8\x48\x24\x69\ 271 | \xf2\x01\x29\x4a\xda\x7e\xa0\xa4\x0f\xa9\x1f\xd2\x24\x45\x2d\x91\ 272 | \xa2\x08\x55\x09\x0d\x0a\x10\x02\xb5\x21\x04\x99\x38\x04\xb0\x81\ 273 | \xb5\x91\x1f\x6b\xaf\xd7\xeb\xd9\xc7\xbc\x6e\xaf\xc7\x38\x52\x43\ 274 | \x1f\x12\x4d\x3e\x54\xca\x5f\xfb\xd3\xd9\xab\xb9\x73\xce\xf9\x9f\ 275 | \x59\xdd\x1d\x7c\xa9\xcf\x93\xf0\x62\x06\x8f\x06\x2c\xdb\x11\xd2\ 276 | \x56\x3c\x1a\x0b\x2f\xdb\x19\x0e\xa4\xbb\x3d\x74\xd1\x06\x2f\xbe\ 277 | \x50\x65\x37\xcd\x17\xb8\xeb\xc9\xe4\xd2\xf5\x2f\x34\xec\xdd\x70\ 278 | \x20\x7b\xf4\x9e\x83\xd9\xb3\x22\xbe\xbf\xee\xc5\x86\x03\xdd\x4f\ 279 | \xa5\xee\x69\xfd\x5e\x48\x5e\xf1\xa3\x18\x3e\x2b\x82\xff\x51\x1d\ 280 | \xbb\x22\x18\xef\x9b\xa1\xcb\x1e\x4a\x6d\xd7\x12\xca\xb3\x92\x46\ 281 | \x96\x71\x00\x9c\x73\x17\xc7\x12\xd4\x78\xd1\x9c\xb1\x0f\x96\x6f\ 282 | \x1a\xfb\x99\x97\x16\x7a\x7f\x3e\x8a\x05\xd1\x3b\x2a\xfa\x70\x04\ 283 | \x0f\x5e\xb8\x1b\xdd\x7b\xd3\x6b\x40\xe9\xba\xf6\x87\x33\xbb\x42\ 284 | \x8d\xde\x83\x5a\x4c\x5e\xc6\x54\x09\x92\x4c\xc1\x4d\x40\xbf\x5e\ 285 | \xc3\xd4\xb9\xb2\x9e\xff\xa0\x5c\xa8\x4e\xd9\xdf\x95\x83\xd2\xbe\ 286 | \xda\xa4\xe9\x5b\xf5\x58\x02\x0b\x62\xb8\x03\x71\x0e\xbc\xbc\xf2\ 287 | \x34\xdd\xfc\xbb\x96\xc7\x3d\x21\x79\x7b\x20\xeb\xb1\x3d\x11\x16\ 288 | \xb0\x2d\x0e\x2a\x71\x94\xf3\x06\x26\xcf\xcf\x5a\x85\x81\x4a\xff\ 289 | \xe4\x47\xb5\x63\xe5\x51\xf3\x94\x27\xc6\x72\xcd\xdb\x43\x5d\x92\ 290 | \x42\x97\x80\xe0\xc3\x3b\x78\x04\x0c\xbf\xd8\x1c\xc2\xf5\x09\x5b\ 291 | \x6e\xca\xd0\xc6\x80\x1f\xf7\x9d\xd8\x14\xfd\x89\xde\xea\x5b\x42\ 292 | \x08\xe0\x38\x1c\x5c\x50\x29\x18\x18\x39\x59\xb0\xc7\xcf\x96\x4f\ 293 | \x8e\x9e\xd1\xdf\xb2\x6b\xfc\x38\x80\x0f\x04\xba\xf8\x61\x52\x70\ 294 | \x4e\x40\x89\xdd\xff\xd2\xe4\x7f\x6f\x20\x0c\x09\x2f\x7c\x2b\x86\ 295 | \x2b\x23\x96\x92\x49\xd1\x46\xbf\x0f\x3d\x3e\x1f\xb6\xfa\xbd\x58\ 296 | \xeb\xd5\x78\xfa\x48\x47\x44\x1a\x5e\x11\x06\xb1\x1d\x38\x36\x87\ 297 | \x55\x73\x90\x3b\x39\x89\xc2\x7b\x33\xd7\x6f\x1c\x9f\xfd\x93\xae\ 298 | \x3b\xc7\x00\xbc\x2b\xa8\xfc\x7b\x5b\x9f\x51\x82\x50\x1c\x78\x20\ 299 | \x89\x8b\x43\x35\xa5\x3e\xc9\x9a\x25\x2f\x7a\x3a\x3b\xe9\x56\x55\ 300 | \xe5\xdd\x1e\x0f\x4f\x7b\x54\x50\x0f\x23\x20\x04\x20\x32\x05\x53\ 301 | \x24\x10\x9b\xb8\x13\x98\xc9\x55\x50\xf9\x58\x47\xe3\x94\x99\x5e\ 302 | \xd5\xae\x7d\xa7\x2d\xa1\x56\x13\xb2\x34\x78\xfe\x52\xe5\x6a\x5d\ 303 | \x98\xd9\xcf\x9e\x99\xfe\xd7\x0d\x74\xaa\x04\xfb\x76\xd4\xa1\xff\ 304 | \x5a\x45\x4d\x84\xe5\x16\x1d\xf6\x86\xa5\x6d\xd2\x16\xc2\xec\x6e\ 305 | \xca\xec\x7a\xc6\x1c\xca\x24\x02\x22\xe0\x9c\xc0\x72\x16\xee\x26\ 306 | \x90\x55\x09\xb0\x08\x6c\xd3\x41\x61\xb0\x0c\x65\xca\x84\xc7\xb2\ 307 | \xe4\x96\x8c\xdc\xb2\xaa\x89\xec\x95\x41\x77\xd5\xd7\xfb\xdf\x2e\ 308 | \x16\xf9\x9f\xf7\x49\x81\xf7\x9f\x7a\x6f\x77\xb1\x59\x7a\x1e\x43\ 309 | \xb7\x72\xb0\xfd\xf7\x87\x65\x9f\x2a\xb5\x4f\x97\x9d\x9e\x96\x45\ 310 | \xde\x4d\xf5\x29\xdf\xda\x32\xaf\x26\xf3\xc5\x22\xe5\xb6\x0d\xc5\ 311 | \xb5\x4a\x41\xe7\x70\xdc\x5a\xae\x38\x08\xb8\x34\x3f\x01\x10\x02\ 312 | \x42\x09\xc2\x8b\xbd\xc8\x45\x4b\x30\x8a\x16\x2c\x9b\x83\x10\x9b\ 313 | \x06\x7c\x3c\x1b\x0d\x4a\x3f\x4c\xc6\xe5\x07\x1a\xb2\x75\xe7\xfe\ 314 | \xf8\xd0\x2b\x87\x9f\xf8\x66\xfc\xaf\x05\xdd\xba\xac\x29\xd4\xa2\ 315 | \x00\xb2\xa6\xcd\x1f\xcd\xcf\xda\xdd\x1e\xaf\x7c\x77\x43\x36\x94\ 316 | \x6a\x6f\x6d\xa0\x2b\x3b\x5a\x50\x5f\x9f\x80\x24\xcb\x73\xc9\x04\ 317 | \x8e\x1b\xcd\x5b\x18\x62\xcd\x19\x85\xa4\x4a\x20\x22\xda\x55\x07\ 318 | \x5e\x99\x22\x00\xc0\xc3\x00\xc7\x99\xdf\xc7\x14\x0f\xc2\xf5\x29\ 319 | \x2c\xed\x5a\xed\xed\xda\xba\x61\x7d\x32\x5b\xff\x9c\xc3\xf9\x4b\ 320 | \x7e\x55\xda\x73\x69\xcc\x90\xc8\xf2\xa4\xcc\x98\xe5\xc4\x1e\xdb\ 321 | \x96\xfc\xd9\x9a\xce\xe8\x9e\x60\xd8\x2b\x51\xa6\x80\xa9\x2a\x88\ 322 | \x24\xa3\x5c\x35\x30\x3e\x91\x47\x7e\x7c\x1c\x46\x45\x87\x44\x00\ 323 | \x26\x51\x40\xc4\xde\xce\x04\x8a\x49\x0d\xf6\x40\x01\xe6\x65\xe1\ 324 | \x3c\x57\x45\x9c\x70\x34\x44\x54\x34\x37\x44\xd1\xdc\x94\x46\x5d\ 325 | \x3a\x03\x5f\x38\x0a\xa6\x6a\x90\x18\xc3\xf8\x48\xde\x3a\xfc\xea\ 326 | \xf1\x5f\x5e\x18\x18\xfd\x43\xbe\x46\x06\x48\x8f\x02\xba\x67\x67\ 327 | \x7a\xcf\x92\x25\xc1\xfd\xe1\xa8\xd7\x4b\x99\x2c\x5c\x2b\x60\x8a\ 328 | \x02\x49\x51\xc1\x54\x8f\x58\xab\x30\x4c\x0b\x93\xa2\x91\xd1\x91\ 329 | \x1c\x66\xa6\x26\xe1\x58\x26\x0c\x26\xa1\x54\xb6\x30\x36\x51\x81\ 330 | \xb0\x81\x78\xd8\x87\xc6\x86\x38\x32\xe9\x24\x22\xb1\x28\x54\xcd\ 331 | \x07\x2a\x2b\xee\x14\x45\x5e\x37\x12\x2a\xe1\x93\x0f\x07\xaf\xbc\ 332 | \xf5\xfa\xa9\x6f\x27\xe3\xbe\x7e\x76\xef\xda\x60\x56\x56\xe8\x0f\ 333 | \x04\x5e\x42\x00\x4a\x09\x88\xfb\xdc\x6f\x45\xcc\x47\x9f\xdf\x8f\ 334 | \x60\x34\x86\x6c\x6b\x2b\x0a\x93\x79\x0c\x0f\x0e\x22\x7f\x73\x04\ 335 | \x4c\x25\x88\x34\xfa\x91\xa9\x8b\x20\x1e\x09\xc2\xe3\xf5\x82\x89\ 336 | \xa2\x70\x1c\x58\x46\x0d\x12\x5c\x7d\x9a\x47\x52\x28\x9a\xda\x17\ 337 | \x2d\xb9\x6b\xac\xed\xc9\x43\xbf\x3f\xb1\x9b\xbd\x76\xb1\x3c\x76\ 338 | \x76\xdc\x7a\xa6\x73\xa8\xb2\xf3\x2b\xad\xc1\x75\xad\x2d\xd1\x54\ 339 | \x24\xa6\x52\x42\x28\x20\x58\x68\x06\x10\x08\x29\x8a\x82\x74\xb6\ 340 | \x11\xc9\x86\x2c\x46\x06\x87\x50\xbe\x39\x08\x99\x72\x77\xbc\x84\ 341 | \x70\xd8\xa6\x01\x21\xb7\xb0\x6b\xe2\x56\x0e\x42\xa9\xbb\xae\x94\ 342 | \x6b\x18\x1f\x2d\x9a\x13\x85\x72\x46\xab\xf3\x25\xd8\xe5\x29\xab\ 343 | \x22\x38\x72\xe4\x52\xb9\xb7\xad\x77\xaa\xeb\xe9\x5d\x81\xe7\xd6\ 344 | \x24\x43\xcb\x2d\xcb\x84\x26\xc3\x75\xbf\xd0\xc4\x02\x1c\xc0\xf4\ 345 | \x64\x11\xa6\xe1\x40\x89\xa4\x60\x4f\x8f\x00\x96\x0d\xca\x17\x9c\ 346 | \x2e\x40\x61\x8b\x68\x3b\x1c\xa8\xd6\x50\x9c\x9a\xe1\x47\xde\x19\ 347 | \x3a\x71\xf4\xdc\xd8\x9b\x17\x6e\xcc\xfe\xed\xc6\x2c\x1f\x66\x98\ 348 | \x97\xb9\x7e\xb1\x7a\xb3\xef\x7a\xed\x68\x2c\xe2\xfd\x71\x2c\x1e\ 349 | \x5e\xae\xeb\x55\xcc\x08\x98\x61\x20\x18\x64\xf0\x2a\x9f\x26\xc5\ 350 | \xec\xcc\x2c\x06\x3f\x1e\x44\x32\xae\x81\x04\x13\x30\x4a\xd3\x20\ 351 | \xb6\x0e\xc7\x01\x60\x13\xb7\x4f\x87\x13\xd4\x2c\x11\x2b\x16\x28\ 352 | \x1c\x48\x30\x31\x33\x31\x63\xe6\x72\xf9\xdf\xbe\xf9\x51\xe9\x10\ 353 | \x00\x53\xc0\x29\x6e\x89\x12\x02\x09\x70\xc0\x1d\x81\x05\xbf\x26\ 354 | \x21\x1a\x52\xdc\x9b\xc7\xc6\x0a\x18\xce\x4d\xa0\x54\x2a\xa3\xac\ 355 | \x57\x70\xf9\xe2\x55\x18\xfa\x2c\x14\x89\xc3\xe3\x51\x50\x93\xa3\ 356 | \x70\x88\xe4\x9e\x86\x86\x45\x50\x32\x18\x74\x8b\xc1\x01\x15\x7b\ 357 | \x6c\xc8\x30\x01\xc7\x02\xb8\xc3\xeb\x83\x6c\xfa\xf0\xae\x94\x01\ 358 | \x80\xff\xd3\x51\xcc\xc1\x41\x00\xb7\xbe\x63\x9a\x00\x77\x00\xc7\ 359 | \x86\x4f\xe5\x50\x29\xa0\x97\x4b\x18\xbe\x32\x8d\x9a\xc9\x31\x53\ 360 | \x9c\x45\xc8\x4b\x40\xc4\x75\x55\x21\x80\xa4\x42\x27\x11\x50\xca\ 361 | \xa1\x78\x3c\x08\x68\x92\x28\xec\x00\xb6\x29\x3e\xb6\x48\x63\xb9\ 362 | \xb8\xde\x38\x87\x44\x6f\xff\x2f\x70\x8b\xd3\x85\x06\xdc\xcd\xb6\ 363 | \x7b\x0e\x30\x5f\x00\x76\x69\x0a\x9a\xcc\xa1\x10\x8e\x72\xd5\x04\ 364 | \x34\x22\xd6\x70\xf7\x31\xc2\xe1\x15\x05\xb9\x1a\x9a\x2f\x4c\x45\ 365 | \x41\xcb\x10\xd7\x44\x1e\x0e\x11\x6d\x17\xee\xb8\x2c\xb8\xbd\xfd\ 366 | \x85\xa4\x6a\x01\x65\x80\xcf\x96\x2a\x55\xbd\xa8\xbb\x49\x88\xc4\ 367 | \x10\x6c\x59\x89\x60\xe3\x0a\xf8\xd2\x2d\xa0\xb2\x0c\x0f\x73\x90\ 368 | \x08\x52\xb7\xa1\x85\x46\xeb\xa2\x2a\x92\x11\x15\x2a\x9b\x77\xc8\ 369 | \x7c\xa2\x99\x6c\x3b\x82\x4d\xcb\x01\xd7\x94\x05\xb8\xc6\xe6\xae\ 370 | \x43\xc0\x6f\x6f\xe0\xe2\xb8\x01\x0b\x30\x5e\x39\x36\xfc\x9b\x97\ 371 | \x5f\xbf\xf8\x46\x5f\x5f\x6e\x7c\x6a\x62\x86\x8b\x29\x40\xab\xcb\ 372 | \x20\xd4\xdc\x09\x25\x14\x87\x6d\x9a\xe0\x6e\x61\x6b\xde\x9d\x35\ 373 | \x97\x5c\x44\x77\xdc\xa6\x7b\xd0\x04\x16\x77\xc0\xbf\x68\x29\xbc\ 374 | \x75\x0d\xe0\x84\xa2\x38\x5d\xe5\x03\x57\x8a\xd3\x67\xfa\x8b\xc7\ 375 | \x3f\x19\xab\x5d\xbb\x3a\x61\xfc\xc7\x77\x42\x45\x90\x5a\x91\x60\ 376 | \x6b\x36\xae\x4c\x6c\xb9\xef\x6b\xab\xef\x5d\xdd\xd5\xd1\x94\x6a\ 377 | \xcc\x28\xd3\x97\xce\xa0\x78\x6d\xc0\x75\xc0\x85\x23\xc5\xeb\x47\ 378 | \x28\x9d\x75\x9b\xb0\x2d\x13\x8e\x69\x80\x2a\x1e\xc4\x3a\x7b\x50\ 379 | \xd6\x0d\x5c\x1b\xb8\xa2\x9f\x79\xfb\xdd\xab\xe7\x2e\xe5\x4f\xf7\ 380 | \x0d\x55\x4e\xf4\x8f\x19\x7f\xaf\xda\x18\x02\x60\xde\xde\xc0\xed\ 381 | \x48\x82\x70\x9d\x07\x6d\x1b\x3b\xe3\xf7\x6d\xfc\x6a\xeb\xfd\xad\ 382 | \x71\x6b\x65\x54\x29\x05\x35\x4d\x02\x38\xc0\x34\x1f\x82\xc9\x8c\ 383 | \x3b\x0d\xdb\x30\xa0\x97\xca\xc8\x4f\x19\xb5\x9b\x95\x40\xae\xef\ 384 | \xc2\x8d\xde\x53\xe7\x73\xc7\xcf\x5e\x2f\xf7\x96\x2c\x5c\x03\x50\ 385 | \x14\x58\xb8\x03\x11\x81\x4f\x21\x68\x5f\x97\x55\x1f\x79\x62\x73\ 386 | \xf4\xd0\x6b\xbb\xb3\xc3\xa7\x9f\x6e\xb5\x2f\xff\xba\x8b\x0f\xbf\ 387 | \xba\x8d\x9f\xff\xd5\x7a\xf3\x2f\x8f\x77\xe4\xf6\x7d\x23\xf5\xc6\ 388 | \xd7\xdb\x7c\x3f\x4d\xa8\xa4\x07\x40\xbd\x40\xc1\xe7\x2c\x45\x90\ 389 | \x59\x1a\x65\xdb\x1e\x59\x1b\x7c\xf1\xc0\x83\x8b\x7a\x9f\xff\xfe\ 390 | \xe2\x77\x76\xac\x0e\x3e\xd3\x18\x94\xb6\x00\xc8\x0a\x34\x01\xc1\ 391 | \x17\x2c\x2a\x88\x68\x14\x1d\x32\x41\x0b\x00\xbf\x80\xe2\xff\x51\ 392 | \x5f\xea\x1f\xf7\x30\x84\xbb\x78\x25\xd6\xa3\x00\x00\x00\x00\x49\ 393 | \x45\x4e\x44\xae\x42\x60\x82\ 394 | " 395 | 396 | qt_resource_name = "\ 397 | \x00\x07\ 398 | \x07\x3b\xe0\xb3\ 399 | \x00\x70\ 400 | \x00\x6c\x00\x75\x00\x67\x00\x69\x00\x6e\x00\x73\ 401 | \x00\x0e\ 402 | \x0a\x79\xb2\xf5\ 403 | \x00\x51\ 404 | \x00\x67\x00\x69\x00\x73\x00\x47\x00\x65\x00\x6f\x00\x70\x00\x61\x00\x63\x00\x6b\x00\x61\x00\x67\x00\x65\ 405 | \x00\x08\ 406 | \x0b\x77\x58\x47\ 407 | \x00\x72\ 408 | \x00\x65\x00\x61\x00\x64\x00\x2e\x00\x70\x00\x6e\x00\x67\ 409 | \x00\x09\ 410 | \x06\xc7\x98\x67\ 411 | \x00\x61\ 412 | \x00\x62\x00\x6f\x00\x75\x00\x74\x00\x2e\x00\x70\x00\x6e\x00\x67\ 413 | \x00\x09\ 414 | \x00\xa8\xaa\x67\ 415 | \x00\x77\ 416 | \x00\x72\x00\x69\x00\x74\x00\x65\x00\x2e\x00\x70\x00\x6e\x00\x67\ 417 | " 418 | 419 | qt_resource_struct = "\ 420 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ 421 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ 422 | \x00\x00\x00\x14\x00\x02\x00\x00\x00\x03\x00\x00\x00\x03\ 423 | \x00\x00\x00\x64\x00\x00\x00\x00\x00\x01\x00\x00\x0f\x5f\ 424 | \x00\x00\x00\x4c\x00\x00\x00\x00\x00\x01\x00\x00\x08\x88\ 425 | \x00\x00\x00\x36\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ 426 | " 427 | 428 | def qInitResources(): 429 | QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) 430 | 431 | def qCleanupResources(): 432 | QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) 433 | 434 | qInitResources() 435 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | write.png 4 | read.png 5 | about.png 6 | 7 | 8 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/qgis_plugin/qgpkg/test/__init__.py -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/ui_about_dialog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'ui_about_dialog.ui' 4 | # 5 | # Created by: PyQt4 UI code generator 4.11.4 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt4 import QtCore, QtGui 10 | 11 | try: 12 | _fromUtf8 = QtCore.QString.fromUtf8 13 | except AttributeError: 14 | def _fromUtf8(s): 15 | return s 16 | 17 | try: 18 | _encoding = QtGui.QApplication.UnicodeUTF8 19 | def _translate(context, text, disambig): 20 | return QtGui.QApplication.translate(context, text, disambig, _encoding) 21 | except AttributeError: 22 | def _translate(context, text, disambig): 23 | return QtGui.QApplication.translate(context, text, disambig) 24 | 25 | class Ui_qgpkgDlg(object): 26 | def setupUi(self, qgpkgDlg): 27 | qgpkgDlg.setObjectName(_fromUtf8("qgpkgDlg")) 28 | qgpkgDlg.resize(456, 358) 29 | icon = QtGui.QIcon() 30 | icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/plugins/QgisGeopackage/about.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) 31 | qgpkgDlg.setWindowIcon(icon) 32 | self.verticalLayout = QtGui.QVBoxLayout(qgpkgDlg) 33 | self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) 34 | self.textEdit = QtGui.QTextEdit(qgpkgDlg) 35 | self.textEdit.setReadOnly(True) 36 | self.textEdit.setObjectName(_fromUtf8("textEdit")) 37 | self.verticalLayout.addWidget(self.textEdit) 38 | self.button_box = QtGui.QDialogButtonBox(qgpkgDlg) 39 | self.button_box.setOrientation(QtCore.Qt.Horizontal) 40 | self.button_box.setStandardButtons(QtGui.QDialogButtonBox.Close) 41 | self.button_box.setObjectName(_fromUtf8("button_box")) 42 | self.verticalLayout.addWidget(self.button_box) 43 | 44 | self.retranslateUi(qgpkgDlg) 45 | QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(_fromUtf8("accepted()")), qgpkgDlg.accept) 46 | QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(_fromUtf8("rejected()")), qgpkgDlg.reject) 47 | QtCore.QMetaObject.connectSlotsByName(qgpkgDlg) 48 | 49 | def retranslateUi(self, qgpkgDlg): 50 | qgpkgDlg.setWindowTitle(_translate("qgpkgDlg", "QGIS map project GeoPackage extension", None)) 51 | self.textEdit.setHtml(_translate("qgpkgDlg", "\n" 52 | "\n" 55 | "

ABOUT

\n" 56 | "


\n" 57 | "

This plugin reads and writes QGIS map projects, including data, style and related resources from/into a geopackage file.

\n" 58 | "


\n" 59 | "

It supports the qgis and ows geopackage extensions. The qgis geopackage extension was created with the goal of enabling QGIS users to share their projects, while the ows geopackage extension was designed for interoperability, enabling porting map projects between different mapping frameworks; on the former the approach is to store a QGIS project file in an sqlite table, while on the latter the project is encoded using OGC OWS context standard, on a different sqlite table

\n" 60 | "


\n" 61 | "

Currently, writing is only supported using the qgis geopackage extension.

\n" 62 | "


\n" 63 | "

Authors: Cedric Christen, Pirmin Kalberer (pka@sourcepole.ch), Joana Simoes (joana.simoes@geocat.net), Paul van Genuchten

\n" 64 | "

from SourcePole and GeoCat

", None)) 65 | 66 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/ui_about_dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | qgpkgDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 456 10 | 358 11 | 12 | 13 | 14 | QGIS map project GeoPackage extension 15 | 16 | 17 | 18 | :/plugins/QgisGeopackage/about.png:/plugins/QgisGeopackage/about.png 19 | 20 | 21 | 22 | 23 | 24 | true 25 | 26 | 27 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 28 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 29 | p, li { white-space: pre-wrap; } 30 | </style></head><body style=" font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;"> 31 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:9pt; font-weight:600;">ABOUT</span></p> 32 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:9pt;"><br /></p> 33 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:9pt;">This plugin reads and writes QGIS map projects, including data, style and related resources from/into a geopackage file.</span></p> 34 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> 35 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:9pt;">It supports the </span><a href="https://github.com/pka/qgpkg/blob/master/qgis_geopackage_extension.md"><span style=" text-decoration: underline; color:#2980b9;">qgis</span></a><span style=" font-family:'Ubuntu'; font-size:9pt;"> and </span><a href="https://github.com/pka/qgpkg/blob/master/ows_geopackage_extension.md"><span style=" text-decoration: underline; color:#2980b9;">ows</span></a><span style=" font-family:'Ubuntu'; font-size:9pt;"> geopackage extensions. The </span><span style=" font-family:'Ubuntu'; font-size:9pt; font-weight:600;">qgis geopackage extension</span><span style=" font-family:'Ubuntu'; font-size:9pt;"> was created with the goal of enabling QGIS users to share their projects, while the </span><span style=" font-family:'Ubuntu'; font-size:9pt; font-weight:600;">ows geopackage extension</span><span style=" font-family:'Ubuntu'; font-size:9pt;"> was designed for interoperability, enabling porting map projects between different mapping frameworks; on the former the approach is to store a QGIS project file in an sqlite table, while on the latter the project is encoded using OGC OWS context standard, on a different sqlite table</span></p> 36 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:9pt;"><br /></p> 37 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:9pt;">Currently, writing is only supported using the qgis geopackage extension.</span></p> 38 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Ubuntu'; font-size:9pt;"><br /></p> 39 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:9pt;">Authors: Cedric Christen, Pirmin Kalberer (pka@sourcepole.ch), Joana Simoes (joana.simoes@geocat.net), Paul van Genuchten</span></p> 40 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:9pt;">from SourcePole and GeoCat</span></p></body></html> 41 | 42 | 43 | 44 | 45 | 46 | 47 | Qt::Horizontal 48 | 49 | 50 | QDialogButtonBox::Close 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | button_box 60 | accepted() 61 | qgpkgDlg 62 | accept() 63 | 64 | 65 | 20 66 | 20 67 | 68 | 69 | 20 70 | 20 71 | 72 | 73 | 74 | 75 | button_box 76 | rejected() 77 | qgpkgDlg 78 | reject() 79 | 80 | 81 | 20 82 | 20 83 | 84 | 85 | 20 86 | 20 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /qgis_plugin/qgpkg/write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/qgis_plugin/qgpkg/write.png -------------------------------------------------------------------------------- /qgisgpkg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/qgisgpkg/__init__.py -------------------------------------------------------------------------------- /qgisgpkg/qgpkg.py: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE in the QGIS plugin directory. 2 | # Edit the original library file in the qgpkg directory and 3 | # execute `make` to update the QGIS plugin files. 4 | import os 5 | import sqlite3 6 | import logging 7 | 8 | logger = logging.getLogger('qgpkg') 9 | 10 | class QGpkg: 11 | """Base class for handling data and style information within a GeoPackage database file""" 12 | 13 | def read(self, gpkg_path): pass 14 | """Abstract method to read a QGIS project from geopackage. 15 | 16 | Args: 17 | gpkg_path: The geopackage path on disk. 18 | """ 19 | 20 | def write(self, project_path): pass 21 | """Abstract method to write a QGIS project into a geopackage. 22 | 23 | Args: 24 | gpkg_path: The geopackage path on disk. 25 | """ 26 | 27 | def __init__(self, gpkg, logfunc): 28 | self._gpkg = gpkg 29 | self._log = logfunc 30 | 31 | def log(self, lvl, msg, *args, **kwargs): 32 | self._log(lvl, msg, *args, **kwargs) 33 | 34 | def _connect_read_only(self): 35 | ''' Connect database with sqlite3 ''' 36 | try: 37 | conn = sqlite3.connect(self._gpkg) 38 | # Open in read-only mode needs Python 3.4+ 39 | # conn = sqlite3.connect('file:%s?mode=ro' % self._gpkg, uri=True) 40 | # Workaround: 41 | if os.stat(self._gpkg).st_size == 0: 42 | os.remove(self._gpkg) 43 | self.log(logging.ERROR, 44 | "Couldn't find GeoPackage '%s'" % self._gpkg) 45 | return None 46 | conn.row_factory = sqlite3.Row 47 | return conn.cursor() 48 | except sqlite3.Error as e: 49 | self.log(logging.ERROR, 50 | "Couldn't connect to GeoPackage: %s" % e.args[0]) 51 | return None 52 | 53 | def info(self): 54 | ''' Show information about GeoPackage ''' 55 | cur = self._connect_read_only() 56 | if not cur: 57 | return 58 | data_type = None 59 | try: 60 | for row in cur.execute('''SELECT * FROM gpkg_contents 61 | ORDER BY data_type'''): 62 | if row['data_type'] != data_type: 63 | data_type = row['data_type'] 64 | print("gpkg_contents %s:" % data_type) 65 | print(row['table_name']) 66 | except sqlite3.Error as e: 67 | self.log(logging.ERROR, "GeoPackage access error: ", e.args[0]) 68 | 69 | try: 70 | rows = list(cur.execute('''SELECT extension_name FROM gpkg_extensions''')) 71 | if len(rows) > 0: 72 | print("GPKG extensions:") 73 | for row in rows: 74 | print(row['extension_name']) 75 | except sqlite3.Error: 76 | pass 77 | 78 | try: 79 | rows = list(cur.execute('''SELECT name FROM qgis_projects''')) 80 | if len(rows) > 0: 81 | print("QGIS projects:") 82 | for row in rows: 83 | print(row['name']) 84 | except sqlite3.Error: 85 | pass 86 | 87 | try: 88 | rows = list(cur.execute('''SELECT name, mime_type FROM qgis_resources''')) 89 | if len(rows) > 0: 90 | print("QGIS recources:") 91 | for row in rows: 92 | print(row['name'] + ' (%s)' % row['mime_type']) 93 | except sqlite3.Error: 94 | pass 95 | 96 | def database_connect(self, path): 97 | ''' Connect database with sqlite3 ''' 98 | try: 99 | self.conn = sqlite3.connect(path) 100 | self.c = self.conn.cursor() 101 | return True 102 | except sqlite3.Error as e: 103 | self.log(logging.ERROR, 104 | "Couldn't connect to GeoPackage: %s" % e.args[0]) 105 | return False 106 | 107 | def check_gpkg(self, path): 108 | ''' Check if file is GeoPackage ''' 109 | try: 110 | self.c.execute('SELECT * FROM gpkg_contents') 111 | self.c.fetchone() 112 | return True 113 | except: 114 | return False 115 | 116 | def make_path_absolute(self, path, project_path): 117 | ''' Make path absolut and handle multiplatform issues ''' 118 | if not os.path.isabs(path): 119 | path = os.path.join(os.path.dirname(project_path), path) 120 | return os.path.normpath(path) 121 | -------------------------------------------------------------------------------- /qgisgpkg/qgpkg_owc.py: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE in the QGIS plugin directory. 2 | # Edit the original library file in the qgpkg directory and 3 | # execute `make` to update the QGIS plugin files. 4 | from __future__ import print_function 5 | import sys 6 | import os 7 | import sqlite3 8 | import tempfile 9 | import logging 10 | from xml.etree import ElementTree as ET 11 | from qgis.core import * 12 | from qgis.utils import * 13 | from PyQt4.QtXml import * 14 | from PyQt4.QtCore import * 15 | from StringIO import StringIO 16 | from urlparse import urlparse 17 | import sys 18 | 19 | from qgpkg import QGpkg 20 | 21 | logger = logging.getLogger('qgpkg') 22 | 23 | # Debug code for Pycharm 24 | #sys.path.append('/home/joana/Downloads/pycharm-2016.3.3/debug-eggs/pycharm-debug.egg') 25 | #import pydevd 26 | 27 | #pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True) 28 | 29 | 30 | class QGpkg_owc (QGpkg): 31 | """Read and write QGIS mapping information in a GeoPackage database file, using this spec: 32 | https://github.com/pka/qgpkg/blob/master/ows_geopackage_extension.md 33 | """ 34 | 35 | def write(self, project_path): 36 | self.log(logging.ERROR, u"Sorry, but it appears that writing into this geopackage extension was not implemented yet!") 37 | return 38 | 39 | def read(self, gpkg_path): 40 | 41 | iface.newProject(True) # Clear project, before opening 42 | 43 | ''' Read QGIS project from GeoPackage ''' 44 | # Check if it's a GeoPackage Database 45 | self.database_connect(gpkg_path) 46 | if not self.check_gpkg(gpkg_path): 47 | self.log(logging.ERROR, u"No valid GeoPackage selected.") 48 | return 49 | 50 | try: 51 | self.c.execute('SELECT table_name FROM gpkg_contents') 52 | except sqlite3.OperationalError: 53 | self.log(logging.ERROR, u"Unable to read table Name.") 54 | return 55 | 56 | table_names = self.c.fetchall() 57 | 58 | db_name = QFileInfo(gpkg_path).baseName() 59 | 60 | # Load OWS Context 61 | try: 62 | self.c.execute('SELECT content FROM owc_context') 63 | except sqlite3.OperationalError: 64 | self.log(logging.ERROR, u"Unable to read table owc_context.") 65 | return 66 | 67 | context = self.c.fetchone() 68 | 69 | if context is None: 70 | self.log(logging.ERROR, u"No record found on table owc_context!") 71 | return 72 | 73 | # Everything is read from the context 74 | self.loadContext(context[0], gpkg_path) 75 | 76 | # TODO: read resources 77 | 78 | def loadContext(self, context, gpkg_path): 79 | """Parses and applies the information on OWC_context. 80 | 81 | Args: 82 | context: The contents of owc_context table. 83 | gpkg_path: The path of the gpkg file. 84 | """ 85 | it = ET.iterparse(StringIO(context)) 86 | for _, el in it: 87 | if '}' in el.tag: 88 | el.tag = el.tag.split('}', 1)[1] # strip all namespaces 89 | root = it.root 90 | 91 | # Missing mandatory elements 92 | # spec reference 93 | spec_elem = root.find("specReference") 94 | # if spec_elem is None: 95 | # self.log(logging.ERROR, u"Could not parse project spec feference.") 96 | # return 97 | # Language 98 | lang_elem = root.find("language") 99 | # if lang_elem is None: 100 | # self.log(logging.ERROR, u"Could not parse project language.") 101 | # return 102 | 103 | # Parse project id (mandatory) 104 | id_elem = root.find("id") 105 | if id_elem is None: 106 | self.log(logging.ERROR, u"Could not parse project id.") 107 | return 108 | 109 | # Parse project title (mandatory) 110 | title_elem = root.find("title") 111 | if title_elem is None: 112 | self.log(logging.ERROR, u"Could not parse project title.") 113 | return 114 | 115 | QgsProject.instance().setTitle(title_elem.text) 116 | 117 | # Parse bbox, if it exists (not owc) 118 | where_elem = root.find("where") 119 | if where_elem is not None: 120 | self.loadBBbox(where_elem) 121 | 122 | # OWC (optional) elements 123 | # Parse abstract (optional) 124 | abstract_elem = root.find("abstract") 125 | 126 | # Parse update date (updateDate?) (optional) 127 | update_elem = root.find("update") 128 | 129 | # Parse author (optional) 130 | author_elem = root.find("author") 131 | # TODO: parse comma separated list 132 | 133 | # Parse publisher (optional) 134 | publisher_elem = root.find("publisher") 135 | 136 | # Parse creator (optional) 137 | creator_elem = root.find("creator") 138 | 139 | # Parse rights (optional) 140 | rights_elem = root.find("rights") 141 | 142 | # Parse area of interest (optional) 143 | aio_elem = root.find("areaOfInterest") 144 | # TODO: parse GM_Envelope 145 | 146 | # Parse time interval of interest (optional) 147 | time_elem = root.find("timeIntervalOfInterest") 148 | 149 | # Parse keyword (optional) 150 | keyword_elem = root.find("keyword") 151 | 152 | # Parse context metadata (optional) 153 | metadata_elem = root.find("contextMetadata") 154 | 155 | entry_elems = root.findall("entry") # owc:resource? 156 | if entry_elems is not None: 157 | 158 | entry_elems.reverse() 159 | # Load every entry 160 | for entry_elem in entry_elems: 161 | self.loadOWCLayer(gpkg_path, entry_elem) 162 | 163 | def loadOWCLayer(self, gpkg_path, entry_elem): 164 | """Parses layer information from an entry, on OWC_context, and uses it to load and style the layer. 165 | 166 | Args: 167 | gpkg_path: The geopackage path. 168 | entry_elem: The entry xml node. 169 | """ 170 | 171 | # Id: is it called code? 172 | id_elem = entry_elem.find("id") 173 | if id_elem is None: 174 | self.log(logging.ERROR, u"Could not parse layer uri.") 175 | return 176 | 177 | # Parse RFC and check if there is a valid schema 178 | parsed_url = urlparse(id_elem.text) 179 | if (parsed_url.scheme) is None: 180 | self.log(logging.ERROR, u"Invalid layer uri.") 181 | return 182 | 183 | # Mandatory 184 | title_elem = entry_elem.find("title") 185 | if title_elem is None: 186 | self.log(logging.ERROR, u"Could not parse layer title.") 187 | return 188 | 189 | # TODO: make offering more general, to support other types of data formats (e.g.: wms) 190 | offering_elem = entry_elem.find("offering") 191 | if offering_elem is not None: 192 | # Mandatory 193 | content_elem = offering_elem.find("content") 194 | if content_elem is None: 195 | self.log(logging.ERROR, u"Failed to content '" + name + "' layer!") 196 | return; 197 | href = content_elem.get("href") 198 | name = self.find_between(href, "#table=") 199 | if name is None: 200 | self._log(logging.ERROR, u"Could not parse table name.") 201 | return 202 | 203 | layer = self.loadLayer(gpkg_path, name, title_elem.text) 204 | if layer is None or not layer.isValid(): 205 | self.log(logging.ERROR, u"Layer '" + name + "' failed to load!") 206 | return; 207 | 208 | # layer.setShortName(name) 209 | 210 | # Check visibility (mandatory) 211 | visibility = entry_elem.find("category").get("term") 212 | if visibility is None: 213 | self.log(logging.ERROR, u"Failed to read visibility for '" + name + "' layer!") 214 | return; 215 | 216 | iface.legendInterface().setLayerVisible(layer, visibility.lower() == 'true') 217 | 218 | # Read style (optional) 219 | style_elem = offering_elem.find("styleSet") 220 | if style_elem is not None: 221 | self.loadOWCStyle(style_elem, title_elem.text) 222 | 223 | # Read other OWC (optional) elements ################## 224 | 225 | # Parse abstract (optional) 226 | abstract_elem = entry_elem.find("abstract") 227 | if abstract_elem is not None: 228 | layer.setAbstract(abstract_elem.text) 229 | 230 | # Parse update date (optional): shouldn't this be OWC:updateDate ? 231 | date_elem = entry_elem.find("updated") 232 | 233 | # Parse author (optional) 234 | author_elem = entry_elem.find("author") 235 | if author_elem is not None: 236 | layer.setAttribution(author_elem.text) 237 | 238 | # Parse publisher (optional) 239 | publisher_elem = entry_elem.find("publisher") 240 | 241 | # Parse rights (optional) 242 | rights_elem = entry_elem.find("rights") 243 | 244 | # Parse geospatial extent (optional) 245 | ext_elem = entry_elem.find("geospatialExtent") 246 | # TODO: parse GM_envelope 247 | 248 | # Parse temporal extent (optional) 249 | temp_elem = entry_elem.find("temporalExtent") 250 | # TODO: parse TM_GeometricPrimitive 251 | 252 | # Parse content description (optional) 253 | desc_elem = entry_elem.find("contentDescription") 254 | 255 | # Parse preview (optional) 256 | prev_elem = entry_elem.find("preview") 257 | # TODO: validate uri 258 | 259 | # Parse content reference (optional) 260 | ref_elem = entry_elem.find("contentByRef") 261 | # TODO: validate uri 262 | 263 | # Parse status (optional) 264 | active_elem = entry_elem.find("active") 265 | # TODO: validate boolean 266 | 267 | # Parse keyword (optional) 268 | keyword_elem = entry_elem.find("keyword") 269 | if keyword_elem is not None: 270 | keywords = [keyword_elem.text] 271 | layer.setKeywordList(keywords) 272 | 273 | # Parse minimum scale denominator (optional) 274 | minScale_elem = entry_elem.find("minScaleDenominator") 275 | if minScale_elem is not None: 276 | layer.setMinimumScale(float(minScale_elem.text)) 277 | 278 | # Parse maximum scale denominator (optional) 279 | maxScale_elem = entry_elem.find("maxScaleDenominator") 280 | if maxScale_elem is not None: 281 | layer.setMaximumScale(float(maxScale_elem.text)) 282 | 283 | # Parse resource metadata (optional) 284 | metadata_elem = entry_elem.find("resourceMetadata") 285 | 286 | # Parse folder (optional) 287 | folder_elem = entry_elem.find("folder") 288 | 289 | def loadOWCStyle(self, style_elem, layer_title): 290 | """Parses and applies style information from a styleSet, on OWC_context. 291 | 292 | Args: 293 | style_elem: The styleSet xml node. 294 | layer_title: The title of the layer to which we want to apply the style. 295 | """ 296 | 297 | # Mandatory: given name 298 | stylename_elem = style_elem.find("name") 299 | if stylename_elem is None: 300 | self.log(logging.ERROR, u"Could not parse style name.") 301 | return 302 | 303 | # parse title (optional) 304 | title_elem = style_elem.find("title") 305 | 306 | # parse content (mandatory) 307 | href = style_elem.find("content").get("href") 308 | pref1 = "#table=" 309 | pref2 = "&name=" 310 | style_table = self.find_between(href, pref1, pref2) 311 | 312 | stylename = self.find_between(href, pref2) 313 | if stylename is None or stylename != stylename_elem.text: 314 | self._log(logging.ERROR, u"Could not parse style name.") 315 | return 316 | 317 | type = style_elem.find("content").get("type") 318 | if type != "application/sld+xml": 319 | self._log(logging.ERROR, u"Currently we only support styles in sld/xml format.") 320 | return 321 | 322 | self.loadStyle(stylename, style_table, layer_title) 323 | 324 | # Load layers from gpkg 325 | def loadLayer(self, gpkg_path, layername, title): 326 | """Loads a layer from a geopackage, and it sets its title. 327 | 328 | Args: 329 | gpkg_path: The gpkg path. 330 | layername: The layer name, within the geopackage. 331 | title: The title to be given to the layer. 332 | 333 | Returns: 334 | An handle to the loaded layer. 335 | """ 336 | return iface.addVectorLayer(gpkg_path + "|layername=" + layername, title, "ogr") 337 | 338 | def loadStyle(self, style_name, table_name, given_name): 339 | """Load named style from a table. 340 | 341 | Args: 342 | style_name: The style name, as it is referenced in the style table. 343 | table_name: The name of the table where the style is stored (shouldn't it be a convention?). 344 | given_name: The layer title. 345 | """ 346 | try: 347 | self.c.execute("SELECT content FROM owc_style where name like'" + style_name + "'") 348 | except sqlite3.OperationalError: 349 | self.log(logging.ERROR, u"Could not find style " 350 | + style_name) 351 | return 352 | styles = self.c.fetchone() 353 | 354 | if styles is None: 355 | self.log(logging.ERROR, u"Could not find any styles " 356 | u"named " + style_name) 357 | return 358 | 359 | style = styles[0] 360 | 361 | layerList = QgsMapLayerRegistry.instance().mapLayersByName(given_name) 362 | 363 | if layerList is None: 364 | self.log(logging.ERROR, u"We could not find a loaded layer " 365 | "called " + given_name + ". Something is not right!") 366 | 367 | layer = layerList[0] 368 | 369 | f = QTemporaryFile() 370 | if f.open(): 371 | f.write(style) 372 | f.close() 373 | ret = layer.loadSldStyle(f.fileName()) 374 | # TODO: add style to default styles? 375 | 376 | if ret[1] is True: 377 | self.log(logging.DEBUG, "Style '" + style_name + "' loaded") 378 | else: 379 | self.log(logging.ERROR, "Style '" + style_name + "' not loaded: " + ret[0]) 380 | 381 | f.remove() 382 | 383 | else: 384 | self.log(logging.ERROR, u"Although there was a reference to style " 385 | + style_name + ", we could not find it in table owc_style. Something is not right!") 386 | return 387 | 388 | def loadBBbox(self, where_elem): 389 | """Parses and applies bbox. 390 | 391 | Args: 392 | where_elem: The where xml node. 393 | """ 394 | env_elem = where_elem.find("Envelope") 395 | if env_elem is None: 396 | self.log(logging.ERROR, u"Could not parse envelope.") 397 | return 398 | 399 | lower_elem = env_elem.find("lowerCorner") 400 | if lower_elem is None: 401 | self.log(logging.ERROR, u"Could not parse lower corner.") 402 | return 403 | lc = lower_elem.text.split() 404 | if (len(lc) != 2): 405 | self.log(logging.ERROR, u"Wrong number of entries in lower corner.") 406 | return 407 | 408 | upper_elem = env_elem.find("upperCorner") 409 | if upper_elem is None: 410 | self.log(logging.ERROR, u"Could not parse lower corner.") 411 | return 412 | uc = upper_elem.text.split() 413 | if (len(uc) != 2): 414 | self.log(logging.ERROR, u"Wrong number of entries in upper corner.") 415 | return 416 | 417 | # TODO: review this implementation 418 | # str = (self.find_between(context, "", "")).replace('\n', '').encode('ascii', 419 | # 'ignore') 420 | # d = QDomDocument() 421 | # d.setContent("< ?xml version = \"1.0\" encoding = \"utf-8\"? >" + str.) 422 | # docElem = d.documentElement() 423 | # extent = QgsOgcUtils.rectangleFromGMLEnvelope(docElem.firstChild()) 424 | 425 | # TODO: what happens to srs and dimension? 426 | extent = QgsRectangle(float(lc[0]), float(lc[1]), float(uc[0]), float(uc[1])) 427 | 428 | iface.mapCanvas().setExtent(extent) 429 | iface.mapCanvas().refresh() 430 | 431 | def find_between(self, s, first, last=None): 432 | """Extracts a substring from a string, between one, or two substrings. 433 | If the last parameter is empty, it will extract everything after the first substring. 434 | 435 | Args: 436 | s: The string we want to parse. 437 | first: The first substring. 438 | last: The last substring (optional). 439 | 440 | Returns: 441 | The extracted substring. 442 | """ 443 | try: 444 | start = s.index(first) + len(first) 445 | if last is None: 446 | end = len(s) 447 | else: 448 | end = s.index(last, start) 449 | 450 | return s[start:end] 451 | 452 | except ValueError: 453 | return "" 454 | -------------------------------------------------------------------------------- /qgisgpkg/qgpkg_qgis.py: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE in the QGIS plugin directory. 2 | # Edit the original library file in the qgpkg directory and 3 | # execute `make` to update the QGIS plugin files. 4 | from __future__ import print_function 5 | import os 6 | import sqlite3 7 | import tempfile 8 | import mimetypes 9 | import logging 10 | 11 | from xml.etree import ElementTree as ET 12 | 13 | from qgpkg import QGpkg 14 | 15 | logger = logging.getLogger('qgpkg_qgis') 16 | 17 | # Debug code for Pycharm 18 | #sys.path.append('/home/joana/Downloads/pycharm-2016.3.3/debug-eggs/pycharm-debug.egg') 19 | #import pydevd 20 | 21 | #pydevd.settrace('localhost', port=53100, stdoutToServer=True, stderrToServer=True) 22 | 23 | class QGpkg_qgis(QGpkg): 24 | """Read and write QGIS mapping information in a GeoPackage database file, using this spec: 25 | https://github.com/pka/qgpkg/blob/master/qgis_geopackage_extension.md 26 | """ 27 | 28 | def write(self, project_path): 29 | ''' Store QGIS project ''' 30 | xmltree = self.read_project(project_path) 31 | # If something is messed up with the file, the Method will stop 32 | if not xmltree: 33 | self.log(logging.ERROR, u"Couldn't read project (wrong file format)") 34 | return None 35 | 36 | root = xmltree.getroot() 37 | projectlayers = root.find("projectlayers") 38 | 39 | # Search for layersources 40 | sources = [] 41 | for layer in projectlayers: 42 | layer_path = self.make_path_absolute(layer.find( 43 | "datasource").text.split("|")[0], project_path) 44 | if layer_path not in sources: 45 | self.log(logging.DEBUG, u"Found datasource: %s" % layer_path) 46 | sources.append(layer_path) 47 | 48 | # If there are more than just one different datasource check from where 49 | # they are from 50 | gpkg_found = False 51 | if len(sources) >= 1: 52 | for path in sources: 53 | if self.database_connect(path): 54 | if self.check_gpkg(path) and not gpkg_found: 55 | gpkg_found = True 56 | gpkg_path = path 57 | elif self.check_gpkg(path) and gpkg_found: 58 | # If a project has layer from more than just one 59 | # GeoPackage it can't be written 60 | self.log(logging.ERROR, u"The project uses layers " 61 | "from different GeoPackage databases.") 62 | return None 63 | if gpkg_found and len(sources) > 1: 64 | self.log( 65 | logging.WARNING, 66 | u"Some layers aren't in the GeoPackage. It can't be " 67 | "garanteed that all layers will be shown properly.") 68 | 69 | if not gpkg_found: 70 | self.log(logging.ERROR, u"There is no GeoPackage layer " 71 | "in the project.") 72 | return None 73 | 74 | # Check for images in the composer of the project 75 | images = [] 76 | for composer in root.findall("Composer"): 77 | for comp in composer: 78 | for composer_picture in comp.findall("ComposerPicture"): 79 | img = composer_picture.attrib['file'] 80 | if img not in images: 81 | self.log(logging.DEBUG, u"Image found: %s" % img) 82 | images.append(img) 83 | 84 | # Write data in database 85 | project_name = os.path.basename(project_path) 86 | project_xml = ET.tostring(root) 87 | 88 | self.database_connect(gpkg_path) 89 | 90 | # Create tables 91 | self.c.execute('CREATE TABLE IF NOT EXISTS qgis_projects (name TEXT PRIMARY KEY, xml TEXT NOT NULL)') 92 | self.c.execute( 93 | """CREATE TABLE IF NOT EXISTS qgis_resources 94 | (name TEXT PRIMARY KEY, mime_type TEXT NOT NULL, content BLOB NOT NULL)""") 95 | self.c.execute( 96 | 'CREATE TABLE IF NOT EXISTS gpkg_extensions (table_name TEXT,column_name TEXT,extension_name TEXT NOT NULL,definition TEXT NOT NULL,scope TEXT NOT NULL,CONSTRAINT ge_tce UNIQUE (table_name, column_name, extension_name))') 97 | extension_record = (None, None, 'qgis', 98 | 'http://github.com/pka/qgpkg/blob/master/' 99 | 'qgis_geopackage_extension.md', 100 | 'read-write') 101 | self.c.execute('SELECT count(1) FROM gpkg_extensions WHERE extension_name=?', (extension_record[2],)) 102 | if self.c.fetchone()[0] == 0: 103 | self.c.execute( 104 | 'INSERT INTO gpkg_extensions VALUES (?,?,?,?,?)', extension_record) 105 | 106 | self.c.execute('SELECT count(1) FROM qgis_projects WHERE name=?', (project_name,)) 107 | if self.c.fetchone()[0] == 0: 108 | self.c.execute('INSERT INTO qgis_projects VALUES (?,?)', (project_name, project_xml)) 109 | self.log(logging.DEBUG, u"Project %s saved." % project_name) 110 | else: 111 | # Overwrite existing project (DELETE gives locking problems) 112 | self.c.execute('UPDATE qgis_projects SET xml=? WHERE name=?', 113 | (project_xml, project_name)) 114 | self.log(logging.INFO, u"Project overwritten.") 115 | 116 | if images: 117 | for image in images: 118 | img = self.make_path_absolute(image, project_path) 119 | with open(img, 'rb') as input_file: 120 | blob = input_file.read() 121 | mime_type = mimetypes.MimeTypes().guess_type(image)[0] 122 | self.c.execute('SELECT count(1) FROM qgis_resources WHERE name=?', (image,)) 123 | if self.c.fetchone()[0] == 0: 124 | self.conn.execute( 125 | """INSERT INTO qgis_resources \ 126 | VALUES(?, ?, ?)""", (image, mime_type, sqlite3.Binary(blob))) 127 | self.log(logging.DEBUG, u"Image %s was saved" % image) 128 | else: 129 | # TODO: forced overwrite 130 | self.log(logging.DEBUG, u"Skipping existing image %s" % image) 131 | self.conn.commit() 132 | 133 | return gpkg_path 134 | 135 | def read(self, gpkg_path): 136 | ''' Read QGIS project from GeoPackage ''' 137 | # Check if it's a GeoPackage Database 138 | self.database_connect(gpkg_path) 139 | if not self.check_gpkg(gpkg_path): 140 | self.log(logging.ERROR, u"No valid GeoPackage selected.") 141 | return None 142 | 143 | # Read xml from the project in the Database 144 | try: 145 | self.c.execute('SELECT name, xml FROM qgis_projects') 146 | except sqlite3.OperationalError: 147 | self.log(logging.ERROR, u"There is no Project file " 148 | "in the database.") 149 | return None 150 | file_name, xml = self.c.fetchone() 151 | try: 152 | xml_tree = ET.ElementTree() 153 | root = ET.fromstring(xml) 154 | except: 155 | self.log(logging.ERROR, u"The xml code is corrupted.") 156 | return None 157 | self.log(logging.DEBUG, u"Xml successfully read.") 158 | xml_tree._setroot(root) 159 | projectlayers = root.find("projectlayers") 160 | 161 | # Layerpath in xml adjusted 162 | tmp_folder = tempfile.mkdtemp() 163 | project_path = os.path.join(tmp_folder, file_name) 164 | for layer in projectlayers: 165 | layer_element = layer.find("datasource") 166 | layer_info = layer_element.text.split("|") 167 | layer_path = self.make_path_absolute(gpkg_path, layer_info[0]) 168 | if layer_path.endswith('.gpkg'): 169 | if len(layer_info) >= 2: 170 | for i in range(len(layer_info)): 171 | if i == 0: 172 | layer_element.text = layer_path 173 | else: 174 | layer_element.text += "|" + layer_info[i] 175 | elif len(layer_info) == 1: 176 | layer_element.text = layer_path 177 | self.log(logging.DEBUG, 178 | u"Layerpath from layer %s was adjusted." % 179 | layer.find("layername").text) 180 | 181 | # Check if an image is available 182 | images = [] 183 | for composer in root.findall("Composer"): 184 | for comp in composer: 185 | for composer_picture in comp.findall("ComposerPicture"): 186 | img = self.make_path_absolute( 187 | composer_picture.attrib['file'], project_path) 188 | # If yes, the path will be adjusted 189 | composer_picture.set('file', './' + os.path.basename(img)) 190 | self.log(logging.DEBUG, 191 | u"External image %s found." % os.path.basename(img)) 192 | images.append(img) 193 | 194 | # and the image will be saved in the same folder as the project 195 | if images: 196 | self.c.execute("SELECT name, mime_type, content FROM qgis_resources") 197 | images = self.c.fetchall() 198 | for img in images: 199 | img_name, mime_type, blob = img 200 | img_path = os.path.join(tmp_folder, img_name) 201 | with open(img_path, 'wb') as file: 202 | file.write(blob) 203 | self.log(logging.DEBUG, u"Image saved: %s" % img_name) 204 | 205 | # Project is saved and started 206 | xml_tree.write(project_path) 207 | self.log(logging.DEBUG, u"Temporary project written: %s" % project_path) 208 | return project_path 209 | 210 | def read_project(self, path): 211 | ''' Check if it's a file and give ElementTree object back ''' 212 | if not os.path.isfile(path): 213 | return False 214 | 215 | return ET.parse(path) -------------------------------------------------------------------------------- /qgpkg_cli/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/qgpkg_cli/__init__.py -------------------------------------------------------------------------------- /qgpkg_cli/qgpkg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import sys 5 | import logging 6 | from qgisgpkg.qgpkg import QGpkg 7 | from qgisgpkg.qgpkg_qgis import QGpkg_qgis 8 | 9 | logger = logging.getLogger('qgpkg') 10 | logger.addHandler(logging.StreamHandler()) 11 | 12 | 13 | def log(lvl, msg, *args, **kwargs): 14 | logger.log(lvl, msg, *args, **kwargs) 15 | 16 | 17 | def info(args): 18 | gpkg = QGpkg(args.gpkg, log) 19 | gpkg.info() 20 | return 0 21 | 22 | 23 | def write(args): 24 | gpkg = QGpkg_qgis(args.gpkg, log) 25 | gpkg.write(args.qgs) 26 | return 0 27 | 28 | 29 | def read(args): 30 | gpkg = QGpkg_qgis(args.gpkg, log) 31 | project_path = gpkg.read(args.gpkg) 32 | print "Project extracted: %s" % project_path 33 | return 0 34 | 35 | 36 | def main(): 37 | """Returns 0 on success, 1 on error, for sys.exit.""" 38 | 39 | parser = argparse.ArgumentParser( 40 | description="Store QGIS map information in GeoPackages") 41 | 42 | # Commands 43 | subparsers = parser.add_subparsers(title='commands', 44 | description='valid commands') 45 | # Common parameters 46 | gpkgparam = { 47 | 'help': "input datagpkg" 48 | } 49 | qgsparam = { 50 | 'nargs': '?', 51 | 'help': "output datagpkg", 52 | 'default': sys.stdout 53 | } 54 | parser.add_argument( 55 | '--debug', default=False, action='store_true', 56 | help='Display debugging information') 57 | 58 | subparser = subparsers.add_parser( 59 | 'info', help='GeoPackage content information') 60 | subparser.add_argument('gpkg', **gpkgparam) 61 | subparser.set_defaults(func=info) 62 | 63 | subparser = subparsers.add_parser( 64 | 'write', help='Save QGIS project in GeoPackage') 65 | subparser.add_argument('gpkg', **gpkgparam) 66 | subparser.add_argument('qgs', **qgsparam) 67 | subparser.set_defaults(func=write) 68 | 69 | subparser = subparsers.add_parser( 70 | 'read', help='Read QGIS project from GeoPackage') 71 | subparser.add_argument('gpkg', **gpkgparam) 72 | subparser.set_defaults(func=read) 73 | 74 | args = parser.parse_args() 75 | 76 | if args.debug: 77 | logger.setLevel(logging.DEBUG) 78 | else: 79 | logger.setLevel(logging.INFO) 80 | 81 | return args.func(args) 82 | 83 | 84 | if __name__ == '__main__': 85 | sys.exit(main()) 86 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup( 4 | name='qgpkg', 5 | version='0.0.0', 6 | author='Pirmin Kalberer', 7 | author_email='pka@sourcepole.ch', 8 | packages=['qgisgpkg', 'qgpkg_cli'], 9 | url='https://github.com/pka/qgpkg', 10 | license='LICENSE.txt', 11 | description='Store QGIS map information in GeoPackages.', 12 | long_description=open('README.rst').read(), 13 | # tests_require=['nose'], 14 | # test_suite='nose.collector', 15 | classifiers=[ 16 | 'Development Status :: 4 - Beta', 17 | 'Intended Audience :: Developers', 18 | 'Intended Audience :: Science/Research', 19 | 'License :: OSI Approved :: MIT License', 20 | 'Operating System :: OS Independent', 21 | 'Programming Language :: Python :: 2', 22 | 'Topic :: Scientific/Engineering :: GIS', 23 | ], 24 | entry_points={ 25 | 'console_scripts': ['ogr = gpkg_cli.gpkg:main'], 26 | } 27 | ) 28 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | 4 | logger = logging.getLogger('qgpkg') 5 | logger.addHandler(logging.StreamHandler()) 6 | 7 | 8 | def nolog(lvl, msg, *args, **kwargs): 9 | pass 10 | -------------------------------------------------------------------------------- /tests/data/qgis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/tests/data/qgis.png -------------------------------------------------------------------------------- /tests/data/small_world.gpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/tests/data/small_world.gpkg -------------------------------------------------------------------------------- /tests/data/small_world.qgs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | degrees 18 | 19 | -263.08080742151162212 20 | -175.16116845015005765 21 | 263.08080742151162212 22 | 69.61429554114846496 23 | 24 | 0 25 | 0 26 | 27 | 28 | +proj=longlat +datum=WGS84 +no_defs 29 | 3452 30 | 4326 31 | EPSG:4326 32 | WGS 84 33 | longlat 34 | WGS84 35 | true 36 | 37 | 38 | 0 39 | 40 | 41 | 42 | 43 | small_world20160822231200722 44 | small_world20160822231206236 45 | 46 | 47 | 48 | 49 | 52 | 53 | 54 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -180 159 | -90 160 | 180 161 | 83.64509999999999934 162 | 163 | small_world20160822231200722 164 | ./small_world.gpkg 165 | 166 | 167 | 168 | small_world ne_110m_admin_0_countries Polygon 169 | 170 | 171 | +proj=longlat +datum=WGS84 +no_defs 172 | 3452 173 | 4326 174 | EPSG:4326 175 | WGS 84 176 | longlat 177 | WGS84 178 | true 179 | 180 | 181 | ogr 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 0 361 | 0 362 | 41 363 | name 364 | 365 | 366 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | . 415 | 416 | 417 | 418 | 419 | 420 | 424 | 425 | . 426 | 427 | 0 428 | . 429 | 446 | 0 447 | generatedlayout 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | -180 457 | -90 458 | 180 459 | 90 460 | 461 | small_world20160822231206236 462 | ./small_world.gpkg 463 | 464 | 465 | 466 | small_world 467 | 468 | 469 | +proj=longlat +datum=WGS84 +no_defs 470 | 3452 471 | 4326 472 | EPSG:4326 473 | WGS 84 474 | longlat 475 | WGS84 476 | true 477 | 478 | 479 | 480 | 481 | 482 | gdal 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 0 501 | 502 | 503 | 504 | 505 | meters 506 | m2 507 | 508 | 509 | +proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs 510 | EPSG:21781 511 | 1919 512 | 513 | 514 | false 515 | 516 | 517 | 0 518 | 255 519 | 255 520 | 255 521 | 255 522 | 255 523 | 255 524 | 525 | 526 | 2 527 | current_layer 528 | off 529 | 0 530 | 531 | 532 | 2 533 | true 534 | 535 | 536 | false 537 | 538 | 539 | 540 | 541 | -------------------------------------------------------------------------------- /tests/test_info.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from qgisgpkg.qgpkg import QGpkg 3 | from . import nolog 4 | 5 | 6 | def test_info(): 7 | gpkg = QGpkg('tests/data/small_world.gpkg', nolog) 8 | gpkg.info() 9 | output = sys.stdout.getvalue().strip() 10 | info = """gpkg_contents features: 11 | ne_110m_admin_0_countries 12 | gpkg_contents tiles: 13 | small_world 14 | GPKG extensions: 15 | gpkg_rtree_index""" 16 | assert output == info 17 | 18 | 19 | def test_wrong_file(): 20 | gpkg = QGpkg('wrong_file_name.gpkg', nolog) 21 | gpkg.info() 22 | output = sys.stdout.getvalue().strip() 23 | assert output == "" 24 | 25 | 26 | def test_no_gpkg(): 27 | gpkg = QGpkg("./tests/test_info.py", nolog) 28 | gpkg.info() 29 | output = sys.stdout.getvalue().strip() 30 | assert output == "" 31 | -------------------------------------------------------------------------------- /tests/test_readwrite.py: -------------------------------------------------------------------------------- 1 | from nose.tools import assert_equals 2 | import sys 3 | import tempfile 4 | import shutil 5 | import os 6 | from qgisgpkg.qgpkg_qgis import QGpkg_qgis 7 | import sqlite3 8 | from . import nolog 9 | 10 | 11 | def test_read_without_qgs(): 12 | gpkg = QGpkg_qgis('tests/data/small_world.gpkg', nolog) 13 | gpkg.read('tests/data/small_world.gpkg') 14 | gpkg.info() 15 | output = sys.stdout.getvalue().strip() 16 | info = """gpkg_contents features: 17 | ne_110m_admin_0_countries 18 | gpkg_contents tiles: 19 | small_world 20 | GPKG extensions: 21 | gpkg_rtree_index""" 22 | assert output == info 23 | 24 | 25 | def copy_to_tmp(srcdir): 26 | tmp_folder = tempfile.mkdtemp() 27 | for fn in os.listdir(srcdir): 28 | shutil.copy(os.path.join(srcdir, fn), tmp_folder) 29 | return tmp_folder 30 | 31 | 32 | def test_write(): 33 | # Copy test data 34 | tmp_folder = copy_to_tmp('tests/data') 35 | gpkg_path = os.path.join(tmp_folder, 'small_world.gpkg') 36 | qgs_path = os.path.join(tmp_folder, 'small_world.qgs') 37 | gpkg = QGpkg_qgis(gpkg_path, nolog) 38 | gpkg.write(qgs_path) 39 | gpkg.info() 40 | output = sys.stdout.getvalue().strip() 41 | info = """gpkg_contents features: 42 | ne_110m_admin_0_countries 43 | gpkg_contents tiles: 44 | small_world 45 | GPKG extensions: 46 | qgis 47 | gpkg_rtree_index 48 | QGIS projects: 49 | small_world.qgs 50 | QGIS recources: 51 | ./qgis.png (image/png)""" 52 | assert output == info 53 | 54 | conn = sqlite3.connect(gpkg_path) 55 | curs = conn.cursor() 56 | 57 | curs.execute('SELECT name FROM qgis_projects') 58 | assert_equals('small_world.qgs', curs.fetchone()[0], 'small_world.qgs not found') 59 | assert curs.fetchone() is None 60 | 61 | curs.execute('SELECT name FROM qgis_resources') 62 | assert_equals('./qgis.png', curs.fetchone()[0], 'Image not found') 63 | assert curs.fetchone() is None 64 | 65 | curs.execute("SELECT scope FROM gpkg_extensions WHERE extension_name = 'qgis'") 66 | assert_equals('read-write', curs.fetchone()[0], 'Extension registration missing') 67 | assert curs.fetchone() is None 68 | 69 | # Test overwriting with same project 70 | gpkg.write(qgs_path) 71 | 72 | curs.execute('SELECT name FROM qgis_projects') 73 | assert_equals('small_world.qgs', curs.fetchone()[0], 'small_world.qgs not found') 74 | assert curs.fetchone() is None 75 | 76 | curs.execute('SELECT name FROM qgis_resources') 77 | assert_equals('./qgis.png', curs.fetchone()[0], 'Image not found') 78 | assert curs.fetchone() is None 79 | 80 | curs.execute("SELECT scope FROM gpkg_extensions WHERE extension_name = 'qgis'") 81 | assert_equals('read-write', curs.fetchone()[0], 'Extension registration missing') 82 | assert curs.fetchone() is None 83 | -------------------------------------------------------------------------------- /workflow-owc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/workflow-owc.png -------------------------------------------------------------------------------- /workflow-qgis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pka/qgpkg/eb5e3c309ff97048799ce97b9d6499edde977a20/workflow-qgis.png --------------------------------------------------------------------------------