OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
foreign_storage::anonymous_namespace{TextFileBufferParser.cpp} Namespace Reference

Functions

bool set_coordinates_from_separate_lon_lat_columns (const std::string_view lon_str, const std::string_view lat_str, SQLTypeInfo &ti, std::vector< double > &coords, const bool is_lon_lat_order)
 

Function Documentation

bool foreign_storage::anonymous_namespace{TextFileBufferParser.cpp}::set_coordinates_from_separate_lon_lat_columns ( const std::string_view  lon_str,
const std::string_view  lat_str,
SQLTypeInfo ti,
std::vector< double > &  coords,
const bool  is_lon_lat_order 
)

Definition at line 129 of file TextFileBufferParser.cpp.

References Geospatial::GeoPoint::getColumns(), foreign_storage::TextFileBufferParser::isCoordinateScalar(), gpu_enabled::swap(), and SQLTypeInfo::transforms().

Referenced by foreign_storage::TextFileBufferParser::processGeoColumn().

133  {
134  double lon = std::atof(std::string(lon_str).c_str());
135  double lat = NAN;
136 
137  if (TextFileBufferParser::isCoordinateScalar(lat_str)) {
138  lat = std::atof(std::string(lat_str).c_str());
139  }
140 
141  // Swap coordinates if this table uses a reverse order: lat/lon
142  if (!is_lon_lat_order) {
143  std::swap(lat, lon);
144  }
145 
146  // TODO: should check if POINT column should have been declared with
147  // SRID WGS 84, EPSG 4326 ? if (col_ti.get_dimension() != 4326) {
148  // throw std::runtime_error("POINT column " + cd->columnName + " is
149  // not WGS84, cannot insert lon/lat");
150  // }
151 
152  if (std::isinf(lat) || std::isnan(lat) || std::isinf(lon) || std::isnan(lon)) {
153  return false;
154  }
155 
156  if (ti.transforms()) {
157  Geospatial::GeoPoint pt{std::vector<double>{lon, lat}};
158  if (!pt.transform(ti)) {
159  return false;
160  }
161  pt.getColumns(coords);
162  return true;
163  }
164 
165  coords.push_back(lon);
166  coords.push_back(lat);
167  return true;
168 }
void getColumns(std::vector< double > &coords) const
Definition: Types.cpp:568
bool transforms() const
Definition: sqltypes.h:624
DEVICE void swap(ARGS &&...args)
Definition: gpu_enabled.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function: