### Demonstrate Length Threshold Parameter Source: https://context7.com/mapbox/concaveman/llms.txt Illustrates how the lengthThreshold parameter affects hull refinement by filtering segments below a specified length. This is useful for noise reduction and controlling output detail. Higher thresholds result in simpler outlines. ```javascript import concaveman from 'concaveman'; // Dense point cloud with potential noise const densePoints = []; for (let i = 0; i < 500; i++) { // Main cluster densePoints.push([ 50 + Math.random() * 40 - 20, 50 + Math.random() * 40 - 20 ]); } // Add some outlier noise for (let i = 0; i < 50; i++) { densePoints.push([ Math.random() * 100, Math.random() * 100 ]); } // Without length threshold - may produce overly detailed hull const noThreshold = concaveman(densePoints, 2, 0); console.log('No threshold:', noThreshold.length, 'vertices'); // Small threshold - filters tiny segments const smallThreshold = concaveman(densePoints, 2, 1); console.log('Threshold 1:', smallThreshold.length, 'vertices'); // Medium threshold - smoother result const mediumThreshold = concaveman(densePoints, 2, 5); console.log('Threshold 5:', mediumThreshold.length, 'vertices'); // Large threshold - much simpler outline const largeThreshold = concaveman(densePoints, 2, 10); console.log('Threshold 10:', largeThreshold.length, 'vertices'); // Combine with concavity for optimal results const optimized = concaveman(densePoints, 2.5, 3); console.log('Optimized (c=2.5, t=3):', optimized.length, 'vertices'); ``` -------------------------------- ### Compute Concave Hulls with Concaveman Source: https://context7.com/mapbox/concaveman/llms.txt Demonstrates basic usage, parameter tuning for concavity and length thresholds, and handling of large datasets. ```javascript import concaveman from 'concaveman'; // Basic usage with default parameters (concavity=2, lengthThreshold=0) const points = [ [10, 20], [30, 12.5], [25, 35], [45, 18], [15, 40], [50, 30], [35, 45], [20, 25], [40, 10], [55, 25], [28, 50], [60, 40] ]; const polygon = concaveman(points); // Returns: Array of [x, y] coordinates forming the concave hull // polygon forms a closed loop (first point equals last point) console.log('Hull vertices:', polygon.length); console.log('Hull boundary:', polygon); // Detailed concave hull (concavity = 1) // Lower values create more detailed, tighter-fitting shapes const detailedHull = concaveman(points, 1); console.log('Detailed hull vertices:', detailedHull.length); // Convex hull (concavity = Infinity) // Using Infinity produces a standard convex hull const convexHull = concaveman(points, Infinity); console.log('Convex hull vertices:', convexHull.length); // Tuned parameters for geographic data // Higher concavity (3) for smoother outline // lengthThreshold (0.01) prevents over-refinement of small segments const geoPoints = [ [-122.06851, 37.394206], [-122.06849, 37.393812], [-122.06848, 37.393392], [-122.06849, 37.393059], [-122.06851, 37.392685], [-122.06855, 37.392237], [-122.06868, 37.390828], [-122.06882, 37.389118], [-122.06885, 37.388747], [-122.06885, 37.388346] ]; const geoHull = concaveman(geoPoints, 3, 0.01); console.log('Geographic hull:', geoHull); // Working with large point sets (1000+ points) // The algorithm maintains O(n log n) performance const largeDataset = Array.from({ length: 1000 }, () => [ Math.random() * 100, Math.random() * 100 ]); const largeHull = concaveman(largeDataset, 2, 0.5); console.log('Large dataset hull vertices:', largeHull.length); ``` -------------------------------- ### Demonstrate Concavity Parameter Effects Source: https://context7.com/mapbox/concaveman/llms.txt Compares the resulting hull shapes with different concavity values. Lower concavity results in more vertices and a tighter fit, while higher concavity produces a smoother shape. Infinity yields a convex hull. ```javascript import concaveman from 'concaveman'; // Sample point cloud with irregular distribution const points = [ [0, 0], [10, 0], [20, 0], [30, 0], [40, 0], [5, 5], [15, 5], [25, 5], [35, 5], [0, 10], [20, 10], [40, 10], [10, 15], [30, 15], [5, 20], [15, 20], [25, 20], [35, 20], [0, 25], [10, 25], [20, 25], [30, 25], [40, 25] ]; // Compare different concavity values const concavityLevels = [0.5, 1, 2, 3, 5, Infinity]; concavityLevels.forEach(concavity => { const hull = concaveman(points, concavity); console.log(`Concavity ${concavity}: ${hull.length} vertices`); // Lower concavity = more vertices, tighter fit // Higher concavity = fewer vertices, smoother shape // Infinity = convex hull (minimum vertices) }); // Output example: // Concavity 0.5: 18 vertices (very detailed) // Concavity 1: 14 vertices (detailed) // Concavity 2: 10 vertices (balanced) - default // Concavity 3: 8 vertices (smooth) // Concavity 5: 6 vertices (smoother) // Concavity Infinity: 4 vertices (convex hull) ``` -------------------------------- ### Generate Concave Hull from Points Source: https://github.com/mapbox/concaveman/blob/master/README.md Import the concaveman library and pass an array of [x, y] points to generate a concave hull polygon. Adjust concavity and lengthThreshold for shape complexity. ```javascript import concaveman from 'concaveman'; const points = [[10, 20], [30, 12.5], ...]; const polygon = concaveman(points); ``` -------------------------------- ### Convert Concaveman Output to GeoJSON Source: https://context7.com/mapbox/concaveman/llms.txt Shows how to format the output of the concaveman function into a GeoJSON Feature for use in mapping applications. ```javascript import concaveman from 'concaveman'; // Geographic coordinates (longitude, latitude pairs) const gpsPoints = [ [-122.06851, 37.394206], [-122.06849, 37.393812], [-122.06848, 37.393392], [-122.06849, 37.393059], [-122.06882, 37.389118], [-122.06885, 37.388747], [-122.07331, 37.380096], [-122.07349, 37.380178], [-122.07364, 37.379969], [-122.07373, 37.379837] ]; // Generate concave hull const hullPoints = concaveman(gpsPoints, 2, 0.001); // Convert to GeoJSON Polygon const geojsonPolygon = { type: 'Feature', properties: { name: 'Concave Hull Boundary', vertices: hullPoints.length }, geometry: { type: 'Polygon', coordinates: [hullPoints] // GeoJSON requires array of rings } }; console.log(JSON.stringify(geojsonPolygon, null, 2)); // Output: Valid GeoJSON Feature with Polygon geometry // For use with Leaflet, Mapbox GL JS, or similar libraries // L.geoJSON(geojsonPolygon).addTo(map); ``` -------------------------------- ### Concaveman Main Function Source: https://context7.com/mapbox/concaveman/llms.txt The main export function that computes a concave hull from an array of 2D points. It takes an array of `[x, y]` coordinate pairs and returns a polygon as an array of points forming the concave hull boundary. The `concavity` parameter controls how tightly the hull wraps around the points (1 = detailed, Infinity = convex hull), while `lengthThreshold` sets the minimum segment length for further refinement. ```APIDOC ## concaveman(points, concavity, lengthThreshold) ### Description Computes a concave hull from an array of 2D points. ### Method Function Call ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **points** (Array>) - Required - An array of `[x, y]` coordinate pairs. - **concavity** (number) - Optional - Controls how tightly the hull wraps around the points. Defaults to 2. (1 = detailed, Infinity = convex hull). - **lengthThreshold** (number) - Optional - Sets the minimum segment length for further refinement. Defaults to 0. ### Request Example ```javascript import concaveman from 'concaveman'; const points = [ [10, 20], [30, 12.5], [25, 35], [45, 18], [15, 40], [50, 30], [35, 45], [20, 25], [40, 10], [55, 25], [28, 50], [60, 40] ]; const polygon = concaveman(points); console.log(polygon); // With custom parameters const detailedHull = concaveman(points, 1); const convexHull = concaveman(points, Infinity); const geoHull = concaveman(points, 3, 0.01); ``` ### Response #### Success Response (Array>) - **Array of [x, y] coordinates** - An array of points forming the concave hull boundary. The first and last point are the same to form a closed loop. ``` -------------------------------- ### concaveman(points[, concavity, lengthThreshold]) Source: https://github.com/mapbox/concaveman/blob/master/README.md The primary function to generate a concave hull from an array of 2D points. ```APIDOC ## concaveman(points[, concavity, lengthThreshold]) ### Description Generates a 2D concave hull for a given set of points. ### Parameters #### Arguments - **points** (Array<[number, number]>) - Required - An array of [x, y] coordinates. - **concavity** (number) - Optional - A relative measure of concavity. 1 results in a detailed shape, Infinity results in a convex hull. Defaults to 2. - **lengthThreshold** (number) - Optional - Segments under this length are not considered for further detalization. Higher values result in simpler shapes. Defaults to 0. ### Request Example ```javascript const points = [[10, 20], [30, 12.5], [50, 50]]; const polygon = concaveman(points, 2, 0); ``` ### Response - **polygon** (Array<[number, number]>) - An array of points representing the concave hull outline. ``` -------------------------------- ### Using Concaveman with GeoJSON Source: https://context7.com/mapbox/concaveman/llms.txt Convert concaveman output to GeoJSON format for use with mapping libraries and geographic information systems. ```APIDOC ## Using Concaveman with GeoJSON ### Description Demonstrates how to convert the output of the `concaveman` function into a GeoJSON Polygon Feature. ### Method Function Call and Object Construction ### Parameters None directly for this snippet, assumes `concaveman` function is available. ### Request Example ```javascript import concaveman from 'concaveman'; // Geographic coordinates (longitude, latitude pairs) const gpsPoints = [ [-122.06851, 37.394206], [-122.06849, 37.393812], [-122.06848, 37.393392], [-122.06849, 37.393059], [-122.06882, 37.389118], [-122.06885, 37.388747], [-122.07331, 37.380096], [-122.07349, 37.380178], [-122.07364, 37.379969], [-122.07373, 37.379837] ]; // Generate concave hull const hullPoints = concaveman(gpsPoints, 2, 0.001); // Convert to GeoJSON const geojsonPolygon = { type: 'Feature', properties: { name: 'Concave Hull Boundary', vertices: hullPoints.length }, geometry: { type: 'Polygon', coordinates: [hullPoints] // GeoJSON requires array of rings } }; console.log(JSON.stringify(geojsonPolygon, null, 2)); ``` ### Response #### Success Response (string) - **JSON String** - A stringified GeoJSON Feature object representing the concave hull as a Polygon. #### Response Example ```json { "type": "Feature", "properties": { "name": "Concave Hull Boundary", "vertices": 10 }, "geometry": { "type": "Polygon", "coordinates": [ [ [-122.06851, 37.394206], [-122.06849, 37.393812], [-122.06848, 37.393392], [-122.06849, 37.393059], [-122.06882, 37.389118], [-122.06885, 37.388747], [-122.07331, 37.380096], [-122.07349, 37.380178], [-122.07364, 37.379969], [-122.07373, 37.379837], [-122.06851, 37.394206] // Closing point ] ] } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.