1.1.17 • Published 11 months ago

kml-utils v1.1.17

Weekly downloads
6
License
MIT
Repository
github
Last release
11 months ago

Introduction

This lib is modified from @mapbox/togeojson and @mapbox/tokml, enhanced with folder capability

Install

npm i --save kml-utils

Parse Usage

const { parse, parseFolder, parseGeoJSON, parseDescription } = require('kml-utils')
const fs = require('fs-extra')
const DOMParser = require('xmldom').DOMParser
const kmlDom = new DOMParser().parseFromString(fs.readFileSync('demo.kml', 'utf8'))

/**
 * returns folder tree and feature collection
 * return { folder: [], geoJSON: [] }
 */
parse(kmlDom)

parse(kmlDom, {
    // parse style
    style: true,
    // parse elements to folder tree
    folderElements: ['Document', 'Folder'],
    propertyCallbacks:{
        description(){
            // return a value to replace the property's value
            // return '123'

            // return an object to replace the property
            // return { newName:123 }

            // parse html-type-description
            return parseDescription(data)
        }
    },
    coordCallback(point, attributes){
        // point transform
        return point.map(a => a+1000 )
    }
})

/**
 * returns feature collection
 * This function is ported from @mapbox/togeojson, `tj.kml(kmlDom)`
 * 
 * feature.properties.folder = <folderKey>
 */
parseGeoJSON(kmlDom)

/**
 * returns folder tree
 * folder: [{ key: <folderKey>, parent: <parentFolderKey>, name: <folderName>, children: [] }]
 */
parseFolder(kmlDom)

You can convert to arcgis graphic json object:

const { parseGeoJSON, arcgisConvertor } = require('kml-utils')
const _ = require('lodash')
const graphicJSONs = _.flatten(parseGeoJSON(kmlDom).features.map(arcgisConvertor.graphicJSON))

Kmlify Usage

const { parse, kmlify } = require('kml-utils')
const { geoJSON, folders } = parse(kmlDom)
const kmlString = kmlify(geoJSON, folders)
1.1.12

12 months ago

1.1.11

12 months ago

1.1.16

11 months ago

1.1.15

11 months ago

1.1.14

11 months ago

1.1.13

11 months ago

1.1.17

11 months ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.10

1 year ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago