# GeoGraticle

VTKExamples/Cxx/Geovis/GeoGraticle

### Description¶

vtkGeoGraticle generates polydata to illustrate the distortions introduced by a map projection. The level parameter specifies the number of lines to be drawn. Poles are treated differently than other regions; hence the use of a Level parameter instead of a NumberOfLines parameter. The latitude and longitude are specified as half-open intervals with units of degrees. By default the latitude bounds are (-90,90) and the longitude bounds are (0,180).

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)

Question

If you have a simple question about this example contact us at VTKExamplesProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum

### Code¶

GeoGraticle.cxx

#include <vtkSmartPointer.h>
#include <vtkGeoGraticule.h>

#include <vtkActor.h>
#include <vtkGeoProjection.h>
#include <vtkGeoTransform.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkTransformFilter.h>

#include <vtkNamedColors.h>

int main( int argc, char* argv[] )
{
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();

int latLevel = 2;
int lngLevel = 2;
const char* pname = "rouss";

vtkSmartPointer<vtkGeoGraticule> geoGraticle =
vtkSmartPointer<vtkGeoGraticule>::New();
vtkSmartPointer<vtkGeoTransform> transformProjection =
vtkSmartPointer<vtkGeoTransform>::New();
vtkSmartPointer<vtkGeoProjection> destinationProjection =
vtkSmartPointer<vtkGeoProjection>::New();
vtkSmartPointer<vtkGeoProjection> sourceProjection =
vtkSmartPointer<vtkGeoProjection>::New();
vtkSmartPointer<vtkTransformFilter> transformGraticle =
vtkSmartPointer<vtkTransformFilter>::New();
vtkSmartPointer<vtkTransformFilter>::New();
vtkSmartPointer<vtkPolyDataMapper> graticleMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkActor> graticleActor =
vtkSmartPointer<vtkActor>::New();
vtkSmartPointer<vtkActor>::New();

geoGraticle->SetGeometryType( vtkGeoGraticule::POLYLINES );
geoGraticle->SetLatitudeLevel( latLevel );
geoGraticle->SetLongitudeLevel( lngLevel );
geoGraticle->SetLongitudeBounds( -180, 180 );
geoGraticle->SetLatitudeBounds( -90, 90 );

// destinationProjection defaults to latlong.
destinationProjection->SetName( pname );
destinationProjection->SetCentralMeridian( 0. );
transformProjection->SetSourceProjection( sourceProjection );
transformProjection->SetDestinationProjection( destinationProjection );
transformGraticle->SetInputConnection( geoGraticle->GetOutputPort() );
transformGraticle->SetTransform( transformProjection );
graticleMapper->SetInputConnection( transformGraticle->GetOutputPort() );
graticleActor->SetMapper( graticleMapper );

vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindow->SetInteractor( interactor );
renderWindow->SetSize(640, 480);
renderer->SetBackground(colors->GetColor3d("BurlyWood").GetData());

renderWindow->Render();

interactor->Initialize();
interactor->Start();
return EXIT_SUCCESS;
};


### CMakeLists.txt¶

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(GeoGraticle)

find_package(VTK COMPONENTS
vtkCommonColor
vtkCommonCore
vtkFiltersGeneral
vtkGeovisCore
vtkIOXML
vtkInteractionStyle
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingOpenGL2 QUIET)
if (NOT VTK_FOUND)
message("Skipping GeoGraticle: ${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(GeoGraticle MACOSX_BUNDLE GeoGraticle.cxx ) target_link_libraries(GeoGraticle PRIVATE${VTK_LIBRARIES})
else ()
# include all components
add_executable(GeoGraticle MACOSX_BUNDLE GeoGraticle.cxx )
target_link_libraries(GeoGraticle PRIVATE ${VTK_LIBRARIES}) # vtk_module_autoinit is needed vtk_module_autoinit( TARGETS GeoGraticle MODULES${VTK_LIBRARIES}
)
endif ()


cd GeoGraticle/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:

./GeoGraticle


WINDOWS USERS

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