gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
184 lines • 6.48 kB
TypeScript
import type { KVStore } from '../../dataStore/index.js';
import type { OSMHeader } from './headerBlock.js';
import type { OSMMetadata } from './primitive.js';
import type { FeatureIterator, Reader, ReaderInputs } from '../index.js';
import type { IntermediateNodeMember, IntermediateRelation } from './relation.js';
import type { IntermediateWay, WayNodes } from './way.js';
import type { Properties, VectorFeature, VectorPoint, VectorPointGeometry } from '../../geometry/index.js';
export type * from './blob.js';
export type * from './headerBlock.js';
export type * from './info.js';
export type * from './node.js';
export type * from './primitive.js';
export type * from './relation.js';
export type * from './way.js';
/**
* Filter types
* Options are:
* - All
* - Node
* - Way
* - Relation
*/
export type FilterType = 'All' | 'Node' | 'Way' | 'Relation';
/** Filter map. Used internally by TagFilter */
export type FilterMap = Map<string, string | undefined>;
/**
* # Tag Filter
*
* ## Description
* Builds a filter for the tags when parsing data.
* Can parse tags from nodes, ways and relations.
* Also allows the ability to add tags that apply to all object types.
* Can filter by key, but also both key and value.
*
* ## Usage
*
* Note that if you don't add a filter for a specific type, then that type will pass all
* key-value pairs through.
* ```ts
* const filter = new TagFilter();
* // add a node filter
* filter.addFilter('Node', 'foo', 'bar');
* // add a way filter
* filter.addFilter('Way', 'foo', 'bar');
* // add a relation filter
* filter.addFilter('Relation', 'foo', 'bar');
* // add a filter that effects all types
* filter.addFilter('All', 'foo', 'bar');
* ```
*/
export declare class TagFilter {
#private;
/**
* Add a filter
* @param filterType - The filter type to apply the filter
* @param key - The key to apply the filter
* @param value - The value to apply the filter (optional)
*/
addFilter(filterType: FilterType, key: string, value?: string): void;
/**
* Check if a filter has been found
* @param filterType - The filter type
* @param key - The key
* @param value - The value (optional)
* @returns - True if the filter has been found
*/
matchFound(filterType: FilterType, key: string, value?: string): boolean;
}
/** OSM Reader options */
export interface OsmReaderOptions {
/** if true, remove nodes that have no tags [Default = true] */
removeEmptyNodes?: boolean;
/** If provided, filters of the */
tagFilter?: TagFilter;
/** If set to true, nodes will be skipped. [Default = false] */
skipNodes?: boolean;
/** If set to true, ways will be skipped. [Default = false] */
skipWays?: boolean;
/** If set to true, relations will be skipped. [Default = false] */
skipRelations?: boolean;
/**
* If set to true, ways will be converted to areas if they are closed.
* NOTE: They are upgraded anyways if the tag "area" is set to "yes".
* [Default = false]
*/
upgradeWaysToAreas?: boolean;
/** If set to true, add a bbox property to each feature */
addBBox?: boolean;
}
/** All OSM properties are key-value pairs where both are strings */
export interface OSMProperties extends Properties {
[key: string]: string;
}
/**
* # OSM Reader
*
* ## Description
* Parses OSM PBF files
* Implements the {@link FeatureIterator} interface
*
* ## Usage
* ```ts
* import { OSMReader } from 'gis-tools-ts';
* import { FileReader } from 'gis-tools-ts/file';
* // or use the MMapReader if using Bun:
* // import { MMapReader } from 'gis-tools-ts/mmap';
*
* const reader = new OSMReader(new FileReader('./data.osm.pbf'));
*
* // pull out the header
* const header = reader.getHeader();
*
* // read the features
* for (const feature of reader) {
* console.log(feature);
* }
*
* // close the reader when done
* reader.close();
* ```
*
* ## Links
* - https://wiki.openstreetmap.org/wiki/PBF_Format
* - https://github.com/openstreetmap/pbf/blob/master/OSM-binary.md
*/
export declare class OSMReader implements FeatureIterator<OSMMetadata, Properties, OSMProperties> {
#private;
options?: OsmReaderOptions | undefined;
reader: Reader;
/** if true, remove nodes that have no tags [Default = true] */
removeEmptyNodes: boolean;
/** If provided, filters of the */
tagFilter?: TagFilter;
/** If set to true, nodes will be skipped */
skipNodes: boolean;
/** If set to true, ways will be skipped */
skipWays: boolean;
/** If set to true, relations will be skipped */
skipRelations: boolean;
/**
* If set to true, ways will be converted to areas if they are closed.
* NOTE: They are upgraded anyways if the tag "area" is set to "yes".
* [Default = false]
*/
upgradeWaysToAreas: boolean;
/** If set to true, add a bbox property to each feature */
addBBox: boolean;
nodeGeometry: KVStore<VectorPoint>;
nodes: KVStore<VectorFeature<OSMMetadata, Properties, OSMProperties, VectorPointGeometry>>;
wayGeometry: KVStore<WayNodes>;
ways: KVStore<IntermediateWay>;
relations: KVStore<IntermediateRelation>;
nodeRelationPairs: KVStore<IntermediateNodeMember>;
/**
* @param input - The input (may be a local memory filter or file reader)
* @param options - User defined options to apply when reading the OSM file
*/
constructor(input: ReaderInputs, options?: OsmReaderOptions | undefined);
/**
* An async iterator to read in each feature
* @yields {VectorFeature}
*/
[Symbol.asyncIterator](): AsyncGenerator<VectorFeature<OSMMetadata, Properties, OSMProperties>>;
/** @returns - The header of the OSM file */
getHeader(): OSMHeader;
/**
* @param id - The id of the node to retrieve
* @returns - The node
*/
getNode(id: number): Promise<VectorFeature<OSMMetadata, Properties, OSMProperties, VectorPointGeometry> | undefined>;
/**
* @param id - the id of the way to retrieve
* @returns - the way
*/
getWay(id: number): Promise<IntermediateWay | undefined>;
/**
* @param id - the id of the relation to retrieve
* @returns - the relation
*/
getRelation(id: number): Promise<IntermediateRelation | undefined>;
/** Close out the data which will cleanup any temporary files if they exist */
close(): void;
}
//# sourceMappingURL=index.d.ts.map