polygon-city / citygml-to-obj

Takes a CityGML file and creates an OBJ file for each building
MIT License
18 stars 4 forks source link

Unable to call multiple times #9

Closed MFGiscad closed 9 years ago

MFGiscad commented 9 years ago

I am currently having an issue with calling the function multiple times. For a single .gml file, it works just fine but when i try to call it repeatedly, it doesn't really work out. I tried to work around the asynchronity with a callback function and calling itself after it finished.

     /*
     *Function that uses node script 'citygml-to-obj' to convert a CityGML file to a Wavefront OBJ file
     *@param{Array} fileList Array containing full paths of the input .gml files
     *@param{String} outputDirectory full path of the folder that will contain the output OBJ files
     *@param{Number} fileIndex index of the current .gml file
     *@param{Function} callbackFn callback function to be called after the last call
     */
    convertCityGML: function(fileList, outputDirectory, fileIndex, callbackFn) {
        if (fileIndex === undefined) {
            fileIndex = 0; 
        }
        if (fileIndex < fileList.length) {
            var options = {
                citygmlPath: fileList[fileIndex],    //Path to CityGML input file 
                objPath: outputDirectory,    //Path to OBJ output inputDirectory 
                proj4def: "+proj=tmerc +lat_0=0 +lon_0=12 +k=1 +x_0=4500000 +y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs",
                overwrite: true    // Overwrite existing OBJ files if they already exist 
             };

            citygml2obj(options, function(err) {
                if (err) {
                    console.error(err);
                }
                    GMLtoOBJ._convertCityGML(fileList, outputDirectory, fileIndex+1, callbackFn);
            });
       } else {
            if (callbackFn !== undefined) {
                callbackFn(outputDirectory);
            }
       }

It didn't work as it quits suddenly after calling the Function the second time before finishing the last 4 .obj files from the first call. I looked a bit into the module and noticed that the callback function is called before all files are written. I also noticed that in my case there are 4 workers left, that aren't ready and are not killed before callback() is called.

I hope you understand my issue (and code)!

greetings,

Marius

MFGiscad commented 9 years ago

I worked it out for myself using a sort of shell node script which executes the console commands in a loop.

robhawkes commented 9 years ago

Glad to see you've found a solution. I'll have a look at what can be done to improve the module when called multiple times.