Skip to content

Conversation

@rfontanarosa
Copy link
Collaborator

closes #2252

@rfontanarosa rfontanarosa requested a review from gino-m September 16, 2025 12:13
@rfontanarosa rfontanarosa self-assigned this Sep 16, 2025
const v = pb[k].stringValue || pb[k].numericValue;
}): [string, string | number][] {
const entries: [string, string | number][] = [];
for (const k of Reflect.ownKeys(pb)) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

@rfontanarosa rfontanarosa Sep 26, 2025

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):

Screenshot 2025-09-26 alle 17 16 53

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;
}

@rfontanarosa rfontanarosa requested a review from gino-m September 26, 2025 15:20
…s-order-issue

# Conflicts:
#	functions/src/export-geojson.ts
Copy link
Collaborator

@gino-m gino-m left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export GeoJSON properties order issue

3 participants