Search code examples
node.jsgiskmlreadline

How do I parse a large KML file into JSON


I am designing a map application that shows traffic density in areas of Hong Kong. I have to use road segment data from a .kml file I extracted from a .kmz file provided by the Transport Department website.

The data is publicly available and can be found here: https://data.gov.hk/en-data/dataset/hk-td-tis_15-road-network-v2/resource/aa45b44d-a08b-4638-92d0-1295d815982a

The file is very large, around 500MB.

I am using Node.js to process the data. I just want to extract the street name, the street code and the coordinates of the segment to possibly store in json files named corresponding to each street code.

For example, the json file for the street with the street code 10000 would be 10000.js. Or possibly in the future store that data in a database.

The main problem is that the file is large and I can't store it in memory to parse it with a kml parser.


Solution

  • If you mean GeoJSON then, I can suggest 2 options:

    If you want to convert it to TopoJSON, you can convert the KML to GeoJSON then use topojson to convert the GeoJSON to TopoJSON.