Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
BlueSky
Helper I
Helper I

Can I use this Python function for each row of a tabe ?

I have a table called Activity, there is a coloum called Polyline.
For each polyline I want to return it's corresponding longatude and lattitude cordinates.

 

A polyline is a way of encoding a series of cordinates as a string. There algorithm to do this is described here:
https://developers.google.com/maps/documentation/utilities/polylinealgorithm

 

I have found a Python script and function which converts a polyline into a list of longatude and lattitude cordinates:

 

 

# This function is free of any dependencies.
def decode_polyline(polyline_str):
    '''Pass a Google Maps encoded polyline string; returns list of lat/lon pairs'''
    index, lat, lng = 0, 0, 0
    coordinates = []
    changes = {'latitude': 0, 'longitude': 0}

    # Coordinates have variable length when encoded, so just keep
    # track of whether we've hit the end of the string. In each
    # while loop iteration, a single coordinate is decoded.
    while index < len(polyline_str):
        # Gather lat/lon changes, store them in a dictionary to apply them later
        for unit in ['latitude', 'longitude']: 
            shift, result = 0, 0

            while True:
                byte = ord(polyline_str[index]) - 63
                index += 1
                result |= (byte & 0x1f) << shift
                shift += 5
                if not byte >= 0x20:
                    break

            if (result & 1):
                changes[unit] = ~(result >> 1)
            else:
                changes[unit] = (result >> 1)

        lat += changes['latitude']
        lng += changes['longitude']

        coordinates.append((lat / 100000.0, lng / 100000.0))

    return coordinates

 

 

Borrowed from here https://github.com/geodav-tech/decode-google-maps-polyline


Is it possible to use this Python funciton in PowerBI and pass the polyline for each Activity and return it's coordinates?

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @BlueSky ,

 

Try to transform the data in Power Query with Python script, then create visuals.

v-lionel-msft_0-1620615839917.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

View solution in original post

1 REPLY 1
v-lionel-msft
Community Support
Community Support

Hi @BlueSky ,

 

Try to transform the data in Power Query with Python script, then create visuals.

v-lionel-msft_0-1620615839917.png

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.