Exemplo n.º 1
0
def main(argv=None):
    global DATA_FILE
    # Process commandline arguments
    # If we were just going to process one tile then here would be the place to start
    # Return a file list from process_arguments, adjust OS_GRID_SIZE, return os_grid_cell
    DATA_FILE, os_grid_cell, name = process_arguments(argv)

    # Report on datafiles
    zf = zipfile.ZipFile(DATA_FILE, 'r')
    datafiles = zf.namelist()
    print("Data zip file: {}".format(DATA_FILE))
    print("Found {} datafiles".format(len(datafiles)))
    xorg, yorg = tile_origin(os_grid_cell)

    # Calculate bounding box
    lat_ll, lng_ll = OSGB36toWGS84(xorg, yorg) # lower left
    lat_ur, lng_ur = OSGB36toWGS84(xorg + OS_GRID_SIZE, yorg + OS_GRID_SIZE) 
    bb = "[{}, {}], [{}, {}]".format(lat_ll, lng_ll, lat_ur, lng_ur)
    print("Bounding box: {}".format(bb))

    # Write bounding box to data_dict
    write_to_data_dict(os_grid_cell, bb, name)

    # Iterate over datafiles
    filelist = [x for x in range(len(datafiles))]

    # Assume all tiles in a dataset have the same ncols, nrows, cellsize and NODATA_value
    metadata = get_header_info(datafiles[0])
    # Output_data_size is OS_GRID_SIZE/cellsize
    output_data_size = OS_GRID_SIZE / metadata["cellsize"]

    bigdata = np.zeros((output_data_size, output_data_size), dtype=np.float)
    for idx in filelist:
        # Get data
        metadata = get_header_info(datafiles[idx])
        data = get_image(datafiles[idx], metadata["ncols"], metadata["nrows"])        
        data[data == -9999] = 0.0
        # Calculate x,y offset
        xoffset, yoffset = calculate_offsets(metadata, output_data_size, xorg, yorg)
        width = metadata["ncols"]
        height = metadata["nrows"]
        # Write into array
        bigdata[yoffset - height:yoffset, xoffset:xoffset + width] = data 
    # Show the data
    plot_image(bigdata)

    # Export the data to an image
    filename = "images/" + os_grid_cell
    matplotlib.image.imsave(filename, bigdata, cmap=plt.gray())
Exemplo n.º 2
0
def convert_postcodes() -> List[str]:
    fieldnames = [
        'Postcode', 'Positional_quality_indicator', 'Eastings', 'Northings',
        'Country_code', 'NHS_regional_HA_code', 'NHS_HA_code',
        'Admin_county_code', 'Admin_district_code', 'Admin_ward_code'
    ]

    sys.stdout.write('Finding CSV files...\n')
    csvs = []
    for root, dirs, files in os.walk(os.path.join('download', 'CSV')):
        csvs.extend(os.path.join(root, f) for f in files if f.endswith('csv'))
    num = len(csvs)
    sys.stdout.write('Converting %d CSV files...\n' % num)
    for idx, file_path in enumerate(csvs):
        locations = []
        sys.stdout.write('{0:.0%} ({1}/{2}) {3}\n'.format(
            (idx + 1) / num, idx + 1, num, file_path,
        ))
        # Read the OSGB36 file
        with open(file_path, 'r') as f:
            reader = csv.DictReader(f, fieldnames=fieldnames)
            for row in reader:
                lat, lng = OSGB36toWGS84(
                    int(row['Eastings']),
                    int(row['Northings'])
                )
                locations.append((row['Postcode'], lng, lat))
        # Write the WGD84 file with the same name
        with open(os.path.join('download', 'latlng', file_path), 'w') as f:
            writer = csv.DictWriter(f, fieldnames=['lat', 'lng', 'postcode'])
            for postcode, lng, lat in locations:
                writer.writerow({'postcode': postcode, 'lng': lng, 'lat': lat})
    return csvs
    def overlay_point_map(self, data_frame, basemap):
        """plots point map over existing basemap"""
        data_frame = data_frame.fillna('None')
        for index, row in data_frame.iterrows():
            size = self.dict_size[row.ActionBased]
            html="<small> \
                <h3> Incident #: "                                   + str(row.IncidentNumber) +  "</h3> \
                <p> \
                <b>Action Based: </b>"                                       + str(row.ActionBased) + "<br> \
                <b>Action Parent: </b>"                                        + str(row.ActionParent) + "<br> \
                <b>Action: </b>"                                 + str(row.Action) + "<br> \
                <b>Motive: </b>"                                 + str(row.Motive) + "<br> \
                <b>BriefDescriptionOfFire: </b><i>"                                                    + \
                str(row.BriefDescriptionOfFire) +"</i><br> \
                <b>FurtherInformation: </b><i>"                                                + \
                str(row.FurtherInformation) + "</i><br> \
                <b>PropertyType: </b><i>"                                          + \
                str(row.PropertyType) +"</i><br> \
                <b>Date and time of call: </b>"                                                + str(row.DDDateTimeOfCall) + "<br> \
                </p> \
                </small>"

            iframe = folium.element.IFrame(html=html, width=450, height=200)
            popup = folium.Popup(iframe, max_width=500)
            folium.CircleMarker(
                location=list(
                    OSGB36toWGS84(row.easting / 10, row.northing / 10)),
                radius=size,
                popup=popup,
                color='#00ffffff',  #none
                fill_color='#ff3300'  #red
            ).add_to(basemap)
        return basemap
