Skip to content

Commit

Permalink
update test cases; fix
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Li <lixun910@gmail.com>
  • Loading branch information
lixun910 committed Nov 14, 2023
1 parent ebca927 commit 2336151
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 49 deletions.
52 changes: 34 additions & 18 deletions modules/arrow/src/geoarrow/convert-geoarrow-to-binary-geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];

Expand All @@ -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;
}
}
}

Expand All @@ -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;
Expand All @@ -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;
}
}

Expand Down
Binary file modified modules/arrow/test/data/line.arrow
Binary file not shown.
Binary file modified modules/arrow/test/data/multiline.arrow
Binary file not shown.
Binary file modified modules/arrow/test/data/multipoint.arrow
Binary file not shown.
Binary file modified modules/arrow/test/data/point.arrow
Binary file not shown.
Binary file modified modules/arrow/test/data/polygon.arrow
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,7 +44,7 @@ const expectedPointBinaryGeometry = {
}
}
],
bounds: [1, 1, 1, 1],
bounds: [1, 1, 2, 2],
featureTypes: {polygon: false, point: true, line: false}
};

Expand All @@ -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,
Expand All @@ -73,7 +73,7 @@ const expectedMultiPointBinaryGeometry = {
}
}
],
bounds: [1, 1, 2, 2],
bounds: [1, 1, 4, 4],
featureTypes: {polygon: false, point: true, line: false}
};

Expand All @@ -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,
Expand All @@ -102,7 +102,7 @@ const expectedLineBinaryGeometry = {
}
}
],
bounds: [0, 0, 1, 1],
bounds: [0, 0, 3, 3],
featureTypes: {polygon: false, point: false, line: true}
};

Expand All @@ -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,
Expand All @@ -131,7 +134,7 @@ const expectedMultiLineBinaryGeometry = {
}
}
],
bounds: [1, 1, 4, 4],
bounds: [1, 1, 8, 8],
featureTypes: {polygon: false, point: false, line: true}
};

Expand Down
77 changes: 68 additions & 9 deletions modules/arrow/test/geoarrow/convert-geoarrow-to-geojson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: [
Expand All @@ -61,6 +72,20 @@ const expectedLineStringGeoJson: FeatureCollection = {
[1, 1]
]
}
},
{
type: 'Feature',
properties: {
id: 2,
name: 'name2'
},
geometry: {
type: 'LineString',
coordinates: [
[2, 2],
[3, 3]
]
}
}
]
};
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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]
]
]
}
}
]
};
Expand Down

0 comments on commit 2336151

Please sign in to comment.