我最初尝试使用for循环编写它,并且在尝试多种方式之后它只是无法正常工作。有没有人建议为col1-col15部分编写for循环或有关如何整理此代码的任何其他建议?
它旨在生成网格形式的纬度/经度点列表。最后,我拿出每个点并通过API传递它以获得第3列,然后从那里将光栅重叠在传单地图上。
我觉得我可能正在用这个重新发明轮子,那里可能更容易。重要的一点是生成一个坐标网格,其间距和宽度我可以确定,所有坐标都围绕一个点。谢谢!
This is what the grid looks like, plotted roughly
# Setting a parameter for later
sdist = 20 # search distance radius around each point
# Input location
googleinput = c(39.166178, -105.919274)
mylat = googleinput[1]
mylon = googleinput[2]
# Creating a square
latplus = mylat + 1.8
latminus = mylat - 1.8
lonplus = mylon + 1.8
lonminus = mylon - 1.8
# Doing some geometry to make sure entire area is covered, even w/
# repeats
gridspacekm = sdist * sqrt(2)
gridspacecoord = 0.25 # this equals 28 km
# Setting up the x an y axis for this search grid
gridlat = seq(from = latplus, to = latminus, by = -gridspacecoord)
gridlon = seq(from = lonplus, to = lonminus, by = -gridspacecoord)
# Setting up each column for the grid
col1 = rep(gridlat[1], length(gridlon))
col2 = rep(gridlat[2], length(gridlon))
col3 = rep(gridlat[3], length(gridlon))
col4 = rep(gridlat[4], length(gridlon))
col5 = rep(gridlat[5], length(gridlon))
col6 = rep(gridlat[6], length(gridlon))
col7 = rep(gridlat[7], length(gridlon))
col8 = rep(gridlat[8], length(gridlon))
col9 = rep(gridlat[9], length(gridlon))
col10 = rep(gridlat[10], length(gridlon))
col11 = rep(gridlat[11], length(gridlon))
col12 = rep(gridlat[12], length(gridlon))
col13 = rep(gridlat[13], length(gridlon))
col14 = rep(gridlat[14], length(gridlon))
col15 = rep(gridlat[15], length(gridlon))
# finalizing the grid
# All of the x coordinates
x = c(col1, col2, col3, col4, col5, col6, col7, col8,
col9, col10, col11, col12, col13, col14, col15)
# All of the y coordinates
y = rep(gridlon, 15)
# Together in a data frame
df = data.frame(x, y)