Is there a way to convert gps locations to a local system?

I am trying to convert gps locations to unreal coordinates and having a much harder time than expected.

I have used the standard math found here at stackoverflow to convert from lat, lon, alt to x, y, z and then subtracted point 1 from point 2 to make point 1 my new origin. I have put this into a python script for testing purposes.

def convertToXYZ(lat, lon, alt):
    #trig variables
    cosLat = math.cos(lat)
    sinLat = math.sin(lat)
    cosLon = math.cos(lon)
    sinLon = math.sin(lon)

    #Constants
    rad = 6378137 + alt
    f = 1.0 / 298.257224
    C = 1.0 / math.sqrt(cosLat * cosLat + (1-f) * (1-f) * sinLat * sinLat)
    S = (1.0 - f) * (1.0 - f) * C
    h = 0.0

    #return values
    value = []
    value.append((rad * C + h) * cosLat * cosLon)
    value.append((rad * C + h) * cosLat * sinLon)
    value.append((rad * S + h) * sinLat)

    return value

After doing this I am ending up with a point that has a negative value for Z even when the altitude was positive. Is there a standard rotation that needs to be applied to get the correct location?

I am using a landscape which is currently arranged with the northern edge along the x axis and the western edge along the y axis

Thanks for any help.