getPlaces: Support function for getLatLon

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

Does the actual work of finding locations within a given distance of a lat/lon

Usage

1
getPlaces(lat, lon, distance, locLimit)

Arguments

lat

A latitude

lon

A longitude

distance

A distance in miles

locLimit

A limit on the number of locations

Details

Note that this function is not meant to be called by the user

Value

A list of locations

Note

None

Author(s)

Steve Pittard

References

STATS 290 Website

See Also

None

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## The function is currently defined as
function (lat, lon, distance, locLimit) 
{
    library(RCurl)
    library(RMySQL)
    library(XML)
    print("Querying the local Geonames database to see whats nearby")
    con = dbConnect(MySQL(), user = "wpittard", password = "t41tt", 
        dbname = "wpittard")
    str1 = "SELECT geo_latitude, geo_longitude, geo_name, "
    str2 = paste("(3959*acos(cos(radians(", lat, ")) * cos(radians(geo_latitude)) * cos(radians(geo_longitude) - radians(", 
        lon, "))", sep = "")
    str3 = paste("+ sin(radians(", lat, ")) * sin( radians( geo_latitude)))) AS distance FROM allcountries where ((geo_feature_code like '%ADM%')", 
        sep = "")
    str4 = paste("or (geo_feature_code like '%PPL%') )  having distance < ", 
        distance, ";", sep = "")
    str5 = paste(str1, str2, str3, str4)
    rs = dbSendQuery(con, statement = str5)
    data = fetch(rs, n = -1)
    dbDisconnect(con)
    if (nrow(data) >= locLimit) {
        newdata = data[sample(nrow(data), size = locLimit), ]
    }
    else {
        newdata = data
    }
    return(newdata)
  }

steviep42/PWS documentation built on May 30, 2019, 5:39 p.m.