Geographical unit
GeographicalUnit
Represents a single geographical unit at any level (SGU, MGU, LGU). Generic class that works with any geography, past or present.
Source code in may/geography/geographical_unit.py
5 6 7 8 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 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 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 | |
__eq__(other)
Check if two GeographicalUnit objects are equal.
Compares intrinsic properties (id, name, level, coordinates, properties) and structural position (parent). Does NOT compare collections (children, venues, people) as those should be compared at a higher level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Another object to compare with |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if both units have identical intrinsic properties |
Example
unit1 = GeographicalUnit(id=1, name='E00001', level='SGU') unit2 = GeographicalUnit(id=1, name='E00001', level='SGU') unit1 == unit2 True
Source code in may/geography/geographical_unit.py
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 | |
__hash__()
Return hash of GeographicalUnit based on immutable identifiers.
Uses id and name which should remain constant after creation. Allows GeographicalUnit objects to be used in sets and as dict keys.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Hash value based on id and name |
Note
Two units with same id and name will have same hash, even if other attributes differ. The eq method provides full comparison.
Source code in may/geography/geographical_unit.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
add_child(child)
Add a child unit and set this as its parent
Source code in may/geography/geographical_unit.py
34 35 36 37 | |
add_person(person)
Add a person to this geographical unit
Source code in may/geography/geographical_unit.py
43 44 45 | |
add_venue(venue)
Add a venue to this geographical unit
Source code in may/geography/geographical_unit.py
39 40 41 | |
get_ancestor_by_level(level)
Get ancestor unit at a specific level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
Level name (e.g., "LGU", "MGU", "SGU") |
required |
Returns:
| Type | Description |
|---|---|
|
GeographicalUnit at that level or None if not found |
Source code in may/geography/geographical_unit.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
get_ancestors()
Get all ancestor units up the hierarchy
Source code in may/geography/geographical_unit.py
51 52 53 54 55 56 57 58 | |
get_descendants(level=None)
Get all descendant units. If level specified, only return that level.
Source code in may/geography/geographical_unit.py
83 84 85 86 87 88 89 90 91 92 | |
get_people()
Get all people in the geo_unit and/or all its descendents
Source code in may/geography/geographical_unit.py
94 95 96 97 98 99 100 101 102 | |
get_venues_by_type(venue_type)
Get all venues of a specific type in this geographical unit
Source code in may/geography/geographical_unit.py
47 48 49 | |