Skip to content

Processing: Reproject a vector layer #602

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/base/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ export function addCommands(
}
});

commands.addCommand(CommandIDs.reproject, {
label: trans.__('Reproject'),
isEnabled: () => selectedLayerIsOfType(['VectorLayer'], tracker),
execute: async () => {
await processSelectedLayer(tracker, formSchemaRegistry, 'Reproject', {
sqlQueryFn: (layerName, targetSRS) => `${targetSRS}`,
gdalFunction: 'ogr2ogr',
options: (sqlQuery: string) => ['-f', 'GeoJSON', '-t_srs', sqlQuery]
});
}
});

commands.addCommand(CommandIDs.newGeoJSONEntry, {
label: trans.__('New GeoJSON layer'),
isEnabled: () => {
Expand Down
1 change: 1 addition & 0 deletions packages/base/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export namespace CommandIDs {
// Processing commands
export const buffer = 'jupytergis:buffer';
export const dissolve = 'jupytergis:dissolve';
export const reproject = 'jupytergis:reproject';

// Sources only commands
export const newRasterSource = 'jupytergis:newRasterSource';
Expand Down
3 changes: 2 additions & 1 deletion packages/base/src/dialogs/ProcessingFormDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IProcessingFormDialogOptions extends IBaseFormProps {
parentType: 'dialog' | 'panel'
) => void;
model: IJupyterGISModel;
processingType: 'Buffer' | 'Dissolve' | 'Export';
processingType: 'Buffer' | 'Dissolve' | 'Export' | 'Reproject';
}

/**
Expand Down Expand Up @@ -52,6 +52,7 @@ const ProcessingFormWrapper = (props: IProcessingFormWrapperProps) => {
break;
case 'Buffer':
case 'Export':
case 'Reproject':
default:
FormComponent = BaseForm;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/base/src/processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type GdalFunctions =
export async function processSelectedLayer(
tracker: JupyterGISTracker,
formSchemaRegistry: IJGISFormSchemaRegistry,
processingType: 'Buffer' | 'Dissolve',
processingType: 'Buffer' | 'Dissolve' | 'Reproject',
processingOptions: {
sqlQueryFn: (layerName: string, param: any) => string;
gdalFunction: GdalFunctions;
Expand Down Expand Up @@ -150,6 +150,9 @@ export async function processSelectedLayer(
case 'Dissolve':
processParam = formValues.dissolveField;
break;
case 'Reproject':
processParam = formValues.targetCRS;
break;
default:
console.error(`Unsupported processing type: ${processingType}`);
return;
Expand Down Expand Up @@ -191,7 +194,7 @@ export async function executeSQLProcessing(
gdalFunction: GdalFunctions,
options: string[],
layerNamePrefix: string,
processingType: 'Buffer' | 'Dissolve',
processingType: 'Buffer' | 'Dissolve' | 'Reproject'
embedOutputLayer: boolean,
tracker: JupyterGISTracker,
app: JupyterFrontEnd
Expand Down
18 changes: 18 additions & 0 deletions packages/schema/src/schema/processing/reproject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "object",
"description": "Reproject",
"title": "IReproject",
"required": ["inputLayer", "targetCRS"],
"additionalProperties": false,
"properties": {
"inputLayer": {
"type": "string",
"description": "The input layer for reprojection."
},
"targetCRS": {
"type": "string",
"default": "EPSG:4326",
"description": "The target coordinate reference system (CRS) for reprojection."
}
}
}
1 change: 1 addition & 0 deletions packages/schema/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './_interface/project/layers/heatmapLayer';
// Processing
export * from './_interface/processing/buffer';
export * from './_interface/processing/dissolve';
export * from './_interface/processing/reproject';

// exportLayer
export * from './_interface/export/exportGeojson';
Expand Down
4 changes: 4 additions & 0 deletions python/jupytergis_lab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
command: CommandIDs.dissolve
});

processingSubmenu.addItem({
command: CommandIDs.reproject
});

app.contextMenu.addItem({
type: 'submenu',
selector: '.jp-gis-layerItem',
Expand Down
Loading