mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[file upload] verify CRS for geojson upload (#148403)
Fixes https://github.com/elastic/kibana/issues/146420 and https://github.com/elastic/kibana/issues/138128 PR adds verification logic to ensure Geojson is correct CRS Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
ecf18dbc06
commit
312586043b
2 changed files with 94 additions and 0 deletions
|
@ -278,4 +278,74 @@ describe('previewFile', () => {
|
|||
expect(results.features).toEqual([]);
|
||||
expect(results.invalidFeatures.length).toBe(2);
|
||||
});
|
||||
|
||||
describe('crs', () => {
|
||||
test('should read features with supported CRS', async () => {
|
||||
const file = new File(
|
||||
[
|
||||
JSON.stringify({
|
||||
...FEATURE_COLLECTION,
|
||||
crs: {
|
||||
type: 'name',
|
||||
properties: {
|
||||
name: 'urn:ogc:def:crs:OGC:1.3:CRS84',
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
'testfile.json',
|
||||
{ type: 'text/json' }
|
||||
);
|
||||
|
||||
const importer = new GeoJsonImporter(file);
|
||||
const results = await importer.previewFile();
|
||||
|
||||
expect(results).toEqual({
|
||||
previewCoverage: 100,
|
||||
hasPoints: true,
|
||||
hasShapes: false,
|
||||
features: FEATURE_COLLECTION.features,
|
||||
invalidFeatures: [],
|
||||
});
|
||||
});
|
||||
|
||||
test('should reject "link" CRS', async () => {
|
||||
const file = new File(
|
||||
[
|
||||
JSON.stringify({
|
||||
...FEATURE_COLLECTION,
|
||||
crs: {
|
||||
type: 'link',
|
||||
},
|
||||
}),
|
||||
],
|
||||
'testfile.json',
|
||||
{ type: 'text/json' }
|
||||
);
|
||||
|
||||
const importer = new GeoJsonImporter(file);
|
||||
await expect(importer.previewFile()).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('should reject unsupported CRS', async () => {
|
||||
const file = new File(
|
||||
[
|
||||
JSON.stringify({
|
||||
...FEATURE_COLLECTION,
|
||||
crs: {
|
||||
type: 'name',
|
||||
properties: {
|
||||
name: 'urn:ogc:def:crs:EPSG::25833',
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
'testfile.json',
|
||||
{ type: 'text/json' }
|
||||
);
|
||||
|
||||
const importer = new GeoJsonImporter(file);
|
||||
await expect(importer.previewFile()).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,6 +13,8 @@ import { AbstractGeoFileImporter } from '../abstract_geo_file_importer';
|
|||
|
||||
export const GEOJSON_FILE_TYPES = ['.json', '.geojson'];
|
||||
|
||||
const SUPPORTED_CRS_LIST = ['EPSG:4326', 'urn:ogc:def:crs:OGC:1.3:CRS84'];
|
||||
|
||||
interface LoaderBatch {
|
||||
bytesUsed?: number;
|
||||
batchType?: string;
|
||||
|
@ -51,6 +53,28 @@ export class GeoJsonImporter extends AbstractGeoFileImporter {
|
|||
|
||||
const { value: batch, done } = await this._iterator.next();
|
||||
|
||||
// geojson only supports WGS 84 datum, with longitude and latitude units of decimal degrees.
|
||||
// https://datatracker.ietf.org/doc/html/rfc7946#section-4
|
||||
// Deprecated geojson specification supported crs
|
||||
// https://geojson.org/geojson-spec.html#named-crs
|
||||
// This importer only supports WGS 84 datum
|
||||
if (typeof batch?.container?.crs === 'object') {
|
||||
const crs = batch.container.crs as { type?: string; properties?: { name?: string } };
|
||||
if (
|
||||
crs?.type === 'link' ||
|
||||
(crs?.type === 'name' && !SUPPORTED_CRS_LIST.includes(crs?.properties?.name ?? ''))
|
||||
) {
|
||||
throw new Error(
|
||||
i18n.translate('xpack.fileUpload.geojsonImporter.unsupportedCrs', {
|
||||
defaultMessage: 'Unsupported coordinate reference system, expecting {supportedCrsList}',
|
||||
values: {
|
||||
supportedCrsList: SUPPORTED_CRS_LIST.join(', '),
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._getIsActive() || done) {
|
||||
results.hasNext = false;
|
||||
return results;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue