├── .gitignore ├── .idea ├── .gitignore ├── citygen.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── other.xml └── vcs.xml ├── LICENCE ├── Makefile ├── README.html ├── README.md ├── README.txt ├── __init__.py ├── citygen_dialog.py ├── citygen_dialog_base.ui ├── citygen_loader.py ├── docs ├── austria_vienna.gif ├── brazil_itajai_and_navegantes.gif ├── how-to-use.gif ├── icon.svg └── wms_addresses.txt ├── extensions ├── __init__.py ├── local_dsm │ ├── __init__.py │ ├── config.json │ └── main.py ├── local_dtm │ ├── __init__.py │ ├── config.json │ └── main.py ├── local_footprint │ ├── __init__.py │ ├── config.json │ └── main.py ├── local_ortho │ ├── __init__.py │ ├── config.json │ └── main.py ├── local_street │ ├── __init__.py │ ├── config.json │ └── main.py ├── local_trees │ ├── __init__.py │ ├── config.json │ └── main.py ├── local_water │ ├── __init__.py │ ├── config.json │ └── main.py ├── sc_itj_nvt_dsm │ ├── __init__.py │ ├── config.json │ └── main.py ├── sc_itj_nvt_dtm │ ├── __init__.py │ ├── config.json │ └── main.py ├── sc_itj_nvt_ortho │ ├── __init__.py │ ├── config.json │ └── main.py ├── sc_ortho_wmts │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_dsm │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_dsm2 │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_dtm │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_footprint │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_ortho │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_ortho_wms │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_streets │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_tree │ ├── __init__.py │ ├── config.json │ └── main.py ├── vienna_water │ ├── __init__.py │ ├── config.json │ └── main.py └── world_osm_streets │ ├── __init__.py │ ├── config.json │ └── main.py ├── generate_model ├── Worker.py ├── __init__.py ├── appCtx.py ├── bibliotecas │ ├── DotDict.py │ ├── __init__.py │ ├── execute.py │ ├── extension_manager.py │ ├── file_management.py │ ├── inputa.py │ ├── install_python_package.py │ ├── internet.py │ ├── logger.py │ ├── path_manager.py │ ├── progress_bar.py │ └── t.py ├── getters │ ├── __init__.py │ └── getters_management.py ├── gis │ ├── __init__.py │ └── gis.py ├── main.py └── normalizer │ ├── __init__.py │ ├── normalizer.py │ └── temp.py ├── i18n └── af.ts ├── icon.png ├── metadata.txt ├── pb_tool.cfg ├── plugin_upload.py ├── resources.py ├── resources.qrc └── scripts ├── compile-strings.sh ├── run-env-linux.sh └── update-strings.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # IDE 132 | .idea/ 133 | .vscode/ 134 | 135 | # OS 136 | .DS_Store 137 | desktop.ini 138 | 139 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/citygen.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 20 | 21 | 22 | 24 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/other.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 6 | 7 | Everyone is permitted to copy and distribute verbatim copies 8 | of this license document, but changing it is not allowed. 9 | Preamble 10 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. 11 | 12 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. 13 | 14 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. 15 | 16 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 17 | 18 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. 19 | 20 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. 21 | 22 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 23 | 24 | The precise terms and conditions for copying, distribution and modification follow. 25 | 26 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 27 | 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". 28 | 29 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 30 | 31 | 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 32 | 33 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 34 | 35 | 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: 36 | 37 | a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. 38 | b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. 39 | c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) 40 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. 41 | 42 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. 43 | 44 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 45 | 46 | 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: 47 | 48 | a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 49 | b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, 50 | c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) 51 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. 52 | 53 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 54 | 55 | 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 56 | 57 | 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 58 | 59 | 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 60 | 61 | 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. 62 | 63 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. 64 | 65 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. 66 | 67 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 68 | 69 | 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 70 | 71 | 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 72 | 73 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 74 | 75 | 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. 76 | 77 | NO WARRANTY 78 | 79 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 80 | 81 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 82 | 83 | END OF TERMS AND CONDITIONS 84 | How to Apply These Terms to Your New Programs 85 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 86 | 87 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. 88 | 89 | one line to give the program's name and an idea of what it does. 90 | Copyright (C) yyyy name of author 91 | 92 | This program is free software; you can redistribute it and/or 93 | modify it under the terms of the GNU General Public License 94 | as published by the Free Software Foundation; either version 2 95 | of the License, or (at your option) any later version. 96 | 97 | This program is distributed in the hope that it will be useful, 98 | but WITHOUT ANY WARRANTY; without even the implied warranty of 99 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 100 | GNU General Public License for more details. 101 | 102 | You should have received a copy of the GNU General Public License 103 | along with this program; if not, write to the Free Software 104 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 105 | Also add information on how to contact you by electronic and paper mail. 106 | 107 | If the program is interactive, make it output a short notice like this when it starts in an interactive mode: 108 | 109 | Gnomovision version 69, Copyright (C) year name of author 110 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details 111 | type `show w'. This is free software, and you are welcome 112 | to redistribute it under certain conditions; type `show c' 113 | for details. 114 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. 115 | 116 | You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: 117 | 118 | Yoyodyne, Inc., hereby disclaims all copyright 119 | interest in the program `Gnomovision' 120 | (which makes passes at compilers) written 121 | by James Hacker. 122 | 123 | signature of Ty Coon, 1 April 1989 124 | Ty Coon, President of Vice 125 | This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # citygen 3 | # 4 | # A plugin to generate 3D models of urban areas 5 | # ------------------- 6 | # begin : 2020-04-30 7 | # git sha : $Format:%H$ 8 | # copyright : (C) 2020 by Arthur Ruf Hosang da Costa 9 | # email : arthur.rhc@gmail.com 10 | # ***************************************************************************/ 11 | # 12 | #/*************************************************************************** 13 | # * * 14 | # * This program is free software; you can redistribute it and/or modify * 15 | # * it under the terms of the GNU General Public License as published by * 16 | # * the Free Software Foundation; either version 2 of the License, or * 17 | # * (at your option) any later version. * 18 | # * * 19 | # ***************************************************************************/ 20 | 21 | ################################################# 22 | # Edit the following to match your sources lists 23 | ################################################# 24 | 25 | 26 | #Add iso code for any locales you want to support here (space separated) 27 | # default is no locales 28 | # LOCALES = af 29 | LOCALES = 30 | 31 | # If locales are enabled, set the name of the lrelease binary on your system. If 32 | # you have trouble compiling the translations, you may have to specify the full path to 33 | # lrelease 34 | #LRELEASE = lrelease 35 | #LRELEASE = lrelease-qt4 36 | 37 | 38 | # translation 39 | SOURCES = \ 40 | __init__.py \ 41 | citygen_loader.py citygen_dialog.py 42 | 43 | PLUGINNAME = citygen 44 | 45 | PY_FILES = \ 46 | __init__.py \ 47 | citygen_loader.py citygen_dialog.py 48 | 49 | UI_FILES = citygen_dialog_base.ui 50 | 51 | EXTRAS = metadata.txt icon.png 52 | 53 | EXTRA_DIRS = extensions generate_model 54 | 55 | COMPILED_RESOURCE_FILES = resources.py 56 | 57 | PEP8EXCLUDE=pydev,resources.py,conf.py,third_party,ui 58 | 59 | # QGISDIR points to the location where your plugin should be installed. 60 | # This varies by platform, relative to your HOME directory: 61 | # * Linux: 62 | # .local/share/QGIS/QGIS3/profiles/default/python/plugins/ 63 | # * Mac OS X: 64 | # Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins 65 | # * Windows: 66 | # AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins' 67 | 68 | 69 | # Checks your OS to set QGISDIR variable to your QGIS Plugin Location. You can also set it manually after this IF 70 | OS := $(shell uname) 71 | ifeq ($(OS),Windows_NT) 72 | # Windows 73 | QGISDIR=AppData\Roaming\QGIS\QGIS3\profiles\default' 74 | else 75 | ifeq ($(OS),Darwin) 76 | # MacOS 77 | QGISDIR=Library/Application Support/QGIS/QGIS3/profiles/default 78 | else 79 | # Linux 80 | QGISDIR=.local/share/QGIS/QGIS3/profiles/default 81 | endif 82 | endif 83 | # QGISDIR=enter/the/location/manually 84 | 85 | ################################################# 86 | # Normally you would not need to edit below here 87 | ################################################# 88 | 89 | HELP = help/build/html 90 | 91 | PLUGIN_UPLOAD = $(c)/plugin_upload.py 92 | 93 | RESOURCE_SRC=$(shell grep '^ *@@g;s/.*>//g' | tr '\n' ' ') 94 | 95 | .PHONY: default 96 | default: 97 | @echo While you can use make to build and deploy your plugin, pb_tool 98 | @echo is a much better solution. 99 | @echo A Python script, pb_tool provides platform independent management of 100 | @echo your plugins and runs anywhere. 101 | @echo You can install pb_tool using: pip install pb_tool 102 | @echo See https://g-sherman.github.io/plugin_build_tool/ for info. 103 | 104 | compile: $(COMPILED_RESOURCE_FILES) 105 | 106 | %.py : %.qrc $(RESOURCES_SRC) 107 | pyrcc5 -o $*.py $< 108 | 109 | %.qm : %.ts 110 | $(LRELEASE) $< 111 | 112 | test: compile transcompile 113 | @echo 114 | @echo "----------------------" 115 | @echo "Regression Test Suite" 116 | @echo "----------------------" 117 | 118 | @# Preceding dash means that make will continue in case of errors 119 | @-export PYTHONPATH=`pwd`:$(PYTHONPATH); \ 120 | export QGIS_DEBUG=0; \ 121 | export QGIS_LOG_FILE=/dev/null; \ 122 | nosetests -v --with-id --with-coverage --cover-package=. \ 123 | 3>&1 1>&2 2>&3 3>&- || true 124 | @echo "----------------------" 125 | @echo "If you get a 'no module named qgis.core error, try sourcing" 126 | @echo "the helper script we have provided first then run make test." 127 | @echo "e.g. source run-env-linux.sh ; make test" 128 | @echo "----------------------" 129 | 130 | deploy: compile doc transcompile 131 | @echo 132 | @echo "------------------------------------------" 133 | @echo "Deploying plugin to your .qgis2 directory." 134 | @echo "------------------------------------------" 135 | # The deploy target only works on unix like operating system where 136 | # the Python plugin directory is located at: 137 | # $HOME/$(QGISDIR)/python/plugins 138 | mkdir -p "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" 139 | cp -vf $(PY_FILES) "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" 140 | cp -vf $(UI_FILES) "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" 141 | cp -vf $(COMPILED_RESOURCE_FILES) "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" 142 | cp -vf $(EXTRAS) "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" 143 | cp -vfr i18n "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" 144 | #cp -vfr $(HELP) "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/help" 145 | # Copy extra directories if any 146 | #(foreach EXTRA_DIR,(EXTRA_DIRS), cp -R (EXTRA_DIR) (HOME)/(QGISDIR)/python/plugins/(PLUGINNAME)/;) 147 | $(foreach EXTRA_DIR,$(EXTRA_DIRS), cp -R $(EXTRA_DIR) "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)"/;) 148 | 149 | 150 | # The dclean target removes compiled python files from plugin directory 151 | # also deletes any .git entry 152 | dclean: 153 | @echo 154 | @echo "-----------------------------------" 155 | @echo "Removing any compiled python files." 156 | @echo "-----------------------------------" 157 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "*.pyc" -delete 158 | 159 | @echo 160 | @echo "-----------------------------------" 161 | @echo "Removing git files." 162 | @echo "-----------------------------------" 163 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".git" -prune -exec rm -Rf {} \; 164 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".gitignore" -delete 165 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "docs" -prune -exec rm -Rf {} \; 166 | find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "scripts" -prune -exec rm -Rf {} \; 167 | 168 | 169 | derase: 170 | @echo 171 | @echo "-------------------------" 172 | @echo "Removing deployed plugin." 173 | @echo "-------------------------" 174 | rm -Rf $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) 175 | 176 | zip: deploy dclean 177 | @echo 178 | @echo "---------------------------" 179 | @echo "Creating plugin zip bundle." 180 | @echo "---------------------------" 181 | # The zip target deploys the plugin and creates a zip file with the deployed 182 | # content. You can then upload the zip file on http://plugins.qgis.org 183 | rm -f $(PLUGINNAME).zip 184 | cd $(HOME)/$(QGISDIR)/python/plugins; zip -9r $(CURDIR)/$(PLUGINNAME).zip $(PLUGINNAME) 185 | 186 | package: compile 187 | # Create a zip package of the plugin named $(PLUGINNAME).zip. 188 | # This requires use of git (your plugin development directory must be a 189 | # git repository). 190 | # To use, pass a valid commit or tag as follows: 191 | # make package VERSION=Version_0.3.2 192 | @echo 193 | @echo "------------------------------------" 194 | @echo "Exporting plugin to zip package. " 195 | @echo "------------------------------------" 196 | rm -f $(PLUGINNAME).zip 197 | git archive --prefix=$(PLUGINNAME)/ -o $(PLUGINNAME).zip $(VERSION) 198 | echo "Created package: $(PLUGINNAME).zip" 199 | 200 | upload: zip 201 | @echo 202 | @echo "-------------------------------------" 203 | @echo "Uploading plugin to QGIS Plugin repo." 204 | @echo "-------------------------------------" 205 | $(PLUGIN_UPLOAD) $(PLUGINNAME).zip 206 | 207 | transup: 208 | @echo 209 | @echo "------------------------------------------------" 210 | @echo "Updating translation files with any new strings." 211 | @echo "------------------------------------------------" 212 | @chmod +x scripts/update-strings.sh 213 | @scripts/update-strings.sh $(LOCALES) 214 | 215 | transcompile: 216 | @echo 217 | @echo "----------------------------------------" 218 | @echo "Compiled translation files to .qm files." 219 | @echo "----------------------------------------" 220 | @chmod +x scripts/compile-strings.sh 221 | @scripts/compile-strings.sh $(LRELEASE) $(LOCALES) 222 | 223 | transclean: 224 | @echo 225 | @echo "------------------------------------" 226 | @echo "Removing compiled translation files." 227 | @echo "------------------------------------" 228 | rm -f i18n/*.qm 229 | 230 | clean: 231 | @echo 232 | @echo "------------------------------------" 233 | @echo "Removing uic and rcc generated files" 234 | @echo "------------------------------------" 235 | rm $(COMPILED_UI_FILES) $(COMPILED_RESOURCE_FILES) 236 | 237 | doc: 238 | @echo 239 | @echo "------------------------------------" 240 | @echo "Building documentation using sphinx." 241 | @echo "------------------------------------" 242 | cd help; make html 243 | 244 | pylint: 245 | @echo 246 | @echo "-----------------" 247 | @echo "Pylint violations" 248 | @echo "-----------------" 249 | @pylint --reports=n --rcfile=pylintrc . || true 250 | @echo 251 | @echo "----------------------" 252 | @echo "If you get a 'no module named qgis.core' error, try sourcing" 253 | @echo "the helper script we have provided first then run make pylint." 254 | @echo "e.g. source run-env-linux.sh ; make pylint" 255 | @echo "----------------------" 256 | 257 | 258 | # Run pep8 style checking 259 | #http://pypi.python.org/pypi/pep8 260 | pep8: 261 | @echo 262 | @echo "-----------" 263 | @echo "PEP8 issues" 264 | @echo "-----------" 265 | @pep8 --repeat --ignore=E203,E121,E122,E123,E124,E125,E126,E127,E128 --exclude $(PEP8EXCLUDE) . || true 266 | @echo "-----------" 267 | @echo "Ignored in PEP8 check:" 268 | @echo $(PEP8EXCLUDE) 269 | 270 | html: 271 | @echo "-----------" 272 | @echo "Not Implemented" 273 | @echo "-----------" 274 | 275 | -------------------------------------------------------------------------------- /README.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Plugin Builder Results

4 | 5 | Congratulations! You just built a plugin for QGIS!

6 | 7 |
8 | Your plugin citygen was created in:
9 |   /Volumes/TarDisk/ruf/workspace/ttc/3dcitygen/citygen/citygen 10 |

11 | Your QGIS plugin directory is located at:
12 |   /Users/arthurrufhosangdacosta/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins 13 |

14 |

What's Next

15 |
    16 |
  1. If resources.py is not present in your plugin directory, compile the resources file using pyrcc5 (simply use pb_tool or make if you have automake) 17 |
  2. Optionally, test the generated sources using make test (or run tests from your IDE) 18 |
  3. Copy the entire directory containing your new plugin to the QGIS plugin directory (see Notes below) 19 |
  4. Test the plugin by enabling it in the QGIS plugin manager 20 |
  5. Customize it by editing the implementation file citygen.py 21 |
  6. Create your own custom icon, replacing the default icon.png 22 |
  7. Modify your user interface by opening citygen_dialog_base.ui in Qt Designer 23 |
24 | Notes: 25 |
    26 |
  • You can use pb_tool to compile, deploy, and manage your plugin. Tweak the pb_tool.cfg file included with your plugin as you add files. Install pb_tool using 27 | pip or easy_install. See http://loc8.cc/pb_tool for more information. 28 |
  • You can also use the Makefile to compile and deploy when you 29 | make changes. This requires GNU make (gmake). The Makefile is ready to use, however you 30 | will have to edit it to add addional Python source files, dialogs, and translations. 31 |
32 |
33 |
34 |

35 | For information on writing PyQGIS code, see http://loc8.cc/pyqgis_resources for a list of resources. 36 |

37 |
38 |

39 | ©2011-2019 GeoApt LLC - geoapt.com 40 |

