Converting between units

Use the Coordinate Converter node component to convert offset and absolute values between units of measurement. For example, you can convert coordinates or distances.

The Coordinate Converter:

  1. Takes as its input one or two property values that use one unit of measurement.

    For example, the input can be a property that holds a distance value, or two properties that hold the x and y coordinates of a map location.

  2. Converts the values to another unit of measurement.

    For example, you can convert from projected meters to real-world meters.

  3. Writes the converted values to one or two target properties.

In this example, you use the Coordinate Converter to convert an elevation value that you get from the Height Component. You convert the value from projected meters to real-world meters and use a Text Block node to show the value.

To convert between units:

  1. Create the map content that provides the values that you want to convert from one unit of measurement to another.

    For example, use a Terrain 3D Renderer node to render 3D terrain and a Height Component node component to store to a custom property the elevation in the center of the map. See Using elevation data to control the position of the camera over 3D terrain.

    ../../_images/preview-camera-positioned.png
  2. In the Library > Property Types, create property types to store the values that you want to convert.

    For example, create a float property type and name it RealTerrainHeight.

    You use this property type to store an elevation value that you convert with the Coordinate Converter.

    ../../_images/library-create-property-type.png ../../_images/property-type-real-terrain-height.png
  3. In the node that holds the values that you want to convert, create a Coordinate Converter node component.

    For example, in the Node Tree, select the Map View node. In the Node Components > Kanzi Maps, create a Coordinate Converter.

    ../../_images/map-view-node-21.png ../../_images/node-components-create-coordinate-converter.png
  4. In the Coordinate Converter, set:

    • Unit System to:

      • Offset (supports real 2 cm and meter) to convert an offset value.

        You can convert offset values in:

        • Latitude-longitude coordinates

        • Projected 2 cm units

        • Projected meters

        • Real-world 2 cm units

        • Real-world meters

        Real-world 2 cm units and real-world meters are accurate only around the current map location, and only for offsets of up to about 1000 meters.

      • Absolute to convert an absolute value.

        You can convert absolute values in:

        • Latitude-longitude coordinates

        • Projected 2 cm units

        • Projected meters

        • Viewport 2D coordinates as the target unit

          You can use these coordinates to place a 2D node in a position relative to a specific location on the zero-plane of a map.

      For example, set Unit System to Offset (supports real 2 cm and meter).

    • Source Property X and Source Property Y to the property or properties whose values you want to convert.

      For example, set them to the custom property TerrainRendererHeight, which you created for storing an elevation value provided by a Height Component.

    • Source Unit to the unit that the source property or properties use.

      For example, set it to Projected meter.

    • Target Property X and Target Property Y to the property or properties to which you want the Coordinate Converter to store the converted values.

      For example, set them to RealTerrainHeight.

    • Target Unit to the unit to which you want to convert.

      For example, set it to Real meter (for Offset only).

    ../../_images/node-components-coordinate-converter.png
  5. Use the converted value.

    For example:

    1. In the Node Tree, create a Text Block node and set its appearance and position.

      ../../_images/node-tree-text-block.png ../../_images/preview-text-block.png
    2. In the Properties, click + Add Binding and in the Binding Editor, set:

      • Property to Text

      • Expression to

        height = int({@../Viewport 2D/Scene/Map View/RealTerrainHeight})
        "Elevation: " + string(height) + " m"
        

      With this binding, you get the height value that the Coordinate Converter writes to the RealTerrainHeight property of the Map View node. You convert the value to an integer and insert it to a string.

      ../../_images/binding-editor-text.png ../../_images/preview-text-block-elevation.png

See also

Using elevation data

Using the Terrain 3D Renderer node