Generalize the output to GeoJSON.
Don't store everything in memory before dumping it.