exporter
exporter
api
allowed_extensions = ('qgz', 'qgs')
module-attribute
allowed_output_formats = ('json', 'xml')
module-attribute
app = Flask(__name__)
module-attribute
data_path = os.environ.get('QSL_DATA_ROOT', None)
module-attribute
exporter_host = os.environ.get('QSL_EXPORTER_API_HOST', '127.0.0.1')
module-attribute
exporter_port = int(os.environ.get('QSL_EXPORTER_API_PORT', 5000))
module-attribute
qgs = QgsApplication([], False)
module-attribute
api_export()
Source code in src/qgis_server_light/exporter/api.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
cli
allowed_extensions = ('qgz', 'qgs')
module-attribute
allowed_output_formats = ('json', 'xml')
module-attribute
qgs = QgsApplication([], False)
module-attribute
cli() -> None
Just the central cli entry command. Currently, we don't use it, but its here for future content.
Source code in src/qgis_server_light/exporter/cli.py
21 22 23 24 25 26 27 28 | |
export(project: str, unify_layer_names_by_group: bool = False, output_format: str | None = None, pg_service_conf: str | None = None) -> None
Source code in src/qgis_server_light/exporter/cli.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
common
create_full_pg_service_conf(pg_service_conf: str | None = None) -> dict
Source code in src/qgis_server_light/exporter/common.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
extract
Exporter
Source code in src/qgis_server_light/exporter/extract.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
path = qgis_project_path
instance-attribute
pg_service_configs = pg_service_configs or {}
instance-attribute
qgis_project = self.open_qgis_project(qgis_project_path)
instance-attribute
qgis_project_tree_root = self.qgis_project.layerTreeRoot()
instance-attribute
qsl_config = Config(project=(self.qsl_project), meta_data=(self.qsl_project_metadata), tree=(self.qsl_tree), datasets=(self.qsl_datasets))
instance-attribute
qsl_datasets = Datasets()
instance-attribute
qsl_project = Project(name=(self.assembled_name), version=(self.version))
instance-attribute
qsl_project_metadata = self.extract_metadata(self.qgis_project)
instance-attribute
qsl_tree = Tree()
instance-attribute
unify_layer_names_by_group = unify_layer_names_by_group
instance-attribute
unify_layer_names_by_group_separator = unify_layer_names_by_group_separator
instance-attribute
__init__(qgis_project_path: str, unify_layer_names_by_group=False, unify_layer_names_by_group_separator='.', pg_service_configs=None)
Source code in src/qgis_server_light/exporter/extract.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
create_qsl_bbox_from_qgis_rectangle_extent(extent: QgsRectangle) -> BBox
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
785 786 787 788 789 790 791 792 | |
create_qsl_bbox_from_qgis_rectangle_wgs84(project: QgsProject, layer: QgsMapLayer, extent: QgsRectangle) -> BBox
staticmethod
Reprojects the job_layer_definition's extent using WGS84.
Parameters:
-
project(QgsProject) –The QGIS project instance for projection context.
-
layer(QgsMapLayer) –The job_layer_definition which for the projection context.
-
extent(QgsRectangle) –The extent which will be reprojected.
Returns:
-
BBox–The QSL bbox reprojected to WGS84.
Source code in src/qgis_server_light/exporter/extract.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
create_qsl_crs_from_qgs_layer(layer: QgsMapLayer) -> Crs
staticmethod
Translates the QGIS job_layer_definition crs information into an instance of the QGIS-Server-Light interface Crs instance.
Parameters:
-
layer(QgsMapLayer) –The job_layer_definition to take the crs information from.
Returns:
-
Crs–The instance of the QSL interface Crs.
Source code in src/qgis_server_light/exporter/extract.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
create_qsl_field_from_qgis_field(field: QgsField, is_primary_key: bool) -> Field
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
create_qsl_fields_from_qgis_field(layer: QgsVectorLayer) -> List[Field]
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
428 429 430 431 432 433 434 435 436 437 438 | |
create_qsl_source_gdal(datasource: dict) -> GdalSource
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
637 638 639 | |
create_qsl_source_ogr(datasource: dict) -> OgrSource
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
641 642 643 | |
create_qsl_source_postgresql(datasource: dict) -> PostgresSource
Source code in src/qgis_server_light/exporter/extract.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
create_qsl_source_vector_tiles(datasource: dict) -> VectorTileSource
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
625 626 627 | |
create_qsl_source_wms(datasource: dict) -> WmsSource
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
621 622 623 | |
create_qsl_source_wmts(datasource: dict) -> WmtsSource
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
633 634 635 | |
create_qsl_source_xyz(datasource: dict) -> XYZSource
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
629 630 631 | |
create_style_list(qgs_layer: QgsMapLayer) -> List[Style]
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | |
create_unified_short_name(short_name: str, path: list[str])
Creates the unified short name, separated by the configured separator.
Parameters:
-
short_name(str) –The short name either of the group or the job_layer_definition.
-
path(list[str]) –The path is a list of string which stores the information of the current tree path. This is used to construct a string for unifying job_layer_definition names by their tree path.
Returns:
Source code in src/qgis_server_light/exporter/extract.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
decide_sslmode(ssl_mode: int) -> str
staticmethod
Mapper to map ssl modes from QGIS to plain postgres.
Parameters:
-
ssl_mode(int) –The ssl mode of the datasource.
Returns:
-
str–The string representation of the ssl mode as it is used by postgres connections.
Source code in src/qgis_server_light/exporter/extract.py
699 700 701 702 703 704 705 706 707 708 709 710 | |
decode_datasource(layer: QgsMapLayer) -> dict
Decodes a QGIS map job_layer_definition datasource into a dict and ensures that types are pythonic and pathes are clean for further usage.
Parameters:
-
layer(QgsMapLayer) –The job_layer_definition which the datasource should be extracted from.
Returns:
-
dict–The decoded and cleaned datasource.
Source code in src/qgis_server_light/exporter/extract.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
extract_group(group: QgsLayerTreeGroup, path: list[str])
Collects data pertaining to a QGIS job_layer_definition tree group. Basically this translates a QgsLayerTreeGroup into a QGIS-Server-Light TreeGroup.
Parameters:
-
group(QgsLayerTreeGroup) –The group which is handled.
-
path(list[str]) –The path is a list of string which stores the information of the current tree path. This is used to construct a string for unifying job_layer_definition names by their tree path.
Source code in src/qgis_server_light/exporter/extract.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
extract_metadata(project: QgsProject) -> MetaData
staticmethod
Creates a QSL interface instance for metadate pulled out of the QGIS project.
Parameters:
-
project(QgsProject) –The instantiated QGIS project.
Returns:
-
MetaData–The metadata interface instance.
Source code in src/qgis_server_light/exporter/extract.py
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
extract_save_layer(child: QgsLayerTreeLayer, path: list[str], types_from_editor_widget: bool = False)
Save the given job_layer_definition to the output path.
Source code in src/qgis_server_light/exporter/extract.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
get_group_short_name(group: QgsLayerTreeGroup) -> str
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
get_group_title(group: QgsLayerTreeGroup) -> str
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
477 478 479 480 481 482 483 484 485 486 487 | |
get_layer_short_name(layer: QgsLayerTreeLayer) -> str
staticmethod
This method determines which name is used as the short name of the job_layer_definition.
Parameters:
-
layer(QgsLayerTreeLayer) –The job_layer_definition which the short name should be derived from.
Returns:
-
str–The short name.
Source code in src/qgis_server_light/exporter/extract.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
get_layer_type(layer: QgsMapLayer) -> str | None
staticmethod
Gets the type of the given Qgis job_layer_definition as a string if the type is supported. This is to flatten the understanding of layers from qgis into something we can handle.
Parameters:
-
layer(QgsMapLayer) –The job_layer_definition to decide the type for.
Returns:
-
str | None–"raster", "vector" or "custom" if a job_layer_definition matched and None otherwise.
Source code in src/qgis_server_light/exporter/extract.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | |
get_project_server_entries(project, scope_or_scopes: Union[str, list]) -> dict
staticmethod
Gets values from the fields displayed in QGIS under Project > Properties > Server.
Returns a Dictionary holding all pairs of
Source code in src/qgis_server_light/exporter/extract.py
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
make_wgs84_geom_transform(project, layer) -> QgsCoordinateTransform
staticmethod
Creates a QgisCoordinateTransform context to transform a job_layer_definition to EPSG:4326 aka wgs84.
Parameters:
-
project–The QGIS project instance.
-
layer–The job_layer_definition which's extent should be reprojected.
Returns:
-
QgsCoordinateTransform–The QGIS transformation context.
Source code in src/qgis_server_light/exporter/extract.py
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | |
merge_dicts(a, b)
staticmethod
Merges two dicts recursively, b values overwrites a values.
Parameters:
-
a–Dictionary which is the base.
-
b–Dictionary which is merged in and whose values overwrites the one.
Returns:
-
–
The merged dict.
Source code in src/qgis_server_light/exporter/extract.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
obtain_editor_widget_type_from_qgis_field(field: QgsField) -> Tuple[str, str, str, str] | Tuple[str, None, None, None]
staticmethod
We simply mimikri QGIS Server here
TODO: This could be improved alot! Maybe we can also backport that to QGIS core some day?
Parameters:
-
field(QgsField) –The field of an
QgsVectorLayer.
Returns:
-
Tuple[str, str, str, str] | Tuple[str, None, None, None]–Unified type name regarding
-
Tuple[str, str, str, str] | Tuple[str, None, None, None]–
Source code in src/qgis_server_light/exporter/extract.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
obtain_nullable(field: QgsField)
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
403 404 405 406 407 408 409 410 | |
obtain_simple_types_from_qgis_field_json(field: QgsField) -> Tuple[str, str] | Tuple[str, None]
staticmethod
Delivers the type match for json based on the field QgsField type.
Parameters:
-
field(QgsField) –The field of an
QgsVectorLayer.
Returns:
-
Tuple[str, str] | Tuple[str, None]–Unified type name and format in a tuple.
Source code in src/qgis_server_light/exporter/extract.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
obtain_simple_types_from_qgis_field_xml(field: QgsField) -> str
staticmethod
Parameters:
-
field(QgsField) –The field of an
QgsVectorLayer.
Returns:
-
str–Unified type name regarding
-
str– -
IMPORTANT(str) –If type is not matched within the function it will be
stringalways!
Source code in src/qgis_server_light/exporter/extract.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
open_qgis_project(path_to_project: str) -> QgsProject
staticmethod
Parameters:
-
path_to_project(str) –The absolute path on the file system where the project can be read from.
Returns:
-
QgsProject–The opened project (read).
Source code in src/qgis_server_light/exporter/extract.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
prepare_qgis_project_name(project: QgsProject) -> tuple[str, str]
staticmethod
Parameters:
-
project(QgsProject) –The instantiated QGIS project.
Returns:
-
tuple[str, str]–Tuple of str version, name
Source code in src/qgis_server_light/exporter/extract.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | |
provide_field_length(field: QgsField) -> int | None
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
412 413 414 415 416 417 418 | |
provide_field_precision(field: QgsField) -> int | None
staticmethod
Source code in src/qgis_server_light/exporter/extract.py
420 421 422 423 424 425 426 | |
run() -> Config
Source code in src/qgis_server_light/exporter/extract.py
96 97 98 | |
sanitize_name(raw: str, lower: bool = False) -> str
staticmethod
Transforms an arbitrary string into a WMS/WFS and URL compatible short name for a job_layer_definition or group.
Steps: 1. Unicode‑NFD → ASCII‑transliteration (removes umlauts/diacritics). 2. All chars, which are NOT [A‑Za‑z0‑9_.‑], will be replaced by '' ersetzen. 3. Reduce multiple underscore '' to a single one. 4. Remove leading '', '.', '-'. 5. If the string is empty OR does not start with a letter OR not start with '', a leading '_' will be added. 6. Optional all will be converted to lowercase (lower=True).
Source code in src/qgis_server_light/exporter/extract.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
short_name(short_name: str, path: list[str]) -> str
Decides if to use the short name itself or the unified version by the tree path.
Parameters:
-
short_name(str) –The short name either of the group or the job_layer_definition.
-
path(list[str]) –The path is a list of string which stores the information of the current tree path. This is used to construct a string for unifying job_layer_definition names by their tree path.
Returns:
-
str–The short name itself or its unified tree path.
Source code in src/qgis_server_light/exporter/extract.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
walk_qgis_project_tree(entity: QgsLayerTreeNode, path: list[str])
This is a highly recursive function which walks to the qgis job_layer_definition tree to extract all knowledge out of it. It is called from itself again for each level of group like elements which are found.
Parameters:
-
entity(QgsLayerTreeNode) –The QGIS projects tree node which can be a QgsLayerTree, QgsLayerTreeGroup or QgsLayerTreeLayer.
-
path(list[str]) –The path is a list of string which stores the information of the current tree path. This is used to construct a string for unifying job_layer_definition names by their tree path.
Source code in src/qgis_server_light/exporter/extract.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |