def voronoiplot(df):
    Datalist=[]
    for i in df.index:
        #print i,[df['Latitude'][i],df['Longitude'][i]]
        Datalist.append([float(df['Latitude'][i]),float(df['Longitude'][i])] )
    points = np.array(Datalist)
    #print points
    vor = Voronoi(points)
    #voronoi_plot_2d(vor)
    region,vertices=Vorplots.voronoi_finite_polygons_2d(vor)
    print len(region)
    geo_json,data_csv=DO.geojsonwrite(vor,region,vertices,df)
    print data_csv
    target = open(Constants.filelocations.VORONOI_GEOJSON, 'w')
    target.write(geo_json)
    target.close()
    data_csv.to_csv(Constants.filelocations.GEOJSON_CSV_DATA, header= True, index=False)
    return

# LOCATION='/Users/Wuga/Documents/DATA/SFREHPDATA/HousingSales2012PL_GOOGLE.csv'
# df=DO.readgeofile(LOCATION)
# train,test,train_index,test_index=DO.dataseperator(df)
# print [float(train['Latitude'][1]),float(train['Longitude'][1])] 
# voronoiplot(train)
'''
Created on 09-23-2015

@author: Wuga
'''
import folium

import geocoder
import DataOperation as DO
import DataPreprocess as DP
import Vorplots as V
import Constants
import pandas as pd

g=geocoder.osm('dublin,ireland')
loca=g.latlng
print loca
LOCATION=Constants.filelocations.DUBLIN_2010
df=DO.readgeofile(LOCATION)
train,test,train_index,test_index=DO.dataseperator(df)
map_osm = folium.Map(location=loca, zoom_start=9, max_zoom=18)
train=DP.elim(train)
train = train.reset_index(drop=True)
V.voronoiplot(DP.elim(train))
map_osm.geo_json(geo_path=r'autovoronoi.json', data_out='/Users/Wuga/Documents/DATA/SFREHPDATA/pricedata.json',data=pd.read_csv('/Users/Wuga/Documents/DATA/SFREHPDATA/pricedata.csv'),columns=['Id','Price'],key_on='feature.id', threshold_scale=[200000,250000,300000,350000,400000,500000], fill_color='YlOrRd', fill_opacity=0.5, line_opacity=0.5, legend_name='SF house price')
map_osm.create_map(path=Constants.filelocations.MAP_HTML)