Tutorial

Analysis interface (GeospatialAnalyzer)

GeospatialAnalyzer - Mapapps Integration Demo

This tutorial demonstrates the new GeospatialAnalyzer API. Select an example to see the request structure.

Read more in the API documentation: geospatialAnalyze API reference or using the Swagger Documentation via Test-Env or Prod-Env


Build a custom analysis request:

  1. Select the analysis operation
  2. Select one or more topics (hold Ctrl for multiple)
  3. Configure output format and parameters
  4. Add geometries using the sketching tool or manually
  5. Send the request

API Endpoint

Input Geometries

GeospatialAnalyzer API Documentation

The GeospatialAnalyzer API provides modern spatial analysis operations for geospatial data. It supports both EsriJSON and GeoJSON input/output formats.

Base URL: https://geoservicestest.sachsen.de/api

API Operations

Operation Description Endpoint
intersect Returns all features that are intersected by the input geometries POST /v1/intersect
within Returns all features in which the input geometries are completely contained POST /v1/within
nearestNeighbour Returns features within a specified distance, ordered by proximity POST /v1/nearestNeighbour
valuesAtPoint Returns attribute values at specific point locations (e.g., elevation) POST /v1/valuesAtPoint

Request Parameters

Parameter Type Description Required
operation string The analysis operation: "intersect", "within", "nearestNeighbour", or "valuesAtPoint" Yes
parameters.topics string[] Array of topic identifiers to analyze. Available topics can be fetched from /v1/{operation}/topics Yes
parameters.inputGeometries array Array of geometries (EsriJSON or GeoJSON format). Supports Point, Polyline, Polygon Yes
parameters.outputFormat string "esrijson" or "geojson" Yes
parameters.returnGeometry boolean Whether to include geometries in the response Yes
parameters.outSRS number Spatial reference WKID for output geometries (e.g., 25833, 4326) Yes
parameters.count number Maximum number of results (nearestNeighbour only). Default: 10 No
parameters.maxDistanceToNeighbour number Maximum search distance in meters (nearestNeighbour only). Default: 1000 No

Topics Endpoints

Each operation has a corresponding topics endpoint to retrieve available analysis topics:

  • GET /v1/intersect/topics
  • GET /v1/within/topics
  • GET /v1/nearestNeighbour/topics
  • GET /v1/valuesAtPoint/topics
  • GET /v1/topics - Returns all available topics

Coordinate Systems

Important: When using EsriJSON, geometries can be in any coordinate system. Specify the WKID in the spatialReference property.

When using GeoJSON, coordinates must be in EPSG:4326 (WGS84) format [longitude, latitude].

Common coordinate systems for Saxony:

  • EPSG:25833 - ETRS89 / UTM zone 33N (recommended for Saxony)
  • EPSG:4326 - WGS 84 (required for GeoJSON)
  • EPSG:31467 - DHDN / 3-degree Gauss-Kruger zone 3

Implementation Examples

Using IntegrationAPI (Recommended)


// Define the analysis request
const analysisRequest = {
    operation: "intersect",
    parameters: {
        topics: ["kreis", "gemeinde"],
        inputGeometries: [
            {
                geometry: {
                    x: 413093.3077572279,
                    y: 5659110.3644715585,
                    spatialReference: { wkid: 25833 }
                },
                attributes: {}
            }
        ],
        outputFormat: "esrijson",
        returnGeometry: true,
        outSRS: 25833
    }
};

// Send request via IntegrationAPI
function postEvent(functionName, detail) {
    const integrationElement = document.getElementById('mapIntegrationElement').contentWindow;
    if (integrationElement) {
        integrationElement.postMessage({
            functionName: functionName,
            detail: detail
        }, "*");
    }
}

postEvent("geospatialAnalyze", analysisRequest);

// Listen for response
window.addEventListener("message", (evt) => {
    if (evt.data.functionName === "geospatialAnalyze") {
        const results = evt.data.detail.data;
        console.log("Analysis results:", results);

        // Process results...
        results.forEach(feature => {
            console.log("Feature attributes:", feature.attributes);
        });
    }
}, false);
    

Direct REST API Call


// Direct fetch to GeospatialAnalyzer API
const url = "https://geoservicestest.sachsen.de/api/v1/intersect";

const requestBody = {
    topics: ["kreis", "gemeinde"],
    inputGeometries: [
        {
            geometry: {
                x: 413093.3077572279,
                y: 5659110.3644715585,
                spatialReference: { wkid: 25833 }
            },
            attributes: {}
        }
    ],
    outputFormat: "esrijson",
    returnGeometry: true,
    outSRS: 25833
};

fetch(url, {
    method: "POST",
    headers: {
        "Accept": "application/json",
        "Content-Type": "application/json"
    },
    body: JSON.stringify(requestBody)
})
.then(response => {
    if (!response.ok) {
        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    }
    return response.json();
})
.then(results => {
    console.log("Analysis results:", results);

    // Process results...
    results.forEach(feature => {
        console.log("Feature:", feature.attributes);
    });
})
.catch(error => {
    console.error("Analysis error:", error);
});
    

Using GeoJSON Input


// Example with GeoJSON input (coordinates must be in EPSG:4326)
const analysisRequest = {
    operation: "intersect",
    parameters: {
        topics: ["kreis"],
        inputGeometries: [
            {
                type: "Feature",
                geometry: {
                    type: "Point",
                    coordinates: [13.7373, 51.0504] // [longitude, latitude]
                },
                properties: {
                    name: "Dresden"
                }
            }
        ],
        outputFormat: "geojson",
        returnGeometry: true,
        outSRS: 4326
    }
};

postEvent("geospatialAnalyze", analysisRequest);
    

Error Handling

The API returns structured error responses:


window.addEventListener("message", (evt) => {
    if (evt.data.functionName === "geospatialAnalyze") {
        if (evt.data.error) {
            console.error("Analysis failed:", evt.data.error);
            // Handle error...
        } else {
            const results = evt.data.detail.data;
            // Process results...
        }
    }
}, false);
    

Comparison: Legacy API vs GeospatialAnalyzer

Feature Legacy API GeospatialAnalyzer
Input Format EsriJSON only EsriJSON and GeoJSON
Output Format EsriJSON only EsriJSON and GeoJSON
Topics Discovery Manual/Documentation Dynamic via /topics endpoints
Request Structure URL parameters + POST body Unified JSON structure
Error Handling HTTP status codes Structured error responses
IntegrationAPI "analyze" function "geospatialAnalyze" function

Benefits of GeospatialAnalyzer API:

  • Modern RESTful design with clear operation endpoints
  • Support for both EsriJSON and GeoJSON formats
  • Dynamic topic discovery for flexible analysis
  • Better error handling and validation
  • Consistent request/response structure
  • Built-in coordinate transformation support