This page exlains how to visualize geospatial log data from Axiom using Hex interactive maps.
Hex is a powerful collaborative data platform that allows you to create notebooks with Python/SQL code and interactive visualizations.
This page explains how to integrate Hex with Axiom to visualize geospatial data from your logs. You ingest location data into Axiom, query it using APL, and create interactive map visualizations in Hex.
Send your sample location data to Axiom using the API endpoint. For example, the following HTTP request sends sample robot location data with latitude, longitude, status, and satellite information.
Write the Python code in your Hex notebook that retrieves data from Axiom. For example, customize the code below:
python
import requestsimport pandas as pdfrom datetime import datetime, timedeltaimport os# Retrieve the API token from Hex secretsaxiom_token = os.environ.get("AXIOM_TOKEN")# Define Axiom API endpoint and headersbase_url = "https://AXIOM_DOMAIN/v1/query/_apl"headers = { 'Authorization': f'Bearer {axiom_token}', 'Content-Type': 'application/json', 'Accept': 'application/json', 'Accept-Encoding': 'gzip'}# Define the time range for your queryend_time = datetime.utcnow()start_time = end_time - timedelta(days=3) # Get data from the last 3 days# Construct the APL queryquery = { "apl": """DATASET_NAME| project ['data.latitude'], ['data.longitude'], ['data.num_satellites'], ['data.robot_id'], ['data.status']""", "startTime": start_time.strftime("%Y-%m-%dT%H:%M:%SZ"), "endTime": end_time.strftime("%Y-%m-%dT%H:%M:%SZ")}try: # Send the request to Axiom API response = requests.post( f"{base_url}?format=tabular", headers=headers, json=query, timeout=10 ) # Print request details for debugging print("Request Details:") print(f"URL: {base_url}?format=tabular") print(f"Query: {query['apl']}") print(f"Response Status: {response.status_code}") if response.status_code == 200: data = response.json() if 'tables' in data: table = data['tables'][0] if table.get('columns') and len(table['columns']) > 0: columns = [field['name'] for field in table['fields']] rows = table['columns'] # Create DataFrame with proper column orientation df = pd.DataFrame(list(zip(*rows)), columns=columns) # Ensure data types are appropriate for mapping df['data.latitude'] = pd.to_numeric(df['data.latitude']) df['data.longitude'] = pd.to_numeric(df['data.longitude']) df['data.num_satellites'] = pd.to_numeric(df['data.num_satellites']) # Display the first few rows to verify our data print("\nDataFrame Preview:") display(df.head()) # Store the DataFrame for visualization robot_locations = df else: print("\nNo data found in the specified time range.") else: print("\nNo tables found in response") print("Response structure:", data.keys())except Exception as e: print(f"\nError: {str(e)}")