Spaces:
Running
Running
Update oda-converter.js
Browse files- oda-converter.js +18 -2
oda-converter.js
CHANGED
|
@@ -98,8 +98,24 @@ async function convertFile(options) {
|
|
| 98 |
const dxfFile = path.join(tempOutputDir, outputFile);
|
| 99 |
|
| 100 |
try {
|
| 101 |
-
const
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
const zipCommand = `cd "${shapeOutputDir}" && zip -r "${finalPath}" .`;
|
| 105 |
await execAsync(zipCommand, { timeout: 60000 });
|
|
|
|
| 98 |
const dxfFile = path.join(tempOutputDir, outputFile);
|
| 99 |
|
| 100 |
try {
|
| 101 |
+
const geomTypes = [
|
| 102 |
+
{ suffix: 'points', nlt: 'POINT' },
|
| 103 |
+
{ suffix: 'lines', nlt: 'LINESTRING' },
|
| 104 |
+
{ suffix: 'polygons', nlt: 'POLYGON' },
|
| 105 |
+
{ suffix: 'multipatch', nlt: 'MULTIPATCH' }
|
| 106 |
+
];
|
| 107 |
+
|
| 108 |
+
const srsFlag = options.targetCRS ? `-a_srs "${options.targetCRS}" ` : '';
|
| 109 |
+
|
| 110 |
+
for (const t of geomTypes) {
|
| 111 |
+
const shpFile = path.join(shapeOutputDir, `${baseName}_${t.suffix}.shp`);
|
| 112 |
+
const ogrCommand = `ogr2ogr -f "ESRI Shapefile" "${shpFile}" "${dxfFile}" -nlt ${t.nlt} ${srsFlag}-skipfailures`;
|
| 113 |
+
try {
|
| 114 |
+
await execAsync(ogrCommand, { timeout: 120000 });
|
| 115 |
+
} catch (e) {
|
| 116 |
+
// Ignore errors for individual types (e.g. if the DXF has no polygons)
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
|
| 120 |
const zipCommand = `cd "${shapeOutputDir}" && zip -r "${finalPath}" .`;
|
| 121 |
await execAsync(zipCommand, { timeout: 60000 });
|