geeViz.eeAuth.vector_convert

Convert an uploaded vector file to a GeoJSON FeatureCollection in EPSG:4326.

Backs POST <proxy base>/convert/vector on both servers that serve the geeViz viewer: the eeAuth proxy app (geeViz.eeAuth.server, mounted at /ee-api) and geeViz’s own local static server (geeView._GeeVizRequestHandler, for direct-token mode). Both call handle_upload(), so the two behave the same.

Reads with GDAL in-process through pyogrio (its wheels bundle GDAL with the LIBKML driver); nothing is shelled out and no third-party service is contacted. Supported: a zipped shapefile (.zip), KML, KMZ, GeoJSON (.geojson/.json), GeoPackage, GPX and FlatGeobuf. Every layer is read and merged; each feature gets a layer property naming its layer (a source field already called layer is kept as layer_original), and the response says when layers were combined.

Uploads are untrusted, so:

  • the upload, the unpacked size and the zip member count are capped (see the limits below);

  • zips and KMZs are unpacked by this module, never by GDAL, into a fresh temp dir, refusing members that would land outside it (zip slip), symbolic links and encrypted members, and counting the bytes actually written; only vector files and shapefile sidecars are unpacked;

  • text files carrying GDAL’s VRT or streamed-algorithm markers are refused before GDAL opens them (both can read other local files), and each layer’s driver must be one expected for its extension;

  • raster files are refused;

  • more features or vertices than the caps is an error, never a silent truncation;

  • conversion runs in a worker thread with a timeout and at most MAX_CONCURRENT at once, and the temp dir is always removed.

The endpoints add no CORS headers (same as the proxy’s other routes) and refuse browser requests marked Sec-Fetch-Site: cross-site.

Functions

convert_bytes(filename, data)

Convert one uploaded file.

handle_upload(headers, body)

Convert a request: (status, JSON bytes).

is_convert_path(path[, prefix])

True for <prefix>/convert/vector and <prefix>/t/<tenant>/convert/vector.

max_body_bytes()

oversize_reply()

(413, body) for a body found to be over max_body_bytes() while reading.

parse_multipart(content_type, body)

(filename, bytes) of the one file in a multipart/form-data body.

request_rejection(headers)

(status, body) to send without reading the body, or None.

Exceptions

ConvertError(error[, hint, status])

A conversion that cannot be done; error and hint go to the user.

exception geeViz.eeAuth.vector_convert.ConvertError(error, hint='', status=400)[source]

Bases: Exception

A conversion that cannot be done; error and hint go to the user.

payload()[source]
geeViz.eeAuth.vector_convert.is_convert_path(path, prefix='/ee-api')[source]

True for <prefix>/convert/vector and <prefix>/t/<tenant>/convert/vector.

geeViz.eeAuth.vector_convert.convert_bytes(filename, data)[source]

Convert one uploaded file. Returns a GeoJSON FeatureCollection dict.

Foreign members: layers ([{name, features}]) and notes (plain-language sentences: layers combined, reprojection, a missing projection read as longitude/latitude). Raises ConvertError.

geeViz.eeAuth.vector_convert.parse_multipart(content_type, body)[source]

(filename, bytes) of the one file in a multipart/form-data body.

geeViz.eeAuth.vector_convert.request_rejection(headers)[source]

(status, body) to send without reading the body, or None.

Refuses cross-site browser posts and declared oversize bodies.

geeViz.eeAuth.vector_convert.max_body_bytes()[source]
geeViz.eeAuth.vector_convert.oversize_reply()[source]

(413, body) for a body found to be over max_body_bytes() while reading.

geeViz.eeAuth.vector_convert.handle_upload(headers, body)[source]

Convert a request: (status, JSON bytes). Never raises.

headers is any mapping of request headers; body the raw request body, read by the caller up to max_body_bytes() plus one.