turf.feature
What is turf.feature?
turf.feature wraps a raw GeoJSON Geometry object (or null) into a valid GeoJSON Feature, attaching optional properties, a bounding box, and an id. It is the lowest-level constructor in @turf/helpers — every other helper (point, lineString, polygon…) ultimately calls it.
turf.feature(geometry, properties?, options?) → FeatureOptions include:
bbox— bounding box array[minX, minY, maxX, maxY]id— an identifier string or number
When would you use turf.feature?
Use turf.feature when you already have a bare Geometry object — for example from a vector-tile decoder, a PostGIS ST_AsGeoJSON result's geometry field, or turf.union's geometry output — and you need to attach properties or an id before adding it to a FeatureCollection.
It is also useful for tests and fixtures where you want to assemble arbitrary geometry shapes without going through the geometry-specific helpers.
1const geometry = { type: 'Point', coordinates: [-122.42, 37.77] };
2const feature = turf.feature(geometry, { name: 'SF' }, { id: 'sf-001' });FAQs
How do I install Turf.js to use this function?
Install the helpers package: npm install @turf/helpers, then import { feature } from '@turf/helpers'. It is also available on the umbrella @turf/turf bundle.
Can I pass null as the geometry?
Yes. GeoJSON allows a Feature's geometry to be null — useful when you have attributes but no location yet. turf.feature(null, { name: 'Unknown' }) produces a valid Feature.
Does turf.feature deep-clone the geometry?
No, it references the same geometry object. If you later mutate the geometry, the Feature sees those changes. Use turf.clone when you need an independent copy.
Should I use turf.feature or turf.point/polygon/lineString?
Prefer the geometry-specific helpers (point, polygon, lineString, etc.) because they validate coordinate shape at construction time. Reach for turf.feature only when you already have a well-formed Geometry object or need the null geometry case.