def get_lat_long_coords(data_frame):
    """returns a long and lat from easting and northing"""
    coords_list = []
    for index, row in data_frame.iterrows():
        coords_list.append(
            list(OSGB36toWGS84(row.easting / 10, row.northing / 10)))
        coords = pd.DataFrame(coords_list, columns=['long', 'lat'])
    return coords
print('################################')
print('Working Base :',Base, ' using ', sys.platform)
print('################################')
################################################################
sFileNameIn=Base+'/01-Vermeulen/00-RawData/public-toilets.csv'
sFileNameOut=Base+'/01-Vermeulen/06-Report/01-EDS/02-Python/colchester_toilets_clusters.html'
# Load map centred on Colchester
uk = folium.Map(location=[51.8860942,0.8336077], zoom_start=10, control_scale=True)
 
# Load locally stored colchester public toilets data
os.chdir('C:/VKHCG/01-Vermeulen/00-RawData')
toilets = pd.read_csv("public-toilets.csv")
 
t=0
for each in toilets.iterrows(): 
    datalist=list(OSGB36toWGS84(each[1]['Geo X'],each[1]['Geo Y']))
    t+=1
    if t==1:
        data=[datalist]
    else:
        data.append(datalist)

# create a marker cluster called "Public toilet cluster"
marker_cluster = folium.plugins.FastMarkerCluster(data).add_to(uk)

#add a marker for each toilet, add it to the cluster, not the map
for each in toilets.iterrows():  
    print(list([each[1]['Geo X'],each[1]['Geo Y']]))
    print(list(OSGB36toWGS84(each[1]['Geo X'],each[1]['Geo Y'])))
    folium.Marker(list(OSGB36toWGS84(each[1]['Geo X'],each[1]['Geo Y'])), popup=each[1]['Street Address']).add_to(marker_cluster)
 
Exemplo n.º 6
0
 def __lat_lng(self):
     if self.easting is not None and self.northing is not None:
         return OSGB36toWGS84(self.easting, self.northing)
     else:
         return None, None
