# Service Area Coverage Validator (`afkdigital/service-area-coverage-validator`) Actor

Validate customer coordinates against your GeoJSON service zones. Polygon/MultiPolygon, holes, overlap and explicit boundary policies. JSON/CSV results and area summaries; no geocoding or routing API.

- **URL**: https://apify.com/afkdigital/service-area-coverage-validator.md
- **Developed by:** [AFK Digital](https://apify.com/afkdigital) (community)
- **Categories:** Business, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 evaluated unique coordinates

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Service Area Coverage Validator

Match customer coordinates against your own service-area GeoJSON. Find covered locations, overlapping zones, boundaries and coverage gaps without a map account, paid geocoding or routing API.

### What this Actor does

- Validates Polygon and MultiPolygon topology, including interior holes.
- Matches all service areas using an indexed geometry engine.
- Reports overlap without silently choosing a zone.
- Produces a JSON/CSV Dataset, downloadable JSON and CSV, and a per-area summary.
- Reports invalid customer coordinates separately. Invalid service-area geometry fails the entire run before evaluation or charging.

Membership is a geometric result. It does **not** guarantee driving time, route access, delivery eligibility or deliverability.

### Quick start

Run the prefilled synthetic example. It contains inside, outside, boundary, overlap, hole, invalid and duplicate locations. An empty input object also runs this example. When providing your own data, provide both locations and serviceAreasGeoJson.

Locations JSON:

```json
{"locationsJson":[{"location_id":"customer-1","latitude":1,"longitude":1}],"serviceAreasGeoJson":{"type":"FeatureCollection","features":[{"type":"Feature","id":"zone-A","properties":{},"geometry":{"type":"Polygon","coordinates":[[[0,0],[10,0],[10,10],[0,10],[0,0]]]}}]},"boundaryPolicy":"include","areaPriority":[],"maxLocations":10000}
```

### Files and input fields

| Input | Format |
|---|---|
| locationsJson | Array of objects with latitude, longitude and optional location_id |
| locationsFile | Instead of locationsJson: {"key":"LOCATIONS.csv","storeId":"YOUR_STORE_ID"} or {"content":"latitude,longitude\n1,2"} |
| serviceAreasGeoJson | Inline Polygon, MultiPolygon, Feature or FeatureCollection; or {"key":"AREAS.geojson","storeId":"YOUR_STORE_ID"} |
| boundaryPolicy | include (default), exclude, report_only |
| areaPriority | Area IDs ordered highest first. All matched IDs must be ranked to resolve overlap |
| sourceStores | Select each referenced key-value-store ID; grants read-only access under limited permissions |
| maxLocations | Integer from 1 to 10000; exceeding the cap fails rather than truncates |

For store references, also set sourceStores to an array of the referenced store IDs, for example {"sourceStores":\["YOUR_STORE_ID"]}. The storage picker grants READ access only to these stores. Files must already be in an Apify key-value store accessible to the run token, or supplied as inline UTF-8 content. Omit storeId to use the run's default store. Arbitrary URLs, local paths, ZIP and compressed files are unsupported. The Actor does not need access to a map service. Only requested records are read.

CSV requires a header with latitude and longitude; location_id is optional. JSON files contain an array, not a FeatureCollection. Decimal strings in location rows are accepted; invalid rows receive invalid_coordinate, no coordinate echo and no charge. Missing IDs use the 1-based input row number. GeoJSON Features need a string/integer id or properties.area_id; standalone geometry gets area-1.

### Coordinates and geometry

Supports RFC 7946 WGS84 decimal degrees with GeoJSON positions **\[longitude, latitude]**. Location fields are explicitly named latitude and longitude. Bounds are latitude -90..90 and longitude -180..180. Numeric geometry positions only; optional finite altitude is accepted but ignored for 2D membership. Legacy crs members are rejected: transform source data to RFC 7946 first. No automatic CRS transformation or axis guessing. Swapped coordinates that both remain in range cannot be detected; check your source.

Polygon rings must be closed and contain at least four positions. Self-intersections, invalid/outside holes, zero-area geometry, overlapping MultiPolygon parts, null geometry and duplicate area IDs are rejected. Ring winding direction does not affect membership. No automatic repair, buffering or snapping is applied.

Edges spanning more than 180 degrees longitude are rejected; cut antimeridian-crossing regions into valid parts first. Membership uses straight segments in longitude/latitude coordinate space, as represented in GeoJSON. It does not calculate geodesic distances.

### Boundaries and overlaps

| Policy | Boundary behavior |
|---|---|
| include | Boundary is a match, including hole boundaries |
| exclude | Boundary is not a match; boundary_excluded when no interior match exists |
| report_only | Any boundary contact produces boundary_review and no assignment |

Boundary means exact topological contact at double precision, without a distance tolerance. A point strictly inside a hole is outside that polygon.

matched_area_ids contains all policy-eligible matches, sorted by ID. boundary_area_ids identifies every touched boundary. One match is assigned automatically. Multiple matches keep coverage_status=overlap. Without a complete explicit priority list, assigned_area_id stays null. With complete priority, the highest-ranked match is assigned and the overlap remains visible. Unknown or duplicate priority IDs fail validation.

### Output

Each location returns location_id, latitude, longitude, matched_area_ids, assigned_area_id, coverage_status, boundary_status, assignment_reason and evidence_reference, plus boundary_area_ids.

coverage_status: covered, outside, overlap, boundary_excluded, boundary_review, invalid_coordinate.
boundary_status: on_boundary, not_on_boundary, not_evaluated.
evidence_reference is locations/N, a zero-based row reference in the supplied array or parsed file. Area IDs identify the corresponding source Features. Invalid coordinates are null in outputs.

Dataset exports JSON and CSV through Apify. Key-value-store records:

- OUTPUT: JSON rows; OUTPUT.csv: spreadsheet-safe CSV.
- SUMMARY: validation/evaluation counts, delivered counts, boundary policy, complexity and disclaimer.
- AREA_SUMMARY and AREA_SUMMARY.csv: matched, assigned and boundary location counts by area.
- VALIDATION_ERROR on rejected input: safe error code with zero evaluated/charged coordinates.

Duplicate location rows remain in output and area row counts. SUMMARY.unique_evaluated_coordinates deduplicates numeric latitude/longitude pairs; 1, 1.0 and "1" normalize to the same value.

### Billing

Prepared for one custom pay-per-event unit: evaluated-coordinate. One event represents one successfully evaluated **unique coordinate pair per run**. Display pricing per 1,000 events. Outside and boundary classifications are successful evaluations. Repeated rows or multiple matching areas do not add events. Invalid location rows and failed service-area validation are never billed. No Actor-start or default-Dataset-item charge is intended.

Charging is batched; when a spending cap permits only part of the result, whole coordinate groups are delivered, including all duplicate rows belonging to those coordinates. Other valid rows are withheld. SUMMARY.withheld_location_count explains incomplete delivery. Area summary counts describe delivered rows. A fresh run evaluates and bills anew. Resurrected runs and any run with existing charge events are rejected to prevent billing replay. A restart can leave a partial failed run; start a new run only after reviewing its charges.

Price: **$1.00 per 1,000 successfully evaluated unique coordinates** ($0.001 per evaluated-coordinate event). Platform usage is included. No startup or per-Dataset-row fee.

### Limits and privacy

10 MiB per UTF-8 file; 20 MiB total resolved input; 10,000 location rows; 500 Features; 100,000 geometry positions; 2,000,000 candidate geometry checks; 10 MiB serialized result JSON (validated before charging); 120-second validation/analysis deadline; 150-second process watchdog; 180-second run timeout. Default memory 512 MB. These are enforced limits, not a guarantee every maximum-sized geometry finishes.

Customer coordinates are intentionally present in private inputs/results, but application logs contain no location values or geometry coordinates. The Actor neither sends them to external map providers nor retains them outside Apify run storage. Access and retention follow the customer's Apify settings. Use synthetic data for public examples.

### Development

Python 3.13, apify 3.4.1, Shapely 2.2.0. Run python -m pytest locally after installing pytest. Container entry point: python -m src.main.

References: [GeoJSON RFC 7946](https://datatracker.ietf.org/doc/html/rfc7946), [Apify pay-per-event](https://docs.apify.com/actors/monetize/pay-per-event).

# Actor input Schema

## `locationsJson` (type: `array`):

Array of objects with latitude, longitude and optional location_id. Choose this OR locationsFile.

## `locationsFile` (type: `object`):

UTF-8 CSV/JSON. {"key":"LOCATIONS.csv","storeId":"your-store-id"} or {"content":"latitude,longitude\n1,2"}. No arbitrary URLs.

## `serviceAreasGeoJson` (type: `object`):

RFC 7946 Polygon/MultiPolygon FeatureCollection. Each Feature needs id or properties.area_id. Inline GeoJSON or {"key":"AREAS.geojson","storeId":"your-store-id"}.

## `boundaryPolicy` (type: `string`):

Include boundaries, exclude them, or require manual review on any boundary contact.

## `areaPriority` (type: `array`):

Area IDs, highest priority first. Every matched ID must be ranked to resolve overlap.

## `maxLocations` (type: `integer`):

Hard validation cap. Input above this limit fails; it is never silently truncated.

## `sourceStores` (type: `array`):

Select every store referenced by locationsFile.storeId or serviceAreasGeoJson.storeId. At most two stores. No write permission is requested.

## Actor input object example

```json
{
  "locationsJson": [
    {
      "location_id": "inside",
      "latitude": 1,
      "longitude": 1
    },
    {
      "location_id": "outside",
      "latitude": 20,
      "longitude": 20
    },
    {
      "location_id": "boundary",
      "latitude": 0,
      "longitude": 5
    },
    {
      "location_id": "overlap",
      "latitude": 8,
      "longitude": 8
    },
    {
      "location_id": "hole",
      "latitude": 4,
      "longitude": 4
    },
    {
      "location_id": "invalid",
      "latitude": 95,
      "longitude": 1
    },
    {
      "location_id": "duplicate",
      "latitude": 1,
      "longitude": 1
    }
  ],
  "serviceAreasGeoJson": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "id": "central",
        "properties": {},
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                0,
                0
              ],
              [
                10,
                0
              ],
              [
                10,
                10
              ],
              [
                0,
                10
              ],
              [
                0,
                0
              ]
            ],
            [
              [
                3,
                3
              ],
              [
                3,
                5
              ],
              [
                5,
                5
              ],
              [
                5,
                3
              ],
              [
                3,
                3
              ]
            ]
          ]
        }
      },
      {
        "type": "Feature",
        "id": "east",
        "properties": {},
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                7,
                7
              ],
              [
                12,
                7
              ],
              [
                12,
                12
              ],
              [
                7,
                12
              ],
              [
                7,
                7
              ]
            ]
          ]
        }
      }
    ]
  },
  "boundaryPolicy": "include",
  "areaPriority": [],
  "maxLocations": 10000
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `csv` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `areas` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "locationsJson": [
        {
            "location_id": "inside",
            "latitude": 1,
            "longitude": 1
        },
        {
            "location_id": "outside",
            "latitude": 20,
            "longitude": 20
        },
        {
            "location_id": "boundary",
            "latitude": 0,
            "longitude": 5
        },
        {
            "location_id": "overlap",
            "latitude": 8,
            "longitude": 8
        },
        {
            "location_id": "hole",
            "latitude": 4,
            "longitude": 4
        },
        {
            "location_id": "invalid",
            "latitude": 95,
            "longitude": 1
        },
        {
            "location_id": "duplicate",
            "latitude": 1,
            "longitude": 1
        }
    ],
    "serviceAreasGeoJson": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "id": "central",
                "properties": {},
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                0,
                                0
                            ],
                            [
                                10,
                                0
                            ],
                            [
                                10,
                                10
                            ],
                            [
                                0,
                                10
                            ],
                            [
                                0,
                                0
                            ]
                        ],
                        [
                            [
                                3,
                                3
                            ],
                            [
                                3,
                                5
                            ],
                            [
                                5,
                                5
                            ],
                            [
                                5,
                                3
                            ],
                            [
                                3,
                                3
                            ]
                        ]
                    ]
                }
            },
            {
                "type": "Feature",
                "id": "east",
                "properties": {},
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                7,
                                7
                            ],
                            [
                                12,
                                7
                            ],
                            [
                                12,
                                12
                            ],
                            [
                                7,
                                12
                            ],
                            [
                                7,
                                7
                            ]
                        ]
                    ]
                }
            }
        ]
    },
    "areaPriority": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("afkdigital/service-area-coverage-validator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "locationsJson": [
        {
            "location_id": "inside",
            "latitude": 1,
            "longitude": 1,
        },
        {
            "location_id": "outside",
            "latitude": 20,
            "longitude": 20,
        },
        {
            "location_id": "boundary",
            "latitude": 0,
            "longitude": 5,
        },
        {
            "location_id": "overlap",
            "latitude": 8,
            "longitude": 8,
        },
        {
            "location_id": "hole",
            "latitude": 4,
            "longitude": 4,
        },
        {
            "location_id": "invalid",
            "latitude": 95,
            "longitude": 1,
        },
        {
            "location_id": "duplicate",
            "latitude": 1,
            "longitude": 1,
        },
    ],
    "serviceAreasGeoJson": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "id": "central",
                "properties": {},
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                0,
                                0,
                            ],
                            [
                                10,
                                0,
                            ],
                            [
                                10,
                                10,
                            ],
                            [
                                0,
                                10,
                            ],
                            [
                                0,
                                0,
                            ],
                        ],
                        [
                            [
                                3,
                                3,
                            ],
                            [
                                3,
                                5,
                            ],
                            [
                                5,
                                5,
                            ],
                            [
                                5,
                                3,
                            ],
                            [
                                3,
                                3,
                            ],
                        ],
                    ],
                },
            },
            {
                "type": "Feature",
                "id": "east",
                "properties": {},
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [[
                            [
                                7,
                                7,
                            ],
                            [
                                12,
                                7,
                            ],
                            [
                                12,
                                12,
                            ],
                            [
                                7,
                                12,
                            ],
                            [
                                7,
                                7,
                            ],
                        ]],
                },
            },
        ],
    },
    "areaPriority": [],
}

# Run the Actor and wait for it to finish
run = client.actor("afkdigital/service-area-coverage-validator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "locationsJson": [
    {
      "location_id": "inside",
      "latitude": 1,
      "longitude": 1
    },
    {
      "location_id": "outside",
      "latitude": 20,
      "longitude": 20
    },
    {
      "location_id": "boundary",
      "latitude": 0,
      "longitude": 5
    },
    {
      "location_id": "overlap",
      "latitude": 8,
      "longitude": 8
    },
    {
      "location_id": "hole",
      "latitude": 4,
      "longitude": 4
    },
    {
      "location_id": "invalid",
      "latitude": 95,
      "longitude": 1
    },
    {
      "location_id": "duplicate",
      "latitude": 1,
      "longitude": 1
    }
  ],
  "serviceAreasGeoJson": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "id": "central",
        "properties": {},
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                0,
                0
              ],
              [
                10,
                0
              ],
              [
                10,
                10
              ],
              [
                0,
                10
              ],
              [
                0,
                0
              ]
            ],
            [
              [
                3,
                3
              ],
              [
                3,
                5
              ],
              [
                5,
                5
              ],
              [
                5,
                3
              ],
              [
                3,
                3
              ]
            ]
          ]
        }
      },
      {
        "type": "Feature",
        "id": "east",
        "properties": {},
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                7,
                7
              ],
              [
                12,
                7
              ],
              [
                12,
                12
              ],
              [
                7,
                12
              ],
              [
                7,
                7
              ]
            ]
          ]
        }
      }
    ]
  },
  "areaPriority": []
}' |
apify call afkdigital/service-area-coverage-validator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,afkdigital/service-area-coverage-validator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/QDVbS2sDncx3niy1g/builds/7OmTqwdt01iZnUC3Y/openapi.json
