In [1]:
import emapy as epy
import sys;
import pandas as pd

In [2]:
barris = epy.getDatabase(
    'barris',
    'json',
    '../data/raw/barris.geojson',
    '',
    True,
    0,
    1,
    'cartodb_id')

In [3]:
csvFile = '../data/external/densidadPoblacion/superficie-dens2015.csv'
csvData = epy.getDataOfCsv(
                csvFile, 
                ";"
)
dataSize = len(csvData)
barrisSize = len(barris[1])
allBarris = barris[1]

In [4]:
for index, row in csvData.iterrows():
    csvData.set_value(
        index, 
        'Barris', 
        epy.removeIntInxString(
            csvData.get_value(index, 'Barris'), 
            '.').lower())

In [5]:
df = pd.DataFrame({'id' : [], 'data': []})
allId = dict()

for x in range(barrisSize):
    key = allBarris[x]['geometry']['properties']['cartodb_id']
    name = allBarris[x]['geometry']['properties']['neighbourhood']
    for index, row in csvData.iterrows():
        if csvData.iloc[index][1].strip().lower() == name.strip().lower():
            csvNameData = csvData.iloc[index][1]    
            if key in allId:
                allId[key] = -1
            else:
                num = csvData.iloc[index][u'Població']
                if epy.is_number(num) == False:                   
                    num = num.replace('.', '')
                    num = float(num.replace(',', '.'))
                else:
                    num = str(num).replace('.', '')
                    num = float(num.replace(',', '.'))
                allId[key] = num
                
for x in range(barrisSize):
    key = allBarris[x]['geometry']['properties']['cartodb_id']
    if key in allId:
        row = [key, allId[key] * 1.0]  
        df.loc[len(df), ['id', 'data']] = row  
    else:
        df.loc[len(df), ['id', 'data']] = [key,0]

In [6]:
map = epy.mapCreation(41.388790,2.158990)
epy.mapChoropleth(map, 
                 '../data/raw/barris.geojson',
                 'feature.properties.cartodb_id',
                 df,
                 'id',
                 'data',
                 'YlGn',
                 0.7,
                 0.3,
                 [0, 10000, 20000, 37000, 50000, 60000],
                 'bars / barri')

In [7]:
locationAreaBoundingBox = (41.3248770036,2.0520401001,41.4829908452,2.2813796997)
allData = epy.getDatabaseFromOSM(
    'escuelas', 
    'amenity',
    False,
    True, 
    locationAreaBoundingBox, 
    'school')

In [8]:
shoolNames = []
idNodes = []
color = 'blue'
for school in allData:
    if school['type'].strip().lower() == 'point': 
        prop = school['properties']
        name = ''
        if 'name' in prop:
            name = prop['name']
            shoolNames.append(name)
        idNode = str(school['geometry'][0]) +  str(school['geometry'][1]) + name
        
        if idNode not in idNodes:
            idNodes.append(idNode)
            epy.mapAddMarker(
                map,
                school['geometry'][0],
                school['geometry'][1],
                'glyphicon-home',
                color,
                name)

In [9]:
epy.mapSave(map, '../reports/maps/mapOfEsuelasPoblacion.html')
map


Out[9]:

In [ ]:


In [ ]: