carthorse
Version:
A geospatial trail data processing pipeline for building 3D trail databases with elevation data
292 lines • 11 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadConfig = loadConfig;
exports.loadRouteDiscoveryConfig = loadRouteDiscoveryConfig;
exports.getConstants = getConstants;
exports.getSupportedRegions = getSupportedRegions;
exports.getSupportedEnvironments = getSupportedEnvironments;
exports.getDatabaseSchemas = getDatabaseSchemas;
exports.getValidationThresholds = getValidationThresholds;
exports.getTolerances = getTolerances;
exports.getExportSettings = getExportSettings;
exports.getPgRoutingTolerances = getPgRoutingTolerances;
exports.getNetworkConfig = getNetworkConfig;
exports.getNetworkRefinementConfig = getNetworkRefinementConfig;
exports.getNetworkCacheConfig = getNetworkCacheConfig;
exports.getDatabaseConfig = getDatabaseConfig;
exports.getDatabaseConnectionString = getDatabaseConnectionString;
exports.getDatabasePoolConfig = getDatabasePoolConfig;
exports.getExportConfig = getExportConfig;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const yaml = __importStar(require("js-yaml"));
let configCache = null;
let routeConfigCache = null;
/**
* Load the Carthorse configuration from YAML file
*/
function loadConfig() {
if (configCache) {
return configCache;
}
const configPath = path.join(process.cwd(), 'configs/carthorse.config.yaml');
if (!fs.existsSync(configPath)) {
throw new Error(`Configuration file not found: ${configPath}`);
}
try {
const configContent = fs.readFileSync(configPath, 'utf8');
const config = yaml.load(configContent);
configCache = config;
return config;
}
catch (error) {
throw new Error(`Failed to load configuration: ${error}`);
}
}
/**
* Load the route discovery configuration from YAML file
*/
function loadRouteDiscoveryConfig() {
if (routeConfigCache) {
return routeConfigCache;
}
const configPath = path.join(process.cwd(), 'configs/route-discovery.config.yaml');
if (!fs.existsSync(configPath)) {
throw new Error(`Route discovery configuration file not found: ${configPath}`);
}
try {
const configContent = fs.readFileSync(configPath, 'utf8');
const config = yaml.load(configContent);
routeConfigCache = config;
return config;
}
catch (error) {
throw new Error(`Failed to load route discovery configuration: ${error}`);
}
}
/**
* Get constants from the configuration
*/
function getConstants() {
const config = loadConfig();
return config.constants;
}
/**
* Get specific constant values
*/
function getSupportedRegions() {
return getConstants().supportedRegions;
}
function getSupportedEnvironments() {
return getConstants().supportedEnvironments;
}
function getDatabaseSchemas() {
return getConstants().databaseSchemas;
}
function getValidationThresholds() {
return getConstants().validationThresholds;
}
function getTolerances() {
const routeConfig = loadRouteDiscoveryConfig();
const tolerances = routeConfig.routing;
// Allow environment variable overrides
return {
intersectionTolerance: process.env.INTERSECTION_TOLERANCE ?
parseFloat(process.env.INTERSECTION_TOLERANCE) : tolerances.intersectionTolerance,
edgeTolerance: process.env.EDGE_TOLERANCE ?
parseFloat(process.env.EDGE_TOLERANCE) : tolerances.edgeTolerance,
minTrailLengthMeters: process.env.MIN_TRAIL_LENGTH_METERS ?
parseFloat(process.env.MIN_TRAIL_LENGTH_METERS) : tolerances.minTrailLengthMeters
};
}
function getExportSettings() {
const config = loadConfig();
return config.constants.exportSettings;
}
/**
* Get pgRouting tolerance settings from config
*/
function getPgRoutingTolerances() {
const config = loadConfig();
return config.postgis?.processing?.pgrouting || {
intersectionDetectionTolerance: 0.0005, // ~50 meters
edgeToVertexTolerance: 0.0005, // ~50 meters
graphAnalysisTolerance: 0.0005, // ~50 meters
trueLoopTolerance: 10.0, // 10 meters
minTrailLengthMeters: 0.1, // 0.1 meters
maxTrailLengthMeters: 100000 // 100km
};
}
/**
* Load consolidated network configuration (optional file)
*/
function getNetworkConfig() {
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const cfgPath = path.join(process.cwd(), 'configs', 'network.config.yaml');
if (fs.existsSync(cfgPath)) {
try {
const raw = fs.readFileSync(cfgPath, 'utf8');
const y = yaml.load(raw) || {};
return y.network || {};
}
catch (e) {
return {};
}
}
return {};
}
/**
* Refinement settings (connector tolerance, dead-end pruning) with env overrides
*/
function getNetworkRefinementConfig() {
const net = getNetworkConfig();
const refinement = net.refinement || {};
return {
connectorToleranceMeters: process.env.CONNECTOR_TOLERANCE_METERS ? parseFloat(process.env.CONNECTOR_TOLERANCE_METERS) : (refinement.connectorToleranceMeters ?? 3),
minDeadEndMeters: process.env.MIN_DEAD_END_METERS ? parseFloat(process.env.MIN_DEAD_END_METERS) : (refinement.minDeadEndMeters ?? 5),
applyCachedConnectors: typeof refinement.applyCachedConnectors === 'boolean' ? refinement.applyCachedConnectors : false,
persistDiscoveredConnectors: typeof refinement.persistDiscoveredConnectors === 'boolean' ? refinement.persistDiscoveredConnectors : false,
enableEndpointEdgeSnapping: typeof refinement.enableEndpointEdgeSnapping === 'boolean' ? refinement.enableEndpointEdgeSnapping : false,
enableAtGradeCrossings: typeof refinement.enableAtGradeCrossings === 'boolean' ? refinement.enableAtGradeCrossings : false,
atGradeToleranceMeters: typeof refinement.atGradeToleranceMeters === 'number' ? refinement.atGradeToleranceMeters : 1,
densifySegmentMeters: typeof (getNetworkConfig().routing?.densifySegmentMeters) === 'number' ? (getNetworkConfig().routing?.densifySegmentMeters) : (getNetworkConfig().network?.routing?.densifySegmentMeters) || 0
};
}
/**
* Network cache configuration (completed network cache)
*/
function getNetworkCacheConfig() {
const net = getNetworkConfig();
const cache = net.cache || {};
return {
enableCompletedNetworkCache: typeof cache.enableCompletedNetworkCache === 'boolean' ? cache.enableCompletedNetworkCache : false,
cacheSchema: cache.cacheSchema || 'carthorse_cache',
maxEntries: typeof cache.maxEntries === 'number' ? cache.maxEntries : 20
};
}
/**
* Get database configuration with environment variable overrides
*/
function getDatabaseConfig(environment = 'development') {
const config = loadConfig();
const dbConfig = config.database;
// Get environment-specific config with proper typing
const envConfig = dbConfig.environments[environment] || dbConfig.connection;
// Environment variables take precedence
return {
host: process.env.PGHOST || envConfig.host,
port: parseInt(process.env.PGPORT || envConfig.port.toString()),
user: process.env.PGUSER || envConfig.user,
password: process.env.PGPASSWORD || envConfig.password,
database: process.env.PGDATABASE || envConfig.database,
pool: dbConfig.pool,
timeouts: dbConfig.timeouts
};
}
/**
* Get database connection string
*/
function getDatabaseConnectionString(environment = 'development') {
const dbConfig = getDatabaseConfig(environment);
if (dbConfig.password) {
return `postgresql://${dbConfig.user}:${dbConfig.password}@${dbConfig.host}:${dbConfig.port}/${dbConfig.database}`;
}
else {
return `postgresql://${dbConfig.user}@${dbConfig.host}:${dbConfig.port}/${dbConfig.database}`;
}
}
/**
* Get pool configuration for database connections
*/
function getDatabasePoolConfig(environment = 'development') {
const dbConfig = getDatabaseConfig(environment);
return {
host: dbConfig.host,
port: dbConfig.port,
user: dbConfig.user,
password: dbConfig.password,
database: dbConfig.database,
max: dbConfig.pool.max,
idleTimeoutMillis: dbConfig.pool.idleTimeoutMillis,
connectionTimeoutMillis: dbConfig.pool.connectionTimeoutMillis
};
}
/**
* Get export configuration from carthorse config
*/
function getExportConfig() {
const config = loadConfig();
return config.export || {
geojson: {
layers: {
trails: true,
edges: true,
endpoints: true,
routes: true
},
styling: {
trails: {
color: "#228B22",
stroke: "#228B22",
strokeWidth: 2,
fillOpacity: 0.6
},
edges: {
color: "#4169E1",
stroke: "#4169E1",
strokeWidth: 1,
fillOpacity: 0.4
},
endpoints: {
color: "#FF0000",
stroke: "#FF0000",
strokeWidth: 2,
fillOpacity: 0.8,
radius: 5
},
routes: {
color: "#FF8C00",
stroke: "#FF8C00",
strokeWidth: 3,
fillOpacity: 0.8
}
}
}
};
}
//# sourceMappingURL=config-loader.js.map