Skip to content

Fix slowness on proj_create_crs_to_crs() on WGS 84 <--> UTM conversions #4319

@plumewind

Description

@plumewind

problem

When using proj-9.5.0, find very slow on proj_create_crs_to_crs().
My code like this:

  int zone = static_cast<int>((lon_rad * 180 / M_PI + 180) / 6) + 1;
  std::string latlon_src =
      "+proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs";
  std::string utm_dst =
      absl::StrCat("+proj=utm +zone=", zone, " +ellps=GRS80 +units=m +no_defs");

  PJ_CONTEXT *C = proj_context_create();
  PJ *pj_latlon =
      proj_create_crs_to_crs(C, latlon_src.c_str(), utm_dst.c_str(), NULL);
  if (0 == pj_latlon) {
    fprintf(stderr, "Failed to create transformation object.\n");
    return false;
  }

  PJ *norm = proj_normalize_for_visualization(C, pj_latlon);
  if (0 == norm) {
    fprintf(stderr, "Failed to normalize transformation object.\n");
    return false;
  }
  proj_destroy(pj_latlon);
  pj_latlon = norm;

  PJ_COORD a = proj_coord(lon_rad * RAD_TO_DEG, lat_rad * RAD_TO_DEG, 0, 0);
  PJ_COORD b = proj_trans(pj_latlon, PJ_FWD, a);
  utm_xy->x = b.xy.x;
  utm_xy->y = b.xy.y;

  proj_destroy(pj_latlon);
  proj_context_destroy(C); 

Problem description

When I was processing the conversion, I found that the process was very slow. Then, I counted the time taken for each process and found the following:
image

Expected Output

Normally, this process on proj_create_crs_to_crs() should be very fast, almost 0 milliseconds.

Environment Information

  • PROJ version (proj-9.5.0)
  • Operation System Information (ubuntu 20.04)

Installation method

mkdir -p build           
cd ./build              
cmake .. -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=/opt 
 -DCMAKE_BUILD_TYPE=Release
make
sudo make install

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions