findProvinceFromCoordinate runs point-in-polygon containment against Iran’s province boundaries (from a GeoJSON dataset) and returns the matching province’s Persian and English names.
Function
Behaviour
- Iterate the polygons (one per province, from
irGeoJSON.ts). - Run a horizontal ray-cast point-in-polygon test.
- Return
{ fa, en }for the first match. - If no polygon contains the point, throw
PersianToolsError("findProvinceFromCoordinate", "no province found").
Return type is the object{ fa, en }— not a string. Wrap intry/catchfor graceful fallback when the coordinate is outside Iran.
Pitfalls
- Throws on out-of-Iran coordinates.
- Coordinate order is
{ longitude, latitude }(object form), not the GeoJSON[lng, lat]array. - The dataset is approximate. Near administrative borders, expect occasional misclassification.
- Don’t expect a bare string — index into
.faor.en.
Composition
Source
src/modules/findProvinceFromCoordinate/index.ts, irGeoJSON.ts · Tests: test/findProvinceFromCoordinate.spec.ts