def project_coordinates(coordinates, projection, **kwargs):
    """
    Apply projection to given coordinates

    Allows to apply projections to any number of coordinates, assuming
    that the first ones are ``longitude`` and ``latitude``.

    Examples
    --------

    >>> # Define a custom projection function
    >>> def projection(lon, lat, inverse=False):
    ...     "Simple projection of geographic coordinates"
    ...     radius = 1000
    ...     if inverse:
    ...         return (lon / radius, lat / radius)
    ...     return (lon * radius, lat * radius)

    >>> # Apply the projection to a set of coordinates containing:
    >>> # longitude, latitude and height
    >>> coordinates = (1., -2., 3.)
    >>> project_coordinates(coordinates, projection)
    (1000.0, -2000.0, 3.0)

    >>> # Apply the inverse projection
    >>> coordinates = (-500.0, 1500.0, -19.0)
    >>> project_coordinates(coordinates, projection, inverse=True)
    (-0.5, 1.5, -19.0)

    """
    proj_coordinates = projection(*coordinates[:2], **kwargs)
    if len(coordinates) > 2:
        proj_coordinates += tuple(coordinates[2:])
    return proj_coordinates