41 | 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 3D City Builder 2 | This QGIS Plugin generates 3D Models of Urban Areas using Aerial Imagery (Satellite Image), DTM (Digital Terrain Model), DSM (Digital Surface Model) and a Footprint layer (the contour of the buildings) from both, files stored on your computer and online. 3 | 4 | This plugin requires QGIS 3.0 or superior 5 | 6 | To see it on QGIS Plugin Repository, go to: https://plugins.qgis.org/plugins/citygen/ 7 | 8 | If you want to help in this project I'll be glad :D 9 | Plus, if you have any suggestins, please, let me know :D 10 | 11 | I appreciate any help to make this code compliant with PEP8. 12 | 13 | **Vienna, Austria** 14 | ![Result in Vienna, Austria](https://github.com/arthurRuf/3dcitybuilder/blob/main/docs/austria_vienna.gif?raw=true) 15 | 16 | **Cities of Itajaí and Navegantes, Santa Catarina, Brazil** 17 | ![Result in the cities of Itajaí and Navegantes, Santa Catarina, Brazil](https://github.com/arthurRuf/3dcitybuilder/blob/main/docs/brazil_itajai_and_navegantes.gif?raw=true) 18 | 19 | 20 | ## Installing 21 | 22 | "Stable" releases are available through the official QGIS plugins repository. 23 | 24 | 1. In QGIS 3 select Plugins->Manage and Install Plugins... 25 | 2. On the sidebar go to `Settings` and check the `Show also experimental plugins` checkbox 26 | 3. Now, go to `All` on the sidebar and search for `3D City Generator`. Select the plugin and click `Install Plugin` 27 | 28 | After installing the plugin, please run these commands on the terminal 29 | ```shell script 30 | brew reinstall libcapn 31 | brew install capnp 32 | brew install spatialindex 33 | ``` 34 | 35 | Opitionally, you can run these commands on the QGIS Python 36 | ```shell script 37 | python3 -m pip install geopandas numpy osmnx 38 | ``` 39 | Opitionally, you can follow the steps under https://landscapearchaeology.org/2018/installing-python-packages-in-qgis-3-for-windows/ to install the following libraries on QGIS Python: geopandas numpy osmnx. 40 | 41 | ## Using 42 | 43 | To run the 3D City Generator, just follow this steps: 44 | 1. Go to the menu `Plugins >> citygen >> 3D City Generator` to open the plugin. 45 | 2. Fill the information on `Definitions` and `Advanced` tabs. Then click `Run`. 46 | 3. Close the Plugins' window, go to `View >> New 3D Map View` 47 | 4. Have fun :D 48 | 49 | Animation demonstrating how to use this Plugin 50 | ![Image demonstrating how to use the plugin](https://github.com/arthurRuf/3dcitybuilder/blob/main/docs/how-to-use.gif?raw=true) 51 | 52 | 53 | A sample dataset is available to: 54 | To make it easier for you to test this plugin, we've made available a sample dataset: 55 | * Vienna, Austria: https://3dcitygen-test-dataset.s3.amazonaws.com/test-dataset-vienna.zip 56 | 57 | 58 | ## Development 59 | 60 | You can use `make` to assist you while developing. 61 | 62 | The following rules can be useful: 63 | * `make deploy`: will automatically copy the required files to your QGIS plugins' folder. **BEWARE:** *it only works out-of-the-box for macOS. For other operating systems you might have to change the `QGISDIR` variable in `Makefile`.* 64 | * `make package VERSION=GIT_REF`: (where *GIT_REF* is a branch, tag or any other git ref) will make a zip package to be installed manually from QGIS or uploaded to the QGIS plugins' repository. 65 | 66 | ## License 67 | The project is licensed under the GNU GPLv2 license. 68 | 69 | You are free to download, modify and redistribute this plugin, since you reference this repo ;D 70 | 71 | 72 | **Third Party Licences** 73 | * geopandas: © GeoPandas - BSD Licence (https://geopandas.org/) 74 | * numpy: © NumPy - BSD Licence (https://www.numpy.org) 75 | * osmnx: © OSMnx - MIT Licence (https://github.com/gboeing/osmnx) 76 | 77 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Plugin Builder Results 2 | 3 | Your plugin citygen was created in: 4 | /Volumes/TarDisk/ruf/workspace/ttc/3dcitygen/citygen/citygen 5 | 6 | Your QGIS plugin directory is located at: 7 | /Users/arthurrufhosangdacosta/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins 8 | 9 | What's Next: 10 | 11 | * Copy the entire directory containing your new plugin to the QGIS plugin 12 | directory 13 | 14 | * Compile the resources file using pyrcc5 15 | 16 | * Run the tests (``make test``) 17 | 18 | * Test the plugin by enabling it in the QGIS plugin manager 19 | 20 | * Customize it by editing the implementation file: ``citygen.py`` 21 | 22 | * Create your own custom icon, replacing the default icon.png 23 | 24 | * Modify your user interface by opening citygen_dialog_base.ui in Qt Designer 25 | 26 | * You can use the Makefile to compile your Ui and resource files when 27 | you make changes. This requires GNU make (gmake) 28 | 29 | For more information, see the PyQGIS Developer Cookbook at: 30 | http://www.qgis.org/pyqgis-cookbook/index.html 31 | 32 | (C) 2011-2018 GeoApt LLC - geoapt.com 33 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa 11 | email : arthur.rhc@gmail.com 12 | git sha : $Format:%H$ 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | This script initializes the plugin, making it known to QGIS. 24 | """ 25 | 26 | 27 | # noinspection PyPep8Naming 28 | def classFactory(iface): # pylint: disable=invalid-name 29 | """Load citygen class from file citygen. 30 | 31 | :param iface: A QGIS interface instance. 32 | :type iface: QgsInterface 33 | """ 34 | # 35 | from .citygen_loader import citygen 36 | return citygen(iface) 37 | -------------------------------------------------------------------------------- /citygen_dialog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygenDialog 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | import os 26 | 27 | from qgis.PyQt import uic 28 | from qgis.PyQt import QtWidgets 29 | 30 | # This loads your .ui file so that PyQt can populate your plugin with the elements from Qt Designer 31 | FORM_CLASS, _ = uic.loadUiType(os.path.join( 32 | os.path.dirname(__file__), 'citygen_dialog_base.ui')) 33 | 34 | 35 | class citygenDialog(QtWidgets.QDialog, FORM_CLASS): 36 | def __init__(self, parent=None): 37 | """Constructor.""" 38 | super(citygenDialog, self).__init__(parent) 39 | # Set up the user interface from Designer through FORM_CLASS. 40 | # After self.setupUi() you can access any designer object by doing 41 | # self., and you can use autoconnect slots - see 42 | # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html 43 | # #widgets-and-dialogs-with-auto-connect 44 | self.setupUi(self) 45 | -------------------------------------------------------------------------------- /docs/austria_vienna.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/docs/austria_vienna.gif -------------------------------------------------------------------------------- /docs/brazil_itajai_and_navegantes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/docs/brazil_itajai_and_navegantes.gif -------------------------------------------------------------------------------- /docs/how-to-use.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/docs/how-to-use.gif -------------------------------------------------------------------------------- /docs/wms_addresses.txt: -------------------------------------------------------------------------------- 1 | Bayern Geoservices 2 | https://geoservices.bayern.de/wms/v1/ogc_schummerung.cgi 3 | 4 | European Data Portal 5 | https://www.europeandataportal.eu/data/en/dataset?tags=wind+speed 6 | 7 | Germany Terrestris WMS 8 | https://ows.terrestris.de/osm/service?VERSION=1.1.1 9 | 10 | OSM 11 | http://ows.mundialis.de/services/service 12 | 13 | Sccotland 14 | https://map.sepa.org.uk/arcgis/services/WMS_Habitats_and_Biotopes/MapServer/WMSServer 15 | 16 | UK 17 | https://map.bgs.ac.uk/arcgis/services/UKSO/UKSO_Crowdsourced/MapServer/WmsServer 18 | 19 | United Kindom 2 20 | https://catalogue.ceh.ac.uk/maps/c89cc9a0-dcfa-11e3-8b68-0800200c9a66?cache=false 21 | 22 | United States New York State 23 | https://orthos.dhses.ny.gov/ArcGIS/services/Latest/MapServer/WMSServer 24 | 25 | USA National Map 26 | https://services.nationalmap.gov/arcgis/services/3DEPElevationIndex/MapServer/WMSServer 27 | -------------------------------------------------------------------------------- /extensions/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | -------------------------------------------------------------------------------- /extensions/local_dsm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_dsm/__init__.py -------------------------------------------------------------------------------- /extensions/local_dsm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "dsm", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/local_dsm/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | def execute(appResources, appContext): 30 | appContext.update_layer_with_loaded( 31 | appContext, 32 | appContext.user_parameters.dsm_input, 33 | "dsm" 34 | ) 35 | -------------------------------------------------------------------------------- /extensions/local_dtm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_dtm/__init__.py -------------------------------------------------------------------------------- /extensions/local_dtm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "dtm", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ], 15 | "parameters": { 16 | 17 | } 18 | }, 19 | "geometry": { 20 | "type": "Multipolygon", 21 | "coordinates": [ 22 | [ 23 | [ 24 | [ 25 | -180, 26 | 90 27 | ], 28 | [ 29 | 180, 30 | 90 31 | ], 32 | [ 33 | 180, 34 | -90 35 | ], 36 | [ 37 | -180, 38 | -90 39 | ] 40 | ] 41 | ] 42 | ] 43 | } 44 | } 45 | ] 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /extensions/local_dtm/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | 30 | def execute(appResources, appContext): 31 | appContext.update_layer_with_loaded( 32 | appContext, 33 | appContext.user_parameters.dtm_input, 34 | "dtm" 35 | ) 36 | -------------------------------------------------------------------------------- /extensions/local_footprint/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_footprint/__init__.py -------------------------------------------------------------------------------- /extensions/local_footprint/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "footprint", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/local_footprint/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | 30 | def execute(appResources, appContext): 31 | appContext.update_layer_with_loaded( 32 | appContext, 33 | appContext.user_parameters.footprint_input, 34 | "footprint" 35 | ) 36 | -------------------------------------------------------------------------------- /extensions/local_ortho/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_ortho/__init__.py -------------------------------------------------------------------------------- /extensions/local_ortho/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "ortho", 11 | "crs": "4674", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/local_ortho/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | 30 | def execute(appResources, appContext): 31 | appContext.update_layer_with_loaded( 32 | appContext, 33 | appContext.user_parameters.ortho_input, 34 | "ortho" 35 | ) 36 | -------------------------------------------------------------------------------- /extensions/local_street/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_street/__init__.py -------------------------------------------------------------------------------- /extensions/local_street/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "street", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/local_street/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | 30 | def execute(appResources, appContext): 31 | appContext.update_layer_with_loaded( 32 | appContext, 33 | appContext.user_parameters.street_input, 34 | "street" 35 | ) 36 | -------------------------------------------------------------------------------- /extensions/local_trees/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_trees/__init__.py -------------------------------------------------------------------------------- /extensions/local_trees/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "trees", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/local_trees/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | 30 | def execute(appResources, appContext): 31 | appContext.update_layer_with_loaded( 32 | appContext, 33 | appContext.user_parameters.tree_input, 34 | "tree" 35 | ) 36 | -------------------------------------------------------------------------------- /extensions/local_water/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/local_water/__init__.py -------------------------------------------------------------------------------- /extensions/local_water/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Select a layer from the project", 8 | "format": "layer", 9 | "position": 0, 10 | "layer": "water", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/local_water/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | def configure(appResources, appContext): 27 | pass 28 | 29 | 30 | def execute(appResources, appContext): 31 | appContext.update_layer_with_loaded( 32 | appContext, 33 | appContext.user_parameters.water_input, 34 | "water" 35 | ) 36 | -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_dsm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/sc_itj_nvt_dsm/__init__.py -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_dsm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "SIGSC Itajaí e Navegantes", 8 | "format": "file", 9 | "layer": "dsm", 10 | "crs": "4674", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_dsm/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os 27 | import processing 28 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | 36 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=100) 37 | raw_folder = f"{appContext.execution.raw_temp_folder}/dsm" 38 | raw_file = f"{raw_folder}/dsm.zip" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.plugin_log(f"raw_file: {raw_file}") 42 | 43 | appResources.bibliotecas.logger.update_progress(step_description="Downloading DSM...") 44 | appResources.bibliotecas.internet.download_file( 45 | 'https://ttc-hosang.s3.amazonaws.com/test/sc_dsm.zip', 46 | raw_file) 47 | 48 | # NORMALIZING 49 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 50 | appResources.bibliotecas.file_management.unzip_file(raw_file, f"{appContext.execution.raw_temp_folder}/dsm/") 51 | result = f"{appContext.execution.raw_temp_folder}/dsm/dsm.tif" 52 | 53 | appContext.update_layer( 54 | appContext, 55 | result, 56 | "dsm", 57 | "gdal", 58 | 4674 59 | ) 60 | 61 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 62 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 63 | -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_dtm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/sc_itj_nvt_dtm/__init__.py -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_dtm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "SIGSC Itajaí e Navegantes", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "dtm", 11 | "crs": "4674", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_dtm/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/dtm" 39 | raw_file = f"{raw_folder}/dtm.zip" 40 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 41 | 42 | appResources.bibliotecas.logger.plugin_log(f"raw_file: {raw_file}") 43 | appResources.bibliotecas.logger.plugin_log( 44 | f"https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/dgm_tif/35_4_dgm_tif.zip") 45 | 46 | appResources.bibliotecas.logger.update_progress(step_description="Downloading DTM...") 47 | appResources.bibliotecas.internet.download_file( 48 | "https://ttc-hosang.s3.amazonaws.com/test/sc_dtm.zip", 49 | raw_file) 50 | 51 | # NORMALIZING 52 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 53 | appResources.bibliotecas.file_management.unzip_file(raw_file, f"{appContext.execution.raw_temp_folder}/dtm/") 54 | result = f"{appContext.execution.raw_temp_folder}/dtm/dtm.tif" 55 | 56 | appContext.update_layer( 57 | appContext, 58 | result, 59 | "dtm", 60 | "gdal", 61 | 4674 62 | ) 63 | 64 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 65 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 66 | -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_ortho/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/sc_itj_nvt_ortho/__init__.py -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_ortho/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "SIGSC Itajaí e Navegantes", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "ortho", 11 | "crs": "4674", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/sc_itj_nvt_ortho/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/ortho" 39 | raw_file = f"{raw_folder}/ortho.zip" 40 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 41 | 42 | appResources.bibliotecas.logger.plugin_log(f"raw_file: {raw_file}") 43 | 44 | appResources.bibliotecas.logger.update_progress(step_description="Downloading DTM...") 45 | appResources.bibliotecas.internet.download_file( 46 | "https://ttc-hosang.s3.amazonaws.com/test/sc_ortho.zip", 47 | raw_file) 48 | 49 | # NORMALIZING 50 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 51 | appResources.bibliotecas.file_management.unzip_file(raw_file, f"{appContext.execution.raw_temp_folder}/ortho/") 52 | result = f"{appContext.execution.raw_temp_folder}/ortho/ortho.tif" 53 | 54 | appContext.update_layer( 55 | appContext, 56 | result, 57 | "ortho", 58 | "gdal", 59 | 4674 60 | ) 61 | 62 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 63 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 64 | -------------------------------------------------------------------------------- /extensions/sc_ortho_wmts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/sc_ortho_wmts/__init__.py -------------------------------------------------------------------------------- /extensions/sc_ortho_wmts/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "SIGSC WMTS", 8 | "format": "wmts", 9 | "layer": "ortho", 10 | "crs": "31256", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/sc_ortho_wmts/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import time, shutil, os, sys, requests 27 | from qgis.core import QgsRasterLayer 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | # WMS Server: https://maps.wien.gv.at/wmts/1.0.0/WMTSCapabilities-arcmap.xml 36 | 37 | appContext.update_layer( 38 | appContext, 39 | 'crs=EPSG:3857&dpiMode=7&format=image/jpeg&layers=lb&styles=farbe&tileMatrixSet=google3857&url=http://sigsc.sc.gov.br/sigserver/gwc/service/wmts', 40 | "ortho", 41 | "wms" 42 | ) 43 | 44 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 45 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 46 | -------------------------------------------------------------------------------- /extensions/vienna_dsm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_dsm/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_dsm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Vienna City DSM OLD", 8 | "format": "file", 9 | "layer": "OLD", 10 | "crs": "4326", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/vienna_dsm/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/dsm" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading DSM...") 42 | 43 | region_list = [ 44 | "22_4", 45 | "32_2", 46 | "32_4", 47 | "42_2", 48 | "42_4", 49 | "23_3", 50 | "33_1", 51 | "33_3", 52 | "43_1", 53 | "43_3", 54 | "53_1", 55 | "53_3", 56 | "23_4", 57 | "33_2", 58 | "33_4", 59 | "43_2", 60 | "43_4", 61 | "53_2", 62 | "53_4", 63 | "24_1", 64 | "24_3", 65 | "34_1", 66 | "34_3", 67 | "44_1", 68 | "44_3", 69 | "54_1", 70 | "54_3", 71 | "24_2", 72 | "24_4", 73 | "34_2", 74 | "34_4", 75 | "44_2", 76 | "44_4", 77 | "54_2", 78 | "54_4", 79 | "15_3", 80 | "25_1", 81 | "25_3", 82 | "35_1", 83 | "35_3", 84 | "45_1", 85 | "45_3", 86 | "55_1", 87 | "55_3", 88 | "15_1", 89 | "15_4", 90 | "25_2", 91 | "25_4", 92 | "35_2", 93 | "35_4", 94 | "45_2", 95 | "45_4", 96 | "55_2", 97 | "55_4", 98 | "16_1", 99 | "16_3", 100 | "26_1", 101 | "26_3", 102 | "36_1", 103 | "36_3", 104 | "46_1", 105 | "46_3", 106 | "56_1", 107 | "56_3", 108 | "16_2", 109 | "16_4", 110 | "26_2", 111 | "26_4", 112 | "36_2", 113 | "36_4", 114 | "46_2", 115 | "46_4", 116 | "56_2", 117 | "56_4", 118 | "17_3", 119 | "27_1", 120 | "27_3", 121 | "37_1", 122 | "37_3", 123 | "47_1", 124 | "47_3", 125 | "57_1", 126 | "17_4", 127 | "27_2", 128 | "27_4", 129 | "37_2", 130 | "37_4", 131 | "47_2", 132 | "47_4", 133 | "57_2", 134 | "28_3", 135 | "38_1", 136 | "38_3", 137 | "48_1", 138 | "48_3", 139 | "58_1", 140 | "48_4", 141 | "58_2" 142 | ] 143 | 144 | url_list = [] 145 | zip_file_list = [] 146 | destination_list = [] 147 | tiff_list = [] 148 | tiff_epsg_list = [] 149 | for region in region_list: 150 | url_list.append(f"https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/dom_tif/{region}_dom_tif.zip") 151 | zip_file_list.append(f"{raw_folder}/dsm_{region}.zip") 152 | destination_list.append(f"{appContext.execution.raw_temp_folder}/dsm/") 153 | tiff_list.append(f"/Users/arthurrufhosangdacosta/qgis_data/temp/dsm/{region}_dom.tif") 154 | tiff_epsg_list.append(f"/Users/arthurrufhosangdacosta/qgis_data/temp/dsm/{region}_dom_epsg.tif") 155 | 156 | appResources.bibliotecas.internet.download_file_list(url_list, zip_file_list) 157 | 158 | # NORMALIZING 159 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 160 | appResources.bibliotecas.file_management.unzip_file_list(zip_file_list, destination_list) 161 | 162 | for index, layer_path in enumerate(tiff_list): 163 | output = tiff_epsg_list[index] 164 | 165 | processing.run( 166 | "gdal:warpreproject", 167 | { 168 | 'INPUT': layer_path, 169 | 'SOURCE_CRS': appResources.qgis.core.QgsCoordinateReferenceSystem('EPSG:31256'), 170 | 'TARGET_CRS': appResources.qgis.core.QgsCoordinateReferenceSystem('EPSG:4326'), 171 | 'RESAMPLING': 0, 172 | 'NODATA': None, 173 | 'TARGET_RESOLUTION': None, 174 | 'OPTIONS': '', 175 | 'DATA_TYPE': 0, 176 | 'TARGET_EXTENT': None, 177 | 'TARGET_EXTENT_CRS': None, 178 | 'MULTITHREADING': False, 179 | 'EXTRA': '', 180 | 'OUTPUT': output 181 | } 182 | ) 183 | 184 | result = f"{appContext.execution.raw_temp_folder}/dsm/dsm.tif" 185 | result = f"/Users/arthurrufhosangdacosta/qgis_data/temp/dsm/dsm.tif" 186 | processing.run( 187 | "gdal:merge", 188 | { 189 | 'INPUT': tiff_epsg_list, 190 | 'PCT': False, 191 | 'SEPARATE': False, 192 | 'NODATA_INPUT': None, 193 | 'NODATA_OUTPUT': None, 194 | 'OPTIONS': '', 195 | 'DATA_TYPE': 5, 196 | 'OUTPUT': result 197 | } 198 | ) 199 | 200 | appContext.update_layer( 201 | appContext, 202 | result, 203 | "dsm", 204 | "gdal", 205 | "raster", 206 | 4326 207 | ) 208 | 209 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 210 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 211 | -------------------------------------------------------------------------------- /extensions/vienna_dsm2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_dsm2/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_dsm2/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Vienna City", 8 | "format": "file", 9 | "crs": "31256", 10 | "layer": "dsm", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/vienna_dsm2/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/dsm" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading DSM...") 42 | 43 | region_list = [ 44 | "22_4", 45 | "32_2", 46 | "32_4", 47 | "42_2", 48 | "42_4", 49 | "23_3", 50 | "33_1", 51 | "33_3", 52 | "43_1", 53 | "43_3", 54 | "53_1", 55 | "53_3", 56 | "23_4", 57 | "33_2", 58 | "33_4", 59 | "43_2", 60 | "43_4", 61 | "53_2", 62 | "53_4", 63 | "24_1", 64 | "24_3", 65 | "34_1", 66 | "34_3", 67 | "44_1", 68 | "44_3", 69 | "54_1", 70 | "54_3", 71 | "24_2", 72 | "24_4", 73 | "34_2", 74 | "34_4", 75 | "44_2", 76 | "44_4", 77 | "54_2", 78 | "54_4", 79 | "15_3", 80 | "25_1", 81 | "25_3", 82 | "35_1", 83 | "35_3", 84 | "45_1", 85 | "45_3", 86 | "55_1", 87 | "55_3", 88 | "15_2", 89 | "15_4", 90 | "25_2", 91 | "25_4", 92 | "35_2", 93 | "35_4", 94 | "45_2", 95 | "45_4", 96 | "55_2", 97 | "55_4", 98 | "16_1", 99 | "16_3", 100 | "26_1", 101 | "26_3", 102 | "36_1", 103 | "36_3", 104 | "46_1", 105 | "46_3", 106 | "56_1", 107 | "56_3", 108 | "16_2", 109 | "16_4", 110 | "26_2", 111 | "26_4", 112 | "36_2", 113 | "36_4", 114 | "46_2", 115 | "46_4", 116 | "56_2", 117 | "56_4", 118 | "17_3", 119 | "27_1", 120 | "27_3", 121 | "37_1", 122 | "37_3", 123 | "47_1", 124 | "47_3", 125 | "57_1", 126 | "17_4", 127 | "27_2", 128 | "27_4", 129 | "37_2", 130 | "37_4", 131 | "47_2", 132 | "47_4", 133 | "57_2", 134 | "28_3", 135 | "38_1", 136 | "38_3", 137 | "48_1", 138 | "48_3", 139 | "58_1", 140 | "48_4", 141 | "58_2" 142 | ] 143 | 144 | url_list = [] 145 | zip_file_list = [] 146 | destination_list = [] 147 | tiff_list = [] 148 | for region in region_list: 149 | url_list.append(f"https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/dom_tif/{region}_dom_tif.zip") 150 | zip_file_list.append(f"/Volumes/Arthur1TB/Arthur Hosang/tcc/vienna/dsm_{region}.zip") 151 | destination_list.append(f"{appContext.execution.raw_temp_folder}/dsm/") 152 | tiff_list.append(f"{appContext.execution.raw_temp_folder}/dsm/{region}_dom.tif") 153 | 154 | appResources.bibliotecas.internet.download_file_list(url_list, zip_file_list) 155 | 156 | # NORMALIZING 157 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 158 | appResources.bibliotecas.file_management.unzip_file_list(zip_file_list, destination_list) 159 | 160 | result = f"{appContext.execution.raw_temp_folder}/dsm/dsm.tif" 161 | processing.run( 162 | "gdal:merge", 163 | { 164 | 'INPUT': tiff_list, 165 | 'PCT': False, 166 | 'SEPARATE': False, 167 | 'NODATA_INPUT': None, 168 | 'NODATA_OUTPUT': None, 169 | 'OPTIONS': '', 170 | 'DATA_TYPE': 5, 171 | 'OUTPUT': result 172 | } 173 | ) 174 | 175 | appContext.update_layer( 176 | appContext, 177 | result, 178 | "dsm", 179 | "gdal", 180 | 31256 181 | ) 182 | 183 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 184 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 185 | -------------------------------------------------------------------------------- /extensions/vienna_dtm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_dtm/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_dtm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Vienna City", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "dtm", 11 | "crs": "4326", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/vienna_dtm/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/dtm" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading DTM...") 42 | 43 | region_list = [ 44 | "22_4", 45 | "32_2", 46 | "32_4", 47 | "42_2", 48 | "42_4", 49 | "23_3", 50 | "33_1", 51 | "33_3", 52 | "43_1", 53 | "43_3", 54 | "53_1", 55 | "53_3", 56 | "23_4", 57 | "33_2", 58 | "33_4", 59 | "43_2", 60 | "43_4", 61 | "53_2", 62 | "53_4", 63 | "24_1", 64 | "24_3", 65 | "34_1", 66 | "34_3", 67 | "44_1", 68 | "44_3", 69 | "54_1", 70 | "54_3", 71 | "24_2", 72 | "24_4", 73 | "34_2", 74 | "34_4", 75 | "44_2", 76 | "44_4", 77 | "54_2", 78 | "54_4", 79 | "15_3", 80 | "25_1", 81 | "25_3", 82 | "35_1", 83 | "35_3", 84 | "45_1", 85 | "45_3", 86 | "55_1", 87 | "55_3", 88 | "15_1", 89 | "15_4", 90 | "25_2", 91 | "25_4", 92 | "35_2", 93 | "35_4", 94 | "45_2", 95 | "45_4", 96 | "55_2", 97 | "55_4", 98 | "16_1", 99 | "16_3", 100 | "26_1", 101 | "26_3", 102 | "36_1", 103 | "36_3", 104 | "46_1", 105 | "46_3", 106 | "56_1", 107 | "56_3", 108 | "16_2", 109 | "16_4", 110 | "26_2", 111 | "26_4", 112 | "36_2", 113 | "36_4", 114 | "46_2", 115 | "46_4", 116 | "56_2", 117 | "56_4", 118 | "17_3", 119 | "27_1", 120 | "27_3", 121 | "37_1", 122 | "37_3", 123 | "47_1", 124 | "47_3", 125 | "57_1", 126 | "17_4", 127 | "27_2", 128 | "27_4", 129 | "37_2", 130 | "37_4", 131 | "47_2", 132 | "47_4", 133 | "57_2", 134 | "28_3", 135 | "38_1", 136 | "38_3", 137 | "48_1", 138 | "48_3", 139 | "58_1", 140 | "48_4", 141 | "58_2" 142 | ] 143 | 144 | url_list = [] 145 | zip_file_list = [] 146 | destination_list = [] 147 | tiff_list = [] 148 | tiff_epsg_list = [] 149 | for region in region_list: 150 | url_list.append(f"https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/dgm_tif/{region}_dgm_tif.zip") 151 | zip_file_list.append(f"{raw_folder}/dtm_{region}.zip") 152 | destination_list.append(f"{appContext.execution.raw_temp_folder}/dtm/") 153 | tiff_list.append(f"/Users/arthurrufhosangdacosta/qgis_data/temp/dtm/{region}_dgm.tif") 154 | tiff_epsg_list.append(f"/Users/arthurrufhosangdacosta/qgis_data/temp/dtm/{region}_dgm_epsg.tif") 155 | 156 | appResources.bibliotecas.internet.download_file_list(url_list, zip_file_list) 157 | 158 | # NORMALIZING 159 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 160 | appResources.bibliotecas.file_management.unzip_file_list(zip_file_list, destination_list) 161 | 162 | for index, layer_path in enumerate(tiff_list): 163 | output = tiff_epsg_list[index] 164 | 165 | processing.run( 166 | "gdal:warpreproject", 167 | { 168 | 'INPUT': layer_path, 169 | 'SOURCE_CRS': appResources.qgis.core.QgsCoordinateReferenceSystem('EPSG:31256'), 170 | 'TARGET_CRS': appResources.qgis.core.QgsCoordinateReferenceSystem('EPSG:4326'), 171 | 'RESAMPLING': 0, 172 | 'NODATA': None, 173 | 'TARGET_RESOLUTION': None, 174 | 'OPTIONS': '', 175 | 'DATA_TYPE': 0, 176 | 'TARGET_EXTENT': None, 177 | 'TARGET_EXTENT_CRS': None, 178 | 'MULTITHREADING': False, 179 | 'EXTRA': '', 180 | 'OUTPUT': output 181 | } 182 | ) 183 | 184 | result = f"{appContext.execution.raw_temp_folder}/dtm/dtm.tif" 185 | result = f"/Users/arthurrufhosangdacosta/qgis_data/temp/dtm/dtm.tif" 186 | processing.run( 187 | "gdal:merge", 188 | { 189 | 'INPUT': tiff_epsg_list, 190 | 'PCT': False, 191 | 'SEPARATE': False, 192 | 'NODATA_INPUT': None, 193 | 'NODATA_OUTPUT': None, 194 | 'OPTIONS': '', 195 | 'DATA_TYPE': 5, 196 | 'OUTPUT': result 197 | } 198 | ) 199 | 200 | appContext.update_layer( 201 | appContext, 202 | result, 203 | "dtm", 204 | "gdal", 205 | "raster", 206 | 4326 207 | ) 208 | 209 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 210 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 211 | -------------------------------------------------------------------------------- /extensions/vienna_footprint/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_footprint/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_footprint/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "OSM Austria", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "footprint", 11 | "crs": "4326", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/vienna_footprint/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/footprint" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading Footprint...") 42 | 43 | zip_file_path = f"{raw_folder}/footprint.zip" 44 | 45 | 46 | uncompressed_file_path = f"{raw_folder}" 47 | appResources.bibliotecas.internet.download_file("http://download.geofabrik.de/europe/austria-latest-free.shp.zip", 48 | zip_file_path) 49 | 50 | # NORMALIZING 51 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 52 | appResources.bibliotecas.file_management.unzip_file(zip_file_path, uncompressed_file_path) 53 | 54 | result = f"{uncompressed_file_path}/gis_osm_buildings_a_free_1.shp" 55 | 56 | appContext.update_layer( 57 | appContext, 58 | path=result, 59 | name="footprint", 60 | data_provider="ogr", 61 | type="vector", 62 | crs=4626 63 | ) 64 | 65 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 66 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 67 | -------------------------------------------------------------------------------- /extensions/vienna_ortho/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_ortho/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_ortho/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Vienna City Download", 8 | "format": "file", 9 | "layer": "ortho", 10 | "crs": "4326", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/vienna_ortho/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/ortho" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading ortho...") 42 | 43 | region_list = [ 44 | "22_4", 45 | "32_2", 46 | "32_4", 47 | "42_2", 48 | "42_4", 49 | "23_3", 50 | "33_1", 51 | "33_3", 52 | "43_1", 53 | "43_3", 54 | "53_1", 55 | "53_3", 56 | "23_4", 57 | "33_2", 58 | "33_4", 59 | "43_2", 60 | "43_4", 61 | "53_2", 62 | "53_4", 63 | "24_1", 64 | "24_3", 65 | "34_1", 66 | "34_3", 67 | "44_1", 68 | "44_3", 69 | "54_1", 70 | "54_3", 71 | "24_2", 72 | "24_4", 73 | "34_2", 74 | "34_4", 75 | "44_2", 76 | "44_4", 77 | "54_2", 78 | "54_4", 79 | "15_3", 80 | "25_1", 81 | "25_3", 82 | "35_1", 83 | "35_3", 84 | "45_1", 85 | "45_3", 86 | "55_1", 87 | "55_3", 88 | "15_1", 89 | "15_4", 90 | "25_2", 91 | "25_4", 92 | "35_2", 93 | "35_4", 94 | "45_2", 95 | "45_4", 96 | "55_2", 97 | "55_4", 98 | "16_1", 99 | "16_3", 100 | "26_1", 101 | "26_3", 102 | "36_1", 103 | "36_3", 104 | "46_1", 105 | "46_3", 106 | "56_1", 107 | "56_3", 108 | "16_2", 109 | "16_4", 110 | "26_2", 111 | "26_4", 112 | "36_2", 113 | "36_4", 114 | "46_2", 115 | "46_4", 116 | "56_2", 117 | "56_4", 118 | "17_3", 119 | "27_1", 120 | "27_3", 121 | "37_1", 122 | "37_3", 123 | "47_1", 124 | "47_3", 125 | "57_1", 126 | "17_4", 127 | "27_2", 128 | "27_4", 129 | "37_2", 130 | "37_4", 131 | "47_2", 132 | "47_4", 133 | "57_2", 134 | "28_3", 135 | "38_1", 136 | "38_3", 137 | "48_1", 138 | "48_3", 139 | "58_1", 140 | "48_4", 141 | "58_2" 142 | ] 143 | 144 | url_list = [] 145 | zip_file_list = [] 146 | destination_list = [] 147 | tiff_list = [] 148 | tiff_epsg_list = [] 149 | for region in region_list: 150 | url_list.append( 151 | f"https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/op_img/{region}_op_2019.zip") 152 | zip_file_list.append(f"{raw_folder}/ortho_{region}.zip") 153 | destination_list.append(f"{appContext.execution.raw_temp_folder}/ortho/") 154 | tiff_list.append(f"/Users/arthurrufhosangdacosta/qgis_data/temp/ortho/{region}_op_2019.jpg") 155 | tiff_epsg_list.append(f"/Users/arthurrufhosangdacosta/qgis_data/temp/ortho/{region}_op_epsg.jpg") 156 | 157 | appResources.bibliotecas.internet.download_file_list(url_list, zip_file_list) 158 | 159 | # NORMALIZING 160 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing all files...") 161 | appResources.bibliotecas.file_management.unzip_file_list(zip_file_list, destination_list) 162 | 163 | appResources.bibliotecas.logger.update_progress(step_description=f"Fixing CRS...") 164 | count = 0 165 | for index, layer_path in enumerate(tiff_list): 166 | output = tiff_epsg_list[index] 167 | 168 | processing.run( 169 | "gdal:warpreproject", 170 | { 171 | 'INPUT': layer_path, 172 | 'SOURCE_CRS': appResources.qgis.core.QgsCoordinateReferenceSystem('EPSG:31256'), 173 | 'TARGET_CRS': appResources.qgis.core.QgsCoordinateReferenceSystem('EPSG:4326'), 174 | 'RESAMPLING': 0, 175 | 'NODATA': None, 176 | 'TARGET_RESOLUTION': None, 177 | 'OPTIONS': '', 178 | 'DATA_TYPE': 0, 179 | 'TARGET_EXTENT': None, 180 | 'TARGET_EXTENT_CRS': None, 181 | 'MULTITHREADING': False, 182 | 'EXTRA': '', 183 | 'OUTPUT': output 184 | } 185 | ) 186 | 187 | 188 | appResources.bibliotecas.logger.plugin_log(f"Running Merge...") 189 | result = f"{appContext.execution.raw_temp_folder}/ortho/ortho.jpg" 190 | result = f"/Users/arthurrufhosangdacosta/qgis_data/temp/ortho/ortho.jpg" 191 | processing.run( 192 | "gdal:merge", 193 | { 194 | 'INPUT': tiff_epsg_list, 195 | 'PCT': False, 196 | 'SEPARATE': False, 197 | 'NODATA_INPUT': None, 198 | 'NODATA_OUTPUT': None, 199 | 'OPTIONS': '', 200 | 'DATA_TYPE': 5, 201 | 'OUTPUT': result 202 | } 203 | ) 204 | 205 | appResources.bibliotecas.logger.plugin_log(f"Updating Layer...") 206 | appContext.update_layer( 207 | appContext, 208 | result, 209 | "ortho", 210 | "gdal", 211 | "raster", 212 | 4326 213 | ) 214 | 215 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 216 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 217 | -------------------------------------------------------------------------------- /extensions/vienna_ortho_wms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_ortho_wms/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_ortho_wms/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "Vienna City WMS Server", 8 | "format": "wmts", 9 | "layer": "ortho", 10 | "crs": "31256", 11 | "cropIncluded": false, 12 | "requirements": [ 13 | "urllib" 14 | ] 15 | }, 16 | "geometry": { 17 | "type": "Multipolygon", 18 | "coordinates": [ 19 | [ 20 | [ 21 | [ 22 | -180, 23 | 90 24 | ], 25 | [ 26 | 180, 27 | 90 28 | ], 29 | [ 30 | 180, 31 | -90 32 | ], 33 | [ 34 | -180, 35 | -90 36 | ] 37 | ] 38 | ] 39 | ] 40 | } 41 | } 42 | ] 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /extensions/vienna_ortho_wms/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import time, shutil, os, sys, requests 27 | from qgis.core import QgsRasterLayer 28 | import traceback 29 | 30 | 31 | def configure(appResources, appContext): 32 | pass 33 | 34 | 35 | def execute(appResources, appContext): 36 | # WMS Server: https://maps.wien.gv.at/wmts/1.0.0/WMTSCapabilities-arcmap.xml 37 | try: 38 | appContext.update_layer( 39 | appContext, 40 | "crs=EPSG:4326&dpiMode=7&format=image/jpeg&layers=lb&styles=farbe&tileMatrixSet=google3857&url=https://maps.wien.gv.at/wmts/1.0.0/WMTSCapabilities-arcmap.xml", 41 | "ortho", 42 | "wms" 43 | ) 44 | 45 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 46 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 47 | except Exception as e: 48 | try: 49 | appResources.bibliotecas.logger.plugin_log(repr(e), "ERROR") 50 | except Exception as e: 51 | appResources.bibliotecas.logger.plugin_log("Error for command 0", "ERROR") 52 | appResources.bibliotecas.logger.plugin_log(repr(e), "ERROR") 53 | try: 54 | appResources.bibliotecas.logger.plugin_log(e.message, "ERROR") 55 | except Exception as e: 56 | appResources.bibliotecas.logger.plugin_log("Error for command 1", "ERROR") 57 | appResources.bibliotecas.logger.plugin_log(repr(e), "ERROR") 58 | try: 59 | appResources.bibliotecas.logger.plugin_log(traceback.format_exc(), "ERROR") 60 | appResources.bibliotecas.logger.plugin_log(repr(e), "ERROR") 61 | except Exception as e: 62 | appResources.bibliotecas.logger.plugin_log("Error for command 2", "ERROR") 63 | appResources.bibliotecas.logger.plugin_log(repr(e), "ERROR") 64 | try: 65 | e.print_exc() 66 | except Exception as e: 67 | appResources.bibliotecas.logger.plugin_log("Error for command 3", "ERROR") 68 | appResources.bibliotecas.logger.plugin_log(repr(e), "ERROR") 69 | 70 | 71 | -------------------------------------------------------------------------------- /extensions/vienna_streets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_streets/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_streets/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "OSM Austria", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "street", 11 | "crs": "4326", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/vienna_streets/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/water" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading Water...") 42 | 43 | zip_file_path = f"{raw_folder}/water.zip" 44 | 45 | 46 | zip_file_path = f"{appContext.execution.raw_temp_folder}/downolads/osm.zip" 47 | uncompressed_file_path = f"{raw_folder}" 48 | 49 | if os.path.exists(zip_file_path) == False: 50 | appResources.bibliotecas.internet.download_file( 51 | "http://download.geofabrik.de/europe/austria-latest-free.shp.zip", 52 | zip_file_path) 53 | 54 | # NORMALIZING 55 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 56 | appResources.bibliotecas.file_management.unzip_file(zip_file_path, uncompressed_file_path) 57 | 58 | result = f"{uncompressed_file_path}/gis_osm_water_a_free_1.shp" 59 | 60 | appContext.update_layer( 61 | appContext, 62 | path=result, 63 | name="water", 64 | data_provider="ogr", 65 | type="vector", 66 | crs=4626 67 | ) 68 | 69 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 70 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 71 | -------------------------------------------------------------------------------- /extensions/vienna_tree/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_tree/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_tree/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "OSM Austria", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "trees", 11 | "crs": "4326", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/vienna_tree/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/tree" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading Trees...") 42 | 43 | zip_file_path = f"{appContext.execution.raw_temp_folder}/downolads/osm.zip" 44 | uncompressed_file_path = f"{raw_folder}" 45 | 46 | if os.path.exists(zip_file_path) == False: 47 | appResources.bibliotecas.internet.download_file("http://download.geofabrik.de/europe/austria-latest-free.shp.zip", 48 | zip_file_path) 49 | 50 | # NORMALIZING 51 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 52 | appResources.bibliotecas.file_management.unzip_file(zip_file_path, uncompressed_file_path) 53 | 54 | result = f"{uncompressed_file_path}/gis_osm_natural_free_1.shp" 55 | 56 | appContext.update_layer( 57 | appContext, 58 | path=result, 59 | name="tree", 60 | data_provider="ogr", 61 | type="vector", 62 | crs=4626 63 | ) 64 | 65 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 66 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 67 | -------------------------------------------------------------------------------- /extensions/vienna_water/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/vienna_water/__init__.py -------------------------------------------------------------------------------- /extensions/vienna_water/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "OSM Austria", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "water", 11 | "crs": "4326", 12 | "cropIncluded": false, 13 | "requirements": [ 14 | "urllib" 15 | ] 16 | }, 17 | "geometry": { 18 | "type": "Multipolygon", 19 | "coordinates": [ 20 | [ 21 | [ 22 | [ 23 | -180, 24 | 90 25 | ], 26 | [ 27 | 180, 28 | 90 29 | ], 30 | [ 31 | 180, 32 | -90 33 | ], 34 | [ 35 | -180, 36 | -90 37 | ] 38 | ] 39 | ] 40 | ] 41 | } 42 | } 43 | ] 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /extensions/vienna_water/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f"{appContext.execution.raw_temp_folder}/water" 39 | appResources.bibliotecas.file_management.create_dirs(raw_folder) 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading Water...") 42 | 43 | zip_file_path = f"{raw_folder}/water.zip" 44 | 45 | 46 | zip_file_path = f"{appContext.execution.raw_temp_folder}/downolads/osm.zip" 47 | uncompressed_file_path = f"{raw_folder}" 48 | 49 | if os.path.exists(zip_file_path) == False: 50 | appResources.bibliotecas.internet.download_file( 51 | "http://download.geofabrik.de/europe/austria-latest-free.shp.zip", 52 | zip_file_path) 53 | 54 | # NORMALIZING 55 | appResources.bibliotecas.logger.update_progress(step_description="Uncompressing...") 56 | appResources.bibliotecas.file_management.unzip_file(zip_file_path, uncompressed_file_path) 57 | 58 | result = f"{uncompressed_file_path}/gis_osm_roads_free_1.shp" 59 | 60 | appContext.update_layer( 61 | appContext, 62 | path=result, 63 | name="road", 64 | data_provider="ogr", 65 | type="vector", 66 | crs=4626 67 | ) 68 | 69 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 70 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 71 | -------------------------------------------------------------------------------- /extensions/world_osm_streets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/extensions/world_osm_streets/__init__.py -------------------------------------------------------------------------------- /extensions/world_osm_streets/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "feature", 6 | "properties": { 7 | "name": "OpenStreetMap (via OSMNX library)", 8 | "position": 10, 9 | "format": "file", 10 | "layer": "street", 11 | "crs": "4326", 12 | "cropIncluded": true, 13 | "requirements": [ 14 | "urllib", 15 | "geopandas", 16 | "osmnx" 17 | ] 18 | }, 19 | "geometry": { 20 | "type": "Multipolygon", 21 | "coordinates": [ 22 | [ 23 | [ 24 | [ 25 | -180, 26 | 90 27 | ], 28 | [ 29 | 180, 30 | 90 31 | ], 32 | [ 33 | 180, 34 | -90 35 | ], 36 | [ 37 | -180, 38 | -90 39 | ] 40 | ] 41 | ] 42 | ] 43 | } 44 | } 45 | ] 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /extensions/world_osm_streets/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import os, processing 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | 29 | 30 | def configure(appResources, appContext): 31 | pass 32 | 33 | 34 | def execute(appResources, appContext): 35 | print(os.path) 36 | 37 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=5) 38 | raw_folder = f'{appContext.execution.raw_temp_folder}/street' 39 | result_file = f'{raw_folder}/street.shp' 40 | 41 | appResources.bibliotecas.logger.update_progress(step_description="Downloading Street Network...") 42 | 43 | try: 44 | import osmnx as ox 45 | import geopandas as gpd 46 | except: 47 | appResources.bibliotecas.logger.plugin_log("Unable to Download Street Networks", "ERROR") 48 | appResources.bibliotecas.logger.plugin_log( 49 | "You need to install geopandas and osmnx python library into QGIS Python in order to use this functionality", "ERROR") 50 | 51 | # ox.config(log_console=True, use_cache=True) 52 | raw_folder="/Volumes/TarDisk/ruf" 53 | import osmnx as ox 54 | import geopandas as gpd 55 | calif = gpd.read_file('/Volumes/TarDisk/ruf/workspace/ttc/test/osmnx-examples/notebooks/input_data/ZillowNeighborhoods-CA/ZillowNeighborhoods-CA.shp') 56 | mission_district = calif 57 | polygon = mission_district['geometry'].iloc[0] 58 | 59 | G = ox.graph_from_polygon(polygon, network_type='drive_service') 60 | 61 | ox.save_graph_shapefile(G, folder=raw_folder, filename='drive') 62 | 63 | appResources.bibliotecas.copy_file(f'{raw_folder}/drive/edges/edges.shp', result_file) 64 | appResources.bibliotecas.copy_file(f'{raw_folder}/drive/edges/edges.cpg', f'{raw_folder}/street.cpg') 65 | appResources.bibliotecas.copy_file(f'{raw_folder}/drive/edges/edges.dbf', f'{raw_folder}/street.dbf') 66 | appResources.bibliotecas.copy_file(f'{raw_folder}/drive/edges/edges.prj', f'{raw_folder}/street.prj') 67 | appResources.bibliotecas.copy_file(f'{raw_folder}/drive/edges/edges.shp', f'{raw_folder}/street.shp') 68 | appResources.bibliotecas.copy_file(f'{raw_folder}/drive/edges/edges.shx', f'{raw_folder}/street.shx') 69 | 70 | 71 | appContext.update_layer( 72 | appContext, 73 | result_file, 74 | "street", 75 | "ogr", 76 | "vector", 77 | 4326 78 | ) 79 | 80 | appResources.bibliotecas.logger.update_progress(step_current=1, step_maximum=1) 81 | appResources.bibliotecas.logger.plugin_log("Done!", "SUCCESS") 82 | -------------------------------------------------------------------------------- /generate_model/Worker.py: -------------------------------------------------------------------------------- 1 | # import some modules used in the example 2 | from qgis.core import * 3 | import traceback 4 | import time 5 | from PyQt5 import QtCore, QtGui 6 | from PyQt5.QtCore import Qt, QThread, pyqtSignal 7 | 8 | from .main import start 9 | 10 | 11 | class Worker(QtCore.QObject): 12 | '''Example worker for calculating the total area of all features in a layer''' 13 | 14 | def __init__(self): 15 | QtCore.QObject.__init__(self) 16 | self.killed = False 17 | 18 | def run(self): 19 | ret = None 20 | try: 21 | start() 22 | 23 | if self.killed is False: 24 | self.change_value.emit(100) 25 | self.finished.emit() 26 | # self.progress.emit(100) 27 | # ret = (self.layer, total_area,) 28 | except Exception as e: 29 | # forward the exception upstream 30 | # self.error_method.emit(e, traceback.format_exc()) 31 | # self.error_method.emit() 32 | pass 33 | # self.finished.emit(ret) 34 | 35 | def kill(self): 36 | self.killed = True 37 | 38 | change_value = pyqtSignal(int) 39 | -------------------------------------------------------------------------------- /generate_model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/generate_model/__init__.py -------------------------------------------------------------------------------- /generate_model/appCtx.py: -------------------------------------------------------------------------------- 1 | import sys, os, random, string 2 | from typing import Dict, List, Union 3 | 4 | from qgis.core import QgsVectorLayer, QgsRasterLayer 5 | from .bibliotecas import DotDict, logger 6 | 7 | 8 | def add_layer(filePath, type="raster", layer_name="", provider="gdal", crs_id=None): 9 | layer = None 10 | 11 | if type == "vector": 12 | layer = QgsVectorLayer(filePath, layer_name, provider) 13 | else: 14 | layer = QgsRasterLayer(filePath, layer_name, provider) 15 | 16 | if not layer.isValid(): 17 | raise Exception("Error!") 18 | 19 | if crs_id != None: 20 | crs = layer.crs() 21 | crs.createFromId(crs_id) 22 | 23 | return layer 24 | 25 | 26 | class appContext: 27 | BUILDING_HEIGHT_METHODS: List[Dict[str, Union[str, int]]] = [ 28 | { 29 | "title": "Mode (the value that most repeats)", 30 | "algorithm": "native:zonalstatistics", 31 | "method_id": 9, 32 | }, 33 | { 34 | "title": "Maximum Value", 35 | "algorithm": "grass7:v.rast.stats", 36 | "method_id": 2, 37 | }, 38 | { 39 | "title": "Average", 40 | "algorithm": "grass7:v.rast.stats", 41 | "method_id": 4, 42 | }, 43 | { 44 | "title": "Median", 45 | "algorithm": "grass7:v.rast.stats", 46 | "method_id": 10, 47 | }, 48 | { 49 | "title": "Third Quartile", 50 | "algorithm": "grass7:v.rast.stats", 51 | "method_id": 11, 52 | }, 53 | { 54 | "title": "Percentile", 55 | "algorithm": "grass7:v.rast.stats", 56 | "method_id": 12, 57 | }, 58 | { 59 | "title": "Mode", 60 | "algorithm": "process:mode", 61 | }, 62 | ] 63 | 64 | plugins = DotDict.DotDict({ 65 | "getter_ortho_list": [], 66 | "getter_dtm_list": [], 67 | "getter_dsm_list": [], 68 | "getter_footprint_list": [], 69 | "footprint_algorithm":[], 70 | "getter_street_list": [], 71 | "getter_tree_list": [], 72 | "getter_water_list": [], 73 | }) 74 | 75 | user_parameters = DotDict.DotDict({ 76 | "x1": 0, 77 | "y1": 0, 78 | "x2": 0, 79 | "y2": 0, 80 | 81 | "ortho_getter": None, 82 | "dtm_getter": None, 83 | "dsm_getter": None, 84 | "footprint_getter": None, 85 | "street_getter": None, 86 | "tree_getter": None, 87 | "water_getter": None, 88 | 89 | "ortho_output": "", 90 | "dtm_output": "", 91 | "dsm_output": "", 92 | "footprint_output": "", 93 | "street_output": "", 94 | "tree_output": "", 95 | "water_output": "", 96 | 97 | "building_height_method": "", 98 | "clip_layer": None 99 | }) 100 | 101 | layers = DotDict.DotDict({ 102 | "ortho": { 103 | "layer": None, 104 | "data_provider": None, 105 | "type": "raster", 106 | "crs": None 107 | }, 108 | "dtm": { 109 | "layer": None, 110 | "data_provider": None, 111 | "type": "raster", 112 | "crs": None 113 | }, 114 | "dsm": { 115 | "layer": None, 116 | "data_provider": None, 117 | "type": "raster", 118 | "crs": None 119 | }, 120 | "footprint": { 121 | "layer": None, 122 | "data_provider": None, 123 | "type": "vector", 124 | "crs": None 125 | }, 126 | "street": { 127 | "layer": None, 128 | "data_provider": None, 129 | "type": "vector", 130 | "crs": None 131 | }, 132 | "tree": { 133 | "layer": None, 134 | "data_provider": None, 135 | "type": "vector", 136 | "crs": None 137 | }, 138 | "water": { 139 | "layer": None, 140 | "data_provider": None, 141 | "type": "vector", 142 | "crs": None 143 | }, 144 | "clipping_polygon": { 145 | "layer": None, 146 | "data_provider": None, 147 | "type": "vector", 148 | "crs": None 149 | }, 150 | }) 151 | 152 | qgis = DotDict.DotDict({ 153 | "iface": None, 154 | "dlg": None, 155 | "geopandas": None, 156 | "osmx": None 157 | }) 158 | 159 | execution = DotDict.DotDict({ 160 | "id": "", 161 | "temp_folder": "", 162 | "raw_temp_folder": "", 163 | "normalized_temp_folder": "", 164 | "overall": { 165 | "description": "", 166 | "current": 0, 167 | "maximum": 100 168 | }, 169 | "step": { 170 | "description": "", 171 | "current": 0, 172 | "maximum": 100 173 | } 174 | }) 175 | 176 | def update_layer(self, path, name, data_provider=None, type=None, crs=None): 177 | data_provider = data_provider or self.layers[name].data_provider 178 | type = type or self.layers[name].type 179 | crs = crs or self.layers[name].crs or None 180 | 181 | self.layers[name].data_provider = data_provider 182 | self.layers[name].type = type 183 | self.layers[name].crs = crs 184 | 185 | layer = add_layer(path, type, name, data_provider, crs) 186 | 187 | self.layers[name].layer = layer 188 | 189 | return layer 190 | 191 | def update_layer_with_loaded(self, layer, layer_name): 192 | self.layers[layer_name].layer = layer 193 | self.layers[layer_name].data_provider = layer.dataProvider().name() 194 | 195 | return layer 196 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/DotDict.py: -------------------------------------------------------------------------------- 1 | 2 | class DotDict(dict): 3 | def __init__(self, *args, **kwargs): 4 | super().__init__(*args, **kwargs) 5 | # Recursively turn nested dicts into DotDicts 6 | for key, value in self.items(): 7 | if type(value) is dict: 8 | self[key] = DotDict(value) 9 | 10 | def __setitem__(self, key, item): 11 | if type(item) is dict: 12 | item = DotDict(item) 13 | super().__setitem__(key, item) 14 | 15 | __setattr__ = __setitem__ 16 | __getattr__ = dict.__getitem__ 17 | 18 | 19 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/generate_model/bibliotecas/__init__.py -------------------------------------------------------------------------------- /generate_model/bibliotecas/execute.py: -------------------------------------------------------------------------------- 1 | from subprocess import Popen, PIPE, STDOUT 2 | import subprocess, sys 3 | 4 | 5 | def execute_terminal_command(command): 6 | with open('test.log', 'w') as f: # replace 'w' with 'wb' for Python 3 7 | process = subprocess.Popen(command, stdout=subprocess.PIPE) 8 | for c in iter(lambda: process.stdout.read(1), ''): # replace '' with b'' for Python 3 9 | pass 10 | # sys.stdout.write(c) 11 | # f.write(c) 12 | 13 | # process = Popen(command.split(" "), shell=True, stdout=PIPE, stderr=STDOUT, stdin=PIPE) 14 | # # Poll process for new output until finished 15 | # while True: 16 | # nextline = process.stdout.readline() 17 | # if nextline == '' and process.poll() is not None: 18 | # break 19 | # You can add here some progress infos 20 | # 21 | # output = process.communicate()[0] 22 | # exitCode = process.returncode 23 | # 24 | # if exitCode == 0: 25 | # return output 26 | # else: 27 | # raise Exception(command, exitCode, output) 28 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/extension_manager.py: -------------------------------------------------------------------------------- 1 | import os, importlib, json, pathlib 2 | import qgis 3 | from . import DotDict, logger 4 | from .. import bibliotecas 5 | from ..normalizer import normalizer 6 | from ..appCtx import appContext 7 | 8 | 9 | def get_list(): 10 | plugin_list = load_plugin_list() 11 | return list(plugin_list) 12 | 13 | 14 | def load_plugin_list(): 15 | logger.plugin_log("Loading Plugins... ") 16 | 17 | file_re = os.path.dirname(os.path.realpath(__file__)) 18 | path = pathlib.Path(file_re) 19 | plugins_path = os.path.join(str(path.parent.parent), "extensions") 20 | 21 | appContext.plugins.path = plugins_path 22 | 23 | logger.plugin_log("Loading getters from: " + plugins_path) 24 | 25 | directory_list = os.listdir(plugins_path) 26 | 27 | plugin_list = [] 28 | for index, directory_name in enumerate(directory_list): 29 | try: 30 | if "__init__.py" == directory_name or "DS_Store" == directory_name: 31 | continue 32 | 33 | with open(rf'{plugins_path}/{directory_name}/config.json') as file: 34 | plugin_configuration_file = json.load(file) 35 | 36 | if "features" not in plugin_configuration_file \ 37 | or len(plugin_configuration_file["features"]) != 1 \ 38 | or "properties" not in plugin_configuration_file["features"][0] \ 39 | or "geometry" not in plugin_configuration_file["features"][0]: 40 | logger.plugin_log( 41 | f"Invalid config.json file for plugin {directory_name}.", "ERROR") 42 | raise Exception() 43 | 44 | plugin_feature = plugin_configuration_file["features"][0] 45 | plugin_properties = plugin_feature["properties"] 46 | plugin_geometry = plugin_feature["geometry"] 47 | 48 | if "layer" not in plugin_properties: 49 | logger.plugin_log( 50 | f"Invalid config.json file for plugin {directory_name}.\n Property 'layer' is mandatory on features[0].properties.", "ERROR") 51 | raise Exception() 52 | 53 | plugin_list.append({ 54 | "id": directory_name, 55 | "position": 0 if directory_name in ["local_ortho", "local_dtm", "local_dsm", "local_footprint"] else index + 1, 56 | "name": plugin_properties.get("name", directory_name), 57 | "format": plugin_properties["format"], 58 | "layer": plugin_properties["layer"], 59 | "crs": plugin_properties.get("crs", None), 60 | "cropIncluded": plugin_properties.get("cropIncluded", False), 61 | "requirements": plugin_properties.get("requirements", []), 62 | "parameters": plugin_properties.get("parameters", {}), 63 | "geometry": plugin_geometry 64 | }) 65 | except FileExistsError: 66 | logger.plugin_log(f"Fail to load {directory_name} plugin! The plugin does not have a config.yml file", "ERROR") 67 | except Exception: 68 | logger.plugin_log(f"Fail to load {directory_name} plugin!", "ERROR") 69 | 70 | 71 | plugin_list = sorted(plugin_list, key=lambda k: (k['position'], k['name'])) 72 | 73 | logger.plugin_log("Done!", "SUCCESS") 74 | return plugin_list 75 | 76 | 77 | def run_plugin_method(plugin_id, method_name): 78 | logger.plugin_log(f"plugin_id: {plugin_id}") 79 | path = f"{appContext.plugins.path}/{plugin_id}" 80 | plugin_main_module = importlib.machinery.SourceFileLoader('mainnn', f'{path}/main.py').load_module() 81 | 82 | 83 | 84 | appResources = DotDict.DotDict({ 85 | "configure_plugin": configure_plugin, 86 | "execute_plugin": execute_plugin, 87 | "bibliotecas": bibliotecas, 88 | "equalize_layer": normalizer.equalize_layer, 89 | "qgis": qgis 90 | }) 91 | 92 | method = getattr(plugin_main_module, method_name) 93 | method(appResources, appContext) 94 | 95 | 96 | 97 | def configure_plugin(plugin_id): 98 | run_plugin_method(plugin_id, "configure") 99 | 100 | 101 | def execute_plugin(plugin_id): 102 | run_plugin_method(plugin_id, "execute") 103 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/file_management.py: -------------------------------------------------------------------------------- 1 | import zipfile, shutil,os 2 | from . import progress_bar, logger 3 | 4 | def create_dirs(path): 5 | os.makedirs(path, exist_ok=True) 6 | 7 | def create_temp_dirs(path): 8 | os.makedirs(os.path.join(path, "ortho"), exist_ok=True) 9 | os.makedirs(os.path.join(path, "dtm"), exist_ok=True) 10 | os.makedirs(os.path.join(path, "dsm"), exist_ok=True) 11 | os.makedirs(os.path.join(path, "footprint"), exist_ok=True) 12 | os.makedirs(os.path.join(path, "street"), exist_ok=True) 13 | os.makedirs(os.path.join(path, "tree"), exist_ok=True) 14 | os.makedirs(os.path.join(path, "water"), exist_ok=True) 15 | os.makedirs(os.path.join(path, "downolads"), exist_ok=True) 16 | 17 | def unzip_file(zip_file, destination): 18 | zf = zipfile.ZipFile(f"{zip_file}") 19 | 20 | p = progress_bar.create(len(zf.infolist())) 21 | logger.update_progress(step_current=0, step_maximum=len(zf.infolist())) 22 | for file in zf.infolist(): 23 | progress_bar.update(p) 24 | logger.increase_step_current() 25 | zf.extract(file, path=f"{destination}/") 26 | 27 | progress_bar.done(p) 28 | 29 | def unzip_file_list(zip_file_list, destination_list): 30 | total = len(zip_file_list) 31 | count = 0 32 | 33 | for index, url in enumerate(zip_file_list): 34 | count = count + 1 35 | logger.update_progress(step_description=f"Unzipping {count} of {total}...") 36 | logger.plugin_log(f"Unzipping {count} of {total}...") 37 | 38 | unzip_file(zip_file_list[index], destination_list[index]) 39 | 40 | 41 | def copy_file(source, destination): 42 | shutil.copy(f"{source}", f"{destination}") 43 | 44 | def move_file(source, destination): 45 | shutil.move(f"{source}", f"{destination}") 46 | 47 | def path_cleanup(path): 48 | return path.split("|")[0] 49 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/inputa.py: -------------------------------------------------------------------------------- 1 | import re, logging 2 | from . import path_manager 3 | 4 | INPUT_TYPES = { 5 | "FLOAT": { 6 | "validate": lambda x: bool(re.compile(r'^[-+]?[-0-9]\d*$').match(x)), 7 | "convert": lambda x: float(x) 8 | }, 9 | "INT": { 10 | "validate": lambda x: bool(re.compile(r'^[-+]?[-0-9]\d*\.\d*|[-+]?\.?[0-9]\d*$').match(x)), 11 | "convert": lambda x: int(x) 12 | }, 13 | "STR": { 14 | "validate": lambda x: True, 15 | "convert": lambda x: str(x) 16 | }, 17 | "BOOL": { 18 | "validate": lambda x: True if x.upper() in ["Y", "YES", "T", "TRUE", "1", 19 | "N", "NO", "F", "FALSE", "0"] else False, 20 | "convert": lambda x: True if x.upper() in ["Y", "YES", "T", "TRUE", "1"] else False 21 | }, 22 | "PATH_CREATABLE": { 23 | "validate": lambda x: validate_PATH_CREATABLE(x), 24 | "convert": lambda x: str(x) 25 | }, 26 | "PATH_READABLE": { 27 | "validate": lambda x: path_manager.is_path_exists(x), 28 | "convert": lambda x: str(x) 29 | }, 30 | } 31 | 32 | 33 | def validate_PATH_CREATABLE(path): 34 | if path_manager.is_path_exists_or_creatable(path): 35 | 36 | if path_manager.is_path_exists(path): 37 | overrite = validate("Output file location already exists. Do you want to override it? [yes/no]: ", 38 | INPUT_TYPES["BOOL"]) 39 | 40 | if not overrite: 41 | return False 42 | return True 43 | 44 | return False 45 | 46 | 47 | def validate(msg, predicate=INPUT_TYPES["STR"], default_value=None, is_mandatory=True, error_string="Illegal Input"): 48 | while True: 49 | result = input(msg).strip() 50 | 51 | if (result == "" and default_value != None): 52 | result = default_value 53 | if result == "" and is_mandatory: 54 | continue 55 | if predicate["validate"](result): 56 | return predicate["convert"](result) 57 | 58 | logging.error(error_string) 59 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/install_python_package.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import sys 3 | 4 | def install_package(package): 5 | try: 6 | pass 7 | # subprocess.check_call([sys.executable, "-m", "pip", "install", package]) 8 | except Exception(e): 9 | pass 10 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/internet.py: -------------------------------------------------------------------------------- 1 | import urllib, sys, requests 2 | from . import progress_bar, logger 3 | 4 | 5 | def download_file(url, file_destination): 6 | with open(file_destination, "wb") as f: 7 | print("Downloading...") 8 | response = requests.get(url, stream=True) 9 | total_length = response.headers.get('content-length') 10 | 11 | if total_length is None: # no content length header 12 | f.write(response.content) 13 | print( 14 | "Unable to retrieve file size. You will be informed when the download has finished. It might take a while") 15 | urllib.request.urlretrieve(url, file_destination) 16 | print("Done!") 17 | else: 18 | dl = 0 19 | total_length = int(total_length) 20 | 21 | chunk_size = 1024 22 | progress_bar_helper = progress_bar.create(total_length / chunk_size) 23 | logger.update_progress(step_current=0, step_maximum=total_length / chunk_size) 24 | for data in response.iter_content(chunk_size=chunk_size): 25 | dl += len(data) 26 | logger.increase_step_current() 27 | progress_bar.update(progress_bar_helper) 28 | f.write(data) 29 | 30 | progress_bar.done(progress_bar_helper) 31 | 32 | 33 | def download_file_list(url_list, file_destination_list): 34 | total = len(url_list) 35 | count = 0 36 | 37 | for index, url in enumerate(url_list): 38 | count = count + 1 39 | logger.update_progress(step_description=f"Downloading {count} of {total}...") 40 | logger.plugin_log(f"Downloading {count} of {total}...") 41 | logger.plugin_log(f"Downloading from: {url_list[index]}") 42 | logger.plugin_log(f"Downloading to: {file_destination_list[index]}") 43 | 44 | download_file(url_list[index], file_destination_list[index]) 45 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/logger.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | from datetime import datetime 4 | from qgis.core import Qgis, QgsMessageLog 5 | from ..appCtx import appContext 6 | 7 | 8 | def write_into_log_file(text, log_level): 9 | home = str(Path.home()) 10 | with open(os.path.join(home, "citygen_log.log"), "a") as fd: 11 | fd.write(f"\n{log_level} {str(datetime.now())}: {text}") 12 | 13 | def general_log(message): 14 | QgsMessageLog.logMessage(message) 15 | 16 | 17 | def message_bar_log(title, message="", level=Qgis.Success): 18 | appContext.qgis.iface.messageBar().pushMessage(title, message, level=level, duration=3) 19 | write_into_log_file(f"message_bar_log: {title}: {message}", "BAR") 20 | 21 | 22 | def plugin_log(message="", log_level="INFO"): 23 | if message != "" and message != " ": 24 | appContext.qgis.segf.dlg.txtLog.append(message) 25 | write_into_log_file(f"plugin_log - {message}", log_level) 26 | 27 | 28 | def update_progress(step_current=None, step_description=None, step_maximum=None, 29 | overall_current=None, overall_description=None, overall_maximum=None): 30 | if step_current is not None: 31 | appContext.execution.step.current = step_current 32 | if step_description is not None and step_description != "": 33 | plugin_log(f"Current step: {step_description}") 34 | if step_description is not None: 35 | appContext.execution.step.description = step_description 36 | if step_maximum is not None: 37 | appContext.execution.step.maximum = step_maximum 38 | if overall_current is not None: 39 | appContext.execution.overall.current = overall_current 40 | if overall_description is not None: 41 | appContext.execution.overall.description = overall_description 42 | if overall_maximum is not None: 43 | appContext.execution.overall.maximum = overall_maximum 44 | 45 | if appContext.execution.overall.description != "" or appContext.execution.step.description != "": 46 | appContext.qgis.segf.dlg.lblStepDescription.setText(f"{appContext.execution.overall.description} - {appContext.execution.step.description}") 47 | appContext.qgis.dlg.prgStepProgress.setValue(appContext.execution.step.current) 48 | appContext.qgis.dlg.prgStepProgress.setMaximum(appContext.execution.step.maximum) 49 | 50 | appContext.qgis.dlg.prgOverallProgress.setValue(appContext.execution.overall.current) 51 | appContext.qgis.dlg.prgOverallProgress.setMaximum(appContext.execution.overall.maximum) 52 | 53 | 54 | def increase_step_current(step_description=appContext.execution.step.description): 55 | update_progress(step_current=appContext.execution.step.current + 1, step_description=step_description) 56 | 57 | 58 | def increase_overall_current(overall_description=appContext.execution.overall.description): 59 | update_progress(overall_current=appContext.execution.overall.current + 1, overall_description=overall_description) 60 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/path_manager.py: -------------------------------------------------------------------------------- 1 | import errno, os, sys 2 | 3 | # Source: https://stackoverflow.com/questions/9532499/check-whether-a-path-is-valid-in-python-without-creating-a-file-at-the-paths-ta 4 | 5 | # Sadly, Python fails to provide the following magic number for us. 6 | ERROR_INVALID_NAME = 123 7 | ''' 8 | Windows-specific error code indicating an invalid pathname. 9 | 10 | See Also 11 | ---------- 12 | https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- 13 | Official listing of all such codes. 14 | ''' 15 | 16 | 17 | def is_pathname_valid(pathname: str) -> bool: 18 | ''' 19 | `True` if the passed pathname is a valid pathname for the current OS; 20 | `False` otherwise. 21 | ''' 22 | # If this pathname is either not a string or is but is empty, this pathname 23 | # is invalid. 24 | try: 25 | if not isinstance(pathname, str) or not pathname: 26 | return False 27 | 28 | # Strip this pathname's Windows-specific drive specifier (e.g., `C:\`) 29 | # if any. Since Windows prohibits path components from containing `:` 30 | # characters, failing to strip this `:`-suffixed prefix would 31 | # erroneously invalidate all valid absolute Windows pathnames. 32 | _, pathname = os.path.splitdrive(pathname) 33 | 34 | # Directory guaranteed to exist. If the current OS is Windows, this is 35 | # the drive to which Windows was installed (e.g., the "%HOMEDRIVE%" 36 | # environment variable); else, the typical root directory. 37 | root_dirname = os.environ.get('HOMEDRIVE', 'C:') \ 38 | if sys.platform == 'win32' else os.path.sep 39 | assert os.path.isdir(root_dirname) # ...Murphy and her ironclad Law 40 | 41 | # Append a path separator to this directory if needed. 42 | root_dirname = root_dirname.rstrip(os.path.sep) + os.path.sep 43 | 44 | # Test whether each path component split from this pathname is valid or 45 | # not, ignoring non-existent and non-readable path components. 46 | for pathname_part in pathname.split(os.path.sep): 47 | try: 48 | os.lstat(root_dirname + pathname_part) 49 | # If an OS-specific exception is raised, its error code 50 | # indicates whether this pathname is valid or not. Unless this 51 | # is the case, this exception implies an ignorable kernel or 52 | # filesystem complaint (e.g., path not found or inaccessible). 53 | # 54 | # Only the following exceptions indicate invalid pathnames: 55 | # 56 | # * Instances of the Windows-specific "WindowsError" class 57 | # defining the "winerror" attribute whose value is 58 | # "ERROR_INVALID_NAME". Under Windows, "winerror" is more 59 | # fine-grained and hence useful than the generic "errno" 60 | # attribute. When a too-long pathname is passed, for example, 61 | # "errno" is "ENOENT" (i.e., no such file or directory) rather 62 | # than "ENAMETOOLONG" (i.e., file name too long). 63 | # * Instances of the cross-platform "OSError" class defining the 64 | # generic "errno" attribute whose value is either: 65 | # * Under most POSIX-compatible OSes, "ENAMETOOLONG". 66 | # * Under some edge-case OSes (e.g., SunOS, *BSD), "ERANGE". 67 | except OSError as exc: 68 | if hasattr(exc, 'winerror'): 69 | if exc.winerror == ERROR_INVALID_NAME: 70 | return False 71 | elif exc.errno in {errno.ENAMETOOLONG, errno.ERANGE}: 72 | return False 73 | # If a "TypeError" exception was raised, it almost certainly has the 74 | # error message "embedded NUL character" indicating an invalid pathname. 75 | except TypeError as exc: 76 | return False 77 | # If no exception was raised, all path components and hence this 78 | # pathname itself are valid. (Praise be to the curmudgeonly python.) 79 | else: 80 | return True 81 | # If any other exception was raised, this is an unrelated fatal issue 82 | # (e.g., a bug). Permit this exception to unwind the call stack. 83 | # 84 | # Did we mention this should be shipped with Python already? 85 | 86 | 87 | def is_path_creatable(pathname: str) -> bool: 88 | ''' 89 | `True` if the current user has sufficient permissions to create the passed 90 | pathname; `False` otherwise. 91 | ''' 92 | # Parent directory of the passed path. If empty, we substitute the current 93 | # working directory (CWD) instead. 94 | dirname = os.path.dirname(os.path.expanduser(pathname)) 95 | return os.access(dirname, os.W_OK) 96 | 97 | 98 | def is_path_exists(pathname): 99 | pathname = os.path.expanduser(pathname) 100 | return os.access(pathname, os.R_OK) and os.path.isfile(pathname) 101 | 102 | 103 | def is_path_exists_or_creatable(pathname: str) -> bool: 104 | ''' 105 | `True` if the passed pathname is a valid pathname for the current OS _and_ 106 | either currently exists or is hypothetically creatable; `False` otherwise. 107 | 108 | This function is guaranteed to _never_ raise exceptions. 109 | ''' 110 | try: 111 | # To prevent "os" module calls from raising undesirable exceptions on 112 | # invalid pathnames, is_pathname_valid() is explicitly called first. 113 | return is_pathname_valid(pathname) and ( 114 | is_path_exists(pathname) or is_path_creatable(pathname)) 115 | # Report failure on non-fatal filesystem complaints (e.g., connection 116 | # timeouts, permissions issues) implying this path to be inaccessible. All 117 | # other exceptions are unrelated fatal issues and should not be caught here. 118 | except OSError: 119 | return False 120 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/progress_bar.py: -------------------------------------------------------------------------------- 1 | import sys, time 2 | from numpy import linspace 3 | from . import DotDict 4 | 5 | 6 | def ProgressBar(iterObj): 7 | def SecToStr(sec): 8 | m, s = divmod(sec, 60) 9 | h, m = divmod(m, 60) 10 | return u'%d:%02d:%02d' % (h, m, s) 11 | 12 | L = len(iterObj) 13 | steps = {int(x): y for x, y in zip(linspace(0, L, min(100, L), endpoint=False), 14 | linspace(0, 100, min(100, L), endpoint=False))} 15 | qSteps = ['', u'\u258E', u'\u258C', u'\u258A'] # quarter and half block chars 16 | startT = time.time() 17 | timeStr = ' [0:00:00, -:--:--]' 18 | activity = [' -', ' \\', ' |', ' /'] 19 | for nn, item in enumerate(iterObj): 20 | if nn in steps: 21 | done = u'\u2588' * int(steps[nn] / 4.0) + qSteps[int(steps[nn] % 4)] 22 | todo = ' ' * (25 - len(done)) 23 | barStr = u'%4d%% |%s%s|' % (steps[nn], done, todo) 24 | if nn > 0: 25 | endT = time.time() 26 | timeStr = ' [%s, %s]' % (SecToStr(endT - startT), 27 | SecToStr((endT - startT) * (L / float(nn) - 1))) 28 | # sys.stdout.write('\r' + barStr + activity[nn % 4] + timeStr); 29 | # sys.stdout.flush() 30 | yield item 31 | barStr = u'%4d%% |%s|' % (100, u'\u2588' * 25) 32 | timeStr = ' [%s, 0:00:00]\n' % (SecToStr(time.time() - startT)) 33 | # sys.stdout.write('\r' + barStr + timeStr); 34 | # sys.stdout.flush() 35 | 36 | 37 | def SecToStr(sec): 38 | m, s = divmod(sec, 60) 39 | h, m = divmod(m, 60) 40 | return u'%d:%02d:%02d' % (h, m, s) 41 | 42 | 43 | def create(total): 44 | obj= DotDict.DotDict({ 45 | "total": total, 46 | "current": 0, 47 | "start_time": time.time() 48 | }) 49 | 50 | update(obj, 0) 51 | 52 | return obj 53 | 54 | def update(progress_bar_obj, current_step=None): 55 | current = current_step 56 | if current is None: 57 | current = progress_bar_obj.current + 1 58 | 59 | currentPorcentage = current*100/progress_bar_obj.total 60 | 61 | L = progress_bar_obj.total 62 | PARTIAL_STEPS = ['', u'\u258E', u'\u258C', u'\u258A'] # quarter and half block chars 63 | startT = progress_bar_obj.start_time 64 | timeStr = ' [0:00:00, -:--:--]' 65 | activity = [' -', ' \\', ' |', ' /'] 66 | 67 | done = u'\u2588' * int(currentPorcentage / 4.0) + PARTIAL_STEPS[int((currentPorcentage) % 4)] 68 | todo = ' ' * (25 - len(done)) 69 | barStr = u'%4d%% |%s%s|' % (currentPorcentage, done, todo) 70 | if progress_bar_obj.current > 0: 71 | endT = time.time() 72 | timeStr = ' [%s, %s]' % (SecToStr(endT - startT), 73 | SecToStr((endT - startT) * (L / float(currentPorcentage) - 1))) 74 | # sys.stdout.write('\r' + barStr + activity[int(currentPorcentage % 4)] + timeStr) 75 | # sys.stdout.flush() 76 | 77 | progress_bar_obj.current = current 78 | 79 | def done(progress_bar_obj): 80 | barStr = u'%4d%% |%s|' % (100, u'\u2588' * 25) 81 | timeStr = ' [%s, 0:00:00]\n' % (SecToStr(time.time() - progress_bar_obj.start_time)) 82 | # sys.stdout.write('\r' + barStr + timeStr); 83 | -------------------------------------------------------------------------------- /generate_model/bibliotecas/t.py: -------------------------------------------------------------------------------- 1 | import os, pathlib 2 | 3 | if __name__ == '__main__': 4 | file_re = os.path.dirname(os.path.realpath(__file__)) 5 | path = pathlib.Path(file_re) 6 | print(path.parent) 7 | -------------------------------------------------------------------------------- /generate_model/getters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/generate_model/getters/__init__.py -------------------------------------------------------------------------------- /generate_model/getters/getters_management.py: -------------------------------------------------------------------------------- 1 | from ..appCtx import appContext 2 | from ..bibliotecas import progress_bar, extension_manager, logger 3 | from ..normalizer.normalizer import normalize_layer 4 | 5 | 6 | 7 | def execute_getters(): 8 | # Ortho 9 | logger.increase_overall_current("Data Retrieve") 10 | logger.update_progress(step_current=1, step_description="Satellite Image (Ortho)", step_maximum=100) 11 | extension_manager.execute_plugin(appContext.user_parameters.ortho_getter.id) 12 | normalize_layer("ortho", "raster") 13 | logger.plugin_log("Done!", "SUCCESS") 14 | 15 | # DTM 16 | logger.increase_overall_current() 17 | logger.update_progress(step_current=1, step_description="Digital Terrain Model (DTM)", step_maximum=100) 18 | extension_manager.execute_plugin(appContext.user_parameters.dtm_getter.id) 19 | normalize_layer("dtm", "raster") 20 | logger.plugin_log("Done!", "SUCCESS") 21 | 22 | # DSM 23 | logger.increase_overall_current() 24 | logger.update_progress(step_current=1, step_description="Digital Surface Model (DSM)", step_maximum=100) 25 | extension_manager.execute_plugin(appContext.user_parameters.dsm_getter.id) 26 | normalize_layer("dsm", "raster") 27 | logger.plugin_log("Done!", "SUCCESS") 28 | 29 | 30 | # Footprint 31 | logger.increase_overall_current() 32 | logger.update_progress(step_current=1, step_description="Footprint", step_maximum=100) 33 | # if appContext.user_parameters.footprint_getter.format == "algorithm": 34 | # extension_management.run_plugin_method(appContext.user_parameters.footprint_getter.id, "identify_footprint") 35 | extension_manager.execute_plugin(appContext.user_parameters.footprint_getter.id) 36 | logger.plugin_log("Done!", "SUCCESS") 37 | 38 | # Street 39 | if appContext.user_parameters.street_getter is not None: 40 | logger.increase_overall_current() 41 | logger.update_progress(step_current=1, step_description="Street", step_maximum=100) 42 | # if appContext.user_parameters.street_getter.format == "algorithm": 43 | # extension_management.run_plugin_method(appContext.user_parameters.street_getter.id, "identify_street") 44 | extension_manager.execute_plugin(appContext.user_parameters.street_getter.id) 45 | logger.plugin_log("Done!", "SUCCESS") 46 | 47 | 48 | # Tree 49 | if appContext.user_parameters.tree_getter is not None: 50 | logger.increase_overall_current() 51 | logger.update_progress(step_current=1, step_description="Tree", step_maximum=100) 52 | # if appContext.user_parameters.tree_getter.format == "algorithm": 53 | # extension_management.run_plugin_method(appContext.user_parameters.tree_getter.id, "identify_tree") 54 | extension_manager.execute_plugin(appContext.user_parameters.tree_getter.id) 55 | logger.plugin_log("Done!", "SUCCESS") 56 | 57 | 58 | # Water 59 | if appContext.user_parameters.water_getter is not None: 60 | logger.increase_overall_current() 61 | logger.update_progress(step_current=1, step_description="Water", step_maximum=100) 62 | # if appContext.user_parameters.water_getter.format == "algorithm": 63 | # extension_management.run_plugin_method(appContext.user_parameters.water_getter.id, "identify_water") 64 | extension_manager.execute_plugin(appContext.user_parameters.water_getter.id) 65 | logger.plugin_log("Done!", "SUCCESS") 66 | -------------------------------------------------------------------------------- /generate_model/gis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/generate_model/gis/__init__.py -------------------------------------------------------------------------------- /generate_model/gis/gis.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # sys.path.append("/Volumes/TarDisk/ruf/workspace/ttc/3dcitybuilder/citygen/generate_model/gis/dependencies/") 4 | # sys.path.append("/Volumes/TarDisk/ruf/workspace/ttc/3dcitybuilder/citygen/generate_model/gis/dependencies/osmnx/") 5 | # sys.path.append("/Volumes/TarDisk/ruf/workspace/ttc/3dcitybuilder/citygen/generate_model/gis/dependencies/geopandas/") 6 | 7 | import os, processing 8 | import qgis 9 | 10 | from qgis.core import QgsRasterLayer, QgsProject, QgsCoordinateReferenceSystem, QgsProperty, QgsVectorLayer, QgsFeature, \ 11 | QgsGeometry, QgsPointXY, QgsVectorFileWriter, QgsFields, QgsSimpleLineSymbolLayer 12 | from qgis.core.additions.edit import edit 13 | import qgis._3d as d 14 | from PyQt5.QtGui import QColor 15 | from ..appCtx import appContext, add_layer 16 | from ..bibliotecas import logger, file_management, extension_manager 17 | from ..normalizer import normalizer 18 | 19 | 20 | def create_viewport_polygon(): 21 | extent = appContext.qgis.iface.mapCanvas().extent() 22 | 23 | layer = QgsVectorLayer(f"Polygon?crs={QgsProject.instance().crs().toWkt()}", 'polygon', "memory") 24 | feature = QgsFeature() 25 | points = [ 26 | QgsPointXY( 27 | extent.xMinimum(), 28 | extent.yMaximum() 29 | ), 30 | QgsPointXY( 31 | extent.xMaximum(), 32 | extent.yMaximum() 33 | ), 34 | QgsPointXY( 35 | extent.xMaximum(), 36 | extent.yMinimum() 37 | ), 38 | QgsPointXY( 39 | extent.xMinimum(), 40 | extent.yMinimum() 41 | ) 42 | ] 43 | # or points = [QgsPointXY(50,50),QgsPointXY(50,150),QgsPointXY(100,150),QgsPointXY(100,50)] 44 | feature.setGeometry(QgsGeometry.fromPolygonXY([points])) 45 | layer.dataProvider().addFeatures([feature]) 46 | layer.updateExtents() 47 | QgsProject.instance().addMapLayers([layer]) 48 | 49 | path = f"{appContext.execution.raw_temp_folder}/viewport.geojson" 50 | error, error_string = QgsVectorFileWriter.writeAsVectorFormat( 51 | layer, 52 | path, 53 | 'utf-8', 54 | # destCRS=QgsProject.instance().crs(), 55 | driverName="GeoJSON" 56 | ) 57 | 58 | if error != QgsVectorFileWriter.NoError: 59 | raise Exception('Error on creating Clipping Polygon: {details}'.format(details=error_string)) 60 | 61 | loaded_layer = add_layer(path, "vector", "clipping_polygon", "ogr", layer.crs().postgisSrid()) 62 | 63 | return loaded_layer 64 | 65 | 66 | def extrude_footprint(): 67 | logger.plugin_log("Extruding footprint.infos") 68 | # vectorlayer = qgis.utils.iface.mapCanvas().currentLayer() 69 | # rasterfile = qgis.utils.iface.mapCanvas().currentLayer() 70 | 71 | logger.plugin_log( 72 | f"appContext.user_parameters.building_height_method: {appContext.user_parameters.building_height_method}") 73 | 74 | building_height_method = 2 75 | if appContext.user_parameters.building_height_method == 0: 76 | building_height_method = 1 77 | elif appContext.user_parameters.building_height_method == 1: 78 | building_height_method = 2 79 | elif appContext.user_parameters.building_height_method == 2: 80 | building_height_method = 4 81 | elif appContext.user_parameters.building_height_method == 3: 82 | building_height_method = 9 83 | elif appContext.user_parameters.building_height_method == 4: 84 | building_height_method = 10 85 | elif appContext.user_parameters.building_height_method == 5: 86 | building_height_method = 11 87 | elif appContext.user_parameters.building_height_method == 6: 88 | building_height_method = 12 89 | 90 | logger.plugin_log(f"building_height_method: {building_height_method}") 91 | 92 | output = "" 93 | 94 | if appContext.user_parameters.building_height_method.algorithm == "grass7:v.rast.stats": 95 | output = f"{appContext.execution.raw_temp_folder}/footprint/footprint_height.gpkg" 96 | output = f"{appContext.execution.raw_temp_folder}/footprint/footprint_height.geojson" 97 | 98 | processing.run( 99 | "grass7:v.rast.stats", 100 | { 101 | 'map': appContext.layers.footprint.layer.dataProvider().dataSourceUri(), 102 | 'raster': appContext.layers.dsm.layer.dataProvider().dataSourceUri(), 103 | 'column_prefix': "cb_heigh", 104 | 'method': [appContext.user_parameters.building_height_method.method_id], 105 | 'percentile': 90, 106 | 'output': output, 107 | 'GRASS_REGION_PARAMETER': None, 108 | 'GRASS_REGION_CELLSIZE_PARAMETER': 0, 109 | 'GRASS_SNAP_TOLERANCE_PARAMETER': -1, 110 | 'GRASS_MIN_AREA_PARAMETER': 0.0001, 111 | 'GRASS_OUTPUT_TYPE_PARAMETER': 3, 112 | 'GRASS_VECTOR_DSCO': '', 113 | 'GRASS_VECTOR_LCO': '', 114 | 'GRASS_VECTOR_EXPORT_NOCAT': False 115 | } 116 | ) 117 | elif appContext.user_parameters.building_height_method.algorithm == "saga:addrastervaluestofeatures": 118 | output = f"{appContext.execution.raw_temp_folder}/footprint/footprint_height.shp" 119 | 120 | processing.run( 121 | "saga:addrastervaluestofeatures", 122 | { 123 | 'SHAPES': appContext.layers.footprint.layer.dataProvider().dataSourceUri(), 124 | 'GRIDS': [ 125 | appContext.layers.dsm.layer.dataProvider().dataSourceUri() 126 | ], 127 | 'RESAMPLING': appContext.user_parameters.building_height_method.method_id, 128 | 'RESULT': output 129 | } 130 | ) 131 | elif appContext.user_parameters.building_height_method.algorithm == "native:zonalstatistics": 132 | output = appContext.layers.footprint.layer.dataProvider().dataSourceUri() 133 | 134 | processing.run( 135 | "native:zonalstatistics", 136 | { 137 | 'INPUT_RASTER': appContext.layers.dsm.layer.dataProvider().dataSourceUri(), 138 | 'RASTER_BAND': 1, 139 | 'INPUT_VECTOR': appContext.layers.footprint.layer.dataProvider().dataSourceUri(), 140 | 'COLUMN_PREFIX': 'cg_', 141 | 'STATISTICS': [ 142 | appContext.user_parameters.building_height_method.method_id 143 | ]}) 144 | elif appContext.user_parameters.building_height_method.algorithm == "process:mode": 145 | output = appContext.layers.footprint.layer.dataProvider().dataSourceUri() 146 | intermediary_shapefile = f'{appContext.execution.normalized_temp_folder}/dsm/dsm_points.shp' 147 | 148 | processing.run( 149 | "native:pixelstopoints", 150 | { 151 | 'INPUT_RASTER': appContext.layers.dsm.layer.dataProvider().dataSourceUri(), 152 | 'RASTER_BAND': 1, 153 | 'FIELD_NAME': 'height', 154 | 'OUTPUT': intermediary_shapefile 155 | } 156 | ) 157 | 158 | # v.vect.stats 159 | # output 160 | # intermediary_shapefile 161 | 162 | footprint = appContext.update_layer(appContext, output, "footprint", "ogr", "vector") 163 | 164 | normalizer.normalize_layer("footprint", "vector") 165 | 166 | findex = len(footprint.dataProvider().fields()) - 1 167 | if findex != -1: 168 | with edit(footprint): 169 | footprint.dataProvider().renameAttributes({findex: "cb_heigh"}) 170 | footprint.updateFields() 171 | else: 172 | loggeer.log("It was not possible to rename Buildings Height Variable.") 173 | 174 | 175 | def move(source, destination, layer_name): 176 | file_management.copy_file(file_management.path_cleanup(source), destination) 177 | 178 | if "|" in source: 179 | destination = f"{destination}|{source.split('|')[1]}" 180 | 181 | appContext.update_layer(appContext, destination, layer_name) 182 | 183 | 184 | def save_files(): 185 | if (appContext.user_parameters.ortho_output != ""): 186 | move(appContext.layers.ortho.layer.dataProvider().dataSourceUri(), appContext.user_parameters.ortho_output, 187 | "ortho") 188 | 189 | if (appContext.user_parameters.dtm_output != ""): 190 | move(appContext.layers.dtm.layer.dataProvider().dataSourceUri(), appContext.user_parameters.dtm_output, "dtm") 191 | 192 | if (appContext.user_parameters.dsm_output != ""): 193 | move(appContext.layers.dsm.layer.dataProvider().dataSourceUri(), appContext.user_parameters.dsm_output, "dsm") 194 | 195 | if (appContext.user_parameters.footprint_output != ""): 196 | move(appContext.layers.footprint.layer.dataProvider().dataSourceUri(), 197 | appContext.user_parameters.footprint_output, "footprint") 198 | 199 | if (appContext.user_parameters.street_output != ""): 200 | move(appContext.layers.street.layer.dataProvider().dataSourceUri(), 201 | appContext.user_parameters.street_output, "street") 202 | 203 | if (appContext.user_parameters.tree_output != ""): 204 | move(appContext.layers.tree.layer.dataProvider().dataSourceUri(), 205 | appContext.user_parameters.tree_output, "tree") 206 | 207 | if (appContext.user_parameters.water_output != ""): 208 | move(appContext.layers.water.layer.dataProvider().dataSourceUri(), 209 | appContext.user_parameters.water_output, "water") 210 | 211 | 212 | def load_layers_to_project(): 213 | QgsProject.instance().addMapLayer(appContext.layers.ortho.layer) 214 | QgsProject.instance().addMapLayer(appContext.layers.dtm.layer) 215 | QgsProject.instance().addMapLayer(appContext.layers.dsm.layer) 216 | 217 | # Footprint 218 | symbol = d.QgsPolygon3DSymbol() 219 | symbol.setAddBackFaces(False) 220 | symbol.setAltitudeBinding(1) 221 | symbol.setAltitudeClamping(0) 222 | symbol.setCullingMode(0) 223 | 224 | symbol.setEdgesEnabled(True) 225 | symbol.setEdgeWidth(0.4) 226 | 227 | # symbol.setExtrusionHeight(QgsProperty.fromExpression('"dsm"')) 228 | 229 | renderer = d.QgsVectorLayer3DRenderer() 230 | renderer.setSymbol(symbol) 231 | 232 | materialSettings = d.QgsPhongMaterialSettings() 233 | materialSettings.setAmbient(QColor(246, 141, 131)) 234 | materialSettings.setDiffuse(QColor(192, 173, 159)) 235 | materialSettings.setSpecular(QColor(255, 0, 0)) 236 | symbol.setMaterial(materialSettings) 237 | 238 | appContext.layers.footprint.layer.setRenderer3D(renderer) 239 | # renderer.setLayer(appContext.layers.footprint.layer) 240 | QgsProject.instance().addMapLayer(appContext.layers.footprint.layer) 241 | 242 | # Street 243 | if appContext.user_parameters.street_getter is not None: 244 | appContext.layers.street.layer.renderer().symbol().setWidth(10.50000) 245 | appContext.layers.street.layer.renderer().symbol().setColor(QColor("#000000")) 246 | 247 | symbol_layer = [None, None, None] 248 | 249 | symbol_layer[0] = QgsSimpleLineSymbolLayer() 250 | symbol_layer[0].setWidth(0.4) 251 | symbol_layer[0].setColor(QColor("#cdd31b")) 252 | symbol_layer[0].setPenJoinStyle(1) 253 | symbol_layer[0].setPenCapStyle(0) 254 | 255 | symbol_layer[1] = QgsSimpleLineSymbolLayer() 256 | symbol_layer[1].setWidth(10) 257 | symbol_layer[1].setColor(QColor("#3b3b3b")) 258 | symbol_layer[1].setPenJoinStyle(1) 259 | symbol_layer[1].setPenCapStyle(0) 260 | 261 | symbol_layer[2] = QgsSimpleLineSymbolLayer() 262 | symbol_layer[2].setWidth(10.5) 263 | symbol_layer[2].setColor(QColor("#000000")) 264 | symbol_layer[2].setPenJoinStyle(1) 265 | symbol_layer[2].setPenCapStyle(0) 266 | 267 | appContext.layers.street.layer.renderer().symbol().appendSymbolLayer(symbol_layer[0]) 268 | appContext.layers.street.layer.renderer().symbol().appendSymbolLayer(symbol_layer[1]) 269 | appContext.layers.street.layer.renderer().symbol().appendSymbolLayer(symbol_layer[2]) 270 | 271 | QgsProject.instance().addMapLayer(appContext.layers.street.layer) 272 | 273 | # Tree 274 | if appContext.user_parameters.tree_getter is not None: 275 | QgsProject.instance().addMapLayer(appContext.layers.tree.layer) 276 | 277 | # Water 278 | if appContext.user_parameters.water_getter is not None: 279 | QgsProject.instance().addMapLayer(appContext.layers.water.layer) 280 | 281 | 282 | def generate_3d_model(): 283 | extrude_footprint() 284 | save_files() 285 | load_layers_to_project() 286 | -------------------------------------------------------------------------------- /generate_model/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | /*************************************************************************** 4 | citygen 5 | A QGIS plugin 6 | A plugin to generate 3D models of urban areas 7 | Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 8 | ------------------- 9 | begin : 2020-04-30 10 | git sha : $Format:%H$ 11 | copyright : (C) 2020 by Arthur Ruf Hosang da Costa (https://github.com/arthurRuf) 12 | email : arthur.rhc@gmail.com 13 | ***************************************************************************/ 14 | 15 | /*************************************************************************** 16 | * * 17 | * This program is free software; you can redistribute it and/or modify * 18 | * it under the terms of the GNU General Public License as published by * 19 | * the Free Software Foundation; either version 2 of the License, or * 20 | * (at your option) any later version. * 21 | * * 22 | ***************************************************************************/ 23 | """ 24 | 25 | 26 | import sys, os, random, string, traceback 27 | from qgis.core import QgsProcessingUtils, QgsRasterLayer, QgsProject 28 | from .bibliotecas import logger, file_management, install_python_package 29 | from .appCtx import appContext 30 | 31 | from .getters import getters_management 32 | from .normalizer import normalizer 33 | from .gis import gis 34 | 35 | # def cleanup_temp(): 36 | # os.rmdir("temp") 37 | # 38 | # os.mkdir("temp") 39 | # 40 | # os.mkdir("temp/raw") 41 | # os.mkdir("temp/raw/ortho") 42 | # os.mkdir("temp/raw/dtm") 43 | # os.mkdir("temp/raw/dsm") 44 | # 45 | # os.mkdir("temp/normalized") 46 | # os.mkdir("temp/normalized/ortho") 47 | # os.mkdir("temp/normalized/dtm") 48 | # os.mkdir("temp/normalized/dsm") 49 | 50 | def appContext_setup(): 51 | logger.update_progress(step_current=0, step_description="Loading...", step_maximum=27, 52 | overall_current=1, overall_description="Initialization", overall_maximum=12) 53 | 54 | appContext.execution.id = ''.join(random.choices(string.ascii_letters + string.digits, k=16)) 55 | 56 | logger.plugin_log("") 57 | logger.plugin_log("==============================================") 58 | logger.plugin_log(f"EXECUTION ID: {appContext.execution.id}") 59 | logger.plugin_log("==============================================") 60 | logger.plugin_log("") 61 | 62 | # temp_folder = QgsProcessingUtils.tempFolder() 63 | # appContext.execution.temp_folder = f"{temp_folder}" 64 | # appContext.execution.raw_temp_folder = f"{appContext.execution.temp_folder}/raw" 65 | # appContext.execution.normalized_temp_folder = f"{appContext.execution.temp_folder}/normalized" 66 | 67 | temp_folder = os.path.join(QgsProcessingUtils.tempFolder(), "citygen", appContext.execution.id) 68 | appContext.execution.temp_folder = f"{temp_folder}" 69 | appContext.execution.raw_temp_folder = os.path.join(appContext.execution.temp_folder, "raw") 70 | appContext.execution.normalized_temp_folder = os.path.join(appContext.execution.temp_folder, "normalized") 71 | 72 | file_management.create_temp_dirs(appContext.execution.raw_temp_folder) 73 | file_management.create_temp_dirs(appContext.execution.normalized_temp_folder) 74 | 75 | logger.plugin_log(f"Plugin Temp folder: {appContext.execution.temp_folder}") 76 | 77 | logger.update_progress(step_current=100, overall_current=2) 78 | 79 | if appContext.user_parameters.clip_layer == "viewport": 80 | appContext.user_parameters.clip_layer = gis.create_viewport_polygon() 81 | 82 | install_python_package.install_package("geopandas") 83 | install_python_package.install_package("numpy") 84 | install_python_package.install_package("osmnx") 85 | 86 | 87 | def start(): 88 | try: 89 | logger.plugin_log("OUTPUT LOCATION: " + appContext.user_parameters.ortho_output) 90 | 91 | appContext_setup() 92 | 93 | logger.plugin_log("Getting files...") 94 | getters_management.execute_getters() 95 | 96 | gis.generate_3d_model() 97 | 98 | logger.plugin_log("Process complete without errors!") 99 | 100 | logger.plugin_log("OUTPUT LOCATION: " + appContext.user_parameters.ortho_output) 101 | 102 | logger.update_progress(step_current=1, step_description="Done!", step_maximum=1, 103 | overall_current=1, overall_description="", overall_maximum=1) 104 | except Exception as e: 105 | try: 106 | logger.plugin_log(repr(e), "ERROR") 107 | except Exception as e: 108 | logger.plugin_log("Error for command 0", "ERROR") 109 | try: 110 | if hasattr(e, "message"): 111 | logger.plugin_log(e.message, "ERROR") 112 | except Exception as e: 113 | logger.plugin_log("Error for command 1", "ERROR") 114 | try: 115 | logger.plugin_log(traceback.format_exc(), "ERROR") 116 | except Exception as e: 117 | logger.plugin_log("Error for command 2", "ERROR") 118 | try: 119 | if hasattr(e, "print_exc"): 120 | e.print_exc() 121 | except Exception as e: 122 | logger.plugin_log("Error for command 3", "ERROR") 123 | -------------------------------------------------------------------------------- /generate_model/normalizer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/generate_model/normalizer/__init__.py -------------------------------------------------------------------------------- /generate_model/normalizer/normalizer.py: -------------------------------------------------------------------------------- 1 | import sys, os, processing 2 | import qgis 3 | from qgis.core import QgsRasterLayer, QgsProject, QgsCoordinateReferenceSystem 4 | from ..appCtx import appContext 5 | from ..bibliotecas import logger 6 | 7 | 8 | def equalize_layer(layer_name, loaded_layer, layer_type, output_path=""): 9 | project_csr = QgsProject.instance().crs() 10 | layer_crs = loaded_layer.crs() 11 | 12 | result_path = loaded_layer.dataProvider().dataSourceUri() 13 | 14 | if loaded_layer.dataProvider().name() != 'wms': 15 | project_epsg = f'EPSG:{project_csr.postgisSrid() or "ERR"}' 16 | layer_epsg = f'EPSG:{appContext.layers[layer_name].crs or layer_crs.postgisSrid()}' 17 | 18 | if project_epsg != layer_epsg: 19 | logger.plugin_log(f"Converting layer {loaded_layer.name()} CRS...") 20 | 21 | if layer_type == "raster": 22 | result_path = output_path or f"{appContext.execution.raw_temp_folder}/{layer_name}/{layer_name}_epsg.tif" 23 | 24 | # processing.run( 25 | # "grass7:r.proj", 26 | # { 27 | # 'input': loaded_layer.dataProvider().dataSourceUri(), 28 | # 'crs': QgsCoordinateReferenceSystem(project_epsg), 29 | # 'method': 0, 30 | # 'memory': 300, 31 | # 'resolution': None, 32 | # '-n': False, 33 | # 'output': result_path, 34 | # 'GRASS_REGION_PARAMETER': None, 35 | # 'GRASS_REGION_CELLSIZE_PARAMETER': 0, 36 | # 'GRASS_RASTER_FORMAT_OPT': '', 37 | # 'GRASS_RASTER_FORMAT_META': '' 38 | # } 39 | # ) 40 | 41 | processing.run( 42 | "gdal:warpreproject", 43 | { 44 | 'INPUT': loaded_layer.dataProvider().dataSourceUri(), 45 | 'SOURCE_CRS': QgsCoordinateReferenceSystem(layer_epsg), 46 | 'TARGET_CRS': QgsCoordinateReferenceSystem(project_epsg), 47 | 'RESAMPLING': 0, 48 | 'NODATA': None, 49 | 'TARGET_RESOLUTION': None, 50 | 'OPTIONS': '', 51 | 'DATA_TYPE': 0, 52 | 'TARGET_EXTENT': None, 53 | 'TARGET_EXTENT_CRS': None, 54 | 'MULTITHREADING': False, 55 | 'EXTRA': '', 56 | 'OUTPUT': result_path 57 | } 58 | ) 59 | else: 60 | result_path = output_path or f"{appContext.execution.raw_temp_folder}/{layer_name}/{layer_name}_epsg.shp" 61 | processing.run( 62 | 'qgis:reprojectlayer', 63 | { 64 | 'INPUT': loaded_layer.dataProvider().dataSourceUri(), 65 | 'TARGET_CRS': project_epsg, 66 | 'OUTPUT': result_path 67 | } 68 | ) 69 | 70 | appContext.update_layer( 71 | appContext, 72 | result_path, 73 | layer_name, 74 | crs=project_csr.postgisSrid() 75 | ) 76 | 77 | return result_path 78 | 79 | 80 | def clip_layer(layer_name, loaded_layer, layer_type): 81 | result_path = loaded_layer.dataProvider().dataSourceUri() 82 | 83 | if True and \ 84 | appContext.user_parameters.clip_layer != None: 85 | logger.plugin_log(f"Cropping layer {loaded_layer.name()}...") 86 | 87 | layer_path = loaded_layer.dataProvider().dataSourceUri() 88 | polygon_path = appContext.user_parameters.clip_layer.dataProvider().dataSourceUri() 89 | 90 | if layer_path != polygon_path: 91 | if layer_type == "raster": 92 | result_path = f"{appContext.execution.raw_temp_folder}/{layer_name}/{layer_name}_croped.tif" 93 | 94 | processing.run( 95 | "gdal:cliprasterbymasklayer", 96 | { 97 | 'INPUT': layer_path, 98 | 'MASK': polygon_path, 99 | 'SOURCE_CRS': None, 100 | 'TARGET_CRS': None, 101 | 'NODATA': None, 102 | 'ALPHA_BAND': False, 103 | 'CROP_TO_CUTLINE': True, 104 | 'KEEP_RESOLUTION': False, 105 | 'SET_RESOLUTION': False, 106 | 'X_RESOLUTION': None, 107 | 'Y_RESOLUTION': None, 108 | 'MULTITHREADING': False, 109 | 'OPTIONS': '', 110 | 'DATA_TYPE': 0, 111 | 'OUTPUT': result_path 112 | } 113 | ) 114 | else: 115 | result_path = f"{appContext.execution.raw_temp_folder}/{layer_name}/{layer_name}_croped.shp" 116 | processing.run( 117 | "native:clip", 118 | { 119 | 'INPUT': layer_path, 120 | 'OVERLAY': polygon_path, 121 | 'OUTPUT': result_path 122 | } 123 | ) 124 | 125 | appContext.update_layer( 126 | appContext, 127 | result_path, 128 | layer_name 129 | ) 130 | 131 | return result_path 132 | 133 | 134 | def normalize_layer(layer_name, layer_type): 135 | layer = appContext.layers[layer_name] 136 | 137 | if layer.data_provider != "wms" and layer.data_provider != "wmts": 138 | equalize_layer(layer_name, layer.layer, layer_type) 139 | layer_final_path = clip_layer(layer_name, layer.layer, layer_type) 140 | 141 | appContext.update_layer(appContext, layer_final_path, layer_name, layer.data_provider) 142 | 143 | 144 | def normalize_layers(): 145 | normalize_layer("ortho", "raster") 146 | normalize_layer("dtm", "raster") 147 | normalize_layer("dsm", "raster") 148 | 149 | if appContext.user_parameters.street_getter is not None: 150 | normalize_layer("street", "vector") 151 | 152 | if appContext.user_parameters.tree_getter is not None: 153 | normalize_layer("tree", "vector") 154 | 155 | if appContext.user_parameters.water_getter is not None: 156 | normalize_layer("water", "vector") 157 | 158 | -------------------------------------------------------------------------------- /generate_model/normalizer/temp.py: -------------------------------------------------------------------------------- 1 | layer = QgsVectorLayer('Point', 'points', "memory") 2 | pr = layer.dataProvider() 3 | # add the first point 4 | pt = QgsFeature() 5 | point1 = QgsPointXY(extent.xMaximum(), extent.yMaximum()) 6 | pt.setGeometry(QgsGeometry.fromPoint(point1)) 7 | pr.addFeatures([pt]) 8 | # update extent of the layer 9 | layer.updateExtents() 10 | # add the second point 11 | pt = QgsFeature() 12 | point2 = QgsPointXY(extent.xMinimum(), extent.yMinimum()) 13 | pt.setGeometry(QgsGeometry.fromPoint(point2)) 14 | pr.addFeatures([pt]) 15 | # update extent 16 | layer.updateExtents() 17 | # add the layer to the canvas 18 | QgsProject.instance().addMapLayers([layer]) 19 | 20 | layer = QgsVectorLayer('Polygon', 'poly', "memory") 21 | pr = layer.dataProvider() 22 | poly = QgsFeature() 23 | points = [ 24 | QgsPointXY( 25 | extent.xMinimum(), 26 | extent.yMaximum() 27 | ), 28 | QgsPointXY( 29 | extent.xMaximum(), 30 | extent.yMaximum() 31 | ), 32 | QgsPointXY( 33 | extent.xMaximum(), 34 | extent.yMinimum() 35 | ), 36 | QgsPointXY( 37 | extent.xMinimum(), 38 | extent.yMinimum() 39 | ) 40 | ] 41 | # or points = [QgsPointXY(50,50),QgsPointXY(50,150),QgsPointXY(100,150),QgsPointXY(100,50)] 42 | poly.setGeometry(QgsGeometry.fromPolygon([points])) 43 | pr.addFeatures([poly]) 44 | layer.updateExtents() 45 | QgsProject.instance().addMapLayers([layer]) 46 | 47 | 48 | 49 | ############################################## 50 | 51 | viewport_memory_layer = QgsVectorLayer(f"Polygon?crs={QgsProject.instance().crs().toWkt()}", "viewport", "memory") 52 | # viewport_memory_layer = QgsVectorFileWriter(f"{appContext.execution.raw_temp_folder}/viewport.shp", "viewport", "ogr") 53 | 54 | # if viewport_memory_layer.isValid(): 55 | # raise Exception("Error!") 56 | 57 | extent = appContext.qgis.iface.mapCanvas().extent() 58 | 59 | # viewport_memory_layer.startEditing() 60 | feature = QgsFeature() 61 | feature.setGeometry(QgsGeometry.fromPolygonXY([ 62 | [ 63 | QgsPointXY( 64 | extent.xMinimum(), 65 | extent.yMaximum() 66 | ), 67 | QgsPointXY( 68 | extent.xMaximum(), 69 | extent.yMaximum() 70 | ), 71 | QgsPointXY( 72 | extent.xMaximum(), 73 | extent.yMinimum() 74 | ), 75 | QgsPointXY( 76 | extent.xMinimum(), 77 | extent.yMinimum() 78 | ), 79 | ] 80 | ])) 81 | viewport_memory_layer.addFeature(feature) 82 | viewport_memory_layer.commitChanges() 83 | 84 | QgsProject.instance().addMapLayer(viewport_memory_layer) 85 | 86 | return viewport_memory_layer 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /i18n/af.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @default 5 | 6 | 7 | Good morning 8 | Goeie more 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arthurRuf/3dcitybuilder/c536db01eb3130a15f2e14b1ffed12bffece78af/icon.png -------------------------------------------------------------------------------- /metadata.txt: -------------------------------------------------------------------------------- 1 | # This file contains metadata for your plugin. 2 | 3 | # This file should be included when you package your plugin.# Mandatory items: 4 | 5 | [general] 6 | name=3D City Builder 7 | qgisMinimumVersion=3.0 8 | description=Generate 3D models of urban areas using DEM. 9 | version=0.3 10 | author=Arthur Ruf Hosang da Costa 11 | email=arthur.rhc@gmail.com 12 | 13 | about=Create 3D Models of Urban Areas using your files or online databases. 14 | To generate the 3D Model, this plugin uses Aerial Imagery (Satellite Image), DTM (Digital Terrain Model aka DEM, Digital Elevation Model), DSM (Digital Surface Model) and a Footprint layer (the contour of the buildings). 15 | 16 | A sample dataset is available to make it easier for you to test this plugin: https://3dcitygen-test-dataset.s3.amazonaws.com/test-dataset-vienna.zip 17 | 18 | Opitionally, you can follow the steps under https://landscapearchaeology.org/2018/installing-python-packages-in-qgis-3-for-windows/ to install the following libraries on QGIS Python: geopandas numpy osmnx. 19 | 20 | 21 | tracker=https://github.com/arthurRuf/3dcitybuilder/issues 22 | repository=https://github.com/arthurRuf/3dcitybuilder 23 | # End of mandatory metadata 24 | 25 | # Recommended items: 26 | 27 | hasProcessingProvider=no 28 | # Uncomment the following line and add your changelog: 29 | changelog=0.2(2020-09-30z) 30 | - Some updates to match QGIS Plugin Repository requirements 31 | 0.1: 32 | - Start Plugin for QGIS 3 33 | 34 | 35 | # Tags are comma separated with spaces allowed 36 | tags=python, 3d, dem, dtm, dsm, river, openstreetmap, osm, urban planning, water, view 37 | 38 | homepage=https://github.com/arthurRuf/3dcitybuilder 39 | category=Plugins 40 | icon=icon.png 41 | # experimental flag 42 | experimental=True 43 | 44 | # deprecated flag (applies to the whole plugin, not just a single version) 45 | deprecated=False 46 | 47 | # Since QGIS 3.8, a comma separated list of plugins to be installed 48 | # (or upgraded) can be specified. 49 | # Check the documentation for more information. 50 | # plugin_dependencies= 51 | 52 | Category of the plugin: Raster, Vector, Database or Web 53 | # category= 54 | 55 | # If the plugin can run on QGIS Server. 56 | server=False 57 | 58 | -------------------------------------------------------------------------------- /pb_tool.cfg: -------------------------------------------------------------------------------- 1 | #/*************************************************************************** 2 | # citygen 3 | # 4 | # Configuration file for plugin builder tool (pb_tool) 5 | # Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ 6 | # ------------------- 7 | # begin : 2020-04-30 8 | # copyright : (C) 2020 by Arthur Ruf Hosang da Costa 9 | # email : arthur.rhc@gmail.com 10 | # ***************************************************************************/ 11 | # 12 | #/*************************************************************************** 13 | # * * 14 | # * This program is free software; you can redistribute it and/or modify * 15 | # * it under the terms of the GNU General Public License as published by * 16 | # * the Free Software Foundation; either version 2 of the License, or * 17 | # * (at your option) any later version. * 18 | # * * 19 | # ***************************************************************************/ 20 | # 21 | # 22 | # You can install pb_tool using: 23 | # pip install http://geoapt.net/files/pb_tool.zip 24 | # 25 | # Consider doing your development (and install of pb_tool) in a virtualenv. 26 | # 27 | # For details on setting up and using pb_tool, see: 28 | # http://g-sherman.github.io/plugin_build_tool/ 29 | # 30 | # Issues and pull requests here: 31 | # https://github.com/g-sherman/plugin_build_tool: 32 | # 33 | # Sane defaults for your plugin generated by the Plugin Builder are 34 | # already set below. 35 | # 36 | # As you add Python source files and UI files to your plugin, add 37 | # them to the appropriate [files] section below. 38 | 39 | [plugin] 40 | # Name of the plugin. This is the name of the directory that will 41 | # be created in .qgis2/python/plugins 42 | name: citygen 43 | 44 | # Full path to where you want your plugin directory copied. If empty, 45 | # the QGIS default path will be used. Don't include the plugin name in 46 | # the path. 47 | plugin_path: 48 | 49 | [files] 50 | # Python files that should be deployed with the plugin 51 | python_files: __init__.py citygen.py citygen_dialog.py 52 | 53 | # The main dialog file that is loaded (not compiled) 54 | main_dialog: citygen_dialog_base.ui 55 | 56 | # Other ui files for dialogs you create (these will be compiled) 57 | compiled_ui_files: 58 | 59 | # Resource file(s) that will be compiled 60 | resource_files: resources.qrc 61 | 62 | # Other files required for the plugin 63 | extras: metadata.txt icon.png 64 | 65 | # Other directories to be deployed with the plugin. 66 | # These must be subdirectories under the plugin directory 67 | extra_dirs: 68 | 69 | # ISO code(s) for any locales (translations), separated by spaces. 70 | # Corresponding .ts files must exist in the i18n directory 71 | locales: 72 | 73 | [help] 74 | # the built help directory that should be deployed with the plugin 75 | dir: help/build/html 76 | # the name of the directory to target in the deployed plugin 77 | target: help 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /plugin_upload.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | """This script uploads a plugin package to the plugin repository. 4 | Authors: A. Pasotti, V. Picavet 5 | git sha : $TemplateVCSFormat 6 | """ 7 | 8 | import sys 9 | import getpass 10 | import xmlrpc.client 11 | from optparse import OptionParser 12 | 13 | standard_library.install_aliases() 14 | 15 | # Configuration 16 | PROTOCOL = 'https' 17 | SERVER = 'plugins.qgis.org' 18 | PORT = '443' 19 | ENDPOINT = '/plugins/RPC2/' 20 | VERBOSE = False 21 | 22 | 23 | def main(parameters, arguments): 24 | """Main entry point. 25 | 26 | :param parameters: Command line parameters. 27 | :param arguments: Command line arguments. 28 | """ 29 | address = "{protocol}://{username}:{password}@{server}:{port}{endpoint}".format( 30 | protocol=PROTOCOL, 31 | username=parameters.username, 32 | password=parameters.password, 33 | server=parameters.server, 34 | port=parameters.port, 35 | endpoint=ENDPOINT) 36 | print("Connecting to: %s" % hide_password(address)) 37 | 38 | server = xmlrpc.client.ServerProxy(address, verbose=VERBOSE) 39 | 40 | try: 41 | with open(arguments[0], 'rb') as handle: 42 | plugin_id, version_id = server.plugin.upload( 43 | xmlrpc.client.Binary(handle.read())) 44 | print("Plugin ID: %s" % plugin_id) 45 | print("Version ID: %s" % version_id) 46 | except xmlrpc.client.ProtocolError as err: 47 | print("A protocol error occurred") 48 | print("URL: %s" % hide_password(err.url, 0)) 49 | print("HTTP/HTTPS headers: %s" % err.headers) 50 | print("Error code: %d" % err.errcode) 51 | print("Error message: %s" % err.errmsg) 52 | except xmlrpc.client.Fault as err: 53 | print("A fault occurred") 54 | print("Fault code: %d" % err.faultCode) 55 | print("Fault string: %s" % err.faultString) 56 | 57 | 58 | def hide_password(url, start=6): 59 | """Returns the http url with password part replaced with '*'. 60 | 61 | :param url: URL to upload the plugin to. 62 | :type url: str 63 | 64 | :param start: Position of start of password. 65 | :type start: int 66 | """ 67 | start_position = url.find(':', start) + 1 68 | end_position = url.find('@') 69 | return "%s%s%s" % ( 70 | url[:start_position], 71 | '*' * (end_position - start_position), 72 | url[end_position:]) 73 | 74 | 75 | if __name__ == "__main__": 76 | parser = OptionParser(usage="%prog [options] plugin.zip") 77 | parser.add_option( 78 | "-w", "--password", dest="password", 79 | help="Password for plugin site", metavar="******") 80 | parser.add_option( 81 | "-u", "--username", dest="username", 82 | help="Username of plugin site", metavar="user") 83 | parser.add_option( 84 | "-p", "--port", dest="port", 85 | help="Server port to connect to", metavar="80") 86 | parser.add_option( 87 | "-s", "--server", dest="server", 88 | help="Specify server name", metavar="plugins.qgis.org") 89 | options, args = parser.parse_args() 90 | if len(args) != 1: 91 | print("Please specify zip file.\n") 92 | parser.print_help() 93 | sys.exit(1) 94 | if not options.server: 95 | options.server = SERVER 96 | if not options.port: 97 | options.port = PORT 98 | if not options.username: 99 | # interactive mode 100 | username = getpass.getuser() 101 | print("Please enter user name [%s] :" % username, end=' ') 102 | 103 | res = input() 104 | if res != "": 105 | options.username = res 106 | else: 107 | options.username = username 108 | if not options.password: 109 | # interactive mode 110 | options.password = getpass.getpass() 111 | main(options, args) 112 | -------------------------------------------------------------------------------- /resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /scripts/compile-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LRELEASE=$1 3 | LOCALES=$2 4 | 5 | 6 | for LOCALE in ${LOCALES} 7 | do 8 | echo "Processing: ${LOCALE}.ts" 9 | # Note we don't use pylupdate with qt .pro file approach as it is flakey 10 | # about what is made available. 11 | $LRELEASE i18n/${LOCALE}.ts 12 | done 13 | -------------------------------------------------------------------------------- /scripts/run-env-linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | QGIS_PREFIX_PATH=/usr/local/qgis-2.0 4 | if [ -n "$1" ]; then 5 | QGIS_PREFIX_PATH=$1 6 | fi 7 | 8 | echo ${QGIS_PREFIX_PATH} 9 | 10 | 11 | export QGIS_PREFIX_PATH=${QGIS_PREFIX_PATH} 12 | export QGIS_PATH=${QGIS_PREFIX_PATH} 13 | export LD_LIBRARY_PATH=${QGIS_PREFIX_PATH}/lib 14 | export PYTHONPATH=${QGIS_PREFIX_PATH}/share/qgis/python:${QGIS_PREFIX_PATH}/share/qgis/python/plugins:${PYTHONPATH} 15 | 16 | echo "QGIS PATH: $QGIS_PREFIX_PATH" 17 | export QGIS_DEBUG=0 18 | export QGIS_LOG_FILE=/tmp/inasafe/realtime/logs/qgis.log 19 | 20 | export PATH=${QGIS_PREFIX_PATH}/bin:$PATH 21 | 22 | echo "This script is intended to be sourced to set up your shell to" 23 | echo "use a QGIS 2.0 built in $QGIS_PREFIX_PATH" 24 | echo 25 | echo "To use it do:" 26 | echo "source $BASH_SOURCE /your/optional/install/path" 27 | echo 28 | echo "Then use the make file supplied here e.g. make guitest" 29 | -------------------------------------------------------------------------------- /scripts/update-strings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LOCALES=$* 3 | 4 | # Get newest .py files so we don't update strings unnecessarily 5 | 6 | CHANGED_FILES=0 7 | PYTHON_FILES=`find . -regex ".*\(ui\|py\)$" -type f` 8 | for PYTHON_FILE in $PYTHON_FILES 9 | do 10 | CHANGED=$(stat -c %Y $PYTHON_FILE) 11 | if [ ${CHANGED} -gt ${CHANGED_FILES} ] 12 | then 13 | CHANGED_FILES=${CHANGED} 14 | fi 15 | done 16 | 17 | # Qt translation stuff 18 | # for .ts file 19 | UPDATE=false 20 | for LOCALE in ${LOCALES} 21 | do 22 | TRANSLATION_FILE="i18n/$LOCALE.ts" 23 | if [ ! -f ${TRANSLATION_FILE} ] 24 | then 25 | # Force translation string collection as we have a new language file 26 | touch ${TRANSLATION_FILE} 27 | UPDATE=true 28 | break 29 | fi 30 | 31 | MODIFICATION_TIME=$(stat -c %Y ${TRANSLATION_FILE}) 32 | if [ ${CHANGED_FILES} -gt ${MODIFICATION_TIME} ] 33 | then 34 | # Force translation string collection as a .py file has been updated 35 | UPDATE=true 36 | break 37 | fi 38 | done 39 | 40 | if [ ${UPDATE} == true ] 41 | # retrieve all python files 42 | then 43 | echo ${PYTHON_FILES} 44 | # update .ts 45 | echo "Please provide translations by editing the translation files below:" 46 | for LOCALE in ${LOCALES} 47 | do 48 | echo "i18n/"${LOCALE}".ts" 49 | # Note we don't use pylupdate with qt .pro file approach as it is flakey 50 | # about what is made available. 51 | pylupdate4 -noobsolete ${PYTHON_FILES} -ts i18n/${LOCALE}.ts 52 | done 53 | else 54 | echo "No need to edit any translation files (.ts) because no python files" 55 | echo "has been updated since the last update translation. " 56 | fi 57 | --------------------------------------------------------------------------------