def accidentmap():
    data_attendent_18 = spark.read \
        .format("jdbc") \
        .option("url", "jdbc:postgresql://localhost:5432/anuj_db") \
        .option("dbtable", "attendent_18") \
        .option("driver", "org.postgresql.Driver") \
        .option("user", "anuj_db") \
        .option("password", "anuj_db") \
        .load()

    data_attendent_17 = spark.read \
        .format("jdbc") \
        .option("url", "jdbc:postgresql://localhost:5432/anuj_db") \
        .option("dbtable", "attendent_17") \
        .option("driver", "org.postgresql.Driver") \
        .option("user", "anuj_db") \
        .option("password", "anuj_db") \
        .load()

    data_attendent_16 = spark.read \
        .format("jdbc") \
        .option("url", "jdbc:postgresql://localhost:5432/anuj_db") \
        .option("dbtable", "attendent_16") \
        .option("driver", "org.postgresql.Driver") \
        .option("user", "anuj_db") \
        .option("password", "anuj_db") \
        .load()

    data_attendent_15 = spark.read \
        .format("jdbc") \
        .option("url", "jdbc:postgresql://localhost:5432/anuj_db") \
        .option("dbtable", "attendent_15") \
        .option("driver", "org.postgresql.Driver") \
        .option("user", "anuj_db") \
        .option("password", "anuj_db") \
        .load()

    data_attendent_14 = spark.read \
        .format("jdbc") \
        .option("url", "jdbc:postgresql://localhost:5432/anuj_db") \
        .option("dbtable", "attendent_14") \
        .option("driver", "org.postgresql.Driver") \
        .option("user", "anuj_db") \
        .option("password", "anuj_db") \
        .load()

    """""""""""""""""""""""""""""""""""""""""""""""
    LATITUDE LONGITUDE CONVERSION 2018
    """""""""""""""""""""""""""""""""""""""""""""""

    fatal_df = data_attendent_18.filter(data_attendent_18.severitynum == 1)
    east_18 = fatal_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_18 = fatal_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_fatal = fatal_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_fatal = fatal_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_fatal = fatal_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_fatal = fatal_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_fatal = fatal_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_fatal = fatal_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_fatal = []
    long_list_fatal = []
    for i in range(len(east_18)):
        lat, long = OSGB36toWGS84(east_18[i], north_18[i])
        lat_list_fatal.append(lat)
        long_list_fatal.append(long)

    serious_df = data_attendent_18.filter(data_attendent_18.severitynum == 2)
    east_18 = serious_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_18 = serious_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_serious = serious_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_serious = serious_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_serious = serious_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_serious = serious_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_serious = serious_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_serious = serious_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_serious = []
    long_list_serious = []
    for i in range(len(east_18)):
        lat, long = OSGB36toWGS84(east_18[i], north_18[i])
        lat_list_serious.append(lat)
        long_list_serious.append(long)

    """""""""""""""""""""""""""""""""""""""""""""""
    CLUSTER MAP 2018
    """""""""""""""""""""""""""""""""""""""""""""""
    mean_lat = statistics.mean(lat_list_serious)
    mean_long = statistics.mean(long_list_serious)
    acc_map_18 = folium.Map(location=[mean_lat, mean_long], zoom_start=10)
    marker_cluster = MarkerCluster().add_to(acc_map_18)

    for k in range(len(lat_list_fatal)):
        location = lat_list_fatal[k], long_list_fatal[k]
        popup = '<b>FATAL COLLISION, ' + str(casualty_fatal[k]) + ' KILLED</b> <br> <br>On ' + date_fatal[k] + ', ' + \
                day_fatal[k] + ' at ' + time_fatal[k] + ', an accident occured at ' + loc_fatal[k] + ' in ' + \
                borough_fatal[k] + ' killing ' + str(casualty_fatal[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='red')).add_to(marker_cluster)

    for k in range(len(lat_list_serious)):
        location = lat_list_serious[k], long_list_serious[k]
        popup = '<b>SERIOUS COLLISION, ' + str(casualty_serious[k]) + ' INJURED</b> <br> <br>On ' + date_serious[
            k] + ', ' + \
                day_serious[k] + ' at ' + time_serious[k] + ', an accident occured at ' + loc_serious[k] + ' in ' + \
                borough_serious[k] + ' severely injuring ' + str(casualty_serious[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='blue')).add_to(marker_cluster)

    acc_map_18.save('assets/map_18.html')

    """""""""""""""""""""""""""""""""""""""""""""""
    LATITUDE LONGITUDE CONVERSION 2017
    """""""""""""""""""""""""""""""""""""""""""""""
    fatal_df = data_attendent_17.filter(data_attendent_17.severitynum == 1)
    east_17 = fatal_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_17 = fatal_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_fatal = fatal_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_fatal = fatal_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_fatal = fatal_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_fatal = fatal_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_fatal = fatal_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_fatal = fatal_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_fatal = []
    long_list_fatal = []
    for i in range(len(east_17)):
        lat, long = OSGB36toWGS84(east_17[i], north_17[i])
        lat_list_fatal.append(lat)
        long_list_fatal.append(long)

    serious_df = data_attendent_17.filter(data_attendent_17.severitynum == 2)
    east_17 = serious_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_17 = serious_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_serious = serious_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_serious = serious_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_serious = serious_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_serious = serious_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_serious = serious_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_serious = serious_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_serious = []
    long_list_serious = []
    for i in range(len(east_17)):
        lat, long = OSGB36toWGS84(east_17[i], north_17[i])
        lat_list_serious.append(lat)
        long_list_serious.append(long)

    """""""""""""""""""""""""""""""""""""""""""""""
    CLUSTER MAP 2017
    """""""""""""""""""""""""""""""""""""""""""""""
    mean_lat = statistics.mean(lat_list_serious)
    mean_long = statistics.mean(long_list_serious)
    acc_map_17 = folium.Map(location=[mean_lat, mean_long], zoom_start=10)
    marker_cluster = MarkerCluster().add_to(acc_map_17)

    for k in range(len(lat_list_fatal)):
        location = lat_list_fatal[k], long_list_fatal[k]
        popup = '<b>FATAL COLLISION, ' + str(casualty_fatal[k]) + ' KILLED</b> <br> <br>On ' + date_fatal[k] + ', ' + \
                day_fatal[k] + ' at ' + time_fatal[k] + ', an accident occured at ' + loc_fatal[k] + ' in ' + \
                borough_fatal[k] + ' killing ' + str(casualty_fatal[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='red')).add_to(marker_cluster)

    for k in range(len(lat_list_serious)):
        location = lat_list_serious[k], long_list_serious[k]
        popup = '<b>SERIOUS COLLISION, ' + str(casualty_serious[k]) + ' INJURED</b> <br> <br>On ' + date_serious[
            k] + ', ' + \
                day_serious[k] + ' at ' + time_serious[k] + ', an accident occured at ' + loc_serious[k] + ' in ' + \
                borough_serious[k] + ' severely injuring ' + str(casualty_serious[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='blue')).add_to(marker_cluster)

    acc_map_17.save('assets/map_17.html')

    """""""""""""""""""""""""""""""""""""""""""""""
    LATITUDE LONGITUDE CONVERSION 2016
    """""""""""""""""""""""""""""""""""""""""""""""
    fatal_df = data_attendent_16.filter(data_attendent_16.severitynum == 1)
    east_16 = fatal_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_16 = fatal_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_fatal = fatal_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_fatal = fatal_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_fatal = fatal_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_fatal = fatal_df.select("time").rdd.flatMap(lambda x: x).collect()
    loc_fatal = fatal_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_fatal = fatal_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_fatal = []
    long_list_fatal = []
    for i in range(len(east_16)):
        lat, long = OSGB36toWGS84(east_16[i], north_16[i])
        lat_list_fatal.append(lat)
        long_list_fatal.append(long)

    serious_df = data_attendent_16.filter(data_attendent_16.severitynum == 2)
    east_16 = serious_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_16 = serious_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_serious = serious_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_serious = serious_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_serious = serious_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_serious = serious_df.select("time").rdd.flatMap(lambda x: x).collect()
    loc_serious = serious_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_serious = serious_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_serious = []
    long_list_serious = []
    for i in range(len(east_16)):
        lat, long = OSGB36toWGS84(east_16[i], north_16[i])
        lat_list_serious.append(lat)
        long_list_serious.append(long)

    """""""""""""""""""""""""""""""""""""""""""""""
    CLUSTER MAP 2016
    """""""""""""""""""""""""""""""""""""""""""""""
    mean_lat = statistics.mean(lat_list_serious)
    mean_long = statistics.mean(long_list_serious)
    acc_map_16 = folium.Map(location=[mean_lat, mean_long], zoom_start=10)
    marker_cluster = MarkerCluster().add_to(acc_map_16)

    for k in range(len(lat_list_fatal)):
        location = lat_list_fatal[k], long_list_fatal[k]
        popup = '<b>FATAL COLLISION, ' + str(casualty_fatal[k]) + ' KILLED</b> <br> <br>On ' + date_fatal[k] + ', ' + \
                day_fatal[k] + ' at ' + time_fatal[k] + ', an accident occured at ' + loc_fatal[k] + ' in ' + \
                borough_fatal[k] + ' killing ' + str(casualty_fatal[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='red')).add_to(marker_cluster)

    for k in range(len(lat_list_serious)):
        location = lat_list_serious[k], long_list_serious[k]
        popup = '<b>SERIOUS COLLISION, ' + str(casualty_serious[k]) + ' INJURED</b> <br> <br>On ' + date_serious[
            k] + ', ' + \
                day_serious[k] + ' at ' + time_serious[k] + ', an accident occured at ' + loc_serious[k] + ' in ' + \
                borough_serious[k] + ' severely injuring ' + str(casualty_serious[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='blue')).add_to(marker_cluster)

    acc_map_16.save('assets/map_16.html')

    """""""""""""""""""""""""""""""""""""""""""""""
    LATITUDE LONGITUDE CONVERSION 2015
    """""""""""""""""""""""""""""""""""""""""""""""
    fatal_df = data_attendent_15.filter(data_attendent_15.severitynum == 1)
    east_15 = fatal_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_15 = fatal_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_fatal = fatal_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_fatal = fatal_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_fatal = fatal_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_fatal = fatal_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_fatal = fatal_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_fatal = fatal_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_fatal = []
    long_list_fatal = []
    for i in range(len(east_15)):
        lat, long = OSGB36toWGS84(east_15[i], north_15[i])
        lat_list_fatal.append(lat)
        long_list_fatal.append(long)

    serious_df = data_attendent_15.filter(data_attendent_15.severitynum == 2)
    east_15 = serious_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_15 = serious_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_serious = serious_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_serious = serious_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_serious = serious_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_serious = serious_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_serious = serious_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_serious = serious_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_serious = []
    long_list_serious = []
    for i in range(len(east_15)):
        lat, long = OSGB36toWGS84(east_15[i], north_15[i])
        lat_list_serious.append(lat)
        long_list_serious.append(long)

    """""""""""""""""""""""""""""""""""""""""""""""
    CLUSTER MAP 2015
    """""""""""""""""""""""""""""""""""""""""""""""
    mean_lat = statistics.mean(lat_list_serious)
    mean_long = statistics.mean(long_list_serious)
    acc_map_15 = folium.Map(location=[mean_lat, mean_long], zoom_start=10)
    marker_cluster = MarkerCluster().add_to(acc_map_15)

    for k in range(len(lat_list_fatal)):
        location = lat_list_fatal[k], long_list_fatal[k]
        popup = '<b>FATAL COLLISION, ' + str(casualty_fatal[k]) + ' KILLED</b> <br> <br>On ' + date_fatal[k] + ', ' + \
                day_fatal[k] + ' at ' + time_fatal[k] + ', an accident occured at ' + loc_fatal[k] + ' in ' + \
                borough_fatal[k] + ' killing ' + str(casualty_fatal[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='red')).add_to(marker_cluster)

    for k in range(len(lat_list_serious)):
        location = lat_list_serious[k], long_list_serious[k]
        popup = '<b>SERIOUS COLLISION, ' + str(casualty_serious[k]) + ' INJURED</b> <br> <br>On ' + date_serious[
            k] + ', ' + \
                day_serious[k] + ' at ' + time_serious[k] + ', an accident occured at ' + loc_serious[k] + ' in ' + \
                borough_serious[k] + ' severely injuring ' + str(casualty_serious[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='blue')).add_to(marker_cluster)

    acc_map_15.save('assets/map_15.html')

    """""""""""""""""""""""""""""""""""""""""""""""
    LATITUDE LONGITUDE CONVERSION 2014
    """""""""""""""""""""""""""""""""""""""""""""""
    fatal_df = data_attendent_14.filter(data_attendent_14.severitynum == 1)
    east_14 = fatal_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_14 = fatal_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_fatal = fatal_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_fatal = fatal_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_fatal = fatal_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_fatal = fatal_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_fatal = fatal_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_fatal = fatal_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_fatal = []
    long_list_fatal = []
    for i in range(len(east_14)):
        lat, long = OSGB36toWGS84(east_14[i], north_14[i])
        lat_list_fatal.append(lat)
        long_list_fatal.append(long)

    serious_df = data_attendent_14.filter(data_attendent_14.severitynum == 2)
    east_14 = serious_df.select("easting").rdd.flatMap(lambda x: x).collect()
    north_14 = serious_df.select("northing").rdd.flatMap(lambda x: x).collect()
    casualty_serious = serious_df.select("numofcasualties").rdd.flatMap(lambda x: x).collect()
    date_serious = serious_df.select("accidentdate").rdd.flatMap(lambda x: x).collect()
    day_serious = serious_df.select("day").rdd.flatMap(lambda x: x).collect()
    time_serious = serious_df.select("time_new").rdd.flatMap(lambda x: x).collect()
    loc_serious = serious_df.select("location").rdd.flatMap(lambda x: x).collect()
    borough_serious = serious_df.select("borough").rdd.flatMap(lambda x: x).collect()

    lat_list_serious = []
    long_list_serious = []
    for i in range(len(east_14)):
        lat, long = OSGB36toWGS84(east_14[i], north_14[i])
        lat_list_serious.append(lat)
        long_list_serious.append(long)

    """""""""""""""""""""""""""""""""""""""""""""""
    CLUSTER MAP 2014
    """""""""""""""""""""""""""""""""""""""""""""""
    mean_lat = statistics.mean(lat_list_serious)
    mean_long = statistics.mean(long_list_serious)
    acc_map_14 = folium.Map(location=[mean_lat, mean_long], zoom_start=10)
    marker_cluster = MarkerCluster().add_to(acc_map_14)

    for k in range(len(lat_list_fatal)):
        location = lat_list_fatal[k], long_list_fatal[k]
        popup = '<b>FATAL COLLISION, ' + str(casualty_fatal[k]) + ' KILLED</b> <br> <br>On ' + date_fatal[k] + ', ' + \
                day_fatal[k] + ' at ' + time_fatal[k] + ', an accident occured at ' + loc_fatal[k] + ' in ' + \
                borough_fatal[k] + ' killing ' + str(casualty_fatal[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='red')).add_to(marker_cluster)

    for k in range(len(lat_list_serious)):
        location = lat_list_serious[k], long_list_serious[k]
        popup = '<b>SERIOUS COLLISION, ' + str(casualty_serious[k]) + ' INJURED</b> <br> <br>On ' + date_serious[
            k] + ', ' + \
                day_serious[k] + ' at ' + time_serious[k] + ', an accident occured at ' + loc_serious[k] + ' in ' + \
                borough_serious[k] + ' severely injuring ' + str(casualty_serious[k])
        folium.Marker(
            location=location,
            clustered_marker=True,
            popup=folium.Popup(popup, max_width=300, min_width=300),
            icon=folium.Icon(color='blue')).add_to(marker_cluster)

    acc_map_14.save('assets/map_14.html')
