# GeoAssignCoordinates

VTKExamples/Cxx/Geovis/GeoAssignCoordinates

### Description

Note

The vtkGeovisCore classes as well as the module vtkViewsGeovis have been deprecated for VTK 8.2 and will be removed in a future version. See VTK Merge Request 4395

Other Languages

See (Python)

### Code

GeoAssignCoordinates.cxx

    #include <vtkSmartPointer.h>

    #include <vtkDataSetAttributes.h>
    #include <vtkGeoAssignCoordinates.h>
    #include <vtkDoubleArray.h>
    #include <vtkGraphMapper.h>
    #include <vtkRenderer.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkMutableDirectedGraph.h>

    int main(int, char* [])
    {

      vtkSmartPointer<vtkMutableDirectedGraph> g =
        vtkSmartPointer<vtkMutableDirectedGraph>::New();

      vtkSmartPointer<vtkDoubleArray> latitude =
        vtkSmartPointer<vtkDoubleArray>::New();
      latitude->SetName("latitude");

      vtkSmartPointer<vtkDoubleArray> longitude =
        vtkSmartPointer<vtkDoubleArray>::New();
      longitude->SetName("longitude");

      for(int lat = -90; lat <= 90; lat += 10)
      {
        for(int lon = -180; lon <= 180; lon += 20)
        {
          g->AddVertex();
          latitude->InsertNextValue(lat);
          longitude->InsertNextValue(lon);
        }
      }

      g->GetVertexData()->AddArray(latitude);
      g->GetVertexData()->AddArray(longitude);

      vtkSmartPointer<vtkGeoAssignCoordinates> assign =
        vtkSmartPointer<vtkGeoAssignCoordinates>::New();
      assign->SetInputData(g);
      assign->SetLatitudeArrayName("latitude");
      assign->SetLongitudeArrayName("longitude");
      assign->SetGlobeRadius(1.0);
      assign->Update();

      vtkSmartPointer<vtkGraphMapper> mapper =
        vtkSmartPointer<vtkGraphMapper>::New();
      mapper->SetInputConnection(assign->GetOutputPort());
      vtkSmartPointer<vtkActor> actor =
        vtkSmartPointer<vtkActor>::New();
      actor->SetMapper(mapper);

      vtkSmartPointer<vtkRenderer> ren =
        vtkSmartPointer<vtkRenderer>::New();
      ren->AddActor(actor);

      vtkSmartPointer<vtkRenderWindowInteractor> iren =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();

      vtkSmartPointer<vtkRenderWindow> win =
        vtkSmartPointer<vtkRenderWindow>::New();
      win->AddRenderer(ren);
      win->SetInteractor(iren);
      ren->ResetCamera();

      win->Render();
      iren->Initialize();
      iren->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

    project(GeoAssignCoordinates)

    find_package(VTK COMPONENTS
      vtkCommonCore
      vtkCommonDataModel
      vtkGeovisCore
      vtkInteractionStyle
      vtkRenderingContextOpenGL2
      vtkRenderingCore
      vtkRenderingFreeType
      vtkRenderingGL2PSOpenGL2
      vtkRenderingOpenGL2 QUIET)
    if (NOT VTK_FOUND)
      message("Skipping GeoAssignCoordinates: ${VTK_NOT_FOUND_MESSAGE}")
      return ()
    endif()
    message (STATUS "VTK_VERSION: ${VTK_VERSION}")
    if (VTK_VERSION VERSION_LESS "8.90.0")
      # old system
      include(${VTK_USE_FILE})
      add_executable(GeoAssignCoordinates MACOSX_BUNDLE GeoAssignCoordinates.cxx )
      target_link_libraries(GeoAssignCoordinates PRIVATE ${VTK_LIBRARIES})
    else ()
      # include all components
      add_executable(GeoAssignCoordinates MACOSX_BUNDLE GeoAssignCoordinates.cxx )
      target_link_libraries(GeoAssignCoordinates PRIVATE ${VTK_LIBRARIES})
      # vtk_module_autoinit is needed
      vtk_module_autoinit(
        TARGETS GeoAssignCoordinates
        MODULES ${VTK_LIBRARIES}
        )
    endif ()

### Download and Build GeoAssignCoordinates

Click here to download GeoAssignCoordinates and its CMakeLists.txt file. Once the tarball GeoAssignCoordinates.tar has been downloaded and extracted,

    cd GeoAssignCoordinates/build

If VTK is installed:

    cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

    cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

    make

and run it:

    ./GeoAssignCoordinates

WINDOWS USERS

Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.