# vtkGeoTransform and vtkGeoProjection - how the heck to use them?

**URL:** https://discourse.vtk.org/t/vtkgeotransform-and-vtkgeoprojection-how-the-heck-to-use-them/6898
**Category:** Support
**Created:** [October 15, 2021, 7:48pm UTC](https://discourse.vtk.org/t/vtkgeotransform-and-vtkgeoprojection-how-the-heck-to-use-them/6898 "2021-10-15T19:48:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tomasso](https://discourse.vtk.org/user_avatar/discourse.vtk.org/tomasso/32/5786_2.png) [@Tomasso](https://discourse.vtk.org/u/Tomasso)
#### Post date: [October 15, 2021, 7:48pm UTC](https://discourse.vtk.org/t/vtkgeotransform-and-vtkgeoprojection-how-the-heck-to-use-them/6898/1 "2021-10-15T19:48:39Z")

</div>

My vtk-8 C++ app reads [GMT grid files](https://docs.generic-mapping-tools.org/6.2/cookbook/file-formats.html#grid-files) that contain latitude/longitude (degrees) and elevation (meters) into a VtkPointArray. I would like to display the data in various map projections, including Universal Transverse Mercator (UTM). The [vtkGeoTransform](https://vtk.org/doc/nightly/html/classvtkGeoTransform.html) and [VtkGeoProjection](https://vtk.org/doc/nightly/html/classvtkGeoProjection.html) classes looks like they will do what I need, but I haven’t found any concrete examples that use them. Given my dataset where x and y are longitude-latitude, how exactly do I transform the x-y values to UTM easting and northing?

Some code details below - thanks for your help!

Here is code from my GmtGridReader class:

```auto
  // Load points read from grid file
  std::cerr << "GmtGridReader::RequestData() - load points" << std::endl;    
  for (unsigned row = 0; row < gmtGrid_->header->n_rows; row++) {
    for (unsigned col = 0; col < gmtGrid_->header->n_columns; col++) {
      // print debug info
      // fprintf(stderr, "1) x[%d]: %.8f\n", col, gmtGrid_->x[col]);
 
      unsigned dataIndex = GMT_Get_Index(gmtApi, gmtGrid_->header, row, col);
 
      vtkIdType id = gridPoints_->InsertNextPoint(gmtGrid_->x[col],
                                                  gmtGrid_->y[row],
                                                  gmtGrid_->data[dataIndex]);   
    }
  }

```

Here is code that builds the pipeline:

```auto
   // The GmtGridReader outputs data as longitude/latitude/elevation
   vtkSmartPointer<mb_system::GmtGridReader> reader =
     vtkSmartPointer<mb_system::GmtGridReader>::New();
   
   // Read the grid file. 
   reader->SetFileName ( filePath.c_str() );
   reader->Update();
 
   // Get elevation range for elevation colorizer...
   float zMin, zMax;
   reader->zBounds(&zMin, &zMax);

   // Color data points based on z-value
   vtkSmartPointer<vtkElevationFilter> elevationFilter =
     vtkSmartPointer<vtkElevationFilter>::New();

   elevationFilter->SetInputConnection(reader->GetOutputPort());
   elevationFilter->SetLowPoint(0, 0, zMin);
   elevationFilter->SetHighPoint(0, 0, zMax);
   
   // Create renderer
   vtkSmartPointer<vtkRenderer> renderer =
      vtkSmartPointer<vtkRenderer>::New();

   // Create gridMapper
   vtkSmartPointer<vtkPolyDataMapper> gridMapper =
      vtkSmartPointer<vtkPolyDataMapper>::New();

   gridMapper->SetInputConnection(elevationFilter->GetOutputPort());

```

So where and how exactly do I transform the longitude/latitude values to UTM (easting and northing) values?

Thanks!  
Tom

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [October 16, 2021, 8:25am UTC](https://discourse.vtk.org/t/vtkgeotransform-and-vtkgeoprojection-how-the-heck-to-use-them/6898/2 "2021-10-16T08:25:17Z")

</div>

In the vtk-examples there is a deprecated example that may be of use [GeoGraticle](https://gitlab.kitware.com/vtk/vtk-examples/-/blob/master/src/Cxx/Deprecated/Geovis/GeoGraticle.cxx). You can also look in the testing folders of the VTK source, the test is: [TestGeoProjection](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Geovis/Core/Testing/Cxx/TestGeoProjection.cxx). There may be more tests in VTK 8, most of these classes were deprecated back in 2018. In looking at this [GeoVis/Core](https://gitlab.kitware.com/vtk/vtk/-/tree/master/Geovis/Core), I don’t think it has been maintained for long time. This may be of use to you [vtklibproj](https://gitlab.kitware.com/vtk/vtk/-/tree/master/ThirdParty/libproj/vtklibproj).

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [October 16, 2021, 9:20pm UTC](https://discourse.vtk.org/t/vtkgeotransform-and-vtkgeoprojection-how-the-heck-to-use-them/6898/3 "2021-10-16T21:20:51Z")

</div>

The gold standard is [PROJ](https://proj.org/about.html), it has lot of prepackaged installers or you can build it yourself. Also the python interface [pyproj](https://pypi.org/project/pyproj/).
