There are two ways to retrieve the magnetic north declination at a certain location and time.

  • Either create a TLcdMagneticNorthMeasureProviderFactory instance and use it like any other ILcdModelMeasureProviderFactory implementation:

    //Use one of the available model decoders to decode the model
    //LuciadLightspeed offers the TLcdWMMModelDecoder for WMM models,
    //and the TLcdIGRFModelDecoder for IGRF models.
    TLcdWMMModelDecoder modelDecoder = new TLcdWMMModelDecoder();
    
    //Specify the date on the model decoder
    Calendar calendar = Calendar.getInstance();
    calendar.set(2020, Calendar.AUGUST, 26, 16, 52);
    modelDecoder.setDate(calendar);
    
    //Decode the model
    ILcdModel model = modelDecoder.decode("Data/magneticnorth/WMM2020.COF");
    
    //Create an ALcdMeasureProvider for the magnetic north model,
    //using the TLcdMagneticNorthMeasureProviderFactory
    TLcdMagneticNorthMeasureProviderFactory modelMeasureProviderFactory = new TLcdMagneticNorthMeasureProviderFactory();
    ALcdMeasureProvider measureProvider = modelMeasureProviderFactory.createMeasureProvider(model);
    
    //Query the measure provider for the measurements at a specific location
    TLcdISO19103Measure[] declinations =
        measureProvider.retrieveMeasuresAt(new TLcdLonLatPoint(10, 10),
                                           new TLcdGeodeticReference(),
                                           ALcdMeasureProvider.Parameters.newBuilder().build());
    TLcdISO19103Measure declination = declinations[0];
  • Or, query the ILcdMagneticNorthMap directly:

    //Decode the magnetic map.
    //In this example, we use a WMM magnetic map.
    //LuciadLightspeed also supports IGRF maps (see the TLcdIGRFMagneticNorthMap class)
    TLcdWMMMagneticNorthMap map = new TLcdWMMMagneticNorthMap("Data/magneticnorth/WMM2020.COF");
    
    //Set the date you are interested in on the map
    Calendar calendar = Calendar.getInstance();
    calendar.set(2020, Calendar.AUGUST, 26, 16, 52);
    map.setDate(calendar);
    
    //Retrieve the declination for the location of interest.
    //The location is a WGS-84 point
    float declinationValue = map.retrieveDeclinationAt(new TLcdLonLatPoint(10, 10));
    
    //The returned declination value is expressed in degrees
    TLcdISO19103Measure declination = new TLcdISO19103Measure(declinationValue, TLcdAngleUnit.DEGREE);