1 | // Note: as of the RFC 7946 version of GeoJSON, Coordinate Reference Systems
|
2 | // are no longer supported. (See https://tools.ietf.org/html/rfc7946#appendix-B)}
|
3 |
|
4 | export as namespace GeoJSON;
|
5 |
|
6 | /**
|
7 | * The valid values for the "type" property of GeoJSON geometry objects.
|
8 | * https://tools.ietf.org/html/rfc7946#section-1.4
|
9 | */
|
10 | export type GeoJsonGeometryTypes = Geometry["type"];
|
11 |
|
12 | /**
|
13 | * The value values for the "type" property of GeoJSON Objects.
|
14 | * https://tools.ietf.org/html/rfc7946#section-1.4
|
15 | */
|
16 | export type GeoJsonTypes = GeoJSON["type"];
|
17 |
|
18 | /**
|
19 | * Bounding box
|
20 | * https://tools.ietf.org/html/rfc7946#section-5
|
21 | */
|
22 | export type BBox = [number, number, number, number] | [number, number, number, number, number, number];
|
23 |
|
24 | /**
|
25 | * A Position is an array of coordinates.
|
26 | * https://tools.ietf.org/html/rfc7946#section-3.1.1
|
27 | * Array should contain between two and three elements.
|
28 | * The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values),
|
29 | * but the current specification only allows X, Y, and (optionally) Z to be defined.
|
30 | */
|
31 | export type Position = number[]; // [number, number] | [number, number, number];
|
32 |
|
33 | /**
|
34 | * The base GeoJSON object.
|
35 | * https://tools.ietf.org/html/rfc7946#section-3
|
36 | * The GeoJSON specification also allows foreign members
|
37 | * (https://tools.ietf.org/html/rfc7946#section-6.1)
|
38 | * Developers should use "&" type in TypeScript or extend the interface
|
39 | * to add these foreign members.
|
40 | */
|
41 | export interface GeoJsonObject {
|
42 | // Don't include foreign members directly into this type def.
|
43 | // in order to preserve type safety.
|
44 | // [key: string]: any;
|
45 | /**
|
46 | * Specifies the type of GeoJSON object.
|
47 | */
|
48 | type: GeoJsonTypes;
|
49 | /**
|
50 | * Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections.
|
51 | * The value of the bbox member is an array of length 2*n where n is the number of dimensions
|
52 | * represented in the contained geometries, with all axes of the most southwesterly point
|
53 | * followed by all axes of the more northeasterly point.
|
54 | * The axes order of a bbox follows the axes order of geometries.
|
55 | * https://tools.ietf.org/html/rfc7946#section-5
|
56 | */
|
57 | bbox?: BBox | undefined;
|
58 | }
|
59 |
|
60 | /**
|
61 | * Union of GeoJSON objects.
|
62 | */
|
63 | export type GeoJSON<G extends Geometry | null = Geometry, P = GeoJsonProperties> =
|
64 | | G
|
65 | | Feature<G, P>
|
66 | | FeatureCollection<G, P>;
|
67 |
|
68 | /**
|
69 | * Geometry object.
|
70 | * https://tools.ietf.org/html/rfc7946#section-3
|
71 | */
|
72 | export type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon | GeometryCollection;
|
73 | export type GeometryObject = Geometry;
|
74 |
|
75 | /**
|
76 | * Point geometry object.
|
77 | * https://tools.ietf.org/html/rfc7946#section-3.1.2
|
78 | */
|
79 | export interface Point extends GeoJsonObject {
|
80 | type: "Point";
|
81 | coordinates: Position;
|
82 | }
|
83 |
|
84 | /**
|
85 | * MultiPoint geometry object.
|
86 | * https://tools.ietf.org/html/rfc7946#section-3.1.3
|
87 | */
|
88 | export interface MultiPoint extends GeoJsonObject {
|
89 | type: "MultiPoint";
|
90 | coordinates: Position[];
|
91 | }
|
92 |
|
93 | /**
|
94 | * LineString geometry object.
|
95 | * https://tools.ietf.org/html/rfc7946#section-3.1.4
|
96 | */
|
97 | export interface LineString extends GeoJsonObject {
|
98 | type: "LineString";
|
99 | coordinates: Position[];
|
100 | }
|
101 |
|
102 | /**
|
103 | * MultiLineString geometry object.
|
104 | * https://tools.ietf.org/html/rfc7946#section-3.1.5
|
105 | */
|
106 | export interface MultiLineString extends GeoJsonObject {
|
107 | type: "MultiLineString";
|
108 | coordinates: Position[][];
|
109 | }
|
110 |
|
111 | /**
|
112 | * Polygon geometry object.
|
113 | * https://tools.ietf.org/html/rfc7946#section-3.1.6
|
114 | */
|
115 | export interface Polygon extends GeoJsonObject {
|
116 | type: "Polygon";
|
117 | coordinates: Position[][];
|
118 | }
|
119 |
|
120 | /**
|
121 | * MultiPolygon geometry object.
|
122 | * https://tools.ietf.org/html/rfc7946#section-3.1.7
|
123 | */
|
124 | export interface MultiPolygon extends GeoJsonObject {
|
125 | type: "MultiPolygon";
|
126 | coordinates: Position[][][];
|
127 | }
|
128 |
|
129 | /**
|
130 | * Geometry Collection
|
131 | * https://tools.ietf.org/html/rfc7946#section-3.1.8
|
132 | */
|
133 | export interface GeometryCollection<G extends Geometry = Geometry> extends GeoJsonObject {
|
134 | type: "GeometryCollection";
|
135 | geometries: G[];
|
136 | }
|
137 |
|
138 | export type GeoJsonProperties = { [name: string]: any } | null;
|
139 |
|
140 | /**
|
141 | * A feature object which contains a geometry and associated properties.
|
142 | * https://tools.ietf.org/html/rfc7946#section-3.2
|
143 | */
|
144 | export interface Feature<G extends Geometry | null = Geometry, P = GeoJsonProperties> extends GeoJsonObject {
|
145 | type: "Feature";
|
146 | /**
|
147 | * The feature's geometry
|
148 | */
|
149 | geometry: G;
|
150 | /**
|
151 | * A value that uniquely identifies this feature in a
|
152 | * https://tools.ietf.org/html/rfc7946#section-3.2.
|
153 | */
|
154 | id?: string | number | undefined;
|
155 | /**
|
156 | * Properties associated with this feature.
|
157 | */
|
158 | properties: P;
|
159 | }
|
160 |
|
161 | /**
|
162 | * A collection of feature objects.
|
163 | * https://tools.ietf.org/html/rfc7946#section-3.3
|
164 | */
|
165 | export interface FeatureCollection<G extends Geometry | null = Geometry, P = GeoJsonProperties> extends GeoJsonObject {
|
166 | type: "FeatureCollection";
|
167 | features: Array<Feature<G, P>>;
|
168 | }
|