distance

how to group data by LatLong distance in R

别说谁变了你拦得住时间么 提交于 2019-12-04 23:26:52
I have a function distance(lat1,lon1, lat2,lon2) that calculates the distance of 2 points. Suppose I have a dataframe with some points and values: n<-c(lon = -1.729219, lat = 29.730836) o<-c(lon = -5.041928, lat = 28.453022) e<-c(lon = -2.700067, lat = 29.198922) s<-c(lon = -5.212864, lat = 28.531739) centro<-matrix(c(n,o,e,s), ncol=2, byrow=TRUE) d<-data.frame(c=centro, amount=c(3.5,3.5,3.5,3.5), count=c(12,12,12,12)) colnames(d)<-c('lon','lat','amount','count') I want to get a a new frameset with the values aggregated to the closest one of them (I don't care wich) Suppose I have a rad of

Time series distance metric

冷暖自知 提交于 2019-12-04 21:58:33
问题 In order to clusterize a set of time series I'm looking for a smart distance metric. I've tried some well known metric but no one fits to my case. ex: Let's assume that my cluster algorithm extracts this three centroids [s1, s2, s3]: I want to put this new example [sx] in the most similar cluster: The most similar centroids is the second one, so I need to find a distance function d that gives me d(sx, s2) < d(sx, s1) and d(sx, s2) < d(sx, s3) edit Here the results with metrics [cosine,

calculate distance between 2 coordinates iphone - best practice

我是研究僧i 提交于 2019-12-04 20:51:25
I'm finishing an App in wish i need to show the user the distance between him and about 500 coordinates. using the CLLocation method to calculate it, works well, but it takes about 1 minute in iPhone 4 to finish calculations for each location. What is the best way to do it? Using span? Any other faster way? Thanks all, rui I think Sahgal is right, here is some code, perhaps it will help you. +(CGFloat)calculateDistanceBetweenSource:(CLLocationCoordinate2D)firstCoords andDestination:(CLLocationCoordinate2D)secondCoords { // this radius is in KM => if miles are needed it is calculated during

Calculating the driving distance between two points using PHP only (Bing maps)

谁说胖子不能爱 提交于 2019-12-04 20:38:40
I'd like to work out the distance between two points. No map. No javascript. Just the distance. I understand Google maps prohibits this and it's against their terms of service. But Bing Maps doesn't have this restriction. I want to give the points in a general format, i.e "Cambridge" "Church Street, Newcastle" How would I go about doing it? As basic as possible. It's for a mobile device. 1.) Sign up for a Bing Maps key at http://www.bingmapsportal.com . A key is a alphanumeric string of around 64 characters in length, something like: AtGYpcoIpC5zy0P2k4Bc4839b-

Geo distance calculation using SparkR

做~自己de王妃 提交于 2019-12-04 19:17:07
I have a Spark dataframe in R as follows head(df) Lat1 Lng1 Lat2 Lng2 23.123 24.234 25.345 26.456 ... ... ... ... The DataFrame contains two points Latitude and Longitude I would like to calculate the Geo distance between the nodes in each row and add it to a new column. In R I am using distCosine function from geosphere library. df$dist = distCosine(cbind(df$lng1,df$lat1),cbind(df$lng2,df$lat2)) I am wondering how I should calculate it in SparkR. SparkR produces the following error, Error in as.integer(length(x) > 0L) : cannot coerce type 'S4' to vector of type 'integer' You cannot use

Geolocation WatchPosition Distance Calculator

时光怂恿深爱的人放手 提交于 2019-12-04 19:17:03
I am using geolocation to get the users current location and monitor it using the watchPosition method. However, is there a way of calculating the distance between the users starting position and current position? Below is my code: var x = document.getElementById("info"); function getLocation() { if(navigator.geolocation) { navigator.geolocation.watchPosition(showPosition, showError, { enableHighAccuracy: true, maximumAge: 60000, timeout: 27000 }) } else { x.innerHTML = "Geolocation is not supported by this browser."; } } var flightPathCoordinates = []; function showPosition(position) { x

R function to calculate nearest neighbor distance given [inconsistent] constraint?

笑着哭i 提交于 2019-12-04 19:11:51
I have data consisting of tree growth measurements (diameter and height) for trees at known X & Y coordinates. I'd like to determine the distance to each tree's nearest neighbor of equal or greater size . I've seen other SE questions asking about nearest neighbor calculations (e.g., see here , here , here , here , etc.), but none specify constraints on the nearest neighbor to be searched. Is there a function (or other work around) that would allow me to determine the distance of a point's nearest neighbor given that nearest point meets some criteria (e.g., must be equal to or greater in size

OpenLayers : How to calculate distance between two points?

孤者浪人 提交于 2019-12-04 17:49:45
问题 How can one calculate the distance in OpenLayers between 2 points using Mercator projection? Thanks 回答1: use point1.distanceTo(point2) var Geographic = new OpenLayers.Projection("EPSG:4326"); var Mercator = new OpenLayers.Projection("EPSG:900913"); function distanceBetweenPoints(latlng1, latlng2){ var point1 = new OpenLayers.Geometry.Point(latlng1.lon, latlng1.lat).transform(Geographic, Mercator); var point2 = new OpenLayers.Geometry.Point(latlng2.lon, latlng2.lat).transform(Geographic,

Calculate distance between two long lat coordinates in a dataframe

旧城冷巷雨未停 提交于 2019-12-04 17:13:38
I want to calculate the distance between several GPS points. I tried distm(c(lon1,lat1), c(lon2,lat2), fun = distHaversine) which worked for one point, but not for the columns in my data frame. So I tried as recommended here: Calculate distance between 2 lat longs But I do get different results for these two calculations: df <- read.table(sep=",", col.names=c("lat1", "lon1", "lat2", "lon2"),text=" 7.348687,53.36575,7.348940,53.36507 7.348940, 53.36507,7.350939,53.36484") # as recommended in the link above distHaversine(df[,2:1], df[,4:3]) [1] 80.18433 223.97181 # with distm distm(c(7.348687,53

Calculate special correlation distance matrix faster

ぃ、小莉子 提交于 2019-12-04 16:58:32
I would like to build a distance matrix using Pearson correlation distance. I first tried the scipy.spatial.distance.pdist(df,'correlation') which is very fast for my 5000 rows * 20 features dataset. Since I want to build a recommender, I wanted to slightly change the distance, only considering features which are distinct for NaN for both users. Indeed, scipy.spatial.distance.pdist(df,'correlation') output NaN when it meets any feature whose value is float('nan'). Here is my code, df being my 5000*20 pandas DataFrame dist_mat = [] d = df.shape[1] for i,row_i in enumerate(df.itertuples()): for