geojson = GeoJSON() output = geojson.getFormat() progress = Progress( len(dataset_1) ) progress.progressBar("Conversioning") for i in range( len(dataset_1) ): if dataset_1[i][5] > threshold_1 and dataset_2[i][5] > threshold_2: red = int( ( log(dataset_1[i][5]) / log(max_1) ) * 255 ) blue = int( ( log(dataset_2[i][5]) / log(max_2) ) * 255 ) color = "rgba(" + str(red) + ", 0, " + str(blue) + ", 0.5)" output["features"].append( geojson.getFeature("Polygon", [[ [dataset_1[i][2], dataset_1[i][1]], [dataset_1[i][2], dataset_1[i][3]], [dataset_1[i][4], dataset_1[i][3]], [dataset_1[i][4], dataset_1[i][1]] ]], { "color": color, "twitter": {"population": dataset_1[i][5]}, "flickr": {"population": dataset_2[i][5]} }) ) elif dataset_1[i][5] > threshold_1: red = int( ( log(dataset_1[i][5]) / log(max_1) ) * 255 ) color = "rgba(" + str(red) + ", 0, 0, 0.5)" output["features"].append( geojson.getFeature("Polygon", [[ [dataset_1[i][2], dataset_1[i][1]], [dataset_1[i][2], dataset_1[i][3]], [dataset_1[i][4], dataset_1[i][3]], [dataset_1[i][4], dataset_1[i][1]] ]], { "color": color, "twitter": {"population": dataset_1[i][5]}, "flickr": {"population": 0}
geojson = GeoJSON() output = geojson.getFormat() dataset = json.loads(input_text) progress = Progress( len(dataset) ) progress.progressBar("Conversioning") for data in dataset: if data[5] > threshold: alpha = log(data[5]) / log(max_value) if (data_source == "twitter"): color = "rgba(255, 0, 0, " + str(alpha) + ")" elif (data_source == "flickr"): color = "rgba(0, 0, 255, " + str(alpha) + ")" output["features"].append( geojson.getFeature("Polygon", [[ [data[2], data[1]], [data[2], data[3]], [data[4], data[3]], [data[4], data[1]] ]], { "color": color, "population": data[5], "text": data[6] }) ) progress.tick(1) output_text = json.dumps(output, indent=4) output_path = 'json/' + output_file + '.json' with open(output_path, 'w') as f: f.write(output_text) print("[" + str( len(output["features"]) ) + "]")