OmniSciDB  5ade3759e0
geo_compression.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
24 #ifndef SHARED_GEO_COMPRESSION_H
25 #define SHARED_GEO_COMPRESSION_H
26 
27 #include "funcannotations.h"
28 
29 namespace Geo_namespace {
30 
31 DEVICE inline double decompress_longitude_coord_geoint32(const int32_t compressed) {
32  // decompress longitude: -2,147,483,647..2,147,483,647 ---> -180..180
33  return static_cast<double>(compressed) *
34  8.3819031754424345e-08; // (180.0 / 2147483647.0)
35 }
36 
37 DEVICE inline double decompress_lattitude_coord_geoint32(const int32_t compressed) {
38  // decompress latitude: -2,147,483,647..2,147,483,647 ---> -90..90
39  return static_cast<double>(compressed) *
40  4.1909515877212172e-08; // // (90.0 / 2147483647.0)
41 }
42 
43 DEVICE inline uint64_t compress_longitude_coord_geoint32(const double coord) {
44  // compress longitude: -180..180 ---> -2,147,483,647..2,147,483,647
45  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 180.0));
46  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
47 }
48 
49 DEVICE inline uint64_t compress_lattitude_coord_geoint32(const double coord) {
50  // compress latitude: -90..90 ---> -2,147,483,647..2,147,483,647
51  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 90.0));
52  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
53 }
54 
55 }; // namespace Geo_namespace
56 
57 #endif // SHARED_GEO_COMPRESSION_H
#define DEVICE
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
DEVICE uint64_t compress_lattitude_coord_geoint32(const double coord)
DEVICE double decompress_lattitude_coord_geoint32(const int32_t compressed)
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)