我正在弄清楚如何在shape和多边形之间进行交点(空间连接).我的想法是获得最接近的点和那些在多边形内完全匹配的点.在ARGIS中,有一个名为CLOSEST的匹配选项函数,它们定义为:"最接近目标要素的连接要素中的要素是匹配的.两个或更多连接要素可能与目标的距离相同当出现这种情况时,随机选择一个连接特征作为匹配特征."
我有一个函数将点交叉成多边形,它是由Lyndon Estes在r-sig-geo列表中提供的,当所有多边形填满所有区域时代码工作得非常好.第二种情况称为空间连接距离,当match_option为CLOSEST时,在ArcGIS中称为INTERSECT,如ArcGIS所做的那样.因此,当区域未被所有多边形填充时,您可以修改点与多边形之间的最小距离.
这是第一个INTERSECT的数据和功能:
library(rgeos)
library(sp)
library(maptools)
library(rgdal)
library(sp)
xy.map <- readShapeSpatial("http://www.udec.cl/~jbustosm/points.shp")
manzana.map <- readShapeSpatial("http://www.udec.cl/~jbustosm/manzanas_from.shp" )
IntersectPtWithPoly <- function(x, y) {
# Extracts values from a SpatialPolygonDataFrame with SpatialPointsDataFrame, and appends table (similar to
# ArcGIS intersect)
# Args:
# x: SpatialPoints*Frame
# y: SpatialPolygonsDataFrame
# Returns:
# SpatialPointsDataFrame with appended table of polygon attributes
# Set up overlay with new column of join IDs in x
z <- overlay(y, x)
# Bind captured data to points dataframe
x2 <- …Run Code Online (Sandbox Code Playgroud) 我在RODBCORACLE DATA BASE(DB)中使用该程序包。一切都做得很好,但是我需要从该数据库中获取一张表,并获取一些变量作为字符类型,而不是数字。
因此,我这样查询:
e ManzResul_VIII<-sqlQuery(con,"select distinct t.fono_id_dis,
t.id_predio,
t.co_calle,
t.nu_casa,
t.x,
t.y,
t.plancheta from c_araya.proy_dist08_todo t where nvl(t.fono_tipo_dis, '-') not in ('CLIENTE', 'POTENCIAL', 'CARTERA') and nvl(t.x, 0) <> 0 ")
Run Code Online (Sandbox Code Playgroud)
无法将ID号作为Character获取,此查询将我的iDs变量的类型从Character更改为Numeric类型(ID开头为零,但已将其更改为数字)。我已经阅读了功能说明,但可以看到如何对其进行管理。
任何想法将不胜感激,在此先感谢!