Skip to content

Commit a8170d8

Browse files
committed
Support MultiPoint
1 parent d6a33cf commit a8170d8

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[![minzipped](https://img.shields.io/bundlephobia/minzip/geoparquet)](https://www.npmjs.com/package/geoparquet)
77
[![workflow status](https://github.com/hyparam/geoparquet/actions/workflows/ci.yml/badge.svg)](https://github.com/hyparam/geoparquet/actions)
88
[![mit license](https://img.shields.io/badge/License-MIT-orange.svg)](https://opensource.org/licenses/MIT)
9-
![coverage](https://img.shields.io/badge/Coverage-97-darkred)
9+
![coverage](https://img.shields.io/badge/Coverage-94-darkred)
10+
[![dependencies](https://img.shields.io/badge/Dependencies-1-blueviolet)](https://www.npmjs.com/package/geoparquet?activeTab=dependencies)
1011

1112
**GeoParquet** provides a pure JavaScript workflow to read and convert [GeoParquet](https://github.com/opengeospatial/geoparquet) files into [GeoJSON](https://datatracker.ietf.org/doc/html/rfc7946). Under the hood, it uses the [hyparquet](https://github.com/hyparam/hyparquet) library for efficient in-browser parquet parsing, enabling minimal overhead and fast loading.
1213

src/wkb.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,20 @@ export function decodeWKB(wkb) {
103103
return { type: 'MultiPolygon', coordinates: polygons }
104104
} else if (geometryType === geometryTypeMultiPoint) {
105105
// MultiPoint
106-
throw new Error('Unsupported geometry type: MultiPoint')
106+
const numPoints = dv.getUint32(offset, isLittleEndian); offset += 4
107+
const points = []
108+
for (let i = 0; i < numPoints; i++) {
109+
// Each point has its own byte order & geometry type
110+
const pointIsLittleEndian = wkb[offset] === 1; offset += 1
111+
const pointType = dv.getUint32(offset, pointIsLittleEndian); offset += 4
112+
if (pointType !== geometryTypePoint) {
113+
throw new Error(`Expected Point in MultiPoint, got ${pointType}`)
114+
}
115+
const x = dv.getFloat64(offset, pointIsLittleEndian); offset += 8
116+
const y = dv.getFloat64(offset, pointIsLittleEndian); offset += 8
117+
points.push([x, y])
118+
}
119+
return { type: 'MultiPoint', coordinates: points }
107120
} else if (geometryType === geometryTypeMultiLineString) {
108121
// MultiLineString
109122
const numLineStrings = dv.getUint32(offset, isLittleEndian); offset += 4
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"features": [
3+
{
4+
"geometry": {
5+
"coordinates": [
6+
[ 30, 10 ]
7+
],
8+
"type": "MultiPoint"
9+
},
10+
"properties": {
11+
"col": 0
12+
},
13+
"type": "Feature"
14+
},
15+
{
16+
"geometry": {
17+
"coordinates": [
18+
[ 10, 40 ],
19+
[ 40, 30 ],
20+
[ 20, 20 ],
21+
[ 30, 10 ]
22+
],
23+
"type": "MultiPoint"
24+
},
25+
"properties": {
26+
"col": 1
27+
},
28+
"type": "Feature"
29+
},
30+
{
31+
"geometry": {
32+
"coordinates": [],
33+
"type": "MultiPoint"
34+
},
35+
"properties": {
36+
"col": 2
37+
},
38+
"type": "Feature"
39+
}
40+
],
41+
"type": "FeatureCollection"
42+
}
1.58 KB
Binary file not shown.

0 commit comments

Comments
 (0)