This script generates points inside a given geojson feature / polygon using turf.
You can use geojson for visualization or creating your own geojson by hand.
This script generates points inside a given geojson feature / polygon using turf.
You can use geojson for visualization or creating your own geojson by hand.
| import { readFileSync } from 'fs' | |
| import { URL } from 'url' | |
| import bbox from '@turf/bbox' | |
| import pointGrid from '@turf/point-grid' | |
| const FEATURE_FILE_PATH = new URL('./4-my-polygon.geojson', import.meta.url).pathname | |
| const POINT_DISTANCE_IN_KM = 5; | |
| const feature = JSON.parse(readFileSync(FEATURE_FILE_PATH, 'utf-8')) | |
| const boundingBox = bbox(feature) | |
| const points = pointGrid(boundingBox, POINT_DISTANCE_IN_KM, { unit: 'kilometers', mask: feature }) | |
| console.log(JSON.stringify(points)) |
| { | |
| "name": "geopoints", | |
| "version": "1.0.0", | |
| "type": "module", | |
| "description": "calculate the geopoints inside the given polygon", | |
| "main": "2-script.js", | |
| "author": "Yengas", | |
| "license": "ISC", | |
| "dependencies": { | |
| "@turf/bbox": "^6.5.0", | |
| "@turf/point-grid": "^6.5.0" | |
| } | |
| } |