0

I am trying to render a polygon using python matplot Basemap lib.

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

def render_polygon(lat, long):
  map = Basemap(llcrnrlon=-10,llcrnrlat=35,urcrnrlon=35,urcrnrlat=60.,
                                  resolution=None, projection='tmerc', lat_0 =
                                  8.30, lon_0 = 3.46)
  map.plot(lat, long, marker=None,color='m')
  plt.show()

lat = [56.1304, 55.1304, 54.1304, 53.1304, 52.1304]
long = [106.3468, 107.3468, 105.3468, 104.3468, 103.3468]
render_polygon(lat, long)

When I run the program passing the latitude longitude I see an empty rectangle. Can someone point out what am I doing incorrect?

2
  • Please show the data (lat, long), including the lines of code that make use of render_polygon(). Commented Mar 24, 2020 at 13:26
  • @swatchai updated the data that uses render_polygon Commented Mar 28, 2020 at 21:50

1 Answer 1

1

You need to transform coordinates in the process. Try changing

map.plot(lat, long, marker=None, color='m')

to

map.plot(*map(long, lat), marker=None, color='m')

The code *map(long, lat) does the required coordinate transformation, and spreads the result to xs, ys in that place.

Edit 1

The original code have been edited to get appropriate data extent, proper projection parameters.

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

def render_polygon(lat, long):
  map = Basemap(llcrnrlon=103, llcrnrlat=50, urcrnrlon=107.5, urcrnrlat=60.,
                resolution='c', projection='merc', 
                lat_0 = 50, lon_0 = 105)
  map.plot(*map(long, lat), marker=None, color='m')
  #map.drawcoastlines(linewidth=0.7)
  plt.show()

lat = [56.1304, 55.1304, 54.1304, 53.1304, 52.1304]
long = [106.3468, 107.3468, 105.3468, 104.3468, 103.3468]
render_polygon(lat, long)

The output plot:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.