capturegraph.procedures.toolkits.metadata.location_manager
#
Location Management Toolkit#
This module provides utilities for managing target locations for data collection. Location managers handle setting, retrieving, and updating geographic coordinates where data should be captured, with built-in logic for location validation and user-friendly distance checking.
The toolkit enables location-aware data collection workflows where users can:
-
Set target capture locations
-
Check distance from current location to target
-
Ask user if they want to update target location when far from the original location
All location data is persisted across procedure executions for consistency.
set_target_location(location, skip_if_exists)
#
Sets the target capture location for the current capture target.
Establishes the geographic location where data should be captured for this target. The location is persisted and used for distance calculations and location-based workflow decisions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Procedure[PLocation]
|
The procedure that provides the target location coordinates |
required |
skip_if_exists
|
bool
|
Whether to skip setting if a target location already exists |
required |
Returns:
| Type | Description |
|---|---|
Procedure[PVoid]
|
A procedure that saves the location to the target's location file |
Example
import capturegraph.procedures as cgp
# Set a fixed target location
target_coords = cgp.ConstantLocation(latitude=37.7749, longitude=-122.4194)
cgp.set_target_location(target_coords, skip_if_exists=False)
# Set target to current location
cgp.set_target_location(cgp.CaptureLocation(), skip_if_exists=True)
Source code in capturegraph-lib/capturegraph/procedures/toolkits/metadata/location_manager.py
get_target_location(default_location=CaptureLocation())
#
Retrieves the target capture location for the current capture target.
Returns the previously saved target location, or the default location if no target has been set. Used to check distances and validate capture locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default_location
|
Procedure[PLocation]
|
The location to use if no target location is saved (defaults to current GPS location) |
CaptureLocation()
|
Returns:
| Type | Description |
|---|---|
Procedure[PLocation]
|
A procedure that retrieves the target location from persistent storage |
Example
Source code in capturegraph-lib/capturegraph/procedures/toolkits/metadata/location_manager.py
update_target_location(max_distance_meters=100, current_location=CaptureLocation())
#
Conditionally updates the target location when the user is far from the current target.
Calculates the distance between the user's current location and the saved target location. If the distance exceeds the threshold, prompts the user to update the target location to their current position. This enables flexible data collection where the target location can adapt to the user's movements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_distance_meters
|
float | int
|
Maximum allowed distance in meters before prompting for location update (default: 100 meters) |
100
|
current_location
|
Procedure[PLocation]
|
Procedure to get the user's current GPS location (defaults to CaptureLocation()) |
CaptureLocation()
|
Returns:
| Type | Description |
|---|---|
Procedure[PVoid]
|
A procedure that conditionally updates the target location based on distance |
Procedure[PVoid]
|
and user choice. Does nothing if the user is within the allowed distance. |
Example
import capturegraph.procedures as cgp
# Check if user is more than 50 meters from target, prompt to update
cgp.update_target_location(max_distance_meters=50)
# Use a custom location source with default 100m threshold
custom_location = cgp.UserInputLocation(label="Where are you now?")
cgp.update_target_location(current_location=custom_location)