我有以下数据帧(df)并且想要以等距间隔(例如每250米)或时间间隔(例如每2分钟)内插Lat,Lon坐标。
public class JSONParser {
final String TAG = "JsonParser.java";
static InputStream is = null;
static JSONObject jObj = null;
static String jSon = "";
public JSONObject getJSONFromURL(String strURL) {
// TODO Auto-generated method stub
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(strURL);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity entity = httpResponse.getEntity();
is = entity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line + "\n");
}
//Log.e("Nitin", "Builder: " + builder.toString());
is.close();
jSon = builder.toString();
} catch (Exception e) {
Log.e(TAG, "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(jSon);
} catch (JSONException e) {
Log.e(TAG, "Error parsing data " + e.toString());
}
return jObj;
}
}
我尝试使用R package zoo和我在类似问题中找到的以下代码:
> head(df)
ID Latitude Longitude trip date.time
1 1 10.30447 -109.2323 1 2005-01-07 11:25:26
2 1 10.30425 -109.2321 1 2005-01-07 11:25:36
3 1 10.30314 -109.2326 1 2005-01-07 11:25:46
4 1 10.30199 -109.2328 1 2005-01-07 11:25:56
5 1 10.30079 -109.2334 1 2005-01-07 11:26:06
6 1 10.30006 -109.2331 1 2005-01-07 11:26:16
但是,由于我的数据框包含多个人(df $ ID)的多次旅行(df $ trip),我收到以下错误消息:
full.time <- with(df,seq(date.time[1],tail(date.time,1),by=1))
library(zoo)
df.zoo <- zoo(df[,3:4],df$date.time) # convert to zoo object
result <- na.approx(df.zoo,xout=full.time) # interpolate; result is also a zoo object
head(result)
如何运行以上代码(循环?)来计算个别旅行?