Beispiel #1
0
def _parse_coordinates():
    out = None
    args = parser.parse_args()
    if args is None:
        return None
    if ('x' in args) and ('y' in args):
        out = Coordinates(x=args['x'], y=args['y'])
    elif ('lat' in args) and ('lon' in args):
        s = args['lat'] + ', ' + args['lon']
        jtsk = string_wgs_to_jtsk(str)
        if jtsk is not None:
            out = Coordinates(x=jtsk.x, y=jtsk.y)
    return out
Beispiel #2
0
def _parse_coordinates_get():
    args = request.args
    out = None
    if ('x' in args) and ('y' in args):
        x = args['x']
        y = args['y']
        out = Coordinates(x=float(x), y=float(y))
    elif ('lat' in args) and ('lon' in args):
        lat = args['lat']
        lon = args['lon']
        s = lat + ', ' + lon
        jtsk = string_wgs_to_jtsk(s)
        if jtsk is not None:
            out = Coordinates(x=jtsk.x, y=jtsk.y)
    return out
Beispiel #3
0
 def post(self):
     args = parser.parse_args()
     geo = Coordinates(x=args['x'], y=args['y'])
     parc = get_parcela(geo.y, geo.x)
     if parc is None:
         err = {"error": "Geolocation not found", "x": geo.x, "y": geo.y}
         return Response(json.dumps(err), mimetype='application/json')
     return Response(json.dumps(parc.__dict__), mimetype='application/json')
Beispiel #4
0
def _find_locality(identifier):
    work = _find_coordinates(identifier)
    if not work:
        return None
    row = work[0]
    coord = Coordinates(float(row[0]), float(row[1]))
    addr = Address(row[5], row[6], row[7], row[8], row[9], row[10], row[3],
                   row[4], None, row[11], row[2])
    locality = Locality(addr, coord)
    return locality
Beispiel #5
0
def _convert_point_to_jtsk(lat, lon):
    geom = "ST_GeomFromText('POINT({0} {1})',4326)".format(str(lon), str(lat))
    sql = "SELECT ST_Transform(" + geom + ", 5514) AS jtsk_geom;"
    cur = execute_sql(DATABASE_NAME_POVODI, sql)
    row = cur.fetchone()
    cur.close()
    if row is None:
        return None
    out = Coordinates(x=row[0].coords[0], y=row[0].coords[1])
    return out
Beispiel #6
0
def _find_coordinates_by_address(dictionary):
    if "district_number" in dictionary:
        if dictionary["district_number"] != "":
            dictionary[
                "district_number"] = "Praha " + dictionary["district_number"]

    first = True
    sql = "SELECT " + ADDRESSPOINTS_COLUMNS_FIND_COORD + \
          " FROM " + ADDRESSPOINTS_TABLE_NAME + \
          " WHERE "
    for key in dictionary:
        if dictionary[key] != "":
            if first:
                sql += ITEM_TO_FIELD[key] + " = '" + dictionary[key] + "'"
                first = False
            else:
                sql += " AND " + ITEM_TO_FIELD[key] + " = '" + dictionary[
                    key] + "'"

    sql += "LIMIT " + str(MAX_COUNT)
    cur = execute_sql(DATABASE_NAME_RUIAN, sql)
    rows = cur.fetchall()
    coordinates = []
    localities = []
    for row in rows:
        if (row[0] is not None) and (row[1] is not None):
            (house_number,
             record_number) = analyse_row(row[7], number_to_string(row[6]))
            coordinates.append(
                (str("{:10.2f}".format(row[0])).strip(),
                 str("{:10.2f}".format(row[1])).strip(), row[2], row[3],
                 none_to_string(row[4]), none_to_string(row[5]),
                 house_number, record_number, number_to_string(row[8]),
                 none_to_string(row[9]), number_to_string(row[10]),
                 number_value(none_to_string(row[11]))))
            # latitude, longitude, gid, nazev_obce, nazev_casti_obce, nazev_ulice, cislo_domovni, typ_so,
            # cislo_orientacni, znak_cisla_orientacniho, psc, nazev_mop
            coord = Coordinates(row[0], row[1])
            addr = Address(row[5], house_number, record_number, row[8], row[9],
                           row[10], row[3], row[4], None, row[11], row[2])
            loc = Locality(addr, coord)
            localities.append(loc)
        else:
            # co se ma stat kdyz adresa nema souradnice?
            pass
    cur.close()
    # return coordinates
    return localities
Beispiel #7
0
def dictionary_to_locality(dictionary):
    locality = None
    if dictionary:
        coordinates = None
        if dictionary[ADDR_X] and dictionary[ADDR_Y]:
            coordinates = Coordinates(dictionary[ADDR_Y], dictionary[ADDR_X])
        address = Address(dictionary[ADDR_STREET],
                          dictionary[ADDR_HOUSE_NUMBER],
                          dictionary[ADDR_RECORD_NUMBER],
                          dictionary[ADDR_ORIENTATION_NUMBER],
                          dictionary[ADDR_ORIENTATION_NUMBER_CHARACTER],
                          dictionary[ADDR_ZIP_CODE], dictionary[ADDR_LOCALITY],
                          dictionary[ADDR_LOCALITY_PART],
                          dictionary[ADDR_DISTRICT_NUMBER],
                          dictionary[ADDR_DISTRICT], dictionary[ADDR_ID])
        locality = Locality(address, coordinates)
    return locality
Beispiel #8
0
def _convert_coord_to_jtsk(coord: CoordinatesGps):
    point = _convert_point_to_jtsk(coord.lat, coord.lon)
    if point is not None:
        out = Coordinates(point.y, point.x)
        return out
    return None