我有用R编写的代码来检测村庄之间的水量(或shapefile多边形中的点)。我创建了一个超过2379个村庄(村庄有数字名称)的无向图,因此将带来28亿个组合。该图只是一个数据框。我让每个村的坐标:在R中更快地检测shapefile多边形中的点更快R
VillageName1, VillageName2
Village1, Village2
Village1, Village3
Village1, Village4
...
Village2379, Village2378
对于每一个组合,我将在百米间隔创建,比方说,Village1点Village2功能。因此,如果Village1和Village2相距1公里,则会创建8个点。此功能运行速度相对较快。
问题是,如果Village1和Village2在两个独立的岛上,我使用世界海洋shapefile(6.9mb),以便能够检测100米的水量,但它非常缓慢(每次计算约4秒)并且运行28亿次将永远持续下去。
我试图筛选基于这些村庄shape文件(ocean_indo_shapefile)国(印度尼西亚):
sea <- readOGR('World_EEZ_v8_2014.shp')
ocean_indo_shapefile <- sea[sea$Country == "Indonesia", ]
#this function creates the points from Village1 to Village2 in 100m intevals, output is a dataframe
points <- create_coordinates(village1_lat, village1_long, village2_lat, village2_long, 0.1)
coordinates(points) <- ~ Longitude + Latitude
proj4string(points) <- proj4string(ocean_indo_shapefile)
#the calculation below is slow
water_in_meter <- length(points[ocean_indo_shapefile,])
我不知道如果有人能帮助提示,我怎么能做出这样快了很多,我感谢任何帮助。先谢谢你。
postgis可能要走的路 –
只有最后一行很慢? 'points'是一个数据框? –
我以前从未使用过PostGIS,所以我不确定在这种情况下如何去做。 – iPho