Skip to content

Commit 24b9e82

Browse files
committed
Allow user to specify as_geo to create geoparquet files as opposed to plain vanilla parquet #719
WIP
1 parent 7673886 commit 24b9e82

File tree

5 files changed

+113
-153
lines changed

5 files changed

+113
-153
lines changed

web-client/src/components/SrAnalysisMap.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
console.log(msg);
152152
if(newReqId !== oldReqId){
153153
if(newReqId > 0){
154-
await fieldNameStore.loadRecordInfoForReqId(newReqId); // async but don't await
154+
await fieldNameStore.loadMetaForReqId(newReqId); // async but don't await
155155
globalChartStore.setAllColumnMinMaxValues({}); // reset all min/max values
156156
await updateAnalysisMapView('watch selectedReqId');
157157
} else {
@@ -175,7 +175,7 @@
175175
176176
onMounted(async () => {
177177
console.log("SrAnalysisMap onMounted using selectedReqId:",props.selectedReqId);
178-
await fieldNameStore.loadRecordInfoForReqId(props.selectedReqId); // async but don't await
178+
await fieldNameStore.loadMetaForReqId(props.selectedReqId); // async but don't await
179179
// Bind the tooltipRef to the store
180180
if (tooltipRef.value) {
181181
analysisMapStore.tooltipRef = tooltipRef.value;

web-client/src/components/SrExportDialog.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { createDuckDbClient } from '@/utils/SrDuckDb';
5353
import { useSrParquetCfgStore } from '@/stores/srParquetCfgStore';
5454
import {getArrowFetchUrlAndOptions} from "@/utils/fetchUtils";
5555
import { exportCsvStreamed, getWritableFileStream } from "@/utils/SrParquetUtils";
56+
import { useFieldNameStore } from '@/stores/fieldNameStore';
5657
5758
5859
const props = defineProps<{
@@ -65,17 +66,28 @@ const emit = defineEmits<{
6566
}>();
6667
6768
const toast = useToast();
69+
const fieldNameStore = useFieldNameStore();
6870
const visible = ref(props.modelValue);
6971
const exporting = ref(false);
7072
const selectedFormat = ref<'csv' | 'parquet' | 'geoparquet' | null>(null);
7173
const headerCols = ref<string[]>([]);
7274
const rowCount = ref<number | null>(null);
7375
74-
const formats = [
75-
{ label: 'CSV', value: 'csv' },
76-
{ label: 'Parquet', value: 'parquet' },
77-
{ label: 'GeoParquet', value: 'geoparquet' },
78-
];
76+
const formats = computed(() => {
77+
const isGeo = fieldNameStore.isGeoParquet(props.reqId);
78+
if (isGeo) {
79+
return [
80+
{ label: 'GeoParquet', value: 'geoparquet' },
81+
{ label: 'CSV', value: 'csv' },
82+
];
83+
} else {
84+
return [
85+
{ label: 'CSV', value: 'csv' },
86+
{ label: 'Parquet', value: 'parquet' },
87+
{ label: 'GeoParquet', value: 'geoparquet' },
88+
];
89+
}
90+
});
7991
8092
const estimatedSizeMB = computed(() => {
8193
if (rowCount.value !== null && headerCols.value.length > 0) {
@@ -135,7 +147,7 @@ const handleExport = async () => {
135147
if (!fileName) throw new Error("Filename not found");
136148
let status = false;
137149
if (selectedFormat.value === 'csv') {
138-
status = await exportCsvStreamed(fileName,headerCols,true);
150+
status = await exportCsvStreamed(fileName,headerCols);
139151
} else if(selectedFormat.value === 'parquet') {
140152
status = await exportParquet(fileName);
141153
} else if(selectedFormat.value === 'geoparquet') {

web-client/src/stores/fieldNameStore.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useRecTreeStore } from '@/stores/recTreeStore'; // Adjust import path i
44
import { useChartStore } from './chartStore';
55
import { createDuckDbClient } from '@/utils/SrDuckDb';
66
import { db } from '@/db/SlideRuleDb';
7+
import type { SrSvrParmsUsed } from '@/types/SrTypes';
78

89
const curGedi2apElFieldOptions = ref(['elevation_lm','elevation_hr']);
910
const curGedi2apElevationField = ref('elevation_lm');
@@ -199,7 +200,6 @@ function getDefaultColorEncoding(funcStr: string,parentFuncStr?:string): string
199200

200201
interface RecordInfo {
201202
time?: string;
202-
as_geo?: boolean;
203203
x: string;
204204
y: string;
205205
z?: string;
@@ -211,9 +211,12 @@ export const useFieldNameStore = defineStore('fieldNameStore', () => {
211211
const lonFieldCache = ref<Record<number, string>>({});
212212
const timeFieldCache = ref<Record<number, string>>({});
213213
const recordInfoCache = ref<Record<number, RecordInfo | null>>({});
214+
const asGeoCache = ref<Record<number, boolean>>({});
214215

215216
const recTreeStore = useRecTreeStore();
216217

218+
219+
217220
/**
218221
* Fetch recordinfo metadata from parquet file for a given reqId
219222
* This will cache the result to avoid repeated DB queries
@@ -279,7 +282,7 @@ export const useFieldNameStore = defineStore('fieldNameStore', () => {
279282

280283
/**
281284
* Synchronous field name getters - these check recordinfo cache first (if pre-loaded),
282-
* then fall back to hardcoded values. Call loadRecordInfoForReqId() first to populate cache.
285+
* then fall back to hardcoded values. Call loadMetaForReqId() first to populate cache.
283286
*/
284287
function getHFieldName(reqId: number): string {
285288
// Check if we have recordinfo in cache
@@ -330,22 +333,42 @@ export const useFieldNameStore = defineStore('fieldNameStore', () => {
330333
}
331334

332335
/**
333-
* Async function to pre-load recordinfo metadata for a reqId.
334-
* Call this early (e.g., after loading a parquet file) to populate the cache,
335-
* so that subsequent synchronous getters can use recordinfo values.
336+
* Load as_geo flag from server parameters for a given reqId
337+
* This checks the output.as_geo field from the request's server parameters
336338
*/
337-
async function loadRecordInfoForReqId(reqId: number): Promise<RecordInfo | null> {
338-
return await getRecordInfoForReqId(reqId);
339+
async function loadAsGeoFromSvrParams(reqId: number): Promise<void> {
340+
try {
341+
const svrParams = await db.getSvrParams(reqId) as SrSvrParmsUsed;
342+
const asGeo = svrParams?.output?.as_geo === true;
343+
asGeoCache.value[reqId] = asGeo;
344+
if (asGeo) {
345+
console.log(`Request ${reqId} has as_geo=true in server params`);
346+
}
347+
} catch (error) {
348+
console.warn(`Error loading as_geo from server params for reqId ${reqId}:`, error);
349+
asGeoCache.value[reqId] = false;
350+
}
339351
}
340352

341353
/**
342354
* Check if the parquet file for a given reqId is in GeoParquet format.
343-
* This checks the as_geo property from the recordinfo metadata.
344-
* Returns false if recordinfo is not cached or as_geo is not set.
355+
* This checks the as_geo property from the server parameters.
356+
* Returns false if not cached.
345357
*/
346358
function isGeoParquet(reqId: number): boolean {
347-
const recordInfo = recordInfoCache.value[reqId];
348-
return recordInfo?.as_geo === true;
359+
return asGeoCache.value[reqId] === true;
360+
}
361+
362+
/**
363+
* Async function to pre-load recordinfo metadata for a reqId.
364+
* Call this early (e.g., after loading a parquet file) to populate the cache,
365+
* so that subsequent synchronous getters can use recordinfo values.
366+
*/
367+
async function loadMetaForReqId(reqId: number): Promise<RecordInfo | null> {
368+
const recordInfo = await getRecordInfoForReqId(reqId);
369+
// Also load as_geo flag from server parameters
370+
await loadAsGeoFromSvrParams(reqId);
371+
return recordInfo;
349372
}
350373

351374
return {
@@ -363,13 +386,15 @@ export const useFieldNameStore = defineStore('fieldNameStore', () => {
363386
curGedi2apElFieldOptions,
364387
curGedi2apElevationField,
365388
isGeoParquet,
389+
loadAsGeoFromSvrParams,
366390
// for debugging/testing
367391
hFieldCache,
368392
latFieldCache,
369393
lonFieldCache,
370394
timeFieldCache,
371395
recordInfoCache,
396+
asGeoCache,
372397
getRecordInfoForReqId,
373-
loadRecordInfoForReqId,
398+
loadMetaForReqId,
374399
};
375400
});

web-client/src/types/SrTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface Region {
7777
export interface SrSvrParmsUsed extends SrRequestPayload {
7878
server?: Server;
7979
poly?: LatLon[]; // supports atl24x and new format TBD
80+
output: OutputFormat;
8081
recordinfo?: RecordInfo;
8182
atl24?: {};
8283
atl08?: {};

0 commit comments

Comments
 (0)