0

I have a shapefile in polygon type. In table of this shapefile there is a column with NAME name. This column characters are in Farsi font, non-English. I want to read this file with Geopandas in jupyter and then display name of each polygon label based on the NAME column. I use the below code. It can display the map plot but the labels show as ???? character. Is there any idea to solve it?

import geopandas as gpd
import matplotlib.pyplot as plt

cities = gpd.read_file(r'/Maps/my_polygon.shp')

fig, ax = plt.subplots(figsize = (10,5)) 
cities.plot(color='black', edgecolor='k',linewidth = 1,ax=ax)
cities.geometry.boundary.plot(color=None, edgecolor='k',linewidth = 1,ax=ax)

# Labeling name of cities with field of 'NAME'
cities.apply(lambda x: ax.annotate(x.NAME, xy=x.geometry.centroid.coords[0], ha='center'),axis=1);
HMadadi
  • 391
  • 5
  • 22
  • I strongly suspect this is down to the encoding of file. If you have a look at the dataframe after import, are the names parsed correctly? If not, try passing the `encoding` parameter with the appropriate value to `gpd.read_file()` and see if it works. E.g.: `cities = gpd.read_file(r'/Maps/my_polygon.shp', encoding='utf-8')` – bexi Jul 11 '19 at 09:42
  • Hi @bexi, I tried your suggestion and did not work. – HMadadi Jul 12 '19 at 05:03
  • 1
    hi @nickam, it might also be another encoding. Does the shapefile come with a .cpg file (`'/Maps/my_polygon.cpg'` in your case)? This may contain information about the encoding of the shapefile. – bexi Jul 12 '19 at 10:58

0 Answers0