Search code examples
pythonpython-3.xgeography

convert coordinates into a point on an image in python


I have this map:

map

and this coordinates:

lat: 42.60537919708604
lon: -96.8791615271999

I would like to make a point on the map using python, anyone knows how to do that? ( on windows, would be nice if you could do that with PIL or with cv2 )

expected result:

result


Solution

  • I believe this code works if you are using a map where lat and long lines are straight lines such as image

    import cv2
    Directory = "directory of the image" 
    img = cv2.imread(Directory)
    #just displaying the initial image, not needed
    cv2.imshow('image',img)
    cv2.waitKey(5000)
    cv2.destroyAllWindows()
    
    #resize the image to 360,180 for lat and long locations
    img = cv2.resize(img, (360, 180))
    #draw a dot on the image in location: 
    lat = 0 #your lat here
    lat += 90
    long = 0 #your longitude here 
    long += 180 
    img = cv2.circle(img, (x,y), 3, (0,0,255), -1) #format = (image, position, size of circle, colour)
    #display the image in a window for 5 seconds (also not needed
    cv2.imshow('image',img)
    cv2.waitKey(5000)
    cv2.destroyAllWindows()