Repository Public License
1// ORIX Convert — Packages/EngineGeo/Tests/EngineGeoTests/OracleExport.swift2// Description: Development aid, skipped unless ORIX_GEO_EXPORT names a folder: writes outputs of the engine there so3// they can be opened with an outside reader (GDAL) while developing. Not part of the verification.4// Author: Simon-Pierre Boucher — contact@spboucher.ai5import Foundation6import Testing7import ConvertCore8@testable import EngineGeo910@Suite struct OracleExport {11 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORIX_GEO_EXPORT"] != nil)) func export() async throws {12 let out = URL(fileURLWithPath: ProcessInfo.processInfo.environment["ORIX_GEO_EXPORT"] ?? "/tmp/none", isDirectory: true)13 try FileManager.default.createDirectory(at: out, withIntermediateDirectories: true)14 let temp = TempDir()15 func keep(_ r: Converted, _ name: String) throws {16 for (i, f) in r.output.files.enumerated() {17 let target = out.appendingPathComponent(r.output.files.count == 1 ? name : "\(i)-\(name)")18 try? FileManager.default.removeItem(at: target)19 try FileManager.default.copyItem(at: f, to: target)20 }21 }22 let cities = Cities.source(.geojson, in: temp)23 for format in [FormatID.kml, .gpx, .csv, .shapefile, .geopackage] {24 try keep(try await convert(cities, .geojson, to: format, in: temp), "cities." + (format == .shapefile ? "shpdir" : format.rawValue))25 }26 let trip = temp.write("trip.kml", Samples.kml)27 try keep(try await convert(trip, .kml, to: .geopackage, in: temp), "trip.gpkg")28 try keep(try await convert(trip, .kml, to: .shapefile, in: temp, options: ["geometry.explode-collections": .bool(true)]), "trip.shpdir")29 try keep(try await convert(trip, .kml, to: .geojson, in: temp), "trip.geojson")30 try keep(try await convert(temp.write("ride.gpx", Samples.gpx), .gpx, to: .geopackage, in: temp), "ride.gpkg")31 for code in [32618, 32188, 2959, 4269, 4617] {32 try keep(try await convert(cities, .geojson, to: .shapefile, in: temp, options: ["crs.target": .string("EPSG:\(code)")], name: "c\(code)"), "crs\(code).shpdir")33 try keep(try await convert(cities, .geojson, to: .geopackage, in: temp, options: ["crs.target": .string("EPSG:\(code)")], name: "c\(code)"), "crs\(code).gpkg")34 }35 let limits = temp.write("zm.csv", "id,real,wkt\n1,0.1,\"POLYGON ZM ((0 0 1 9, 0 4 2 9, 4 4 3 9, 4 0 4 9, 0 0 1 9), (1 1 0 0, 2 1 0 0, 2 2 0 0, 1 2 0 0, 1 1 0 0))\"\n2,-1234567.891,\"MULTIPOLYGON ZM (((10 10 1 1, 10 11 1 1, 11 11 1 1, 10 10 1 1)))\"\n3,1e-7,\n")36 try keep(try await convert(limits, .csv, to: .shapefile, in: temp, options: ["crs.source": .string("4326")]), "zm.shpdir")37 try keep(try await convert(limits, .csv, to: .geopackage, in: temp, options: ["crs.source": .string("4326")]), "zm.gpkg")38 try keep(try await convert(trip, .kml, to: .gpx, in: temp, options: ["geometry.explode-collections": .bool(true), "gpx.polygons-as-tracks": .bool(true)]), "trip.gpx")39 try keep(try await convert(temp.write("ride.gpx", Samples.gpx), .gpx, to: .kml, in: temp), "ride.kml")40 }41}42