distance

how to group data by LatLong distance in R

℡╲_俬逩灬. 提交于 2020-02-21 06:55:46
问题 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

how to group data by LatLong distance in R

僤鯓⒐⒋嵵緔 提交于 2020-02-21 06:55:33
问题 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

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

给你一囗甜甜゛ 提交于 2020-02-21 05:57:42
问题 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

sorting distance in MySQL PHP [duplicate]

こ雲淡風輕ζ 提交于 2020-02-08 10:18:05
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, boolean given in select My Code: <?php $Sql="SELECT *, (3959 * acos(cos(radians(37)) * cos(radians(44)) * cos(radians(55) - radians(-122)) + sin(radians(37)) * sin(radians(44))) as distance FROM TableName HAVING distance < 25 ORDER BY distance LIMIT 0 , 20"; $result=mysql_query($Sql); while ($row = mysql_fetch_array($result)){ echo $row['Id']; } Error:

Writing a function that looks for element in a matrix based on values of columns of data frame

夙愿已清 提交于 2020-01-24 13:20:20
问题 I have a data frame with origin and destination names like the following (I will simplify to make it clearer): Origin Dest Time A B Mon B C Wed C B Fri I also have a distance matrix that finds the distance between places A , B , and C . A B C A 0 8 11 B 8 0 6 C 11 6 0 How would I go about extracting the distance from the distance matrix and inputting it in a separate column (such as df$Distance ) for each row of the data frame? 回答1: You could reflow the data into long format and merge based

Calculate coordinates of a point with given distances to two other points

匆匆过客 提交于 2020-01-23 18:37:29
问题 If I have three points A, B, C and I know the distances between them and A is at 2D coordinates {0,0} and B is at {ab,0}, then what would be the formula to find the coordinates of the point C? 回答1: The point {cx, cy} has to solve two equations: cx^2+cy^2==ac^2 && (cx-ab)^2+cy^2==bc^2 => cx^2-(cx-ab)^2==ac^2-bc^2 => 2*cx*ab==ac^2-bc^2+ab^2 => cx = (ac^2-bc^2+ab^2)/(2*ab) => cy = +/- sqrt(ac^2-cx^2) iff ac^2-cx^2 > 0 => cy = 0 iff ac^2-cx^2 = 0 => no solution else There are either two points

Pandas Return Separate DataFrame Values Based on Function

安稳与你 提交于 2020-01-23 08:25:17
问题 I have two DataFrames, df1 are locations of places and df2 are locations of stations. I am trying to find a more efficient way to apply a distance function to find which stations are within a certain range and return the station's name. If the distance function is a Latitude Difference of +/- 1 this is my expected outcome: # df1 Lat Long 0 30 31 1 37 48 2 54 62 3 67 63 # df2 Station_Lat Station_Long Station 0 30 32 ABC 1 43 48 DEF 2 84 87 GHI 3 67 62 JKL # ....Some Code that compares df1 and

Pandas Return Separate DataFrame Values Based on Function

爱⌒轻易说出口 提交于 2020-01-23 08:24:06
问题 I have two DataFrames, df1 are locations of places and df2 are locations of stations. I am trying to find a more efficient way to apply a distance function to find which stations are within a certain range and return the station's name. If the distance function is a Latitude Difference of +/- 1 this is my expected outcome: # df1 Lat Long 0 30 31 1 37 48 2 54 62 3 67 63 # df2 Station_Lat Station_Long Station 0 30 32 ABC 1 43 48 DEF 2 84 87 GHI 3 67 62 JKL # ....Some Code that compares df1 and

Geo distance calculation using SparkR

北城余情 提交于 2020-01-23 04:08:38
问题 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

Fastest available algorithm for distance transform

我的梦境 提交于 2020-01-19 04:48:46
问题 I am looking for the fastest available algorithm for distance transform. According to this site http://homepages.inf.ed.ac.uk/rbf/HIPR2/distance.htm, it describes: "The distance transform can be calculated much more efficiently using clever algorithms in only two passes (e.g. Rosenfeld and Pfaltz 1968)." Searching around, I found: "Rosenfeld, A and Pfaltz, J L. 1968. Distance Functions on Digital Pictures. Pattern Recognition, 1, 33-61." But I believe we should have a better and faster