-
Notifications
You must be signed in to change notification settings - Fork 98
Fix GeoJSON properties order #2253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix GeoJSON properties order #2253
Conversation
functions/src/export-geojson.ts
Outdated
| const v = pb[k].stringValue || pb[k].numericValue; | ||
| }): [string, string | number][] { | ||
| const entries: [string, string | number][] = []; | ||
| for (const k of Reflect.ownKeys(pb)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this attempting to preserve the order of properties as they appear in the map in the db? Does that map preserve order, all the way from import to how they're persisted in Firestore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem was not the order itself but the costincency with the CSV order.
In any case, at some point the order change.
This is what we have in the DocumentData:
name: { '1': 'ttt' },
whisp_plotId: { '1': '1' },
whisp_external_id: { '1': 'null' },
whisp_Area: { '2': 0.03500000014901161 },
whisp_Geometry_type: { '1': 'Polygon' },
this is what the firebase console shows (it probably applies a sort):
this is what we have after conversion (toMessage(row.data(), Pb.LocationOfInterest)):
"whisp_nBR_PRODES_deforestation_Brazil_before_2020": 0,
"whisp_nBR_MapBiomas_col9_coffee_2020": 0,
"whisp_ESRI_2023_crop": 0,
"whisp_European_Primary_Forest": 0,
so probably the solution is sort the keys at convertion time (the default one is fine for now) so we can have the control of it:
function propertiesPbToObject(pb: {
[k: string]: Pb.LocationOfInterest.IProperty;
}): {[k: string]: string | number} {
const properties: {[k: string]: string | number} = {};
for (const k of Object.keys(pb).sort()) {
const v = pb[k].stringValue || pb[k].numericValue;
if (v !== null && v !== undefined) {
properties[k] = v;
}
}
return properties;
}
…s-order-issue # Conflicts: # functions/src/export-geojson.ts
gino-m
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please add test to verify ordering.
closes #2252