### Example MCP Server Startup Logs Source: https://docs.wherobots.com/develop/mcp/mcp-server-installation These are example log entries that indicate a Wherobots MCP server has started successfully. They show the server name, connection state transitions, and the number of tools discovered. ```log 2025-11-14 14:12:46.829 [info] Starting server wherobots-mcp-server 2025-11-14 14:12:46.831 [info] Connection state: Starting 2025-11-14 14:12:46.831 [info] Starting server from LocalProcess extension host 2025-11-14 14:12:46.833 [info] Connection state: Running 2025-11-14 14:12:47.953 [info] Discovered 8 tools ``` -------------------------------- ### Install scikit-learn for DBSCAN Source: https://docs.wherobots.com/tutorials/wherobotsai/clustering/dbscan Installs the scikit-learn package, which is a dependency for the DBSCAN example. This command-line instruction is used to set up the necessary environment for running the clustering algorithms. ```bash pip install scikit-learn ``` -------------------------------- ### Install scikit-learn for DBSCAN Source: https://docs.wherobots.com/tutorials/example-notebooks/Clustering-DBSCAN Installs the scikit-learn library, which is a dependency for data generation and preprocessing in the DBSCAN example. This command is typically run in a notebook environment. ```python %pip install scikit-learn ``` -------------------------------- ### Historical Snapshot Example (Python) Source: https://docs.wherobots.com/develop/spatial-catalog/spatial-catalog Provides a Python example using the Sedona library to query a historical snapshot of the `places_place` table, specifically targeting the version '2025-05-21.0'. This enables reproducible analysis of past data states. ```Python historical_sql = """ SELECT * FROM wherobots_open_data.overture_maps_foundation.places_place VERSION AS OF '2025-05-21.0' """ sedona.sql(historical_sql).show() ``` -------------------------------- ### Example: Create Spatial Index for a Table Source: https://docs.wherobots.com/reference/havasu-table/geometry-data/cluster-geometry-table An example demonstrating how to create a spatial index for a specific table, 'wherobots.db.test_table', using the 'geom' column with a Hilbert precision of 10. ```sql CREATE SPATIAL INDEX FOR wherobots.db.test_table USING hilbert(geom, 10); ``` -------------------------------- ### SQL Physical Plan Example Source: https://docs.wherobots.com/reference/wherobots-db/geometry-data/optimizer An example of the physical plan generated for a distance join operation in SQL, illustrating the DistanceJoin operator and file scanning. ```sql == Physical Plan == DistanceJoin pointshape1#12: geometry, pointshape2#33: geometry, 2.0, true :- Project [st_point(cast(_c0#0 as decimal(24,20)), cast(_c1#1 as decimal(24,20)), myPointId) AS pointshape1#12] +- *FileScan csv +- Project [st_point(cast(_c0#21 as decimal(24,20)), cast(_c1#22 as decimal(24,20)), myPointId) AS pointshape2#33] +- *FileScan csv ``` -------------------------------- ### Start WherobotsDB with Sedona Source: https://docs.wherobots.com/tutorials/wherobotsai/wherobots-inference/raster-text-to-segments-airplanes Initializes the SedonaContext to enable WherobotsDB functionalities, including raster processing. This setup is crucial for subsequent data loading and analysis. ```python from sedona.spark import SedonaContext from sedona.raster_utils.SedonaUtils import SedonaUtils from sedona.maps.SedonaKepler import SedonaKepler from pyspark.sql.functions import expr config = ( SedonaContext.builder() .getOrCreate() ) sedona = SedonaContext.create(config) ``` -------------------------------- ### Tune Wherobots Map Matching Configuration Dynamically (Python, Scala, Java) Source: https://docs.wherobots.com/tutorials/wherobotsai/map-matching/map_matching This set of code examples demonstrates how to dynamically tune Wherobots map matching configurations, specifically 'wherobots.tools.mm.maxdist', after the SedonaContext has already been created. Examples are provided for Python, Scala, and Java. ```python sedona.conf.set("wherobots.tools.mm.maxdist", "50.0") ``` ```scala sedona.conf.set("wherobots.tools.mm.maxdist", "50.0") ``` ```java sedona.conf().set("wherobots.tools.mm.maxdist", "50.0"); ``` -------------------------------- ### Set up Sedona Context in Scala Source: https://docs.wherobots.com/tutorials/example-notebooks/Getting-Started Initializes the SedonaContext for Wherobots, connecting your code to the cloud compute environment. This is a prerequisite for most Wherobots operations in Scala. ```scala import org.apache.sedona.spark.SedonaContext val config = SedonaContext.builder().getOrCreate() val sedona = SedonaContext.create(config) ``` -------------------------------- ### Example: Upgrade WKT Column to GEOMETRY Source: https://docs.wherobots.com/reference/havasu-table/geometry-data/convert-geometry-fields An example SQL command demonstrating how to upgrade a table's 'geom' column, which stores WKT values, to use the Havasu GEOMETRY column type. This process serializes new geometry data as WKT. ```sql ALTER TABLE wherobots.db.table_name SET GEOMETRY FIELDS wkt AS 'wkt'; ``` -------------------------------- ### Spatial Query Optimization Example (ST_Intersects) Source: https://docs.wherobots.com/reference/havasu-table/spec Demonstrates how a spatial range query predicate can be converted into an inclusive projection for scan planning. This example uses ST_Intersects to check for overlap between the query window (Q) and the Minimum Bounding Box (MBR) of geometries in a data file. This is a common strategy to prune data files that do not satisfy the query. ```SQL-like SELECT * FROM HavasuTable WHERE ST_Intersects(MBR[geom], Q); ``` -------------------------------- ### Example Audit Log Response (Bash) Source: https://docs.wherobots.com/reference/wherobots-cloud/audit-logs-export This snippet demonstrates an example of the CSV formatted response body for an audit log event. It includes headers and a sample data row, showcasing the expected fields such as event time, user ID, action name, and more. This format is useful for direct inspection or simple scripting. ```bash event_id,event_time,action_name,user_id,user_name,user_agent,source_ip,resource_name,resource_id,compute_region geteweunusi7pw,2025-02-20T20:48:10.355994+00:00,DestroyNotebook,43kh1a3snm0955,USER_IDENTIFIER,"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",IP_ADDRESS,,ev5a3dfnkoc354, ``` -------------------------------- ### Configure S3 Bucket CORS Policy for Wherobots Cloud Source: https://docs.wherobots.com/tutorials/wherobotsdb/tile-generation/cors This JSON policy allows GET and HEAD requests from specified Wherobots Cloud domains to your S3 bucket. It's essential for PMTiles to function correctly when reading tiles directly from your own S3 storage. ```json [ { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "GET", "HEAD" ], "AllowedOrigins": [ "https://cloud.wherobots.com", "https://www.cloud.wherobots.com", "https://*.compute.cloud.wherobots.com", "https://tile-viewer.wherobots.com" ], "ExposeHeaders": [ "x-amz-request-id" ] } ] ``` -------------------------------- ### Initialize SedonaContext and Import Libraries (Python) Source: https://docs.wherobots.com/get-started/initial-storage/connect-to-unity-catalog This snippet demonstrates how to initialize the SedonaContext in a Wherobots Notebook and import necessary libraries like 'expr' from PySpark. The SedonaContext is crucial for working with spatial data and Unity Catalog tables. ```python from sedona.spark import * from pyspark.sql.functions import expr config = SedonaContext.builder().getOrCreate() sedona = SedonaContext.create(config) ``` -------------------------------- ### Start Harlequin CLI for Wherobots Source: https://docs.wherobots.com/develop/spatial-sql-api This command initiates the Harlequin CLI tool, connecting to Wherobots with specified API key, runtime, and region. It's a foundational step for interacting with Wherobots services from the command line. ```bash harlequin -a wherobots --api-key --runtime TINY --region AWS_US_WEST_2 ``` -------------------------------- ### Python DB-API Driver Installation and Usage Source: https://docs.wherobots.com/develop/spatial-sql-api This section details how to install and use the Wherobots Python DB-API driver to connect to WherobotsDB and execute Spatial SQL queries. It includes installation instructions using Poetry or pip, and a Python code example demonstrating connection, query execution, and result fetching. ```APIDOC ## Python DB-API Driver ### Description Access Wherobots DB using a PEP-0249 compatible Python DB-API implementation. This driver allows programmatic connection to a Wherobots DB runtime and execution of Spatial SQL queries. ### Installation **Using Poetry:** ```sh poetry add wherobots-python-dbapi ``` **Using pip:** ```sh pip install wherobots-python-dbapi ``` ### Usage Follow the standard DB-API pattern: establish a connection, acquire a cursor, and execute SQL queries. **Connection and Query Execution:** ```python import logging import sys from wherobots.db import connect from wherobots.db.region import Region from wherobots.db.runtime import Runtime # Optionally, setup logging logging.basicConfig( stream=sys.stdout, level=logging.INFO, format="%(asctime)s.%(msecs)03d %(levelname)s %(name)20s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S", ) # Replace '...' with your actual API key api_key = '...' with connect( host="api.cloud.wherobots.com", api_key=api_key, runtime=Runtime.TINY, # Or Runtime.SMALL, Runtime.MEDIUM, etc. region=Region.AWS_US_WEST_2 # Or other AWS regions ) as conn: curr = conn.cursor() sql = """ SELECT id, names['primary'], geometry, population FROM wherobots_open_data.overture_maps_foundation.divisions WHERE subtype = 'country' SORT BY population DESC LIMIT 10 """ curr.execute(sql) results = curr.fetchall() results.show() ``` **Using Cursor as a Context Manager:** ```python with connect(...) as conn: with conn.cursor() as curr: curr.execute(...) results = curr.fetchall() results.show() ``` **Note:** The `Cursor` also implements a `close()` method for compatibility with `contextmanager.closing()`. ``` -------------------------------- ### Set Up WherobotsDB Context with Sedona Source: https://docs.wherobots.com/tutorials/wherobotsai/wherobots-inference/byom_example Initializes the WherobotsDB context using Sedona Spark. This setup is necessary for subsequent data loading and inference operations. It configures Spark and integrates Sedona's spatial capabilities. ```python import warnings warnings.filterwarnings('ignore') from wherobots.inference.data.io import read_raster_table from sedona.spark import SedonaContext from pyspark.sql.functions import expr config = SedonaContext.builder().appName('segmentation-batch-inference')\ .getOrCreate() sedona = SedonaContext.create(config) ``` -------------------------------- ### GET /audit-logs/export Source: https://docs.wherobots.com/reference/wherobots-cloud/audit-logs-export Exports audit logs based on the provided start time, end time, and an optional search term. The times should be in ISO 8601 format. ```APIDOC ## GET /audit-logs/export ### Description Exports audit logs within a specified time range and with an optional search term. The times should be in ISO 8601 format. ### Method GET ### Endpoint `/audit-logs/export` ### Query Parameters - **startTime** (string) - Required - Only return events at or after this time, expressed in ISO format (e.g., `YYYY-MM-DDTHH:mm:ssZ`). - **endTime** (string) - Required - Only return events at or before this time, expressed in ISO format. - **searchTerm** (string) - Optional - A string to match against each field in the event. If a substring match succeeds on any field, then the event is included in the export. ### Request Example ```bash curl -X GET \ 'https://api.cloud.wherobots.com/audit-logs/export?startTime=2025-01-27T00:07:29Z&endTime=2025-01-27T00:07:29Z&searchTerm=example' \ -H 'X-API-KEY: YOUR-API-KEY' ``` ### Response #### Success Response (200) - **events** (array) - An array of audit log events matching the criteria. - **event** (object) - Represents a single audit log event. - **timestamp** (string) - The time the event occurred in ISO 8601 format. - **message** (string) - The description of the event. - **actor** (string) - The user or system that performed the action. - **details** (object) - Additional details about the event. #### Response Example ```json { "events": [ { "timestamp": "2025-01-27T00:07:29Z", "message": "User logged in", "actor": "user@example.com", "details": { "ip_address": "192.168.1.1" } } ] } ``` ### Explanation **ISO 8601 Date and Time Format** ISO format refers to the ISO 8601 standard, which defines a way to represent dates and times. This format ensures consistency and avoids ambiguity when exchanging date and time information. Basic ISO 8601 format: `YYYY-MM-DDTHH:mm:ss.sssZ` • **YYYY:** Year (e.g., 2025) • **MM:** Month (e.g., 02 for February) • **DD:** Day of the month (e.g., 20) • **T:** Separator indicating the start of the time component • **HH:** Hour (24-hour clock, e.g., 18 for 6 PM) • **mm:** Minute (e.g., 09) • **ss:** Second (e.g., 30) • **sss:** Optional fractional seconds (e.g., 123 for milliseconds) • **Z:** Indicates UTC (Coordinated Universal Time) **Example:** February 20, 2025 6:09PM PST in ISO 8601 format is `2025-02-20T18:09:00-08:00` **Timezone offset** Include the timezone offset, `-08:00`, because Pacific Standard Time is UTC-8. ``` -------------------------------- ### Create Jar File for Scala Notebook Source: https://docs.wherobots.com/develop/notebook-management/jupyter-notebook-management_h=python+file Create a JAR file from a Scala notebook using Maven. This involves navigating to the 'sedona-maven-example' directory in the terminal and running 'mvn clean package'. The JAR file is then located in the 'target' folder and can be downloaded. Dependencies can be added to the 'pom.xml' file. ```bash # Navigate to the sedona-maven-example directory cd sedona-maven-example # Run Maven clean and package mvn clean package # The JAR file will be in the target folder. # Example: sedonadb-example-0.0.1.jar ``` -------------------------------- ### Get Boundary of a Geometry - SQL Source: https://docs.wherobots.com/reference/wherobots-db/geometry-data/function Returns the closure of the combinatorial boundary of a given geometry. For example, the boundary of a polygon is its linestring perimeter. Input is a geometry object. ```SQL SELECT ST_Boundary(ST_GeomFromWKT('POLYGON((1 1,0 0, -1 1, 1 1))')) ``` -------------------------------- ### Historical Snapshot Example (SQL) Source: https://docs.wherobots.com/develop/spatial-catalog/spatial-catalog Demonstrates querying a specific historical data snapshot of the `places_place` table from Overture Maps, using the version tag '2025-05-21.0'. This allows for analysis of data as it existed on a particular date. ```SQL SELECT * FROM wherobots_open_data.overture_maps_foundation.places_place VERSION AS OF '2025-05-21.0' ``` -------------------------------- ### Get Coordinate Dimension of Geometry (XY) Source: https://docs.wherobots.com/reference/wherobots-db/geometry-data/function The ST_NDims function returns the number of coordinate dimensions for a given geometry. This example demonstrates retrieving the dimension for a standard XY geometry. ```sql SELECT ST_NDims(ST_GeomFromText('POINT(1 1)')) ``` -------------------------------- ### Set up Download and Upload Variables Source: https://docs.wherobots.com/tutorials/example-notebooks/PMTiles-railroad This Python code sets up the necessary variables for the `download_and_upload_to_s3` function. It defines the URL of the zip file to download and constructs the destination S3 URI using an environment variable for the user's S3 path. ```python import os zip_url = 'https://www2.census.gov/geo/tiger/TIGER2024/RAILS/tl_2024_us_rails.zip' base_s3_uri = f'{os.getenv("USER_S3_PATH")}PMTiles-example' s3_destination_uri = f'{base_s3_uri}/data' ``` -------------------------------- ### Get Coordinate Dimension of Geometry (with Z) Source: https://docs.wherobots.com/reference/wherobots-db/geometry-data/function The ST_NDims function returns the number of coordinate dimensions for a given geometry. This example demonstrates retrieving the dimension for a geometry with Z coordinates. ```sql SELECT ST_NDims(ST_GeomFromEWKT('POINT(1 1 2)')) ``` -------------------------------- ### Upload Data to S3 URL using AWS CLI Source: https://docs.wherobots.com/develop/storage-management/managed-storage This example shows how to upload data to a specified S3 URL using the AWS CLI's `s3 cp` command. Ensure your AWS CLI is configured with valid credentials before executing this command. ```bash aws s3 cp /path/to/your/local/data s3://your-wherobots-s3-url/ ``` -------------------------------- ### Initialize Wherobots Sedona Context Source: https://docs.wherobots.com/tutorials/example-notebooks/Part-2-Reading-Spatial-Files Initializes the Wherobots Sedona context for Apache Spark. This setup is necessary to leverage Sedona's spatial data processing capabilities within a Spark environment. It requires the Sedona library to be installed. ```python from sedona.spark import * from pyspark.sql import functions as f # Initialize the Wherobots Sedona context config = SedonaContext.builder().getOrCreate() sedona = SedonaContext.create(config) ``` -------------------------------- ### Create Sample Table in Databricks SQL Source: https://docs.wherobots.com/tutorials/example-notebooks/Unity-Catalog-Delta-Tables Creates a sample Delta table named 'forecast_daily_calendar_imperial_wbc_demo' in the specified Databricks catalog and schema, populated with data from the Accuweather sample dataset. Ensure 'YOUR-CATALOG' and 'YOUR-SCHEMA' are updated to your environment's specifics. ```sql CREATE OR REPLACE TABLE `YOUR-CATALOG`.`YOUR-SCHEMA`.`forecast_daily_calendar_imperial_wbc_demo` USING DELTA AS SELECT * FROM `samples`.`accuweather`.`forecast_daily_calendar_imperial` LIMIT 10000; ``` -------------------------------- ### Run Raster Classification with wherobots.inference Python API Source: https://docs.wherobots.com/tutorials/wherobotsai/wherobots-inference/classification This Python snippet demonstrates running raster classification using the `wherobots.inference` module, which registers SQL inference functions as Python functions. It uses `create_single_label_classification_udfs` to get the `rs_classify` function and applies it to the input DataFrame. ```python from wherobots.inference.engine.register import create_single_label_classification_udfs rs_classify, rs_max_confidence = create_single_label_classification_udfs(batch_size = 10, sedona=sedona) df_predictions = df_raster_input.withColumn("preds", rs_classify(model_id, 'outdb_raster')) df_predictions.show(1) ``` -------------------------------- ### Get All Pixel Upper-Left Points and Values - Scala Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-operators This Scala example utilizes Apache Sedona to load raster data and then applies RS_PixelAsPoints. It demonstrates how to explode the resulting list to extract the geometry, value, and coordinates (x, y) for each pixel, facilitating detailed pixel-level analysis. ```scala val df = sedona.read.format("raster").load("/some/path/*.tiff") df.selectExpr( "explode(RS_PixelAsPoints(rast, 1)) as exploded" ).selectExpr( "exploded.geom as geom", "exploded.value as value", "exploded.x as x", "exploded.y as y" ).show(3) ``` -------------------------------- ### Create Spatial Index with Options Source: https://docs.wherobots.com/reference/havasu-table/geometry-data/cluster-geometry-table Demonstrates how to use the OPTIONS clause with 'CREATE SPATIAL INDEX' to pass parameters to the underlying 'rewrite_data_files' procedure. This example sets the target file size to 10MB. ```sql CREATE SPATIAL INDEX FOR wherobots.db.test_table USING hilbert(geom, 10) OPTIONS map('target-file-size-bytes', '10485760') ``` -------------------------------- ### Import SedonaPyDeck for Geospatial Visualization Source: https://docs.wherobots.com/reference/wherobots-db/geometry-data/visualization/visualization_sedona-pydeck Demonstrates how to import the necessary components from the Sedona library to start using SedonaPyDeck for geospatial data visualization. This is the initial step before utilizing any of its mapping functionalities. ```python from sedona.spark import * ``` ```python from sedona.maps.SedonaPyDeck import SedonaPyDeck ``` -------------------------------- ### Get All Pixel Centroids and Values - Scala Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-operators This Scala example demonstrates how to use RS_PixelAsCentroids with Apache Sedona to load raster data and then explode the resulting list of pixel centroids, values, and coordinates for further analysis. It shows how to extract individual components like geometry, value, x, and y. ```scala val df = sedona.read.format("raster").load("/some/path/*.tiff") df.selectExpr( "explode(RS_PixelAsCentroids(rast, 1)) as exploded" ).selectExpr( "exploded.geom as geom", "exploded.value as value", "exploded.x as x", "exploded.y as y" ).show(3) ``` -------------------------------- ### RS_MapAlgebra Example (Two Rasters) Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-map-algebra An SQL example demonstrating the RS_MapAlgebra function with two raster inputs. This specific example performs a weighted average calculation on the first band of each input raster. ```sql RS_MapAlgebra(rast0, rast1, 'D', 'out = rast0[0] * 0.5 + rast1[0] * 0.5;', null) ``` -------------------------------- ### Zip Custom Python Modules for Import Source: https://docs.wherobots.com/develop/notebook-management/jupyter-notebook-management Demonstrates the command-line usage of the 'zip' utility to package Python module files into a .zip archive. This archive can then be uploaded to Wherobots Managed Storage or an S3 bucket for import. ```bash zip -r9 ../zipmoduletest.zip * ``` -------------------------------- ### RS_AsRaster SQL Example with Default NoDataValue Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-writer An SQL example of RS_AsRaster, illustrating its usage when the noDataValue parameter is omitted, allowing the function to use its default behavior. This example focuses on rasterizing a polygon with a specified pixel type. ```SQL SELECT RS_AsRaster( ST_GeomFromWKT('POLYGON((15 15, 18 20, 15 24, 24 25, 15 15))'), RS_MakeEmptyRaster(2, 255, 255, 3, -215, 2, -2, 0, 0, 4326), 'D' ) ``` -------------------------------- ### Client Initialization and Authentication Source: https://docs.wherobots.com/reference/wherobots-db/vector-data/stac This section covers how to initialize the STAC API client and apply different authentication methods. ```APIDOC ## POST /websites/wherobots/open ### Description Opens a connection to the specified STAC API URL. ### Method POST ### Endpoint /websites/wherobots/open ### Parameters #### Query Parameters - **url** (str) - Required - The URL of the STAC API to connect to. - **headers** (dict) - Optional - Optional dictionary of HTTP headers for authentication or custom headers. ### Request Example ```json { "url": "https://planetarycomputer.microsoft.com/api/stac/v1", "headers": { "Authorization": "Bearer token123" } } ``` ### Response #### Success Response (200) - **Client** (Client) - An instance of the `Client` class connected to the specified URL. #### Response Example ```json { "client_instance": "" } ``` ## POST /websites/wherobots/with_basic_auth ### Description Adds HTTP Basic Authentication to the client. This method encodes the username and password using Base64 and adds the appropriate Authorization header for HTTP Basic Authentication. ### Method POST ### Endpoint /websites/wherobots/with_basic_auth ### Parameters #### Query Parameters - **username** (str) - Required - The username for authentication. For API keys, this is typically the API key itself. - **password** (str) - Required - The password for authentication. For API keys, this is often left empty. ### Request Example ```json { "username": "your_api_key", "password": "" } ``` ### Response #### Success Response (200) - **Client** (Client) - Returns self for method chaining. #### Response Example ```json { "client_instance": "" } ``` ## POST /websites/wherobots/with_bearer_token ### Description Adds Bearer Token Authentication to the client. This method adds the appropriate Authorization header for Bearer Token authentication, commonly used with OAuth2 and API tokens. ### Method POST ### Endpoint /websites/wherobots/with_bearer_token ### Parameters #### Query Parameters - **token** (str) - Required - The bearer token for authentication. ### Request Example ```json { "token": "your_access_token_here" } ``` ### Response #### Success Response (200) - **Client** (Client) - Returns self for method chaining. #### Response Example ```json { "client_instance": "" } ``` ``` -------------------------------- ### ST_Isochrone Function Output Example (SQL) Source: https://docs.wherobots.com/reference/wherobots-db/geometry-data/function An example of the Multipolygon output generated by the ST_Isochrone function, representing the calculated isochrone area. ```sql MULTIPOLYGON (((-122.02094635 47.54456145, -122.020948 47.544483799999995, -122.0209437 47.544415900000004, -122.0209447 47.54436885, -122.02095019999999 47.54413635, -122.02110644999999 47.543862649999994, -122.0210717 47.54333215, -122.02054085 47.54287205, -122.02038295 47.54300415, -122.0202897 47.54300395, -122.0202336 47.54300375, -122.0199928 47.54315525, -122.01999190000001 47.54320165, -122.0198403 47.543302600000004, -122.01972169999999 47.54320115, -122.01963305000001 47.543096750000004, -122.01963395 47.54305035, -122.01963645000001 47.5429188, -122.01923500000001 47.5427546, -122.0189525 47.5428578, -122.01888005 47.5433023, -122.018879 47.5433487, -122.0188754 47.54357215, -122.01866415 47.5435717, -122.01852275 47.543848350000005, -122.0182725 47.54439405, -122.0183107 47.54462595, -122.01879455 47.54451245, -122.01885105 47.54451265, -122.01893104999999 47.544512850000004, -122.01917355 47.544513550000005, -122.01942650000001 47.544553449999995, -122.0198258 47.544629099999995, -122.01982415 47.54470675, -122.01999945 47.54509165, -122.02019945 47.54502375, -122.02094635 47.54456145))) ``` -------------------------------- ### SQL Example for RS_Interpolate Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-operators An example SQL query demonstrating the usage of the RS_Interpolate function with specific parameters for raster interpolation. ```sql SELECT RS_Interpolate(raster, 1, 2.0, 'Variable', 12, 1000) ``` -------------------------------- ### Create a Custom Python Module Source: https://docs.wherobots.com/develop/notebook-management/jupyter-notebook-management Defines a simple Python function 'hello' within a module file. This function takes an input string and returns a greeting. This serves as the basic building block for custom modules. ```python def hello(input): return 'hello ' + str(input); ``` -------------------------------- ### Prepare and Write Data to Databricks Delta Table Source: https://docs.wherobots.com/tutorials/example-notebooks/Unity-Catalog-Delta-Tables Prepares the final DataFrame for writing to Databricks by selecting relevant columns and creating a temporary view. It then uses a SQL command to create or replace a Delta table in Unity Catalog, specifying the output table FQN and location. This step requires dropping the geometry column as Databricks does not natively support it. ```python final_df = df_with_threats.select( col("city_name"), col("date"), col("temperature_avg"), col("wind_gust_max"), col("precipitation_lwe_total"), col("distance_to_tokyo_meters"), col("threat_description") # This is our new, actionable feature! ) print("\nFinal schema to be written to Unity Catalog:") final_df.printSchema() # Write the feature back to Unity Catalog final_df.createOrReplaceTempView("temp_final_df_view") # Now, execute the SQL command to create the table from the temporary view. sedona.sql(f""" CREATE OR REPLACE TABLE {OUTPUT_TABLE_FQN} USING delta LOCATION '{OUTPUT_TABLE_LOCATION}' AS SELECT * FROM temp_final_df_view """) ``` -------------------------------- ### Spatially Stratified Sampling Usage Example Source: https://docs.wherobots.com/reference/wherobots-ai/sampling/spatially-stratified-sampling-python Provides an example of how to use the spatially_stratified_sample function. It demonstrates importing the function and calling it with sample parameters. ```python from spatially_stratified_sampling import * # Example usage of spatially_stratified_sample result = spatially_stratified_sample(dataframe=example_value, fraction=example_value, partition_count=example_value) ``` -------------------------------- ### DBSCAN Scala Usage Example Source: https://docs.wherobots.com/reference/wherobots-ai/clustering/dbscan-scala Provides a practical example of how to use the DBSCAN function. It demonstrates importing the necessary class and calling the dbscan method with sample parameters. ```scala import org.apache.sedona.stats.clustering.DBSCAN // Example usage val result = DBSCAN.dbscan(dataframe, epsilon, minPts) ``` -------------------------------- ### Basic Authentication with STAC Client (Python) Source: https://docs.wherobots.com/reference/wherobots-db/vector-data/stac Demonstrates how to configure the STAC client to use Basic Authentication. This method is commonly used with API keys or username/password credentials. Examples include using an API key as a username with an empty password and using both username and password. ```python from sedona.spark.stac import Client # Example 1: Using an API key (common pattern) client = Client.open("https://api.example.com/stac/v1") client.with_basic_auth("your_api_key_here", "") # Search for items with authentication df = client.search(collection_id="example-collection", max_items=10) df.show() # Example 2: Using username and password client = Client.open("https://api.example.com/stac/v1") client.with_basic_auth("username", "password") df = client.search(collection_id="example-collection", max_items=10) df.show() # Example 3: Method chaining df = ( Client.open("https://api.example.com/stac/v1") .with_basic_auth("your_api_key", "") .search(collection_id="example-collection", max_items=10) ) df.show() ``` -------------------------------- ### Create Interactive Map with SedonaKepler Source: https://docs.wherobots.com/tutorials/example-notebooks/NOAA-SWDI This snippet demonstrates how to create an interactive map using SedonaKepler. It involves initializing a map with specific data, applying a configuration, and adding additional data layers. The function `SedonaKepler.create_map` is used for initial map creation, and `SedonaKepler.add_df` is used to add more data. ```python oklahoma_storm_20230427_map = SedonaKepler.create_map(oklahoma_storm_20230427_df.where(col("date") == "2023-04-27"), name="storm", config=map_config) SedonaKepler.add_df(oklahoma_storm_20230427_map, oklahoma_counties_df, name = "counties") oklahoma_storm_20230427_map ``` -------------------------------- ### Set up Apache Sedona Context with Anonymous S3 Access Source: https://docs.wherobots.com/tutorials/example-notebooks/NOAA-SWDI Initializes a SedonaContext in the Wherobots Cloud environment, configuring anonymous S3 access to connect to SWDI data. This setup is crucial for accessing external datasets stored in S3 buckets. ```python from sedona.spark import * try: sedona except NameError: config = SedonaContext.builder() \ .config("fs.s3a.bucket.noaa-swdi-pds.aws.credentials.provider","org.apache.hadoop.fs.s3a.AnonymousAWSCredentialsProvider") \ .config("spark.hadoop.fs.s3a.bucket.noaa-swdi-pds.aws.credentials.provider", "org.apache.hadoop.fs.s3a.AnonymousAWSCredentialsProvider") \ .getOrCreate() sedona = SedonaContext.create(config) ``` -------------------------------- ### Import and Use ST Functions in Scala Source: https://docs.wherobots.com/tutorials/example-notebooks/Getting-Started Imports spatial (ST) functions for use with Wherobots DataFrames in Scala. This example shows how to import ST_MakePoint and use it to add a new geometry column. ```scala import org.apache.spark.sql.sedona_sql.expressions.st_constructors.ST_MakePoint import org.apache.spark.sql.functions.lit buildings.withColumn("geom2", ST_MakePoint(lit(1.2), lit(3.4))) .select("geom") .show(5, false) ``` -------------------------------- ### RS_MapAlgebra Example (Multi-band Output) Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-map-algebra An SQL example showcasing the RS_MapAlgebra function for generating a multi-band raster. The script defines operations for two output bands, and `numBands` is set to 2. ```sql SELECT RS_MapAlgebra(rast, 'D', 'out[0] = rast[0] - rast[1]; out[1] = rast[0] + rast[1];', null, 2) FROM raster_table ``` -------------------------------- ### Install PyTorch for CPU Runtimes Source: https://docs.wherobots.com/tutorials/example-notebooks/RasterFlow-Bring-Your-Own-Model Installs PyTorch and Torchvision specifically for CPU runtimes using `uv pip`. This command is useful for users who need to run PyTorch operations on a CPU environment. ```bash !uv pip install torch==2.8 torchvision --extra-index-url https://download.pytorch.org/whl/cpu ``` -------------------------------- ### Generate and Display Raster Images with Sedona Source: https://docs.wherobots.com/develop/run-operator This snippet shows how to prepare raster data for image display and then render it using `SedonaUtils.display_image`. It selects specific bands, normalizes them, converts them to an image format, and finally displays a limited, randomly ordered subset of these images. ```python htmlDF = df_max_predictions.selectExpr("RS_Band(outdb_raster, Array(4, 3, 2)) as image_raster", "name", "max_confidence_label") .selectExpr("RS_NormalizeAll(image_raster, 1, 65535, True) as image_raster", "name", "max_confidence_label") .selectExpr("RS_AsImage(image_raster, 500) as image_raster", "name", "max_confidence_label") SedonaUtils.display_image(htmlDF.orderBy(rand()).limit(3)) ``` -------------------------------- ### Install Wherobots Airflow Provider using Pip Source: https://docs.wherobots.com/develop/airflow-provider Installs the Wherobots Apache Airflow provider package using pip. This command can be run directly in a terminal or added to your Apache Airflow application's dependencies. ```bash pip install airflow-providers-wherobots ``` -------------------------------- ### Quick Tile Generation Configuration (Scala/Java) Source: https://docs.wherobots.com/tutorials/example-notebooks/Map-Tile-Generation The Scala/Java API for WherobotsDB exposes the `getQuickConfig` method to obtain a `GenerationConfig`. This configuration can then be passed to `vtiles.generate` or `vtiles.generatePMTiles` for efficient tile generation, especially for large datasets. ```scala // Assuming vtiles object is available and configured val quickConfig = vtiles.getQuickConfig() // To generate PMTiles: vtiles.generatePMTiles(features_df, sample_tiles_path, quickConfig) // To generate regular tiles: vtiles.generate(features_df, sample_tiles_path, quickConfig) ``` -------------------------------- ### RS_AsRaster SQL Example with Specific Parameters Source: https://docs.wherobots.com/reference/wherobots-db/raster-data/raster-writer An SQL example demonstrating the RS_AsRaster function with explicit parameters for geometry, reference raster, pixel type, allTouched, value, and noDataValue. This showcases a practical use case for rasterizing a polygon. ```SQL SELECT RS_AsRaster( ST_GeomFromWKT('POLYGON((15 15, 18 20, 15 24, 24 25, 15 15))'), RS_MakeEmptyRaster(2, 255, 255, 3, -215, 2, -2, 0, 0, 4326), 'D', false, 255.0, 0d ) ```