Skip to content

Commit

Permalink
fix: allow proper encoding of string OIDs in PBF format (#946)
Browse files Browse the repository at this point in the history
* fix: allow proper encoding of string OIDs in PBF format
  • Loading branch information
rgwozdz authored Mar 7, 2024
1 parent f2f1f7c commit 969d956
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-wombats-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@koopjs/featureserver": patch
---

- allow proper PBF encoding of string OID values
62 changes: 62 additions & 0 deletions demo/provider-data/points-w-metadata-id-string.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"type": "FeatureCollection",
"metadata": {
"idField": "id",
"fields": [
{ "name": "timestamp", "type": "Date" },
{ "name": "id", "type": "String" },
{ "name": "label", "type": "String" },
{ "name": "category", "type": "String" }
]
},
"features": [
{
"type": "Feature",
"properties": {
"id": "aaa",
"timestamp": "2023-04-10T16:15:30.000Z",
"label": "White Leg",
"category": "pinto"
},
"geometry": {
"type": "Point",
"coordinates": [
-80,
25
]
}
},
{
"type": "Feature",
"properties": {
"id": "bbb",
"timestamp": "2020-04-12T16:15:30.000Z",
"label": "Fireman",
"category": "pinto"
},
"geometry": {
"type": "Point",
"coordinates": [
-120,
45
]
}
},
{
"type": "Feature",
"properties": {
"id": "ccc",
"timestamp": "2015-04-11T16:15:30.000Z",
"label": "Workhorse",
"category": "draft"
},
"geometry": {
"type": "Point",
"coordinates": [
-100,
40
]
}
}
]
}
8 changes: 4 additions & 4 deletions packages/featureserver/coverage-unit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions packages/featureserver/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ function transformToPbfAttributes(attributes, fieldMap) {
name: key,
value,
}))
.orderBy(['name'],['asc'])
.orderBy(['name'], ['asc'])
.map(({ name, value }) => {
const type = fieldMap[name];
const pbfType = typeLookup[type];
const pbfType = dataTypeLookup(type, value);
return { [pbfType]: value };
})
.value();
}

function dataTypeLookup(fieldType, value) {
if (fieldType === 'esriFieldTypeOID') {
return Number.isInteger(value) ? 'uintValue' : 'stringValue';
}
return typeLookup[fieldType];
}
module.exports = {
transformToPbfAttributes
transformToPbfAttributes,
};
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const attributes = {

describe('transformToPbfAttributes', () => {
it('should transform Esri JSON to Esri PBF JSON', () => {
const result = transformToPbfAttributes(attributes ,fieldMap);
const result = transformToPbfAttributes(attributes, fieldMap);
result.should.deepEqual([
{
sint64Value: 1421798400000,
Expand All @@ -105,4 +105,34 @@ describe('transformToPbfAttributes', () => {
},
]);
});

it('should properly handle OIDs that are strings', () => {
const result = transformToPbfAttributes(
{ ...attributes, FID: 'foo' },
fieldMap,
);
result.should.deepEqual([
{
sint64Value: 1421798400000,
},
{
stringValue: '30040-085-3001-0126-000',
},
{
stringValue: 'foo',
},
{
stringValue: '9279699f-5ece-4ca6-8a3b-b559da37bc5e',
},
{
sintValue: 46104019,
},
{
doubleValue: 99,
},
{
sintValue: 6,
},
]);
});
});

0 comments on commit 969d956

Please sign in to comment.