Advertisement
Guest User

PythonUnicodeEmoji_toESRIShapefileBug

a guest
Mar 3rd, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. # emojiShapeUnicodeArcGISTest
  4. import fiona #Fiona needed for reading Shapefile
  5. from fiona.crs import from_epsg
  6. import shapely.geometry as geometry
  7. import pyproj #import Proj, transform
  8. from shapely.ops import transform
  9. import emoji
  10. from unicodedata import name as unicode_name
  11.  
  12. def extract_emojis(str):
  13.   #str = str.decode('utf-32').encode('utf-32', 'surrogatepass')
  14.   return list(c for c in str if c in emoji.UNICODE_EMOJI)
  15.  
  16. #Example Emojis
  17. emojistring = '😍 test text ❤️👨‍⚕️'
  18. emojilist = extract_emojis(emojistring)
  19.  
  20.  
  21. # Define polygon feature geometry
  22. schema = {
  23.     'geometry': 'Polygon',
  24.     'properties': {'emoji': 'str',
  25.                    'emoji_text': 'str'},
  26. }
  27. #write Shapefile
  28. with fiona.open('output.shp', mode='w', encoding='UTF-8', driver='ESRI Shapefile', schema=schema,crs=from_epsg(4326)) as c:
  29.     # Normalize Weights to 0-1000 Range
  30.     for emoji in emojilist:            
  31.         c.write({'geometry': {'coordinates': [[(-4.663611, 51.158333),
  32.                                    (-4.669168, 51.159439),
  33.                                    (-4.673334, 51.161385),
  34.                                    (-4.674445, 51.165276),
  35.                                    (-4.67139, 51.185272),
  36.                                    (-4.669445, 51.193054),
  37.                                    (-4.665556, 51.195),
  38.                                    (-4.65889, 51.195),
  39.                                    (-4.656389, 51.192215),
  40.                                    (-4.646389, 51.164444),
  41.                                    (-4.646945, 51.160828),
  42.                                    (-4.651668, 51.159439),
  43.                                    (-4.663611, 51.158333)]],
  44.                   'type': 'Polygon'},
  45.                   'properties': {'emoji': emoji,
  46.                                  'emoji_text': str(unicode_name(emoji))},
  47.         })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement