0

I am trying to use apache flink to convert latitude and longitude to WGS4 Co-ordinate using pyproj Library. I want to use Vectorized UDF. But whenever i pass data to VDUF. It throws error.

Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

@udf(input_types=[DataTypes.DOUBLE()], result_type=DataTypes.FLOAT(), udf_type="pandas")
def transform_to_wgs_lat(lat, lng, epsg):
    new_lat, new_lng = Transformer.from_crs(epsg, 4326).transform(lat, lng)
    return new_lat

sample Data:

lat = pd.Series([32.620359, 32.23561])
lng = pd.Series([-104.126000001, -104.20343])
proj = pd.Series([4269, 4269])

this is my function, and (lat, lng, epsg) all are series. In VDUF, Input must be Series And Output Must Also Be Series. So i need series of new latitude . But i am getting the above error.

Sudip Adhikari
  • 157
  • 2
  • 12
  • 1
    Can you share a minimum reproducible example (with sample data) so that the community can run your code? With that, they will be able to help you better. – Kabilan Mohanraj Feb 20 '22 at 18:58

1 Answers1

0

It was just an easy way out.

@udf(result_type=DataTypes.DOUBLE(), func_type="pandas")
def transform_to_wgs_lat(lat, lng, epsg):
    lat = lat.fillna(value=0.0)
    lng = lng.fillna(value=0.0)
    epsg = epsg.fillna(value=0.0)
    final_result = []
    for each_lat, each_lng, each_epsg in zip(lat, lng, epsg):
        if each_lat==0.0 or each_lng==0.0 or each_epsg==0.0:
            final_result.append(each_lat)
            continue
        new_lat, new_lng = Transformer.from_crs(each_epsg, 4326).transform(each_lat, each_lng)
        final_result.append(new_lat)
    return pd.Series(final_result)
ouflak
  • 2,458
  • 10
  • 44
  • 49
Sudip Adhikari
  • 157
  • 2
  • 12