Exemplo n.º 8
0
from bng_to_latlon import OSGB36toWGS84


print(OSGB36toWGS84(534627,181456))

from latlon_to_bng import WGS84toOSGB36

print(WGS84toOSGB36(51.51603,-0.06216	))

Exemplo n.º 9
0
import pandas as pd
from bng_to_latlon import OSGB36toWGS84
import webbrowser
################################################################
if sys.platform == 'linux':
    Base = os.path.expanduser('~') + '/VKHCG'
else:
    Base = 'C:/VKHCG'
print('################################')
print('Working Base :', Base, ' using ', sys.platform)
print('################################')
################################################################
sFileNameIn = Base + '/01-Vermeulen/00-RawData/public-toilets.csv'
sFileNameOut = Base + '/01-Vermeulen/06-Report/01-EDS/02-Python/colchester_toilets.html'
# Load map centred on Colchester
uk = folium.Map(location=[51.8860942, 0.8336077], zoom_start=10)

# Load locally stored colchester public toilets data
toilets = pd.read_csv(sFileNameIn)

#add a marker for each toilet
for each in toilets.iterrows():
    print(list([each[1]['Geo X'], each[1]['Geo Y']]))
    print(list(OSGB36toWGS84(each[1]['Geo X'], each[1]['Geo Y'])))
    folium.Marker(list(OSGB36toWGS84(each[1]['Geo X'],each[1]['Geo Y'])), \
                  popup=each[1]['Street Address']).add_to(uk)

# Save map
print('Create HTML page')
uk.save(sFileNameOut)
webbrowser.open('file://' + os.path.realpath(sFileNameOut))