API Reference¶
GISK
¶
GISK(
name=None,
url=None,
api_key=None,
api_version=DEFAULT_API_VERSION,
)
Client for connecting to a Koordinates server.
Provides methods for authenticating, accessing content, and making HTTP requests to the Koordinates API. Used as the main entry point for interacting with Koordinates-hosted data.
Attributes:
-
name(str) –The name of the Koordinates portal.
If this is provided, the url is ignored. -
url(str) –The base URL of the Koordinates server.
-
_api_version(str) –The API version to use.
-
_content_manager(ContentManager or None) –Cached ContentManager instance.
-
_api_key(str) –The API key for authenticating requests.
Parameters:
-
(name¶str, default:None) –The name of the Koordinates portal (e.g., 'linz'). If provided, overrides url.
-
(url¶str, default:None) –The base URL of the Koordinates server. Used if name is not provided.
-
(api_key¶str, default:None) –The API key for authenticating with the Koordinates server.
-
(api_version¶str, default:DEFAULT_API_VERSION) –The API version to use. Defaults to 'v1.x'.
Raises:
-
ValueError–If the portal name is not recognized or if api_key is not provided.
Methods:
-
get–Makes a synchronous GET request to the specified URL with the provided parameters.
-
reset–Resets the GISK instance.
audit
property
¶
audit: AuditManager
Returns the AuditManager instance for this GISK.
Returns:
-
AuditManager(AuditManager) –The audit manager associated with this GISK.
content
property
¶
content: ContentManager
Returns the ContentManager instance for this server.
Returns:
-
ContentManager(ContentManager) –The content manager associated with this server.
get
¶
Makes a synchronous GET request to the specified URL with the provided parameters. Injects the API key into the request headers.
Parameters:
-
(url¶str) –The URL to send the GET request to.
-
(params¶dict, default:None) –Query parameters to include in the request. Defaults to None.
Returns:
-
dict(dict) –The JSON-decoded response from the server.
Raises:
-
BadRequest–If the request fails with a 400 status code.
-
ServerError–For other HTTP errors or request exceptions.
reset
¶
reset() -> None
Resets the GISK instance. This is useful if the API key or other configurations change.
Returns:
-
None–None
ContentManager
¶
Manages content for a GISK instance.
Provides methods to search for, retrieve, and instantiate Koordinates items (layers, tables, etc.) based on their IDs or URLs.
Attributes:
-
jobs(list) –Export jobs list.
-
download_folder(str) –Default folder for downloads.
Parameters:
-
(session¶SessionManager) –The GISK SessionManager.
-
(audit¶AuditManager) –The GISK AuditManager.
Methods:
-
download–Downloads all exports from a list of jobs.
-
get–Retrieves and instantiates a content item by ID from the GISK.
download
¶
download(
jobs: list[JobResults] = None,
folder: str = None,
poll_interval: int = 10,
force_all: bool = False,
) -> list[JobResults]
Downloads all exports from a list of jobs. Polls the jobs until they are finished. As soon as it encounters a finished job, it pauses polling and downloads that file, then resumes polling the remainder.
Parameters:
-
(jobs¶list[JobResult], default:None) –The list of job result objects to download.
-
(folder¶str, default:None) –The output folder where files will be saved.
-
(poll_interval¶int, default:10) –The interval in seconds to poll the jobs. Default is 10.
Returns:
-
list[JobResults]–list[JobResult]: The list of job result objects after download.
get
¶
get(id: str) -> dict
Retrieves and instantiates a content item by ID from the GISK.
Parameters:
-
(id¶str) –The ID of the content to retrieve.
Returns:
-
dict–VectorItem or TableItem or None: The instantiated item, depending on its kind, or None if not found.
Raises:
-
BadRequest–If the content is not found or the request is invalid.
-
UnknownItemTypeError–If the item kind is not supported.
-
ServerError–If the item does not have a URL.
AuditManager
¶
AuditManager()
Manages auditing for a GISK instance.
Provides methods to record and retrieve information relating to interactions with the GISK. All data is stored in a SQLite database.
Methods:
-
add_request_record–Adds a request record to the audit database.
-
disable_auditing–Disables auditing by setting the enabled flag to False.
-
enable_auditing–Enable auditing and create the audit database if it does not exist.
-
get_latest_request_for_item–Returns the most recent audit record for the given item_id, optionally filtered by request_type,
-
save_data–Save the audit data to a local JSON file.
add_request_record
¶
add_request_record(
item_id: int,
item_kind: str,
item_type: str,
request_type: str,
request_url: str,
request_method: str,
request_time: datetime,
request_headers: dict,
request_params: dict,
response: dict = None,
) -> None
Adds a request record to the audit database.
Converts request_headers and request_params dicts to JSON strings for storage.
Parameters:
-
(item_id¶int) –The ID of the item involved in the request.
-
(item_kind¶str) –The kind of the item (e.g., 'vector', 'table').
-
(item_type¶str) –The type of the item.
-
(request_type¶str) –The type of request (e.g., 'GET', 'POST').
-
(request_url¶str) –The URL of the request.
-
(request_method¶str) –The HTTP method used for the request.
-
(request_time¶datetime) –The time the request was made.
-
(request_headers¶dict) –The headers sent with the request.
-
(request_params¶dict) –The parameters sent with the request.
-
(response¶dict, default:None) –The response received from the request.
Returns:
-
None–None
disable_auditing
¶
disable_auditing() -> None
Disables auditing by setting the enabled flag to False.
Returns:
-
None–None
enable_auditing
¶
enable_auditing(
folder: str, retain_data: bool = True
) -> None
get_latest_request_for_item
¶
get_latest_request_for_item(
item_id: int, request_type: str = None
) -> dict
Returns the most recent audit record for the given item_id, optionally filtered by request_type, based on request_time.
Parameters:
-
(item_id¶int) –The ID of the item to search for.
-
(request_type¶str, default:None) –The type of request to filter by.
Returns:
-
dict(dict) –The most recent audit record as a dictionary, or empty dictionary.
save_data
¶
save_data(
item_id: int,
request_type: str,
request_time: datetime,
data: dict,
) -> None
Save the audit data to a local JSON file.
The file will be saved in a 'data' subfolder within the audit folder, with a filename formatted as '{request_type}{item_id}{request_time}.json'.
Parameters:
-
(item_id¶int) –The ID of the item related to the data.
-
(request_type¶str) –The type of request (e.g., 'GET', 'POST').
-
(request_time¶str) –The time the request was made, used in the filename.
-
(data¶dict) –The data to be saved as JSON.
Returns:
-
None–None
Raises:
-
OSError–If the file or directory cannot be created or written.
-
TypeError–If the data cannot be serialized to JSON.
BaseItem
dataclass
¶
BaseItem(
id: int,
url: str,
type: str,
title: str,
description: str,
data: ItemData,
services: str,
kind: str,
categories: List[Any],
tags: List[str],
created_at: str,
license: Any,
metadata: Any,
num_views: int,
num_downloads: int,
)
Bases: ABC
Base class for Items. Should not be created directly. Instead, use the ContentManager to return an Item.
Methods:
-
attach_resources–Attaches session, audit, and content manager resources to the item.
-
export–Exports the item in the specified format.
Attributes:
-
feature_class_name(str) –Return the feature class name that would be used in an export to file geodatabase request.
-
fgb_name(str) –Return the file geodatabase name that would be used in an export to file geodatabase request.
-
supports_changesets(bool) –Returns whether the item supports changesets.
feature_class_name
property
¶
feature_class_name: str
Return the feature class name that would be used in an export to file geodatabase request.
Replace any non-alphanumeric characters with underscore This seems to be the Koordinates method for setting the feature class names
NOTE: This logic is observed from running exports only and does not appear to be documented anywhere by Koordinates.
fgb_name
property
¶
fgb_name: str
Return the file geodatabase name that would be used in an export to file geodatabase request.
NOTE: This logic is observed from running exports only and does not appear to be documented anywhere by Koordinates.
supports_changesets
property
¶
supports_changesets: bool
Returns whether the item supports changesets.
Returns:
-
bool(bool) –True if the item supports changesets, False otherwise.
attach_resources
¶
attach_resources(
session: SessionManager = None,
audit: AuditManager = None,
content: ContentManager = None,
)
Attaches session, audit, and content manager resources to the item.
Parameters:
export
¶
export(
export_format: str,
out_sr: int = None,
bbox_geometry: Union[GeoDataFrame, DataFrame] = None,
filter_geometry: Optional[
Union[dict, GeoDataFrame, DataFrame]
] = None,
poll_interval: int = None,
timeout: int = None,
**kwargs: Any,
) -> JobResult
Exports the item in the specified format.
Parameters:
-
(export_format¶str) –The format to export the item in.
-
(out_sr¶int, default:None) –The coordinate reference system code to use for the export.
-
(filter_geometry¶dict or GeoDataFrame or DataFrame, default:None) –The filter_geometry to use for the export. Should be a GeoJSON dictionary, GeoDataFrame, or SEDF.
-
(poll_interval¶int, default:None) –The interval in seconds to poll the export job status. Default is 10 seconds.
-
(timeout¶int, default:None) –The maximum time in seconds to wait for the export job to complete.
-
(**kwargs¶Any, default:{}) –Additional parameters for the export request.
Returns:
-
JobResult(JobResult) –A JobResult instance containing the export job details.
Raises:
-
ValueError–If export validation fails.
VectorItem
dataclass
¶
VectorItem(
id: int,
url: str,
type: str,
title: str,
description: str,
data: VectorItemData,
services: str,
kind: str,
categories: List[Any],
tags: List[str],
created_at: str,
license: Any,
metadata: Any,
num_views: int,
num_downloads: int,
)
Bases: BaseItem
Represents a vector item in the GISK content system.
Inherits from BaseItem and provides methods for querying and retrieving changesets via WFS.
Methods:
-
attach_resources–Attaches session, audit, and content manager resources to the item.
-
export–Exports the item in the specified format.
-
query–Executes a WFS query on the item and returns the result as JSON.
Attributes:
-
feature_class_name(str) –Return the feature class name that would be used in an export to file geodatabase request.
-
fgb_name(str) –Return the file geodatabase name that would be used in an export to file geodatabase request.
-
supports_changesets(bool) –Returns whether the item supports changesets.
feature_class_name
property
¶
feature_class_name: str
Return the feature class name that would be used in an export to file geodatabase request.
Replace any non-alphanumeric characters with underscore This seems to be the Koordinates method for setting the feature class names
NOTE: This logic is observed from running exports only and does not appear to be documented anywhere by Koordinates.
fgb_name
property
¶
fgb_name: str
Return the file geodatabase name that would be used in an export to file geodatabase request.
NOTE: This logic is observed from running exports only and does not appear to be documented anywhere by Koordinates.
supports_changesets
property
¶
supports_changesets: bool
Returns whether the item supports changesets.
Returns:
-
bool(bool) –True if the item supports changesets, False otherwise.
attach_resources
¶
attach_resources(
session: SessionManager = None,
audit: AuditManager = None,
content: ContentManager = None,
)
Attaches session, audit, and content manager resources to the item.
Parameters:
export
¶
export(
export_format: str,
out_sr: int = None,
bbox_geometry: Union[GeoDataFrame, DataFrame] = None,
filter_geometry: Optional[
Union[dict, GeoDataFrame, DataFrame]
] = None,
poll_interval: int = None,
timeout: int = None,
**kwargs: Any,
) -> JobResult
Exports the item in the specified format.
Parameters:
-
(export_format¶str) –The format to export the item in.
-
(out_sr¶int, default:None) –The coordinate reference system code to use for the export.
-
(filter_geometry¶dict or GeoDataFrame or DataFrame, default:None) –The filter_geometry to use for the export. Should be a GeoJSON dictionary, GeoDataFrame, or SEDF.
-
(poll_interval¶int, default:None) –The interval in seconds to poll the export job status. Default is 10 seconds.
-
(timeout¶int, default:None) –The maximum time in seconds to wait for the export job to complete.
-
(**kwargs¶Any, default:{}) –Additional parameters for the export request.
Returns:
-
JobResult(JobResult) –A JobResult instance containing the export job details.
Raises:
-
ValueError–If export validation fails.
query
¶
query(
*,
from_time: str = None,
to_time: str = None,
cql_filter: str = None,
out_sr: int = None,
out_fields: str | list[str] = None,
result_record_count: int = None,
bbox: str = None,
bbox_geometry: Union[GeoDataFrame, DataFrame] = None,
filter_geometry: Union[GeoDataFrame, DataFrame] = None,
spatial_rel: str = None,
**kwargs: Any,
) -> dict
Executes a WFS query on the item and returns the result as JSON.
Parameters:
-
(cql_filter¶str, default:None) –The CQL filter to apply to the query.
-
(out_sr¶int, default:None) –The spatial reference system code to use for the query.
-
(out_fields¶str, list of strings, default:None) –Attribute fields to include in the response.
-
(result_record_count¶int, default:None) –Restricts the maximum number of results to return.
-
(bbox¶str or GeoDataFrame or DataFrame, default:None) –The bounding box to apply to the query. If a GeoDataFrame or SEDF is provided, it will be converted to a bounding box string in WGS84.
-
(bbox_geometry¶gdf or sdf, default:None) –A dataframe that is converted to a bounding box and used to spatially filter the response.
-
(filter_geometry¶gdf or sdf, default:None) –A dataframe that is used to spatially filter the response.
-
(**kwargs¶Any, default:{}) –Additional parameters for the WFS query.
Returns:
-
dict(dict) –The result of the WFS query in JSON format.
TableItem
dataclass
¶
TableItem(
id: int,
url: str,
type: str,
title: str,
description: str,
data: ItemData,
services: str,
kind: str,
categories: List[Any],
tags: List[str],
created_at: str,
license: Any,
metadata: Any,
num_views: int,
num_downloads: int,
)
Bases: BaseItem
Represents a table item in the GISK content system.
Inherits from BaseItem and provides methods for querying and retrieving changesets via WFS.
Methods:
-
attach_resources–Attaches session, audit, and content manager resources to the item.
-
export–Exports the item in the specified format.
-
query–Executes a WFS query on the item and returns the result as JSON.
Attributes:
-
feature_class_name(str) –Return the feature class name that would be used in an export to file geodatabase request.
-
fgb_name(str) –Return the file geodatabase name that would be used in an export to file geodatabase request.
-
supports_changesets(bool) –Returns whether the item supports changesets.
feature_class_name
property
¶
feature_class_name: str
Return the feature class name that would be used in an export to file geodatabase request.
Replace any non-alphanumeric characters with underscore This seems to be the Koordinates method for setting the feature class names
NOTE: This logic is observed from running exports only and does not appear to be documented anywhere by Koordinates.
fgb_name
property
¶
fgb_name: str
Return the file geodatabase name that would be used in an export to file geodatabase request.
NOTE: This logic is observed from running exports only and does not appear to be documented anywhere by Koordinates.
supports_changesets
property
¶
supports_changesets: bool
Returns whether the item supports changesets.
Returns:
-
bool(bool) –True if the item supports changesets, False otherwise.
attach_resources
¶
attach_resources(
session: SessionManager = None,
audit: AuditManager = None,
content: ContentManager = None,
)
Attaches session, audit, and content manager resources to the item.
Parameters:
export
¶
export(
export_format: str,
out_sr: int = None,
bbox_geometry: Union[GeoDataFrame, DataFrame] = None,
filter_geometry: Optional[
Union[dict, GeoDataFrame, DataFrame]
] = None,
poll_interval: int = None,
timeout: int = None,
**kwargs: Any,
) -> JobResult
Exports the item in the specified format.
Parameters:
-
(export_format¶str) –The format to export the item in.
-
(out_sr¶int, default:None) –The coordinate reference system code to use for the export.
-
(filter_geometry¶dict or GeoDataFrame or DataFrame, default:None) –The filter_geometry to use for the export. Should be a GeoJSON dictionary, GeoDataFrame, or SEDF.
-
(poll_interval¶int, default:None) –The interval in seconds to poll the export job status. Default is 10 seconds.
-
(timeout¶int, default:None) –The maximum time in seconds to wait for the export job to complete.
-
(**kwargs¶Any, default:{}) –Additional parameters for the export request.
Returns:
-
JobResult(JobResult) –A JobResult instance containing the export job details.
Raises:
-
ValueError–If export validation fails.
query
¶
query(
*,
from_time: str = None,
to_time: str = None,
cql_filter: str = None,
out_fields: str | list[str] = None,
result_record_count: int = None,
**kwargs: Any,
) -> dict
ItemData
dataclass
¶
ItemData(
storage: Optional[str],
datasources: Optional[str],
fields: List[FieldDef],
encoding: Optional[str],
primary_key_fields: Optional[List[str]],
source_revision: Optional[int],
omitted_fields: List[Any],
tile_revision: int,
feature_count: int,
datasource_count: int,
change_summary: Optional[ChangeSummary],
source_summary: Optional[str],
import_started_at: str,
import_ended_at: str,
import_log: ImportLog,
import_version: str,
update_available: bool,
sample: Optional[str],
raster_resolution: Optional[Any],
empty_geometry_count: int,
has_z: bool,
export_formats: List[ExportFormat],
)
VectorItemData
dataclass
¶
VectorItemData(
storage: Optional[str],
datasources: Optional[str],
fields: List[FieldDef],
encoding: Optional[str],
primary_key_fields: Optional[List[str]],
source_revision: Optional[int],
omitted_fields: List[Any],
tile_revision: int,
feature_count: int,
datasource_count: int,
change_summary: Optional[ChangeSummary],
source_summary: Optional[str],
import_started_at: str,
import_ended_at: str,
import_log: ImportLog,
import_version: str,
update_available: bool,
sample: Optional[str],
raster_resolution: Optional[Any],
empty_geometry_count: int,
has_z: bool,
export_formats: List[ExportFormat],
crs: CRS,
geometry_field: str,
geometry_type: str,
extent: Dict[str, Any],
)
Bases: ItemData
WFSResponse
¶
Represents a response from a WFS (Web Feature Service) request.
Holds the raw GeoJSON data and provides properties and methods to convert the data into various dataframe formats (Pandas, GeoPandas, Spatially Enabled DataFrame).
Attributes:
-
_json(dict) –The raw GeoJSON data.
-
item(BaseItem) –The associated item metadata.
-
out_sr(Any) –The output spatial reference.
-
_df(DataFrame or None) –Cached Pandas DataFrame.
-
_gdf(GeoDataFrame or None) –Cached GeoPandas DataFrame.
-
_sdf(SpatialDataFrame or None) –Cached Spatially Enabled DataFrame.
-
total_features(int) –The number of features in the GeoJSON.
Parameters:
-
(geojson¶dict) –The raw GeoJSON data.
-
(item¶BaseItem, default:None) –The associated item metadata.
-
(out_sr¶Any, default:None) –The output spatial reference.
df
property
¶
df: DataFrame
Convert the GeoJSON to a Pandas DataFrame.
Returns:
-
DataFrame–pd.DataFrame: The features as a Pandas DataFrame.
Raises:
-
Exception–If conversion fails.
gdf
property
¶
gdf: GeoDataFrame
Convert the GeoJSON to a GeoPandas DataFrame.
Requires the geopandas package to be installed.
Returns:
-
GeoDataFrame–gpd.GeoDataFrame: The features as a GeoPandas DataFrame.
Raises:
-
ValueError–If the geopandas package is not installed.
-
Exception–If conversion fails.
sdf
property
¶
sdf: DataFrame
Convert the GeoJSON to a Spatially Enabled DataFrame (ArcGIS SEDF).
Requires the arcgis package to be installed.
Returns:
-
SpatialDataFrame(DataFrame) –The features as a Spatially Enabled DataFrame.
Raises:
-
ValueError–If the arcgis package is not installed.
-
Exception–If conversion fails.
JobResult
¶
JobResult(
payload: dict,
session: SessionManager,
poll_interval: int = None,
timeout: int = None,
)
Represents the result of an asynchronous export or processing job.
Provides methods to poll for job completion, retrieve job status, and download results. The download and download_async methods return a DownloadResult object containing detailed metadata about the downloaded file. Download metadata is also stored as attributes on the JobResult instance after a successful download.
Attributes:
-
_initial_payload(dict) –The initial job payload from the API.
-
_job_url(str) –The URL to poll for job status.
-
_id(int) –The unique identifier of the job.
-
_poll_interval(int) –Polling interval in seconds.
-
_timeout(int) –Maximum time to wait for job completion in seconds.
-
_last_response(dict) –The most recent job status response.
-
#(Populated after download) – -
download_folder(str) –The directory where the file was saved.
-
download_filename(str) –The name of the downloaded file.
-
download_file_path(str) –The full path to the downloaded file.
-
download_file_size_bytes(int) –The size of the downloaded file in bytes.
-
download_completed_at(float) –The timestamp when the download completed.
-
download_resolved_url(str) –The final resolved URL after redirects.
-
download_checksum(str | None) –The SHA256 checksum of the downloaded file.
Parameters:
-
(payload¶dict) –The job payload, typically from an API response.
-
(session¶SessionManager) –The GISK SessionManager.
-
(poll_interval¶int, default:None) –Interval in seconds to poll the job status. Default is 10.
-
(timeout¶int, default:None) –Maximum time in seconds to wait for the job to complete. Default is 1800 (30 min).
Returns:
-
None–None
Methods:
-
download–Waits for the job to finish, then downloads the file synchronously.
-
output–Blocks until the job completes, then returns the final job response.
-
to_dict–Returns the most recent job status response as a dictionary.
created_at
property
¶
created_at: str | None
Returns the creation time of the job.
Returns:
-
str | None–str | None: The creation timestamp, or None if not available.
progress
property
¶
progress: float | None
Returns the progress of the job as a percentage.
Returns:
-
float | None–float | None: The progress value, or None if not available.
state
property
¶
state: str
Returns the current state of the job.
Returns:
-
str(str) –The job state. Possible values include 'complete', 'processing', 'cancelled', 'error', 'gone'.
status
property
¶
status: JobStatus
Refreshes and returns the current job status.
Returns:
-
JobStatus(JobStatus) –The state and progress of the job.
download
¶
Waits for the job to finish, then downloads the file synchronously.
Parameters:
-
(folder¶str) –The folder where the file will be saved.
-
(file_name¶str, default:None) –The name of the file to save. If None, uses the job name.
Returns:
-
DownloadResult(DownloadResult) –Object containing details about the downloaded file.
Raises:
-
ValueError–If the download URL is not available.
output
¶
output() -> dict
Blocks until the job completes, then returns the final job response.
Returns:
-
dict(dict) –The final job response after completion.
Raises:
-
TimeoutError–If the job does not complete within the timeout.
-
RuntimeError–If the job fails or is cancelled.
to_dict
¶
to_dict() -> dict
Returns the most recent job status response as a dictionary.
Returns:
-
dict(dict) –The most recent job status response.
Custom Errors¶
custom_errors
¶
custom_errors.py Custom exceptions.
Classes:
-
BadRequest–Exception raised for HTTP 400 Bad Request errors.
-
ExportError–Custom exception for errors encountered during export operations.
-
HTTPError–Base exception for HTTP errors.
-
NotFound–Exception raised for HTTP 404 Not Found errors.
-
ServerError–Exception raised for HTTP 500 Server Error errors.
-
Unauthorized–Exception raised for HTTP 401 Unauthorized errors.
-
UnknownItemTypeError–Exception raised when an unknown item type is encountered.
ExportError
¶
Bases: Exception
Custom exception for errors encountered during export operations.
HTTPError
¶
Bases: Exception
Base exception for HTTP errors.
UnknownItemTypeError
¶
UnknownItemTypeError(message: str)
Bases: Exception
Exception raised when an unknown item type is encountered.
This exception is used to signal that an item kind is not supported by the client.
Parameters:
-
(message¶str) –Description of the error.
Attributes:
-
message(str) –Description of the error.
Parameters:
-
(message¶str) –Description of the error.