0
# Vector Features and Geometries
1
2
Feature system with comprehensive geometry support including points, lines, polygons, and collections with spatial operations.
3
4
## Capabilities
5
6
### Feature Class
7
8
Features represent geographic objects with geometry and properties.
9
10
```typescript { .api }
11
/**
12
* Vector feature with geometry and attributes
13
*/
14
class Feature {
15
constructor(geometry?: Geometry);
16
17
/** Get feature geometry */
18
getGeometry(): Geometry | undefined;
19
/** Set feature geometry */
20
setGeometry(geometry: Geometry | undefined): void;
21
22
/** Get feature ID */
23
getId(): string | number | undefined;
24
/** Set feature ID */
25
setId(id: string | number | undefined): void;
26
27
/** Get property value */
28
get(key: string): any;
29
/** Set property value */
30
set(key: string, value: any): void;
31
/** Get all properties */
32
getProperties(): {[key: string]: any};
33
/** Set all properties */
34
setProperties(values: {[key: string]: any}): void;
35
36
/** Get feature style */
37
getStyle(): StyleLike | undefined;
38
/** Set feature style */
39
setStyle(style: StyleLike): void;
40
41
/** Clone the feature */
42
clone(): Feature;
43
}
44
```
45
46
### Base Geometry Classes
47
48
Foundation classes for all geometry types.
49
50
```typescript { .api }
51
/**
52
* Base class for all geometries
53
*/
54
abstract class Geometry {
55
constructor();
56
57
/** Get geometry type */
58
getType(): GeometryType;
59
60
/** Get geometry extent */
61
getExtent(): Extent;
62
63
/** Transform geometry to different projection */
64
transform(source: ProjectionLike, destination: ProjectionLike): Geometry;
65
66
/** Clone the geometry */
67
clone(): Geometry;
68
69
/** Get closest point on geometry to coordinate */
70
getClosestPoint(point: Coordinate): Coordinate;
71
72
/** Check if geometry intersects extent */
73
intersectsExtent(extent: Extent): boolean;
74
75
/** Apply transform function to coordinates */
76
applyTransform(transformFn: TransformFunction): void;
77
78
/** Rotate geometry around anchor point */
79
rotate(angle: number, anchor: Coordinate): void;
80
81
/** Scale geometry */
82
scale(sx: number, sy?: number, anchor?: Coordinate): void;
83
84
/** Translate geometry */
85
translate(deltaX: number, deltaY: number): void;
86
}
87
88
/**
89
* Base class for simple geometries with coordinate arrays
90
*/
91
abstract class SimpleGeometry extends Geometry {
92
constructor();
93
94
/** Get geometry coordinates */
95
getCoordinates(): any;
96
/** Set geometry coordinates */
97
setCoordinates(coordinates: any): void;
98
99
/** Get first coordinate */
100
getFirstCoordinate(): Coordinate;
101
/** Get last coordinate */
102
getLastCoordinate(): Coordinate;
103
104
/** Get geometry layout */
105
getLayout(): GeometryLayout;
106
107
/** Get stride (number of values per coordinate) */
108
getStride(): number;
109
110
/** Get flat coordinates array */
111
getFlatCoordinates(): number[];
112
}
113
114
type GeometryType = 'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'Circle';
115
type GeometryLayout = 'XY' | 'XYZ' | 'XYM' | 'XYZM';
116
```
117
118
### Point Geometries
119
120
```typescript { .api }
121
/**
122
* Point geometry representing a single coordinate
123
*/
124
class Point extends SimpleGeometry {
125
constructor(coordinates: Coordinate, layout?: GeometryLayout);
126
127
/** Get point coordinates */
128
getCoordinates(): Coordinate;
129
/** Set point coordinates */
130
setCoordinates(coordinates: Coordinate): void;
131
}
132
133
/**
134
* Multi-point geometry for multiple points
135
*/
136
class MultiPoint extends SimpleGeometry {
137
constructor(coordinates: Coordinate[], layout?: GeometryLayout);
138
139
/** Get coordinates of all points */
140
getCoordinates(): Coordinate[];
141
/** Set coordinates of all points */
142
setCoordinates(coordinates: Coordinate[]): void;
143
144
/** Get specific point geometry */
145
getPoint(index: number): Point;
146
/** Get all point geometries */
147
getPoints(): Point[];
148
}
149
```
150
151
### Line Geometries
152
153
```typescript { .api }
154
/**
155
* Line string geometry
156
*/
157
class LineString extends SimpleGeometry {
158
constructor(coordinates: Coordinate[], layout?: GeometryLayout);
159
160
/** Get line coordinates */
161
getCoordinates(): Coordinate[];
162
/** Set line coordinates */
163
setCoordinates(coordinates: Coordinate[]): void;
164
165
/** Get coordinate at index */
166
getCoordinateAt(fraction: number): Coordinate;
167
/** Get line length */
168
getLength(): number;
169
170
/** Append coordinate to line */
171
appendCoordinate(coordinate: Coordinate): void;
172
}
173
174
/**
175
* Linear ring (closed line string)
176
*/
177
class LinearRing extends SimpleGeometry {
178
constructor(coordinates: Coordinate[], layout?: GeometryLayout);
179
180
/** Get ring coordinates */
181
getCoordinates(): Coordinate[];
182
/** Set ring coordinates */
183
setCoordinates(coordinates: Coordinate[]): void;
184
185
/** Get ring area */
186
getArea(): number;
187
}
188
189
/**
190
* Multi-line string geometry
191
*/
192
class MultiLineString extends SimpleGeometry {
193
constructor(coordinates: Coordinate[][], layout?: GeometryLayout);
194
195
/** Get coordinates of all lines */
196
getCoordinates(): Coordinate[][];
197
/** Set coordinates of all lines */
198
setCoordinates(coordinates: Coordinate[][]): void;
199
200
/** Get specific line string */
201
getLineString(index: number): LineString;
202
/** Get all line strings */
203
getLineStrings(): LineString[];
204
}
205
```
206
207
### Polygon Geometries
208
209
```typescript { .api }
210
/**
211
* Polygon geometry with optional holes
212
*/
213
class Polygon extends SimpleGeometry {
214
constructor(coordinates: Coordinate[][], layout?: GeometryLayout);
215
216
/** Get polygon coordinates [exterior, ...holes] */
217
getCoordinates(): Coordinate[][];
218
/** Set polygon coordinates */
219
setCoordinates(coordinates: Coordinate[][]): void;
220
221
/** Get exterior ring */
222
getLinearRing(index: number): LinearRing;
223
/** Get all linear rings */
224
getLinearRings(): LinearRing[];
225
226
/** Get polygon area */
227
getArea(): number;
228
/** Get polygon perimeter */
229
getPerimeter(): number;
230
231
/** Get interior point */
232
getInteriorPoint(): Point;
233
}
234
235
/**
236
* Multi-polygon geometry
237
*/
238
class MultiPolygon extends SimpleGeometry {
239
constructor(coordinates: Coordinate[][][], layout?: GeometryLayout);
240
241
/** Get coordinates of all polygons */
242
getCoordinates(): Coordinate[][][];
243
/** Set coordinates of all polygons */
244
setCoordinates(coordinates: Coordinate[][][]): void;
245
246
/** Get specific polygon */
247
getPolygon(index: number): Polygon;
248
/** Get all polygons */
249
getPolygons(): Polygon[];
250
251
/** Get interior points of all polygons */
252
getInteriorPoints(): MultiPoint;
253
}
254
```
255
256
### Special Geometries
257
258
```typescript { .api }
259
/**
260
* Circle geometry
261
*/
262
class Circle extends SimpleGeometry {
263
constructor(center: Coordinate, radius?: number, layout?: GeometryLayout);
264
265
/** Get circle center */
266
getCenter(): Coordinate;
267
/** Set circle center */
268
setCenter(center: Coordinate): void;
269
270
/** Get circle radius */
271
getRadius(): number;
272
/** Set circle radius */
273
setRadius(radius: number): void;
274
275
/** Set center and radius together */
276
setCenterAndRadius(center: Coordinate, radius: number): void;
277
}
278
279
/**
280
* Collection of multiple geometries
281
*/
282
class GeometryCollection extends Geometry {
283
constructor(geometries?: Geometry[]);
284
285
/** Get all geometries in collection */
286
getGeometries(): Geometry[];
287
/** Set geometries in collection */
288
setGeometries(geometries: Geometry[]): void;
289
290
/** Get specific geometry by index */
291
getGeometry(index: number): Geometry;
292
/** Set specific geometry by index */
293
setGeometry(index: number, geometry: Geometry): void;
294
}
295
```
296
297
**Usage Examples:**
298
299
```typescript
300
import Feature from 'ol/Feature';
301
import { Point, LineString, Polygon } from 'ol/geom';
302
303
// Create a point feature
304
const pointFeature = new Feature({
305
geometry: new Point([0, 0]),
306
name: 'My Point',
307
population: 1000
308
});
309
310
// Create a line feature
311
const lineFeature = new Feature({
312
geometry: new LineString([
313
[0, 0], [10, 10], [20, 0]
314
])
315
});
316
317
// Create a polygon feature
318
const polygonFeature = new Feature({
319
geometry: new Polygon([
320
// Exterior ring
321
[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
322
// Interior hole
323
[[2, 2], [8, 2], [8, 8], [2, 8], [2, 2]]
324
])
325
});
326
327
// Get geometry properties
328
const area = polygonFeature.getGeometry().getArea();
329
const center = polygonFeature.getGeometry().getInteriorPoint();
330
```
331
332
## Types
333
334
```typescript { .api }
335
type TransformFunction = (input: number[], output?: number[], dimension?: number) => number[];
336
```