geo-toolkits
Version:
A comprehensive TypeScript library for geospatial operations including geofencing, polygon containment, area calculations, and coordinate processing. Supports GeoJSON, KML, and KMZ file formats with both local file and remote URL loading capabilities.
164 lines (163 loc) • 4.95 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeoToolKit = void 0;
const geofencing_1 = require("../algorithms/geofencing");
const geometry_1 = require("../algorithms/geometry");
const data_loader_1 = require("../loaders/data-loader");
class GeoToolKit {
constructor() {
this.dataLoader = new data_loader_1.DataLoader();
this.geometryCalculator = new geometry_1.GeometryCalculator();
this.geofencingAnalyzer = new geofencing_1.GeofencingAnalyzer();
}
/**
* Load spatial data from URL (converts all formats to GeoJSON internally)
*/
loadFromUrl(url) {
return __awaiter(this, void 0, void 0, function* () {
yield this.dataLoader.loadFromUrl(url);
this.distributeDataToClasses();
});
}
/**
* Load spatial data from file (converts all formats to GeoJSON internally)
*/
loadFromFile(filePath) {
return __awaiter(this, void 0, void 0, function* () {
yield this.dataLoader.loadFromFile(filePath);
this.distributeDataToClasses();
});
}
/**
* Check if spatial data is loaded
*/
isLoaded() {
return this.dataLoader.isLoaded();
}
/**
* Get dataset information
*/
getDatasetInfo() {
return this.dataLoader.getMetadata();
}
/**
* Get all spatial features
*/
getFeatures() {
return this.dataLoader.getFeatures();
}
/**
* Get only polygon features
*/
getPolygons() {
return this.dataLoader.getPolygons();
}
/**
* Get only multipolygon features
*/
getMultiPolygons() {
return this.dataLoader.getMultiPolygons();
}
/**
* Validate if features contain coordinates
*/
contains(lat, lng) {
return this.geofencingAnalyzer.contains(lat, lng);
}
/**
* Find closest feature to coordinates
*/
findClosestFeature(lat, lng) {
return this.geofencingAnalyzer.findClosestFeature(lat, lng);
}
/**
* Find all features that contain coordinates
*/
getAllContainingFeatures(lat, lng) {
return this.geofencingAnalyzer.getAllContainingFeatures(lat, lng);
}
/**
* Get overall bounding box of all features
*/
getBoundingBox() {
return this.geometryCalculator.getBoundingBox();
}
/**
* Calculate total area of all features in square meters
*/
getArea() {
return this.geometryCalculator.getArea();
}
/**
* Calculate detailed area breakdown for each feature
*/
getAreaDetails() {
return this.geometryCalculator.getAreaDetails();
}
/**
* Get total area in specific units
*/
getAreaInUnit(unit) {
return this.geometryCalculator.getAreaInUnit(unit);
}
/**
* Get detailed area breakdown in specific units
*/
getAreaDetailsInUnit(unit) {
return this.geometryCalculator.getAreaDetailsInUnit(unit);
}
/**
* Calculate area of individual feature by index
*/
getFeatureArea(featureIndex) {
return this.geometryCalculator.getFeatureArea(featureIndex);
}
/**
* Validate coordinates
*/
validateCoordinates(lat, lng) {
return this.geofencingAnalyzer.isValidCoordinate(lat, lng);
}
/**
* Get comprehensive area statistics
*/
getAreaStatistics() {
return this.geometryCalculator.getAreaStatistics();
}
/**
* Calculate geometric center (midpoint) of all features
*/
getMidpoint() {
return this.geometryCalculator.getMidpoint();
}
/**
* Check if coordinate is within overall bounding box
*/
isWithinBoundingBox(lat, lng) {
return this.geometryCalculator.isWithinBoundingBox(lat, lng);
}
/**
* Reset all data
*/
reset() {
this.dataLoader.reset();
}
/**
* Distribute loaded data to all specialized classes
*/
distributeDataToClasses() {
const features = this.dataLoader.getFeatures();
this.geometryCalculator.setFeatures(features);
this.geofencingAnalyzer.setFeatures(features);
}
}
exports.GeoToolKit = GeoToolKit;