Skip to content

Commit e2d915f

Browse files
Gauss-Taylor-Eulerelifsu-simula
authored andcommitted
Processing: Bounding boxes of a vector layer(geojupyter#734) (geojupyter#744)
* Processing: Bounding boxes of a vector layer(geojupyter#734) * Change Bounding Boxes and Centroids labels to correspond to qgis naming convention
1 parent c9491e8 commit e2d915f

File tree

9 files changed

+66
-4
lines changed

9 files changed

+66
-4
lines changed

packages/base/src/commands.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,35 @@ export function addCommands(
410410
},
411411
});
412412

413+
commands.addCommand(CommandIDs.boundingBoxes, {
414+
label: trans.__('Bounding Boxes'),
415+
isEnabled: () => selectedLayerIsOfType(['VectorLayer'], tracker),
416+
execute: async () => {
417+
await processSelectedLayer(
418+
tracker,
419+
formSchemaRegistry,
420+
'BoundingBoxes',
421+
{
422+
sqlQueryFn: (layerName, _) => `
423+
SELECT ST_Envelope(geometry) AS geometry, *
424+
FROM "${layerName}"
425+
`,
426+
gdalFunction: 'ogr2ogr',
427+
options: (sqlQuery: string) => [
428+
'-f',
429+
'GeoJSON',
430+
'-dialect',
431+
'SQLITE',
432+
'-sql',
433+
sqlQuery,
434+
'output.geojson',
435+
],
436+
},
437+
app,
438+
);
439+
},
440+
});
441+
413442
commands.addCommand(CommandIDs.newGeoJSONEntry, {
414443
label: trans.__('New GeoJSON layer'),
415444
isEnabled: () => {

packages/base/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export namespace CommandIDs {
4141
export const buffer = 'jupytergis:buffer';
4242
export const dissolve = 'jupytergis:dissolve';
4343
export const centroids = 'jupytergis:centroids';
44+
export const boundingBoxes = 'jupytergis:boundingBoxes';
4445

4546
// Layer and group actions
4647
export const renameLayer = 'jupytergis:renameLayer';

packages/base/src/dialogs/ProcessingFormDialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export interface IProcessingFormDialogOptions extends IBaseFormProps {
2222
parentType: 'dialog' | 'panel',
2323
) => void;
2424
model: IJupyterGISModel;
25-
processingType: 'Buffer' | 'Dissolve' | 'Export' | 'Centroids';
25+
processingType:
26+
| 'Buffer'
27+
| 'Dissolve'
28+
| 'Export'
29+
| 'Centroids'
30+
| 'BoundingBoxes';
2631
}
2732

2833
/**
@@ -57,6 +62,7 @@ const ProcessingFormWrapper = (props: IProcessingFormWrapperProps) => {
5762
case 'Buffer':
5863
case 'Export':
5964
case 'Centroids':
65+
case 'BoundingBoxes':
6066
default:
6167
FormComponent = BaseForm;
6268
}

packages/base/src/processing.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type GdalFunctions =
9191
export async function processSelectedLayer(
9292
tracker: JupyterGISTracker,
9393
formSchemaRegistry: IJGISFormSchemaRegistry,
94-
processingType: 'Buffer' | 'Dissolve' | 'Centroids',
94+
processingType: 'Buffer' | 'Dissolve' | 'Centroids' | 'BoundingBoxes',
9595
processingOptions: {
9696
sqlQueryFn: (layerName: string, param: any) => string;
9797
gdalFunction: GdalFunctions;
@@ -154,6 +154,9 @@ export async function processSelectedLayer(
154154
case 'Centroids':
155155
processParam = null;
156156
break;
157+
case 'BoundingBoxes':
158+
processParam = null;
159+
break;
157160
default:
158161
console.error(`Unsupported processing type: ${processingType}`);
159162
return;
@@ -195,7 +198,7 @@ export async function executeSQLProcessing(
195198
gdalFunction: GdalFunctions,
196199
options: string[],
197200
layerNamePrefix: string,
198-
processingType: 'Buffer' | 'Dissolve' | 'Centroids',
201+
processingType: 'Buffer' | 'Dissolve' | 'Centroids' | 'BoundingBoxes',
199202
embedOutputLayer: boolean,
200203
tracker: JupyterGISTracker,
201204
app: JupyterFrontEnd,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "object",
3+
"description": "BoundingBoxes",
4+
"title": "IBoundingBoxes",
5+
"required": ["inputLayer"],
6+
"additionalProperties": false,
7+
"properties": {
8+
"inputLayer": {
9+
"type": "string",
10+
"description": "The input layer for bounding boxes."
11+
}
12+
}
13+
}

packages/schema/src/schema/processing/centroids.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"properties": {
88
"inputLayer": {
99
"type": "string",
10-
"description": "The input layer for buffering."
10+
"description": "The input layer for centroids."
1111
}
1212
}
1313
}

packages/schema/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export * from './_interface/project/layers/heatmapLayer';
2323
export * from './_interface/processing/buffer';
2424
export * from './_interface/processing/dissolve';
2525
export * from './_interface/processing/centroids';
26+
export * from './_interface/processing/boundingBoxes';
2627

2728
// exportLayer
2829
export * from './_interface/export/exportGeojson';

python/jupytergis_core/src/jgisplugin/plugins.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ const activate = async (
244244
command: CommandIDs.centroids,
245245
category: 'JupyterGIS',
246246
});
247+
248+
palette.addItem({
249+
command: CommandIDs.boundingBoxes,
250+
category: 'JupyterGIS',
251+
});
247252
}
248253
};
249254

python/jupytergis_lab/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
161161
command: CommandIDs.centroids,
162162
});
163163

164+
processingSubmenu.addItem({
165+
command: CommandIDs.boundingBoxes,
166+
});
167+
164168
app.contextMenu.addItem({
165169
type: 'submenu',
166170
selector: '.jp-gis-layerItem',

0 commit comments

Comments
 (0)