-
Notifications
You must be signed in to change notification settings - Fork 30
Add 9 offline geospatial tools using Turf.js #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements the first offline geospatial tool using Turf.js for calculating
great-circle distance between two geographic coordinates.
Features:
- Calculate distance between any two points on Earth
- Support for multiple units: km, miles, meters, feet, nautical miles
- Haversine formula for accurate great-circle distance
- Completely offline - no API calls required
- Fast local calculations with OpenTelemetry tracing
Technical details:
- Uses Turf.js distance function
- Follows project patterns (BaseTool, proper annotations)
- Coordinate format: { longitude, latitude } objects (not tuples)
- Read-only, idempotent, closed-world tool
- Full test coverage with 8 test cases
Dependencies added:
- @turf/turf: Comprehensive geospatial analysis library
All 433 tests passing ✅
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement fundamental geospatial calculation tools that work completely offline without requiring Mapbox API calls: - point_in_polygon_tool: Test if a point is inside a polygon - bearing_tool: Calculate compass direction between coordinates - midpoint_tool: Find geographic midpoint between two points - centroid_tool: Calculate center point of polygons - area_tool: Calculate polygon area in various units (meters, km, acres, etc) - bbox_tool: Calculate bounding box of any geometry - buffer_tool: Create buffer zones around geometries - simplify_tool: Reduce vertex count while preserving shape All tools: - Extend BaseTool (not MapboxApiBasedTool) for offline operation - Use Turf.js (@turf/turf) for geospatial calculations - Include OpenTelemetry tracing - Have proper annotations (openWorldHint: false) - Use coordinate objects for inputs to avoid JSON schema issues Updated test annotations to include all offline tools in exclusion list. All 457 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add new "Offline Geospatial Tools" section documenting all 9 tools - Update intro to mention offline calculations capability - Add example prompts for offline geospatial calculations - Document features and use cases for each offline tool 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
ctufts
reviewed
Jan 12, 2026
Add test suites for 8 offline tools that were missing coverage: 1. **Point in Polygon Tool** (10 tests) - Simple polygons (inside/outside) - Complex polygons - Polygons with holes - Edge cases (boundaries, extreme coordinates) - Large polygons with many vertices 2. **Bearing Tool** (15 tests) - Cardinal directions (N, S, E, W) - Ordinal directions (NE, SE, SW, NW) - Real world locations - Antimeridian crossing - Near poles - Reverse bearing validation 3. **Midpoint Tool** (15 tests) - Points on equator and meridians - Real world city pairs - Same point edge case - Antimeridian crossing - Hemispheres (N/S, E/W) - Precision and rounding 4. **Centroid Tool** (15 tests) - Simple shapes (square, rectangle, triangle) - Polygons with holes - Multipolygons - Complex irregular shapes - Extreme coordinates - Precision validation 5. **Area Tool** (16 tests) - All supported units (meters, km, feet, miles, acres, hectares) - Simple and complex polygons - Polygons with holes - Multipolygons - Different latitudes (equator, poles) - Precision rounding 6. **Bounding Box Tool** (18 tests) - All geometry types (point, line, polygon, multipolygon) - Complex shapes - Extreme coordinates - Precision validation - Format verification 7. **Buffer Tool** (19 tests) - All geometry types (point, line, polygon) - All supported units - Various distances (small to large) - Real world locations - Different hemispheres - Validation of output format 8. **Simplify Tool** (16 tests) - Linestrings and polygons - Various tolerance levels - High quality mode - Straight lines and curves - Polygons with holes - Reduction percentage calculation All 556 tests now passing (124 new tests added). Addresses PR feedback: #96 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
ctufts
reviewed
Jan 12, 2026
ctufts
approved these changes
Jan 12, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add 9 Offline Geospatial Tools Using Turf.js
This PR adds 9 new offline geospatial calculation tools that work completely without internet connectivity or API calls. All tools use Turf.js for accurate geographic computations.
Tools Added
Key Benefits
Test Coverage
Added comprehensive test suites for all 9 tools:
Total: 556 tests passing (432 existing + 124 new)
Demo Scenarios & Screenshots
1. Distance Tool
Calculate straight-line distance between two locations.
Test Scenario:
Expected Result: ~5.2 miles
Screenshot:

2. Point in Polygon Tool
Check if a location is inside a defined area.
Test Scenario:
Expected Result:
inside: trueScreenshot:

3. Bearing Tool
Get compass direction from one location to another.
Test Scenario:
Expected Result: ~270° (roughly west/west-southwest)
Screenshot:

4. Buffer Tool
Create a zone/radius around a location.
Test Scenario:
Expected Result: Polygon representing a ~1-mile radius circle (33 vertices forming the outer ring)
Screenshot:

5. Area Tool
Calculate the size of a geographic area.
Test Scenario:
Expected Result: ~10,000 square meters (approximately)
Screenshot:
![Uploading Screenshot 2026-01-12 at 16.53.53.png…]()
6. Midpoint Tool
Find the geographic center point between two locations.
Test Scenario:
Expected Result: Coordinates near Portland, Oregon area (~42.6°N, -122.3°W)
Screenshot:

7. Centroid Tool
Find the geometric center of a polygon.
Test Scenario:
Expected Result: Coordinates near (40.7842, -73.9697)
Screenshot:

8. Bounding Box Tool
Get rectangular boundaries that contain a shape.
Test Scenario:
Expected Result:
[minLng, minLat, maxLng, maxLat]array containing all pointsScreenshot:

9. Simplify Tool
Reduce complexity of a boundary while maintaining shape.
Test Scenario:
Expected Result: Simplified from 6 vertices down to 2 vertices (start and end points), representing a 67% reduction. The zigzag becomes a straight line since the ±0.1 deviations are within the 0.15 tolerance.
Screenshot:

Files Changed
New Files
src/tools/distance-tool/- Distance calculation toolsrc/tools/point-in-polygon-tool/- Point containment testingsrc/tools/bearing-tool/- Compass direction calculationsrc/tools/midpoint-tool/- Geographic midpoint findersrc/tools/centroid-tool/- Polygon center calculatorsrc/tools/area-tool/- Area measurement toolsrc/tools/bounding-box-tool/- Boundary box calculatorsrc/tools/buffer-tool/- Zone/radius creatorsrc/tools/simplify-tool/- Geometry simplifiertest/tools/*/- 124 new test files for all toolsModified Files
README.md- Documentation for all 9 toolspackage.json- Added@turf/turfdependencysrc/tools/toolRegistry.ts- Registered all new toolsDependencies
Added
@turf/turf@^7.1.0for geospatial calculations.How to Test
Build the server:
Start with MCP Inspector:
Try any of the test scenarios above in Claude Desktop or the Inspector
Documentation
All tools are documented in the README with: