swiss-projection
Version:
Convert from LV03(EPSG:21781) and LV95(EPSG:2056) to WGS84(EPSG:4326)
32 lines (27 loc) • 780 B
text/typescript
import convertGeometry from './convertGeometry'
import {
FeatureCollection,
GeoJSON,
Feature,
} from './geojson.d'
const isFeature = (o: GeoJSON): o is Feature =>
o.type && o.type === 'Feature'
const isCollection = (o: GeoJSON): o is FeatureCollection =>
o.type && o.type === 'FeatureCollection'
const convertFeature = (converter: Function) =>
(feature: Feature): Feature => ({
...feature,
geometry: convertGeometry(converter)(feature.geometry)
})
export default (converter: Function) => (geojson: GeoJSON): GeoJSON => {
if (isFeature(geojson)) {
return convertFeature(converter)(geojson)
}
if (isCollection(geojson)) {
return {
...geojson,
features: geojson.features.map(convertFeature(converter))
}
}
return geojson
}