From 2336151ef2b6ed2f980f0416725542729327d7f9 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Tue, 14 Nov 2023 15:04:53 -0700 Subject: [PATCH] update test cases; fix Signed-off-by: Xun Li --- .../convert-geoarrow-to-binary-geometry.ts | 52 ++++++++---- modules/arrow/test/data/line.arrow | Bin 3146 -> 3202 bytes modules/arrow/test/data/multiline.arrow | Bin 3370 -> 3466 bytes modules/arrow/test/data/multipoint.arrow | Bin 3146 -> 3202 bytes modules/arrow/test/data/point.arrow | Bin 2954 -> 2986 bytes modules/arrow/test/data/polygon.arrow | Bin 3818 -> 3434 bytes ...onvert-geoarrow-to-binary-geometry.spec.ts | 47 ++++++----- .../convert-geoarrow-to-geojson.spec.ts | 77 ++++++++++++++++-- 8 files changed, 127 insertions(+), 49 deletions(-) diff --git a/modules/arrow/src/geoarrow/convert-geoarrow-to-binary-geometry.ts b/modules/arrow/src/geoarrow/convert-geoarrow-to-binary-geometry.ts index 69d6246b25..379b26c6dc 100644 --- a/modules/arrow/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +++ b/modules/arrow/src/geoarrow/convert-geoarrow-to-binary-geometry.ts @@ -163,10 +163,10 @@ function getMeanCentersFromBinaryGeometries(binaryGeometries: BinaryFeatures[]): binaryGeometry.points && binaryGeometry.points.positions.value.length > 0 ? 'points' : binaryGeometry.lines && binaryGeometry.lines.positions.value.length > 0 - ? 'lines' - : binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0 - ? 'polygons' - : null; + ? 'lines' + : binaryGeometry.polygons && binaryGeometry.polygons.positions.value.length > 0 + ? 'polygons' + : null; const binaryContent = binaryGeometryType ? binaryGeometry[binaryGeometryType] : null; if (binaryContent) { @@ -342,9 +342,6 @@ function getBinaryLinesFromChunk(chunk: arrow.Data, geoEncoding: string): Binary const isMultiLineString = geoEncoding === 'geoarrow.multilinestring'; const lineData = isMultiLineString ? chunk.children[0] : chunk; - const partData = isMultiLineString - ? chunk.valueOffsets.map((i) => lineData.valueOffsets.at(i) || i) - : chunk.valueOffsets; const pointData = lineData.children[0]; const coordData = pointData.children[0]; @@ -357,11 +354,23 @@ function getBinaryLinesFromChunk(chunk: arrow.Data, geoEncoding: string): Binary const numOfVertices = flatCoordinateArray.length / nDim; const featureIds = new Uint32Array(numOfVertices); - for (let i = 0; i < partData.length - 1; i++) { - const startIdx = geomOffset[partData[i]]; - const endIdx = geomOffset[partData[i + 1]]; - for (let j = startIdx; j < endIdx; j++) { - featureIds[j] = i; + + if (isMultiLineString) { + const partData = chunk.valueOffsets; + for (let i = 0; i < partData.length - 1; i++) { + const startIdx = geomOffset[partData[i]]; + const endIdx = geomOffset[partData[i + 1]]; + for (let j = startIdx; j < endIdx; j++) { + featureIds[j] = i; + } + } + } else { + for (let i = 0; i < chunk.length; i++) { + const startIdx = geomOffset[i]; + const endIdx = geomOffset[i + 1]; + for (let j = startIdx; j < endIdx; j++) { + featureIds[j] = i; + } } } @@ -384,7 +393,6 @@ function getBinaryPointsFromChunk(chunk: arrow.Data, geoEncoding: string): Binar const isMultiPoint = geoEncoding === 'geoarrow.multipoint'; const pointData = isMultiPoint ? chunk.children[0] : chunk; - const partData = isMultiPoint ? chunk.valueOffsets : chunk; const coordData = pointData.children[0]; const nDim = pointData.stride; @@ -397,11 +405,19 @@ function getBinaryPointsFromChunk(chunk: arrow.Data, geoEncoding: string): Binar const numOfVertices = flatCoordinateArray.length / nDim; const featureIds = new Uint32Array(numOfVertices); - for (let i = 0; i < partData.length - 1; i++) { - const startIdx = geomOffset[partData[i]]; - const endIdx = geomOffset[partData[i + 1]]; - for (let j = startIdx; j < endIdx; j++) { - featureIds[j] = i; + + if (isMultiPoint) { + const partData = chunk.valueOffsets; + for (let i = 0; i < partData.length - 1; i++) { + const startIdx = partData[i]; + const endIdx = partData[i + 1]; + for (let j = startIdx; j < endIdx; j++) { + featureIds[j] = i; + } + } + } else { + for (let i = 0; i < chunk.length; i++) { + featureIds[i] = i; } } diff --git a/modules/arrow/test/data/line.arrow b/modules/arrow/test/data/line.arrow index 2db7920191fba9c86d6d3b9d9428184ba51b2c2a..2eac39b3db5035417b243e6f891c21cd3fc8b8ab 100644 GIT binary patch delta 278 zcmX>l(ImMcfQ7MQav+O5Bh%zU7WK&+SOg}oU=hgWVSoS$D9r_>HJ~(%g7IPMEnpH* z8W-OINgeCtiLAntBUlB1SOMq)4ojFMBap!a<*)*2m@D!Ub5jjLgb_?7L>fXX?b(i~7ehr{L_tN~1{#(D-i#*=wDv>7WlTXG1p007G!95(;} delta 245 zcmZpYJSDLqfQ8Xvav+O5Bje;k7Ij9J$%(AulQ*z%OkTjkQ7^y%0jyA30!qUu7@q?w zpa7E~z(-aGGMf=iAC%7p7iOHS$tpiNf>l5iSt&?sUSe*l;bcRgqbIO%@GvlZu!m^+ cV88hTYXB3gp`L+`;bd11ZAOR9g&cw`0BN2Vx&QzG diff --git a/modules/arrow/test/data/multiline.arrow b/modules/arrow/test/data/multiline.arrow index 2d5728a4653fc05e0f2880a3b8149fc0c1ec1c9e..b4404be8996e2a5c8f482c9ec9025b9af3590aff 100644 GIT binary patch delta 334 zcmZ1_)g`^5gN5S56 z-U228rD1##C_eyA9tU5Dp#e!D8<5R3c_FL(09Q0m@g{?9Ud)#A=~u Spkpz46^9<?iiE5Ib6 zG>p#!MUt|@Ye1%nDato^r(3uL8C$RF!f}E9?n44+@Rn3G% gvrN`xbKksyEtHAXM9)CSWHJ}09%I2~OU^(R0K*~~w*UYD diff --git a/modules/arrow/test/data/multipoint.arrow b/modules/arrow/test/data/multipoint.arrow index 7123a434320b2ec0acda42e5a3d08513071040c1..ff545eecdbd490e0e836b81b15ac4e334e6eee96 100644 GIT binary patch delta 287 zcmX>l(ImMcfQ7MQav+O5Bh%zU7WK&+SOg}oU=gV2VSoS$D9r_>HJ~(%g7IPMEnpH* z8W-OINgXSY&4k1UGAD<#3Qmq-RRFq&!xkpRh@=jr2j-@{#N1Rv5McyU2{Dfa#GO2q nRaqV)&f$Pc3qbh-o42zDGO?QI8R(cy=H<|4tk`VHA;mI$1uKsrNK0N~ZmJPfo@w%0R^`nfSOb_? Vjr0t3j3&EsXfrx&F60no0RTgD6@>r* diff --git a/modules/arrow/test/data/point.arrow b/modules/arrow/test/data/point.arrow index 0b1835023b23a8a0a838b73c2faf5c9ed3fe1f42..3a027d358b570da57e12dbfee40a4ae37fd346b4 100644 GIT binary patch delta 228 zcmeAYUnRalfQ8XxvLK5*BhzF<7WK&mECQ1=SOfxj7$86bN^?PJ4JZwxaPbvj3V<{V z5Hn4F$)X(t5(M#(0V9yZ1QlQf(lDFy5_3}xL4*;q>JRo19*kyifXX^-HemHIE1efE7whKxr6-ix1NWQpW7}qHgki7Eu|H-Fb<*sYY-!KG;K;AM7^=u=+Ex8tNJ77*1ZouEVIY`6ByG FW&n>16EOe) diff --git a/modules/arrow/test/data/polygon.arrow b/modules/arrow/test/data/polygon.arrow index bd926fe7b271aec809e1f5881544d9ec22ccd1e3..f62c688d430009a5387106913a0237a4d0244052 100644 GIT binary patch delta 372 zcmaDQ`$~$}F(}AC+>n9cKM+_<*tf))XKsVe&;@aYmiVADN{mFJTd%EX-0k`2dRwrvgw9$l!{}Z&{QX zUrZKc6&Jk&6cYeqpfzy7Gx;N%bRY+m52InyFg_1dKmtm0L1_(`LNq?ln9cKM>rQ$g3}Qgo%NHg@J(qNHO?8*&qIF^mAgWHvy`N01AVo zJ%PAdDJ?Ta$w~=G=qM%U=alB=6)Ra)gZMzQq_Q9tDCwD3lA4}cq*SY;l$V$b6oJbG zmlS2@r7P9e)&kAq2IBOT#2l;QH&0v%j7^F zb=DFft6*|1k2s^ump>oXW#J9{C)AKJ{Q{V1OiG0M|pOe*gdg diff --git a/modules/arrow/test/geoarrow/convert-geoarrow-to-binary-geometry.spec.ts b/modules/arrow/test/geoarrow/convert-geoarrow-to-binary-geometry.spec.ts index 67fd99181a..4157a71b13 100644 --- a/modules/arrow/test/geoarrow/convert-geoarrow-to-binary-geometry.spec.ts +++ b/modules/arrow/test/geoarrow/convert-geoarrow-to-binary-geometry.spec.ts @@ -26,10 +26,10 @@ const expectedPointBinaryGeometry = { points: { ...BINARY_GEOMETRY_TEMPLATE, type: 'Point', - globalFeatureIds: {value: new Uint32Array([0]), size: 1}, - positions: {value: new Float64Array([1, 1]), size: 2}, - properties: [{index: 0}], - featureIds: {value: new Uint32Array([0]), size: 1} + globalFeatureIds: {value: new Uint32Array([0, 1]), size: 1}, + positions: {value: new Float64Array([1, 1, 2, 2]), size: 2}, + properties: [{index: 0}, {index: 1}], + featureIds: {value: new Uint32Array([0, 1]), size: 1} }, lines: { ...BINARY_GEOMETRY_TEMPLATE, @@ -44,7 +44,7 @@ const expectedPointBinaryGeometry = { } } ], - bounds: [1, 1, 1, 1], + bounds: [1, 1, 2, 2], featureTypes: {polygon: false, point: true, line: false} }; @@ -55,10 +55,10 @@ const expectedMultiPointBinaryGeometry = { points: { ...BINARY_GEOMETRY_TEMPLATE, type: 'Point', - globalFeatureIds: {value: new Uint32Array([0, 0]), size: 1}, - positions: {value: new Float64Array([1, 1, 2, 2]), size: 2}, - properties: [{index: 0}], - featureIds: {value: new Uint32Array([0, 0]), size: 1} + globalFeatureIds: {value: new Uint32Array([0, 0, 1, 1]), size: 1}, + positions: {value: new Float64Array([1, 1, 2, 2, 3, 3, 4, 4]), size: 2}, + properties: [{index: 0}, {index: 1}], + featureIds: {value: new Uint32Array([0, 0, 1, 1]), size: 1} }, lines: { ...BINARY_GEOMETRY_TEMPLATE, @@ -73,7 +73,7 @@ const expectedMultiPointBinaryGeometry = { } } ], - bounds: [1, 1, 2, 2], + bounds: [1, 1, 4, 4], featureTypes: {polygon: false, point: true, line: false} }; @@ -88,11 +88,11 @@ const expectedLineBinaryGeometry = { lines: { ...BINARY_GEOMETRY_TEMPLATE, type: 'LineString', - globalFeatureIds: {value: new Uint32Array([0, 0]), size: 1}, - positions: {value: new Float64Array([0, 0, 1, 1]), size: 2}, - properties: [{index: 0}], - featureIds: {value: new Uint32Array([0, 0]), size: 1}, - pathIndices: {value: new Int32Array([0, 2]), size: 1} + globalFeatureIds: {value: new Uint32Array([0, 0, 1, 1]), size: 1}, + positions: {value: new Float64Array([0, 0, 1, 1, 2, 2, 3, 3]), size: 2}, + properties: [{index: 0}, {index: 1}], + featureIds: {value: new Uint32Array([0, 0, 1, 1]), size: 1}, + pathIndices: {value: new Int32Array([0, 2, 4]), size: 1} }, polygons: { ...BINARY_GEOMETRY_TEMPLATE, @@ -102,7 +102,7 @@ const expectedLineBinaryGeometry = { } } ], - bounds: [0, 0, 1, 1], + bounds: [0, 0, 3, 3], featureTypes: {polygon: false, point: false, line: true} }; @@ -117,11 +117,14 @@ const expectedMultiLineBinaryGeometry = { lines: { ...BINARY_GEOMETRY_TEMPLATE, type: 'LineString', - globalFeatureIds: {value: new Uint32Array([0, 0, 0, 0]), size: 1}, - positions: {value: new Float64Array([1, 1, 2, 2, 3, 3, 4, 4]), size: 2}, - properties: [{index: 0}], - featureIds: {value: new Uint32Array([0, 0, 0, 0]), size: 1}, - pathIndices: {value: new Int32Array([0, 2, 4]), size: 1} + globalFeatureIds: {value: new Uint32Array([0, 0, 0, 0, 1, 1, 1, 1]), size: 1}, + positions: { + value: new Float64Array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]), + size: 2 + }, + properties: [{index: 0}, {index: 1}], + featureIds: {value: new Uint32Array([0, 0, 0, 0, 1, 1, 1, 1]), size: 1}, + pathIndices: {value: new Int32Array([0, 2, 4, 6, 8]), size: 1} }, polygons: { ...BINARY_GEOMETRY_TEMPLATE, @@ -131,7 +134,7 @@ const expectedMultiLineBinaryGeometry = { } } ], - bounds: [1, 1, 4, 4], + bounds: [1, 1, 8, 8], featureTypes: {polygon: false, point: false, line: true} }; diff --git a/modules/arrow/test/geoarrow/convert-geoarrow-to-geojson.spec.ts b/modules/arrow/test/geoarrow/convert-geoarrow-to-geojson.spec.ts index a3400c369d..2dbf3ec2cc 100644 --- a/modules/arrow/test/geoarrow/convert-geoarrow-to-geojson.spec.ts +++ b/modules/arrow/test/geoarrow/convert-geoarrow-to-geojson.spec.ts @@ -26,10 +26,21 @@ const GEOARROW_ENCODINGS = [ 'geoarrow.wkt' ]; -// a simple geojson contains one point +// a simple geojson contains two points const expectedPointGeojson: FeatureCollection = { type: 'FeatureCollection', features: [ + { + type: 'Feature', + properties: { + id: 1, + name: 'name1' + }, + geometry: { + type: 'Point', + coordinates: [1, 1] + } + }, { type: 'Feature', properties: { @@ -38,13 +49,13 @@ const expectedPointGeojson: FeatureCollection = { }, geometry: { type: 'Point', - coordinates: [1, 1] + coordinates: [2, 2] } } ] }; -// a simple geojson contains one linestring +// a simple geojson contains two linestrings const expectedLineStringGeoJson: FeatureCollection = { type: 'FeatureCollection', features: [ @@ -61,6 +72,20 @@ const expectedLineStringGeoJson: FeatureCollection = { [1, 1] ] } + }, + { + type: 'Feature', + properties: { + id: 2, + name: 'name2' + }, + geometry: { + type: 'LineString', + coordinates: [ + [2, 2], + [3, 3] + ] + } } ] }; @@ -110,15 +135,15 @@ const expectedPolygonGeojson: FeatureCollection = { ] }; -// a simple geojson contains one MultiPoint +// a simple geojson contains two MultiPoints const expectedMultiPointGeoJson: FeatureCollection = { type: 'FeatureCollection', features: [ { type: 'Feature', properties: { - id: 2, - name: 'name2' + id: 1, + name: 'name1' }, geometry: { type: 'MultiPoint', @@ -127,19 +152,33 @@ const expectedMultiPointGeoJson: FeatureCollection = { [2, 2] ] } + }, + { + type: 'Feature', + properties: { + id: 2, + name: 'name2' + }, + geometry: { + type: 'MultiPoint', + coordinates: [ + [3, 3], + [4, 4] + ] + } } ] }; -// a simple geojson contains one MultiLinestring +// a simple geojson contains two MultiLinestrings const expectedMultiLineStringGeoJson: FeatureCollection = { type: 'FeatureCollection', features: [ { type: 'Feature', properties: { - id: 2, - name: 'name2' + id: 1, + name: 'name1' }, geometry: { type: 'MultiLineString', @@ -154,6 +193,26 @@ const expectedMultiLineStringGeoJson: FeatureCollection = { ] ] } + }, + { + type: 'Feature', + properties: { + id: 2, + name: 'name2' + }, + geometry: { + type: 'MultiLineString', + coordinates: [ + [ + [5, 5], + [6, 6] + ], + [ + [7, 7], + [8, 8] + ] + ] + } } ] };