Database¶
| CLASS | DESCRIPTION |
|---|---|
Dataset |
A Container for managing workspace connections. |
Relationship |
|
RelationshipManager |
|
Dataset
¶
A Container for managing workspace connections.
A Dataset is initialized using arcpy.da.Walk and will discover all child datasets, tables, and featureclasses.
These discovered objects can be accessed by name directly (e.g. dataset['featureclass_name']) or by inspecting the
property of the type they belong to (e.g. dataset.feature_classes['featureclass_name']). The benefit of the second
method is that you will be able to know you are getting a FeatureClass, Table, or Dataset object.
Usage
>>> dataset = Dataset('dataset/path')
>>> fc1 = dataset.feature_classes['fc1']
>>> fc1 = dataset.feature_classes['fc2']
>>> len(fc1)
243
>>> len(fc2)
778
>>> count(dataset['fc1'][where('LENGTH > 500')])
42
>>> sum(dataset['fc2']['TOTAL'])
3204903
As you can see, the dataset container makes it incredibly easy to interact with data concisely and clearly.
Datasets also implement __contains__ which allows you to check membership from the root node:
Example
>>> 'fc1' in dataset
True
>>> 'fc6' in dataset
True
>>> list(dataset.feature_classes)
['fc1', 'fc2']
>>> list(dataset.datasets)
['ds1']
>>> list(dataset['ds1'].feature_classes)
['fc3', 'fc4', 'fc5', 'fc6']
- Modules
| METHOD | DESCRIPTION |
|---|---|
create_feature_dataset |
Create a FeatureDataset (cannot be done if the parent Dataset is already a FeatureDataset!) |
create_featureclass |
Create a new FeatureClass in the Dataset |
create_table |
Create a new Table in the Dataset |
export_rules |
Export all attribute rules from the dataset into feature subdirectories |
export_schema |
Export the workspace Schema for a GDB dataset |
export_schema_module |
Export the workspace to a python schema file that uses TypedDict and Annotated |
from_schema |
Create a GDB from a schema file (xlsx, json, xml) generated by export_schema |
from_schema_module |
Build a new GDB from an existing schema module generated with |
import_rules |
Import Attribute rules for the dataset from a directory |
walk |
Traverse the connection/path using |
| ATTRIBUTE | DESCRIPTION |
|---|---|
annotations |
A mapping of annotation names to
TYPE:
|
datasets |
A mapping of dataset names to child |
feature_classes |
A mapping of featureclass names to
TYPE:
|
relationships |
A Manager object for interacting with RelationshipClasses
TYPE:
|
tables |
A mapping of table names to |
Source code in src/arcpie/database.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
annotations
property
¶
annotations: dict[str, FeatureClass]
A mapping of annotation names to FeatureClass objects
datasets
property
¶
A mapping of dataset names to child Dataset objects
feature_classes
property
¶
feature_classes: dict[str, FeatureClass]
A mapping of featureclass names to FeatureClass objects in the dataset root
relationships
property
¶
relationships: RelationshipManager
A Manager object for interacting with RelationshipClasses
tables
property
¶
A mapping of table names to Table objects in the dataset root
create_feature_dataset
¶
create_feature_dataset(
name: str,
*,
spatial_reference: SpatialReference | WKID = WGS84,
) -> Dataset
Create a FeatureDataset (cannot be done if the parent Dataset is already a FeatureDataset!)
| PARAMETER | DESCRIPTION |
|---|---|
|
The name for the new feature dataset (must be unique in parent dataset!)
TYPE:
|
|
An optional spatial reference to use for the dataset (default
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Dataset
|
A new Dataset object parented to this Dataset |
Source code in src/arcpie/database.py
496 497 498 499 500 501 502 503 504 505 506 507 508 | |
create_featureclass
¶
create_featureclass(
name: str,
geometry_type: GeoType | None,
feature_dataset: str | None = None,
*,
template: FeatureClass | None = None,
has_m: bool | None = None,
has_z: bool | None = None,
spatial_reference: SpatialReference | WKID = WGS84,
config_keyword: str | None = None,
alias: str | None = None,
oid_type: Literal['64_BIT', '32_BIT'] | None = None,
_ensure_dataset: bool = True,
) -> FeatureClass
Create a new FeatureClass in the Dataset
Source code in src/arcpie/database.py
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 | |
create_table
¶
create_table(
name: str,
*,
template: Table[TS] | None = None,
config_keyword: str | None = None,
alias: str | None = None,
oid_type: Literal['64_BIT', '32_BIT'] | None = '64_BIT',
) -> Table[TS]
Create a new Table in the Dataset
| PARAMETER | DESCRIPTION |
|---|---|
|
The name of the new table
TYPE:
|
|
A Table object to use as a template
TYPE:
|
|
A keyword to pass to the database engine for table setup
TYPE:
|
|
An alias for the table
TYPE:
|
|
The size of OID to use. If template is set and this is
TYPE:
|
Source code in src/arcpie/database.py
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 | |
export_rules
¶
Export all attribute rules from the dataset into feature subdirectories
| PARAMETER | DESCRIPTION |
|---|---|
|
The target directory for the rules |
Usage
>>> # Transfer rules from one dataset to another
>>> ds.export_rules('my_rules')
>>> ds2.import_rules('my_rules')
Source code in src/arcpie/database.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
export_schema
¶
export_schema(
out_loc: Path | str,
*,
schema_name: str | None = None,
out_format: Literal[
'JSON', 'XLSX', 'HTML', 'PDF', 'XML'
] = 'JSON',
remove_rules: bool = False,
) -> Path
Export the workspace Schema for a GDB dataset
| PARAMETER | DESCRIPTION |
|---|---|
|
The output location for the workspace schema |
|
A name for the schema (default: Dataset.name)
TYPE:
|
|
The output format (default: 'json')
TYPE:
|
|
Don't export associated attribute rules for the dataset (default: False)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
The Path object pointing to the output file
TYPE:
|
Source code in src/arcpie/database.py
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 | |
export_schema_module
¶
export_schema_module(
out_loc: Path | str,
*,
tables: bool | Sequence[str] = True,
featureclasses: bool | Sequence[str] = True,
datasets: bool | Sequence[str] = True,
mod_doc: str | None = None,
fallback_type: type = object,
docs: dict[str, dict[str, str]] | None = None,
include_shape_token: bool = True,
include_oid_token: bool = True,
default_doc: Callable[[Field], str]
| Literal['nodoc']
| None = None,
skip_annotations: bool = False,
) -> None
Export the workspace to a python schema file that uses TypedDict and Annotated to store field definitions. This is similar to Pydantic models, but these can be ingested by Table and FeatureClass objects to type their iterators
| PARAMETER | DESCRIPTION |
|---|---|
|
Include table schemas in output (Only specified names if a sequence is provided) |
|
Include featureclasses in output (Only specified names if a sequence is provided) |
|
Include schemas for datasets in the output (Only specified names if a sequence is provided) |
|
The filepath of the output module (e.g. |
|
Optional module documentation to include at the top of the file (default:
TYPE:
|
|
Default type for any fieldtype that can't be mapped to a Python type |
|
Optional docs for each feature class in the format |
|
Include @SHAPE in output schema (will inherit from FC shape)
TYPE:
|
|
Include the @OID token in the output schema
TYPE:
|
|
Optional default docstring func for fields (
TYPE:
|
|
Don't export schema for Annotation Features
TYPE:
|
Note:
If the supplied out_loc is not a valid .py python file, a python file with the name
{self.name}_schema.py will be generated there. Intermediate folders will be created if
they do not exist.
Source code in src/arcpie/database.py
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 | |
from_schema
classmethod
¶
from_schema(
schema: Path | str,
out_loc: Path | str,
gdb_name: str,
*,
remove_rules: bool = False,
) -> Dataset[Any]
Create a GDB from a schema file (xlsx, json, xml) generated by export_schema
| PARAMETER | DESCRIPTION |
|---|---|
|
Path to the schema file |
|
Path to the GDB output directory |
|
The name of the gdb
TYPE:
|
|
Don't import Attribute Rules after building the new dataset (default: False)
TYPE:
|
Usage
>>> ds = Dataset.from_schema('schema.xlsx', 'out_dir', 'new_db.gdb', skip_rules=True)
... # This can take a while depending on the size of the schema
>>> ds
Dataset('new_db' {'Features': 10, 'Tables': 3, Datasets: 0})
Source code in src/arcpie/database.py
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 | |
from_schema_module
classmethod
¶
from_schema_module(
out_loc: Path | str,
schema_module: ModuleType,
*,
spatial_reference: SpatialReference | WKID = WGS84,
overwrite: bool = False,
domain_module: ModuleType | None = None,
) -> Generator[FeatureClass | Table, None, Dataset[Any]]
Build a new GDB from an existing schema module generated with export_schema_module
| PARAMETER | DESCRIPTION |
|---|---|
|
Destination for the generated GDB |
|
The module containing all table definitions
TYPE:
|
|
The Spatial Reference to generate the database in (default:
TYPE:
|
|
If the target database exists, overwrite it
TYPE:
|
|
An optional domain module that will be used to create domains in the new dataset
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
FeatureClass | Table
|
FeatureClasses/Tables as they are created for monitoring purposes |
| RETURNS | DESCRIPTION |
|---|---|
Dataset[Any]
|
A new Dataset object built from the schema |
| RAISES | DESCRIPTION |
|---|---|
FileExistsError
|
When the target directory exists and |
Example
import my_database_schema new_ds = Dataset.from_schema_module('new_database.gdb', my_database_schema, 3857)
Source code in src/arcpie/database.py
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 | |
import_rules
¶
import_rules(
rule_dir: Path | str, *, skip_fail: bool = False
) -> Iterator[AttributeRule | Exception]
Import Attribute rules for the dataset from a directory
| PARAMETER | DESCRIPTION |
|---|---|
|
A directory containing rules in feature sub directories |
|
Skip any attribute rule imports that fail (whole FC) (default: False)
TYPE:
|
Usage
>>> # Transfer rules from one dataset to another
>>> ds.export_rules('my_rules')
>>> ds2.import_rules('my_rules')
Source code in src/arcpie/database.py
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 | |
walk
¶
walk() -> None
Traverse the connection/path using arcpy.da.Walk and discover all dataset children
Note
This is called on dataset initialization and can take some time. Larger datasets can take up to a second or more to initialize.
Note
If the contents of a dataset change during its lifetime, you may need to call walk again. All children that are already initialized will be skipped and only new children will be initialized
Source code in src/arcpie/database.py
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 | |
Relationship
¶
| METHOD | DESCRIPTION |
|---|---|
delete |
Delete the relationship |
update |
Update the relationship class |
| ATTRIBUTE | DESCRIPTION |
|---|---|
destination_keys |
Mapping of destination Primary and Foreign keys
TYPE:
|
destinations |
Destination FeatureClass/Table objects
TYPE:
|
origin_keys |
Mapping of origin Primary and Foreign keys |
origins |
Origin FeatureClass/Table objects
TYPE:
|
Source code in src/arcpie/database.py
857 858 859 | |
destination_keys
property
¶
Mapping of destination Primary and Foreign keys
destinations
property
¶
destinations: list[FeatureClass | Table[Any]]
Destination FeatureClass/Table objects
origin_keys
property
¶
Mapping of origin Primary and Foreign keys
delete
¶
delete() -> None
Delete the relationship
Source code in src/arcpie/database.py
945 946 947 | |
update
¶
update(**options: Unpack[RelationshipOpts]) -> None
Update the relationship class
Source code in src/arcpie/database.py
949 950 951 952 953 954 | |
RelationshipManager
¶
-
Modules
Database
Datasetrelationships
| METHOD | DESCRIPTION |
|---|---|
create |
Create a relationship |
delete |
Delete the relationship and return the settings so it can be made again |
Source code in src/arcpie/database.py
1009 1010 | |
create
¶
create(**options: Unpack[RelationshipOpts]) -> None
Create a relationship
Source code in src/arcpie/database.py
1020 1021 1022 | |
delete
¶
delete(name: str) -> RelationshipOpts | None
Delete the relationship and return the settings so it can be made again
Source code in src/arcpie/database.py
1024 1025 1026 1027 1028 1029 1030 1031 | |