示例#1
0
def _get_corners():
    """
    Populate the Global Dictionary, all_corners, with the coordinates
    of all the nodes in the data set.
    """
    if not all_corners:
        for tag in soup.find_all('node'):
            ref = tag.get('id')
            lat = float(tag.get('lat'))
            lon = float(tag.get('lon'))
            grid = latlong2grid(lat, lon)
            all_corners[ref] = grid.E, grid.N
    def get_property_boundary(lat, lon, likely_boundary=None):

        point = latlong2grid(lat, lon)
        point = (point.E, point.N)

        # Check the likely boundary first to save time
        if likely_boundary and Point(point).within(
                shape(boundaries[likely_boundary])):
            return likely_boundary

        for boundary in boundaries:
            if Point(point).within(boundaries[boundary]):
                return boundary

        raise UnregognisedPropertyLocationException("{},{}".format(lat, lon))
示例#3
0
    def process_item(self, item, spider):
        if item['ngr'] is not None:
            item['ngr'] = self.pad_ngr(item['ngr'])

        if item['wgS84'] is None and item['ngr'] is None:
            raise DropItem('wgS84 and ngr not set %s' % item)

        if item['wgS84'] is None:
            latlong = grid2latlong(item['ngr'], tag='WGS84')
            item['wgS84'] = [latlong.latitude, latlong.longitude]

        if item['ngr'] is None:
            item['ngr'] = str(
                latlong2grid(item['wgS84'][0], item['wgS84'][1], tag='WGS84'))

        return item
示例#4
0
def respond(s, xml):
    ts = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ')
    request = parseCoT(xml)
    print(ts, request)
    if request["cmd"] in commands:
        print(request["lat"], request["lon"])
        if (abs(request["lat"]) + abs(request["lon"])) < 1.0:
            s.sendall(
                geochat(
                    "Set your location (%.1f,%.1f )before requesting a conversion!"
                    % (request["lat"], request["lon"]), request["atakuid"]))
            return
        s.sendall(
            geochat(
                "Tranforming location %.5f, %.5f..." %
                (request["lat"], request["lon"]), request["atakuid"]))

        # WHAT 3 WORDS
        if request["cmd"] == "w3w":
            res = geocoder.convert_to_3wa(
                what3words.Coordinates(request["lat"], request["lon"]))
            if "words" in res:
                s.sendall(geochat(res["words"], request["atakuid"]))
            else:
                print(res)
                s.sendall(geochat(res["error"]["message"], request["atakuid"]))

        # OSGB / EPSG
        if request["cmd"] == "os":
            bng = latlong2grid(request["lat"], request["lon"])
            print(bng)
            s.sendall(geochat(str(bng), request["atakuid"]))
    else:
        s.sendall(
            geochat(
                "Available services. Ensure you have set your lat/lon either manually or with a GPS",
                request["atakuid"]))
        c = 0
        while c < len(commands):
            s.sendall(
                geochat(commands[c] + ": " + helpers[c], request["atakuid"]))
            c += 1
示例#5
0
    def __calculate_bng(self, datum):

        bng = latlong2grid(self.lat, self.lon, datum)

        return (bng.E, bng.N)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Dec  5 16:52:58 2019

@author: thomasjhojlunddodd
"""

from OSGridConverter import latlong2grid
import pandapower.networks as pn

net = pn.case1888rte(ref_bus_idx=1246)

x = range(0, ((len(net.bus_geodata.index)) - 1))
for i in x:
    g = latlong2grid(net.bus_geodata.x[i], net.bus_geodata.y[i])

    net.bus_geodata.x[i] = g.E
    net.bus_geodata.y[i] = g.N

#g = latlong2grid(52.657977,1.716038)

#print(g.E, g.N)

print(net.bus_geodata)
示例#7
0
def convert(latitude, longitude):
    grid = latlong2grid(float(latitude), float(longitude))

    return str(grid)[0:2] + str(grid.E)[1:-2] + str(grid.N)[1:-2]
示例#8
0
with open('parking.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=';')
    line_count = 0
    for row in csv_reader:
        if line_count == 0:
            line_count += 1
        else:
            # print(row[8] +', manchester , UK', )
            responce = requests.get(
                'https://maps.googleapis.com/maps/api/geocode/json?address=' +
                row[8] +
                ', manchester, uk&key=AIzaSyCAcR729aS6d0hfZGpLWsDBBuK1X0hFpB8')

            lattitude = responce.json(
            )['results'][0]['geometry']['location']['lat']
            longtitude = (
                responce.json()['results'][0]['geometry']['location']['lng'])

            line_count += 1

            grid = latlong2grid(lattitude, longtitude)

            grifref = [(str(grid)[0:2] + str(grid.E)[1:-2] + str(grid.N)[1:-2])
                       ]
            # print(grifref)
            # p= csv.writer(grifref)
            with open("output.csv", 'a') as finalfile:
                wr = csv.writer(finalfile, dialect='excel')
                wr.writerow(grifref)
示例#9
0
stations = {
    'IDs': ['W001', 'W006', 'W018', 'W026', 'PC', 'CH'],
    'Names': [
        'Sutton Park', 'Handsworth', 'Hodge Hill', 'Elms Road',
        'Paradise Circus', 'Coleshill'
    ],
    'Lat': [52.566353, 52.50451, 52.49249, 52.45638, 52.4806, 52.48015],
    'Lon': [-1.83791, -1.92291, -1.80763, -1.92767, -1.90493, -1.69075]
}

# Transform co-ordinates for met stations
gridn = []
gride = []
for i, j in zip(stations['Lat'], stations['Lon']):
    g = latlong2grid(i, j)
    gridn.append(g.N)
    gride.append(g.E)

stations['gridn'] = gridn
stations['gride'] = gride
print(gridn, gride)

# Now we have sufficient information for be able to plot our overview map.

fig, ax = plt.subplots(figsize=(4, 4))
ax.set_aspect('equal')

df_bound.plot(ax=ax, zorder=-1, alpha=1, color='white', edgecolors='grey')
brum.plot(ax=ax, zorder=-1, alpha=0.7, color='lightgrey', edgecolors='grey')
df_broad.plot(ax=ax, color='tan')