Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,82 @@ Generate a geojson.io URL to visualize GeoJSON data. This tool:
- "Generate a preview URL for this GeoJSON data"
- "Create a geojson.io link for my uploaded route.geojson file"

#### Validate GeoJSON tool

Validates GeoJSON objects for correctness, checking structure, coordinates, and geometry types. This offline validation tool performs comprehensive checks on GeoJSON data without requiring API access.

**Parameters:**

- `geojson` (string or object, required): GeoJSON object or JSON string to validate

**What it validates:**

- GeoJSON type validity (Feature, FeatureCollection, Point, LineString, Polygon, etc.)
- Required properties (type, coordinates, geometry, features)
- Coordinate array structure and position validity
- Longitude ranges [-180, 180] and latitude ranges [-90, 90]
- Polygon ring closure (first and last coordinates should match)
- Minimum position requirements (LineString needs 2+, Polygon rings need 4+ positions)

**Returns:**

Validation results including:

- `valid` (boolean): Overall validity
- `errors` (array): Critical errors that make the GeoJSON invalid
- `warnings` (array): Non-critical issues (e.g., unclosed polygon rings, out-of-range coordinates)
- `info` (array): Informational messages
- `statistics`: Object with type, feature count, geometry types, and bounding box

Each issue includes:

- `severity`: "error", "warning", or "info"
- `message`: Description of the issue
- `path`: JSON path to the problem (optional)
- `suggestion`: How to fix the issue (optional)

**Example:**

```json
{
"geojson": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {
"name": "Test Point"
}
}
}
```

**Returns:**

```json
{
"valid": true,
"errors": [],
"warnings": [],
"info": [],
"statistics": {
"type": "Feature",
"featureCount": 1,
"geometryTypes": ["Point"],
"bbox": [102.0, 0.5, 102.0, 0.5]
}
}
```

**Example prompts:**

- "Validate this GeoJSON file and tell me if there are any errors"
- "Check if my GeoJSON coordinates are valid"
- "Is this Feature Collection properly formatted?"

**Note:** This is an offline validation tool that doesn't require API access or token scopes.

#### Coordinate Conversion tool

Convert coordinates between different coordinate reference systems (CRS), specifically between WGS84 (EPSG:4326) and Web Mercator (EPSG:3857).
Expand Down
2 changes: 2 additions & 0 deletions src/tools/toolRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { StyleBuilderTool } from './style-builder-tool/StyleBuilderTool.js';
import { StyleComparisonTool } from './style-comparison-tool/StyleComparisonTool.js';
import { TilequeryTool } from './tilequery-tool/TilequeryTool.js';
import { UpdateStyleTool } from './update-style-tool/UpdateStyleTool.js';
import { ValidateGeojsonTool } from './validate-geojson-tool/ValidateGeojsonTool.js';
import { ValidateStyleTool } from './validate-style-tool/ValidateStyleTool.js';
import { httpRequest } from '../utils/httpPipeline.js';

Expand All @@ -44,6 +45,7 @@ export const ALL_TOOLS = [
new GetReferenceTool(),
new StyleComparisonTool(),
new TilequeryTool({ httpRequest }),
new ValidateGeojsonTool(),
new ValidateStyleTool()
] as const;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.

import { z } from 'zod';

export const ValidateGeojsonInputSchema = z.object({
geojson: z
.union([z.string(), z.record(z.unknown())])
.describe('GeoJSON object or JSON string to validate')
});

export type ValidateGeojsonInput = z.infer<typeof ValidateGeojsonInputSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Mapbox, Inc.
// Licensed under the MIT License.

import { z } from 'zod';

const GeojsonIssueSchema = z.object({
severity: z.enum(['error', 'warning', 'info']).describe('Issue severity'),
message: z.string().describe('Description of the issue'),
path: z.string().optional().describe('JSON path to the problem'),
suggestion: z.string().optional().describe('How to fix the issue')
});

export const ValidateGeojsonOutputSchema = z.object({
valid: z.boolean().describe('Whether the GeoJSON is valid'),
errors: z.array(GeojsonIssueSchema).describe('Critical errors'),
warnings: z.array(GeojsonIssueSchema).describe('Non-critical warnings'),
info: z.array(GeojsonIssueSchema).describe('Informational messages'),
statistics: z
.object({
type: z.string().describe('GeoJSON type'),
featureCount: z.number().optional().describe('Number of features'),
geometryTypes: z.array(z.string()).describe('Geometry types found'),
bbox: z
.array(z.number())
.optional()
.describe('Bounding box [minLon, minLat, maxLon, maxLat]')
})
.describe('GeoJSON statistics')
});

export type ValidateGeojsonOutput = z.infer<typeof ValidateGeojsonOutputSchema>;
export type GeojsonIssue = z.infer<typeof GeojsonIssueSchema>;
Loading
Loading