【问题标题】:Creating density plots using coordinates in R使用 R 中的坐标创建密度图
【发布时间】:2017-06-15 23:54:44
【问题描述】:

提前谢谢你

我正在尝试创建一个农场密度图,我有其中的坐标。我有农场长/纬度坐标,我已将其转换为空间数据并使用以下代码绘制在新西兰地图上;

# Read in New Zealand shape file 
NZ <-readShapeLines("ESRI_Shapefile_2016_Digital_Boundaries_High_Def_Clipped/TA2016_HD_Clipped.shp")

# Change projection 
proj4string(NZ)<-CRS("+proj=tmerc +lat_0=0.0 +lon_0=173.0 +k=0.9996 +x_0=1600000.0 +y_0=10000000.0 +datum=WGS84 +units=m")

# Plot map and point data 
plot(NZ)
points(Farm_points) 

有没有一种简单的方法可以将此点数据转换为密度数据并在地图上绘制?

我尝试使用 GISTools 包和以下代码计算每个多边形中的点数;

counts <- poly.counts(Farms_points, NZ)

但是我收到以下错误消息;

Error in identical(spgeom1@proj4string, spgeom2@proj4string) : 
  trying to get slot "proj4string" from an object of a basic class ("matrix") with no slots 

欢迎提出建议……

谢谢

【问题讨论】:

  • 你们能提供样本数据吗?

标签: r spatial density-plot


【解决方案1】:

没有您的数据,我们无法测试为什么它不起作用,但是,错误消息很清楚:如果您希望poly.counts 起作用,您需要将您的矩阵Farms_points 转换为SpatialPoints

Farms_points_sp <- SpatialPoints(Farm_points, proj4string = proj4string(NZ))
counts <- poly.counts(Farms_points_sp, NZ)

【讨论】:

    猜你喜欢
    • 2016-09-26
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多