Advertisement
Guest User

formatJSON

a guest
Oct 5th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Name: formatJSON.py
  3. # Purpose: converts shapfile to formated json for leaflet database application.
  4. # Author: noah.huntington
  5. # Created: 30/09/2015
  6. # Copyright: (c) noah.huntington 2015
  7. # Licence: <your licence>
  8. #-------------------------------------------------------------------------------
  9. import arcpy, os
  10.  
  11. def main():
  12.  
  13. fc = 'E:\db_map\IRExport_100215.csv'
  14. fields = ['JOBNUMBER','LatitudeI', 'LongitudeI','CARDODB PATH']
  15. ## fl = arcpy.MakeFeatureLayer_management(fc)
  16. with arcpy.da.SearchCursor(fc, fields) as cursor:
  17. for row in cursor:
  18. print '{'
  19. print '"job_number": "{0}",' .format(row[0])
  20. print '"lat": "{0}",' .format(row[1])
  21. print '"long": "{0}",' .format(row[2])
  22. if row[3][:1] == 'F':
  23. removeTrailing = os.path.split(row[3])[0]
  24. url = os.path.split(removeTrailing)[0]
  25. print '"url": "file://{0}"' .format(url)
  26. else:
  27. print '"url": "file://{0}"' .format(row[3][:-1])
  28.  
  29. print '},'
  30.  
  31.  
  32. if __name__ == '__main__':
  33. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement