Skip to content
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

Add capability to quantize geometry coordinates for higher compression efficiency #6974

Closed
wants to merge 4 commits into from

Conversation

rouault
Copy link
Member

@rouault rouault commented Dec 22, 2022

and GPKG: add creation options to quantify coordinates

-  **XY_QUANTIZED_PRECISION** =float or string. (GDAL >= 3.7)
   Desired precision for X/Y coordinate quantization.
   This parameter will influence the number of nullified
   least significant bits in the mantissa of the binary representation of
   coordinates as IEEE-754 double-precision floating-point numbers.
   This is only useful if the file is compressed.
   By default, the value is understood as expressed in the units of the CRS
   of the layer (for example, for a geographic Earth CRS, "8.9e-9" corresponds
   to a millimetric precision), unless the 'm', 'cm' or 'mm' suffixes are added
   to express respectively the value in metre, centimetre or millimetre (will work
   for a geographic or projected CRS). For example, "1 mm" for a millimetric
   precision.
-  **Z_QUANTIZED_PRECISION** =float or string. (GDAL >= 3.7)
   Desired precision for Z coordinate quantization.
   This parameter will influence the number of nullified
   least significant bits in the mantissa of the binary representation of
   coordinates as IEEE-754 double-precision floating-point numbers.
   This is only useful if the file is compressed.
   By default, the value is understood as expressed in the units of the CRS
   of the layer, unless the 'm', 'cm' or 'mm' suffixes are added
   to express respectively the value in metre, centimetre or millimetre (will work
   for a geographic or projected CRS). For example, "1 mm" for a millimetric
   precision.
-  **M_QUANTIZED_PRECISION** =float. (GDAL >= 3.7)
   Desired precision for M coordinate quantization.
   This parameter will influence the number of nullified
   least significant bits in the mantissa of the binary representation of
   coordinates as IEEE-754 double-precision floating-point numbers.
   This is only useful if the file is compressed.

and ogr2ogr: add -xy_quantized_prec/-z_quantized_prec/-m_quantized_prec options

On a test dataset, setting XY_QUANTIZED_PRECISION=0.001m reduces the size of the .zip of the .gpkg file from 766 MB to 667 MB (13% size decrease).

@rouault rouault added this to the 3.7.0 milestone Dec 22, 2022
@rouault rouault force-pushed the wkb_nullify_bits branch 2 times, most recently from 8207c3d to 645aafc Compare December 22, 2022 18:03
@rouault rouault marked this pull request as draft December 22, 2022 21:12
@rouault rouault force-pushed the wkb_nullify_bits branch 3 times, most recently from 7183b49 to deba99c Compare December 26, 2022 11:49
@rouault rouault marked this pull request as ready for review December 26, 2022 11:50
@rouault rouault force-pushed the wkb_nullify_bits branch 2 times, most recently from 84eff93 to 4c309ca Compare December 26, 2022 16:07
@rouault rouault changed the title Geometry WKB export: add option to nullify some bits of coordinates Add capability to quantize geometry coordinates for higher compression efficiency Dec 26, 2022
@rouault rouault force-pushed the wkb_nullify_bits branch 6 times, most recently from 6ef9774 to 79335a2 Compare December 27, 2022 11:30
…es with settings to quantize coordinates

The following C functions are added:
```

/** Opaque type for geometry precision options */
typedef struct OGRPrecisionOptions OGRPrecisionOptions;

OGRPrecisionOptions CPL_DLL *OGRPrecisionOptionsCreate(void);
void CPL_DLL OGRPrecisionOptionsDestroy(OGRPrecisionOptions *);
void CPL_DLL OGRPrecisionOptionsSetPrecision(OGRPrecisionOptions *,
                                             double dfXYPrecision,
                                             double dfZPrecision,
                                             double dfMPrecision);
void CPL_DLL OGRPrecisionOptionsSetMetricPrecision(OGRPrecisionOptions *,
                                                   OGRSpatialReferenceH hSRS,
                                                   double dfXYMetricPrecision,
                                                   double dfZMetricPrecision,
                                                   double dfMPrecision);
/** Opaque type for WKB export options */
typedef struct OGRwkbExportOptions OGRwkbExportOptions;

OGRwkbExportOptions CPL_DLL *OGRwkbExportOptionsCreate(void);
void CPL_DLL OGRwkbExportOptionsDestroy(OGRwkbExportOptions *);
OGRwkbByteOrder CPL_DLL
OGRwkbExportOptionsGetByteOrder(const OGRwkbExportOptions *);
void CPL_DLL OGRwkbExportOptionsSetByteOrder(OGRwkbExportOptions *,
                                             OGRwkbByteOrder);
OGRwkbVariant CPL_DLL
OGRwkbExportOptionsGetVariant(const OGRwkbExportOptions *);
void CPL_DLL OGRwkbExportOptionsSetVariant(OGRwkbExportOptions *,
                                           OGRwkbVariant);
void CPL_DLL OGRwkbExportOptionsSetPrecision(OGRwkbExportOptions *,
                                             const OGRPrecisionOptions *);
OGRErr CPL_DLL OGR_G_ExportToWkbEx(OGRGeometryH, unsigned char *,
                                   const OGRwkbExportOptions *);

```
-  **XY_QUANTIZED_PRECISION** =float or string. (GDAL >= 3.7)
   Desired precision for X/Y coordinate quantization.
   This parameter will influence the number of nullified
   least significant bits in the mantissa of the binary representation of
   coordinates as IEEE-754 double-precision floating-point numbers.
   This is only useful if the file is compressed.
   By default, the value is understood as expressed in the units of the CRS
   of the layer (for example, for a geographic Earth CRS, "8.9e-9" corresponds
   to a millimetric precision), unless the 'm' suffix is added to express the
   value in metre (will work for a geographic or projected CRS). For example,
   "0.001 m" for a millimetric precision.
-  **Z_QUANTIZED_PRECISION** =float or string. (GDAL >= 3.7)
   Desired precision for Z coordinate quantization.
   This parameter will influence the number of nullified
   least significant bits in the mantissa of the binary representation of
   coordinates as IEEE-754 double-precision floating-point numbers.
   This is only useful if the file is compressed.
   By default, the value is understood as expressed in the units of the CRS
   of the layer, unless the 'm' suffix is added to express the
   value in metre (will work for a geographic or projected CRS). For example,
   "0.001 m" for a millimetric precision.
-  **M_QUANTIZED_PRECISION** =float. (GDAL >= 3.7)
   Desired precision for M coordinate quantization.
   This parameter will influence the number of nullified
   least significant bits in the mantissa of the binary representation of
   coordinates as IEEE-754 double-precision floating-point numbers.
   This is only useful if the file is compressed.
Copy link
Collaborator

@elpaso elpaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I admit I've got lost in the WKB bit manipulations.

ogr/ogr_geometry.h Outdated Show resolved Hide resolved
*
* @since GDAL 3.7
*/
template <int SPACING>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a template and not a simple argument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To generate better assembly code. ptr + variable * constant can be expressed into a single assembly mnemonic

Co-authored-by: Alessandro Pasotti <elpaso@itopen.it>
@rouault
Copy link
Member Author

rouault commented Feb 20, 2023

I'm putting this on hold because I'm wondering if that shouldn't be part of a larger "framework" to convey coordinate precision between drivers

@rouault
Copy link
Member Author

rouault commented Mar 6, 2024

closing as superseded per #9378

@rouault rouault closed this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants