Skip to content

Instantly share code, notes, and snippets.

@wdsrocha
Forked from RodrigoCMoraes/format_points_list_to_visualization.py
Last active May 16, 2020 19:46
Show Gist options
  • Save wdsrocha/d0b6e809929174f62f1a0b26ee18954e to your computer and use it in GitHub Desktop.
Save wdsrocha/d0b6e809929174f62f1a0b26ee18954e to your computer and use it in GitHub Desktop.
useful snippets to data related to maps visualization

Format point list to visualization

Format a list of Points of Django to able visualization on: https://mobisoftinfotech.com/tools/plot-multiple-points-on-map/

Usage:

from django.contrib.gis.geos import Point

sample_lat_lng = [
    (19.0760,72.8777),
    (18.5204,73.8567),
    (40.7128,-74.0060),
    (-33.9249,18.4241),
    (-22.9068,-43.1729),
]
sample_points = [Point(x=lng, y=lat) for (lat, lng) in sample_lat_lng]
format_points_list_to_visualization(sample_points)

Params

to_print (bool) : print formatted string on terminal

Returns

formatted_string (str) : points formatted as string

def format_points_list_to_visualization(points, to_print=True):
formatted_string = ""
for pos in points:
lng, lat = pos.x, pos.y
formatted_string += f'{lat},{lng},blue,marker\n'
if to_print:
print("https://mobisoftinfotech.com/tools/plot-multiple-points-on-map/")
print(formatted_string)
return formatted_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment