Help with spTransform() function and final plot colors

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with spTransform() function and final plot colors

R-sig-geo mailing list
#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 (build 17763)

Hello. I am running my data through a routine I found that finds clusters of data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the plot itself, seems to work Can this error be corrected somehow, despite the fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the colors but the clusters in the plot are black, see plot call at the end of the routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
      coords.x1 coords.x2        
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) :
  failure in points 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, -122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, -122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, -122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, -122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA, -53L))

Here is the routine:
require(sp)
require(rgdal)
#25*1609.34 = 40233.5      
dis <- 40233.5 #Distance threshold 25miles converted to meters

x <- tmp1b[,c(6)]
head(x)
y <- tmp1b[,c(5)]
head(y)
str(y)

xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
                             proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

str(xy)

xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error occurring here?

chc <- hclust(dist(data.frame(rownames=rownames(xy@data), x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
                              y=coordinates(xy)[,2])), method="complete")
str(chc)

view(xy@data)#Look like 3 clusters

# Distance with a 25 Mile threshold
chc.dis <- cutree(chc, h=dis)
str(chc.dis)
view(chc.dis)

# Join results to meuse sp points
xy@data <- data.frame(xy@data, Clust=chc.dis)
str(xy@data)
view(xy@data)

# Plot results
plot(xy, col=factor(xy@data$Clust), pch=19)
box(col="black")
title(main="Clustering")
legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in demo to 3 in my data
       col=palette()[1:3], pch=rep(19,3), bg="white")


Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with spTransform() function and final plot colors

R-sig-geo mailing list
Hello, I have found an additional problem.

I should be getting 3 columns back in the xy@data at some point.
$ ID                           : int  1 2 3 4 5 6 7 8 9 10 ...
# $ Clust                  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
# $ Clust.1               : int  1 1 1 1 1 1 1 1 1 1 ... This would be the cluster number, like 1-3, I am not getting this column back?


Yet the plot runs and indicates three different clusters?



WHP



Proprietary

-----Original Message-----
From: Poling, William <[hidden email]>
Sent: Monday, May 18, 2020 4:46 AM
To: [hidden email]
Cc: Poling, William <[hidden email]>
Subject: Help with spTransform() function and final plot colors

#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 (build 17763)

Hello. I am running my data through a routine I found that finds clusters of data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the plot itself, seems to work Can this error be corrected somehow, despite the fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the colors but the clusters in the plot are black, see plot call at the end of the routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
      coords.x1 coords.x2        
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) :
  failure in points 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, -122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, -122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, -122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, -122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA, -53L))

Here is the routine:
require(sp)
require(rgdal)
#25*1609.34 = 40233.5      
dis <- 40233.5 #Distance threshold 25miles converted to meters

x <- tmp1b[,c(6)]
head(x)
y <- tmp1b[,c(5)]
head(y)
str(y)

xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
                             proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

str(xy)

xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error occurring here?

chc <- hclust(dist(data.frame(rownames=rownames(xy@data), x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
                              y=coordinates(xy)[,2])), method="complete")
str(chc)

view(xy@data)#Look like 3 clusters

# Distance with a 25 Mile threshold
chc.dis <- cutree(chc, h=dis)
str(chc.dis)
view(chc.dis)

# Join results to meuse sp points
xy@data <- data.frame(xy@data, Clust=chc.dis)
str(xy@data)
view(xy@data)

# Plot results
plot(xy, col=factor(xy@data$Clust), pch=19)
box(col="black")
title(main="Clustering")
legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in demo to 3 in my data
       col=palette()[1:3], pch=rep(19,3), bg="white")


Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with spTransform() function and final plot colors

R-sig-geo mailing list
Hello, I have found an additional problem.

I should be getting 3 columns back in the xy@data at some point.
$ ID                           : int  1 2 3 4 5 6 7 8 9 10 ...
# $ Clust                  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
# $ Clust.1               : int  1 1 1 1 1 1 1 1 1 1 ... This would be the cluster number, like 1-3, I am not getting this column back?


Yet the plot runs and indicates three different clusters?



WHP


Proprietary

-----Original Message-----
From: Poling, William <[hidden email]>
Sent: Monday, May 18, 2020 4:47 AM
To: [hidden email]
Cc: Poling, William <[hidden email]>
Subject: RE: Help with spTransform() function and final plot colors

Hello, I have found an additional problem.

I should be getting 3 columns back in the xy@data at some point.
$ ID                           : int  1 2 3 4 5 6 7 8 9 10 ...
# $ Clust                  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
# $ Clust.1               : int  1 1 1 1 1 1 1 1 1 1 ... This would be the cluster number, like 1-3, I am not getting this column back?


Yet the plot runs and indicates three different clusters?



WHP



Proprietary

-----Original Message-----
From: Poling, William <[hidden email]>
Sent: Monday, May 18, 2020 4:46 AM
To: [hidden email]
Cc: Poling, William <[hidden email]>
Subject: Help with spTransform() function and final plot colors

#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 (build 17763)

Hello. I am running my data through a routine I found that finds clusters of data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the plot itself, seems to work Can this error be corrected somehow, despite the fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the colors but the clusters in the plot are black, see plot call at the end of the routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
      coords.x1 coords.x2        
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) :
  failure in points 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, -122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, -122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, -122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, -122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA, -53L))

Here is the routine:
require(sp)
require(rgdal)
#25*1609.34 = 40233.5      
dis <- 40233.5 #Distance threshold 25miles converted to meters

x <- tmp1b[,c(6)]
head(x)
y <- tmp1b[,c(5)]
head(y)
str(y)

xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
                             proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

str(xy)

xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error occurring here?

chc <- hclust(dist(data.frame(rownames=rownames(xy@data), x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
                              y=coordinates(xy)[,2])), method="complete")
str(chc)

view(xy@data)#Look like 3 clusters

# Distance with a 25 Mile threshold
chc.dis <- cutree(chc, h=dis)
str(chc.dis)
view(chc.dis)

# Join results to meuse sp points
xy@data <- data.frame(xy@data, Clust=chc.dis)
str(xy@data)
view(xy@data)

# Plot results
plot(xy, col=factor(xy@data$Clust), pch=19)
box(col="black")
title(main="Clustering")
legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in demo to 3 in my data
       col=palette()[1:3], pch=rep(19,3), bg="white")


Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with spTransform() function and final plot colors

R-sig-geo mailing list
In reply to this post by R-sig-geo mailing list
Hello again.

I also found this discussion on non-finite transformation error, however, I am not sure what to look for in the output after I apply my data?

https://stackoverflow.com/questions/14880294/non-finite-transformation-detected-in-sptransform-in-rgdal-r-package



str(sample)
GPS.Points <- sample[,c(2,3)]

n_chunks <- 3 #number of pieces you will break you data into n.points <- dim(GPS.Points)[1] breaks <- seq(1,n.points, by=round(n.points/n_chunks)) breaks <- c(breaks, n.points) #make sure to include last points as well

i=1
for (i in 1:(length(breaks)-1)){
  cat('\n','converting points', breaks[i], "to", breaks[i+1])
  temp.GPS.Points=GPS.Points[breaks[i]:breaks[i+1],]
  temp.GPS.Points.Spatial.Data <- SpatialPoints(temp.GPS.Points,
                                                proj4string=CRS("+proj=longlat +ellps=WGS84"))
  temp.GPS.Points.UTM.Spatial.Data <- spTransform(temp.GPS.Points.Spatial.Data,
                                                  CRS("+proj=utm +south +zone=34
+ellps=WGS84"))
}

Thank you for any advice.

WHP


Proprietary

-----Original Message-----
From: Poling, William <[hidden email]>
Sent: Monday, May 18, 2020 4:47 AM
To: [hidden email]
Cc: Poling, William <[hidden email]>
Subject: RE: Help with spTransform() function and final plot colors

Hello, I have found an additional problem.

I should be getting 3 columns back in the xy@data at some point.
$ ID                           : int  1 2 3 4 5 6 7 8 9 10 ...
# $ Clust                  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
# $ Clust.1               : int  1 1 1 1 1 1 1 1 1 1 ... This would be the cluster number, like 1-3, I am not getting this column back?


Yet the plot runs and indicates three different clusters?



WHP



Proprietary

-----Original Message-----
From: Poling, William <[hidden email]>
Sent: Monday, May 18, 2020 4:46 AM
To: [hidden email]
Cc: Poling, William <[hidden email]>
Subject: Help with spTransform() function and final plot colors

#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 (build 17763)

Hello. I am running my data through a routine I found that finds clusters of data points based on distance rule.
https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r

1. I get this error when I get to this point in the routine, see complete routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the plot itself, seems to work Can this error be corrected somehow, despite the fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the colors but the clusters in the plot are black, see plot call at the end of the routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
      coords.x1 coords.x2        
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) :
  failure in points 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, -122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, -122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, -122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, -122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA, -53L))

Here is the routine:
require(sp)
require(rgdal)
#25*1609.34 = 40233.5      
dis <- 40233.5 #Distance threshold 25miles converted to meters

x <- tmp1b[,c(6)]
head(x)
y <- tmp1b[,c(5)]
head(y)
str(y)

xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
                             proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

str(xy)

xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error occurring here?

chc <- hclust(dist(data.frame(rownames=rownames(xy@data), x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
                              y=coordinates(xy)[,2])), method="complete")
str(chc)

view(xy@data)#Look like 3 clusters

# Distance with a 25 Mile threshold
chc.dis <- cutree(chc, h=dis)
str(chc.dis)
view(chc.dis)

# Join results to meuse sp points
xy@data <- data.frame(xy@data, Clust=chc.dis)
str(xy@data)
view(xy@data)

# Plot results
plot(xy, col=factor(xy@data$Clust), pch=19)
box(col="black")
title(main="Clustering")
legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in demo to 3 in my data
       col=palette()[1:3], pch=rep(19,3), bg="white")


Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with spTransform() function and final plot colors

Michael Sumner-2
In reply to this post by R-sig-geo mailing list
Hi, your longlat coordinates are in the western hemisphere (-119, 39) but
EPSG 27700 is designed for (and appropriate for some scenarios) somewhere
in the UK. You need a local projection suitable for the area you are in.
Look for an EPSG for your region, or maybe Albers conic or Lambert
Azimuthal local authority (look on a paper map if you have one). Or define
your own with projstrings (or wkt, it's a bit complicated atm to advise
simple construction). There's some discussion here:
https://geocompr.robinlovelace.net/reproj-geo-data.html#which-crs-to-use

Some will say use UTM, but you should not unless it's a particular local
one used commonly in your work and the region the data is from.

HTH, Mike





On Mon., 18 May 2020, 19:46 Poling, William via R-sig-Geo, <
[hidden email]> wrote:

> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64
> (build 17763)
>
> Hello. I am running my data through a routine I found that finds clusters
> of data points based on distance rule.
>
> https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r
>
> 1. I get this error when I get to this point in the routine, see complete
> routine below?
> xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite
> transformation detected:
>
> I tried converting columns from numeric to Integer but did not help.
>
> However, I continue to run the rest of the routine and the final sequence,
> the plot itself, seems to work Can this error be corrected somehow, despite
> the fact that it continues to work, just curious what it is I guess"
>
> 2. However in the plot at the end of the routine the color key appears
> with the colors but the clusters in the plot are black, see plot call at
> the end of the routine below?
>
> Thank you for any advice.
>
> WHP
>
> ERROR:
> non finite transformation detected:
>       coords.x1 coords.x2
>  [1,] -119.7339  39.53939 Inf Inf
>  [2,] -119.7665  39.39630 Inf Inf
>  [3,] -119.7794  39.28768 Inf Inf
>  [4,] -121.0234  39.20503 Inf Inf
>  [5,] -122.0047  47.19262 Inf Inf
>  [6,] -122.0135  47.18883 Inf Inf
>  [7,] -122.0379  47.52190 Inf Inf
>  [8,] -122.0578  47.60975 Inf Inf
>  [9,] -122.1330  47.13669 Inf Inf
> [10,] -122.1509  47.55962 Inf Inf
> [11,] -122.1706  47.15546 Inf Inf
> [12,] -122.1846  47.23485 Inf Inf
> [13,] -122.1846  48.15307 Inf Inf
> [14,] -122.1851  47.44870 Inf Inf
> [15,] -122.1954  47.68485 Inf Inf
> [16,] -122.1990  47.51610 Inf Inf
> [17,] -122.2014  47.44772 Inf Inf
> [18,] -122.2025  47.69815 Inf Inf
> [19,] -122.2037  47.67190 Inf Inf
> [20,] -122.2090  47.40378 Inf Inf
> [21,] -122.2108  47.25336 Inf Inf
> [22,] -122.2291  47.63880 Inf Inf
> [23,] -122.2419  47.76870 Inf Inf
> [24,] -122.2722  48.04803 Inf Inf
> [25,] -122.2732  47.87700 Inf Inf
> [26,] -122.2804  47.77620 Inf Inf
> [27,] -122.2839  47.82103 Inf Inf
> [28,] -122.2890  47.86899 Inf Inf
> [29,] -122.2993  47.67306 Inf Inf
> [30,] -122.3180  47.38217 Inf Inf
> [31,] -122.3270  47.40378 Inf Inf
> [32,] -122.3474  47.43884 Inf Inf
> [33,] -122.3484  47.53083 Inf Inf
> [34,] -122.3581  47.27678 Inf Inf
> [35,] -122.3618  47.76735 Inf Inf
> [36,] -122.3700  47.56567 Inf Inf
> [37,] -122.3908  47.54938 Inf Inf
> [38,] -122.4128  47.64622 Inf Inf
> [39,] -122.4293  47.17660 Inf Inf
> [40,] -122.4621  47.44505 Inf Inf
> [41,] -122.4904  47.27460 Inf Inf
> [42,] -122.5515  46.93979 Inf Inf
> [43,] -122.7348  42.37320 Inf Inf
> [44,] -122.7827  47.31059 Inf Inf
> [45,] -122.7987  47.23475 Inf Inf
> [46,] -122.8385  42.35119 Inf Inf
> [47,] -122.8537  42.34495 Inf Inf
> [48,] -122.8904  42.39555 Inf Inf
> [49,] -122.8927  42.33022 Inf Inf
> [50,] -122.9451  47.37574 Inf Inf
> [51,] -122.9594  42.30376 Inf Inf
> [52,] -123.0641  47.16428 Inf Inf
> [53,] -123.3413  42.44117 Inf Inf
> Error in spTransform(xSP, CRSobj, ...) :
>   failure in points
> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
> In addition: Warning message:
> In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite
>
> Here is the data:
> dput(sample)
> structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493,
> -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578,
> -122.132971, -122.150901, -122.170608, -122.18462, -122.184639,
> -122.185079, -122.195398, -122.198994, -122.201356, -122.202507,
> -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216,
> -122.273164, -122.280355, -122.28389, -122.289043, -122.299261,
> -122.318009, -122.326987, -122.347382, -122.34844, -122.358115,
> -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136,
> -122.490417, -122.551483, -122.734847, -122.782736, -122.798669,
> -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407,
> -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681,
> 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616,
> 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723,
> 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027,
> 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165,
> 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377,
> 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195,
> 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736,
> 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA,
> -53L))
>
> Here is the routine:
> require(sp)
> require(rgdal)
> #25*1609.34 = 40233.5
> dis <- 40233.5 #Distance threshold 25miles converted to meters
>
> x <- tmp1b[,c(6)]
> head(x)
> y <- tmp1b[,c(5)]
> head(y)
> str(y)
>
> xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2),
> data.frame(ID=seq(1:length(x))),
>                              proj4string=CRS("+proj=longlat +ellps=WGS84
> +datum=WGS84"))
>
> str(xy)
>
> xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error
> occurring here?
>
> chc <- hclust(dist(data.frame(rownames=rownames(xy@data),
> x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
>                               y=coordinates(xy)[,2])), method="complete")
> str(chc)
>
> view(xy@data)#Look like 3 clusters
>
> # Distance with a 25 Mile threshold
> chc.dis <- cutree(chc, h=dis)
> str(chc.dis)
> view(chc.dis)
>
> # Join results to meuse sp points
> xy@data <- data.frame(xy@data, Clust=chc.dis)
> str(xy@data)
> view(xy@data)
>
> # Plot results
> plot(xy, col=factor(xy@data$Clust), pch=19)
> box(col="black")
> title(main="Clustering")
> legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in
> demo to 3 in my data
>        col=palette()[1:3], pch=rep(19,3), bg="white")
>
>
> Proprietary
>
> NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with spTransform() function and final plot colors

Roger Bivand
Administrator
In reply to this post by R-sig-geo mailing list
This messy thread was on R-help first, and comes from a corporation able
to pay for consulting help. It contains no reproducible example, and
"+init=epsg:27700 +datum=WGS84" qualifies to fail GIS001 (the datum of
OSGB is NOT WGS84, the same evident blunder is in the copied&pasted SO
"code"). No mention is made of the versions of the packages used (as
printed to the console when rgdal is loaded or from
rgdal::extSoftVersion(), and no motivation is given.

If the OP really needs assistance, this list expects a fully reproducible
example using a built-in data set - the SO query seems to refer to Meuse.

Roger

On Mon, 18 May 2020, Poling, William via R-sig-Geo wrote:

> Hello, I have found an additional problem.
>
> I should be getting 3 columns back in the xy@data at some point.
> $ ID                           : int  1 2 3 4 5 6 7 8 9 10 ...
> # $ Clust                  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
> # $ Clust.1               : int  1 1 1 1 1 1 1 1 1 1 ... This would be the cluster number, like 1-3, I am not getting this column back?
>
>
> Yet the plot runs and indicates three different clusters?
>
>
>
> WHP
>
>
> Proprietary
>
> -----Original Message-----
> From: Poling, William <[hidden email]>
> Sent: Monday, May 18, 2020 4:47 AM
> To: [hidden email]
> Cc: Poling, William <[hidden email]>
> Subject: RE: Help with spTransform() function and final plot colors
>
> Hello, I have found an additional problem.
>
> I should be getting 3 columns back in the xy@data at some point.
> $ ID                           : int  1 2 3 4 5 6 7 8 9 10 ...
> # $ Clust                  : int  1 1 1 1 1 1 1 1 1 1 ... This is always - 1
> # $ Clust.1               : int  1 1 1 1 1 1 1 1 1 1 ... This would be the cluster number, like 1-3, I am not getting this column back?
>
>
> Yet the plot runs and indicates three different clusters?
>
>
>
> WHP
>
>
>
> Proprietary
>
> -----Original Message-----
> From: Poling, William <[hidden email]>
> Sent: Monday, May 18, 2020 4:46 AM
> To: [hidden email]
> Cc: Poling, William <[hidden email]>
> Subject: Help with spTransform() function and final plot colors
>
> #RStudio Version Version 1.2.1335
> sessionInfo()
> # R version 4.0.0 Patched (2020-05-03 r78349)
> #Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 (build 17763)
>
> Hello. I am running my data through a routine I found that finds clusters of data points based on distance rule.
> https://gis.stackexchange.com/questions/64392/finding-clusters-of-points-based-distance-rule-using-r
>
> 1. I get this error when I get to this point in the routine, see complete routine below?
> xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite transformation detected:
>
> I tried converting columns from numeric to Integer but did not help.
>
> However, I continue to run the rest of the routine and the final sequence, the plot itself, seems to work Can this error be corrected somehow, despite the fact that it continues to work, just curious what it is I guess"
>
> 2. However in the plot at the end of the routine the color key appears with the colors but the clusters in the plot are black, see plot call at the end of the routine below?
>
> Thank you for any advice.
>
> WHP
>
> ERROR:
> non finite transformation detected:
>      coords.x1 coords.x2
> [1,] -119.7339  39.53939 Inf Inf
> [2,] -119.7665  39.39630 Inf Inf
> [3,] -119.7794  39.28768 Inf Inf
> [4,] -121.0234  39.20503 Inf Inf
> [5,] -122.0047  47.19262 Inf Inf
> [6,] -122.0135  47.18883 Inf Inf
> [7,] -122.0379  47.52190 Inf Inf
> [8,] -122.0578  47.60975 Inf Inf
> [9,] -122.1330  47.13669 Inf Inf
> [10,] -122.1509  47.55962 Inf Inf
> [11,] -122.1706  47.15546 Inf Inf
> [12,] -122.1846  47.23485 Inf Inf
> [13,] -122.1846  48.15307 Inf Inf
> [14,] -122.1851  47.44870 Inf Inf
> [15,] -122.1954  47.68485 Inf Inf
> [16,] -122.1990  47.51610 Inf Inf
> [17,] -122.2014  47.44772 Inf Inf
> [18,] -122.2025  47.69815 Inf Inf
> [19,] -122.2037  47.67190 Inf Inf
> [20,] -122.2090  47.40378 Inf Inf
> [21,] -122.2108  47.25336 Inf Inf
> [22,] -122.2291  47.63880 Inf Inf
> [23,] -122.2419  47.76870 Inf Inf
> [24,] -122.2722  48.04803 Inf Inf
> [25,] -122.2732  47.87700 Inf Inf
> [26,] -122.2804  47.77620 Inf Inf
> [27,] -122.2839  47.82103 Inf Inf
> [28,] -122.2890  47.86899 Inf Inf
> [29,] -122.2993  47.67306 Inf Inf
> [30,] -122.3180  47.38217 Inf Inf
> [31,] -122.3270  47.40378 Inf Inf
> [32,] -122.3474  47.43884 Inf Inf
> [33,] -122.3484  47.53083 Inf Inf
> [34,] -122.3581  47.27678 Inf Inf
> [35,] -122.3618  47.76735 Inf Inf
> [36,] -122.3700  47.56567 Inf Inf
> [37,] -122.3908  47.54938 Inf Inf
> [38,] -122.4128  47.64622 Inf Inf
> [39,] -122.4293  47.17660 Inf Inf
> [40,] -122.4621  47.44505 Inf Inf
> [41,] -122.4904  47.27460 Inf Inf
> [42,] -122.5515  46.93979 Inf Inf
> [43,] -122.7348  42.37320 Inf Inf
> [44,] -122.7827  47.31059 Inf Inf
> [45,] -122.7987  47.23475 Inf Inf
> [46,] -122.8385  42.35119 Inf Inf
> [47,] -122.8537  42.34495 Inf Inf
> [48,] -122.8904  42.39555 Inf Inf
> [49,] -122.8927  42.33022 Inf Inf
> [50,] -122.9451  47.37574 Inf Inf
> [51,] -122.9594  42.30376 Inf Inf
> [52,] -123.0641  47.16428 Inf Inf
> [53,] -123.3413  42.44117 Inf Inf
> Error in spTransform(xSP, CRSobj, ...) :
>  failure in points 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
> In addition: Warning message:
> In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite
>
> Here is the data:
> dput(sample)
> structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, -122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, -122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, -122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, -122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA, -53L))
>
> Here is the routine:
> require(sp)
> require(rgdal)
> #25*1609.34 = 40233.5
> dis <- 40233.5 #Distance threshold 25miles converted to meters
>
> x <- tmp1b[,c(6)]
> head(x)
> y <- tmp1b[,c(5)]
> head(y)
> str(y)
>
> xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
>                             proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))
>
> str(xy)
>
> xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error occurring here?
>
> chc <- hclust(dist(data.frame(rownames=rownames(xy@data), x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
>                              y=coordinates(xy)[,2])), method="complete")
> str(chc)
>
> view(xy@data)#Look like 3 clusters
>
> # Distance with a 25 Mile threshold
> chc.dis <- cutree(chc, h=dis)
> str(chc.dis)
> view(chc.dis)
>
> # Join results to meuse sp points
> xy@data <- data.frame(xy@data, Clust=chc.dis)
> str(xy@data)
> view(xy@data)
>
> # Plot results
> plot(xy, col=factor(xy@data$Clust), pch=19)
> box(col="black")
> title(main="Clustering")
> legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in demo to 3 in my data
>       col=palette()[1:3], pch=rep(19,3), bg="white")
>
>
> Proprietary
>
> NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Help with spTransform() function and final plot colors

R-sig-geo mailing list
In reply to this post by Michael Sumner-2

Thank you Michael this is very helpful. I see now where my trouble is, the EPSG.

Best regards.

WHP

From: Michael Sumner <[hidden email]>
Sent: Monday, May 18, 2020 5:02 AM
To: Poling, William <[hidden email]>
Cc: RsigGeo <[hidden email]>
Subject: [EXTERNAL] Re: [R-sig-Geo] Help with spTransform() function and final plot colors

**** External Email - Use Caution ****
Hi, your longlat coordinates are in the western hemisphere (-119, 39) but EPSG 27700 is designed for (and appropriate for some scenarios) somewhere in the UK. You need a local projection suitable for the area you are in. Look for an EPSG for your region, or maybe Albers conic or Lambert Azimuthal local authority (look on a paper map if you have one). Or define your own with projstrings (or wkt, it's a bit complicated atm to advise simple construction). There's some discussion here:
https://urldefense.proofpoint.com/v2/url?u=https-3A__geocompr.robinlovelace.net_reproj-2Dgeo-2Ddata.html-23which-2Dcrs-2Dto-2Duse&d=DwMFaQ&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=fDdQM1OwedGCkkG0UQTfAOUnp2_nUYnL-S_lSDHqxzM&s=bfYXSOc0JPxDRml-FQoxYoyDQ0nKdjPoNQrEE7yMzik&e=

Some will say use UTM, but you should not unless it's a particular local one used commonly in your work and the region the data is from.

HTH, Mike




On Mon., 18 May 2020, 19:46 Poling, William via R-sig-Geo, <mailto:[hidden email]> wrote:
#RStudio Version Version 1.2.1335
sessionInfo()
# R version 4.0.0 Patched (2020-05-03 r78349)
#Platform: x86_64-w64-mingw32/x64 (64-bit) #Running under: Windows 10 x64 (build 17763)

Hello. I am running my data through a routine I found that finds clusters of data points based on distance rule.
https://urldefense.proofpoint.com/v2/url?u=https-3A__gis.stackexchange.com_questions_64392_finding-2Dclusters-2Dof-2Dpoints-2Dbased-2Ddistance-2Drule-2Dusing-2Dr&d=DwMFaQ&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=fDdQM1OwedGCkkG0UQTfAOUnp2_nUYnL-S_lSDHqxzM&s=uZzRrl9yVqRTRQ2iHvphq2JK7UrTcUx61LL4r9ZLVEQ&e=

1. I get this error when I get to this point in the routine, see complete routine below?
xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84")) non finite transformation detected:

I tried converting columns from numeric to Integer but did not help.

However, I continue to run the rest of the routine and the final sequence, the plot itself, seems to work Can this error be corrected somehow, despite the fact that it continues to work, just curious what it is I guess"

2. However in the plot at the end of the routine the color key appears with the colors but the clusters in the plot are black, see plot call at the end of the routine below?

Thank you for any advice.

WHP

ERROR:
non finite transformation detected:
      coords.x1 coords.x2       
 [1,] -119.7339  39.53939 Inf Inf
 [2,] -119.7665  39.39630 Inf Inf
 [3,] -119.7794  39.28768 Inf Inf
 [4,] -121.0234  39.20503 Inf Inf
 [5,] -122.0047  47.19262 Inf Inf
 [6,] -122.0135  47.18883 Inf Inf
 [7,] -122.0379  47.52190 Inf Inf
 [8,] -122.0578  47.60975 Inf Inf
 [9,] -122.1330  47.13669 Inf Inf
[10,] -122.1509  47.55962 Inf Inf
[11,] -122.1706  47.15546 Inf Inf
[12,] -122.1846  47.23485 Inf Inf
[13,] -122.1846  48.15307 Inf Inf
[14,] -122.1851  47.44870 Inf Inf
[15,] -122.1954  47.68485 Inf Inf
[16,] -122.1990  47.51610 Inf Inf
[17,] -122.2014  47.44772 Inf Inf
[18,] -122.2025  47.69815 Inf Inf
[19,] -122.2037  47.67190 Inf Inf
[20,] -122.2090  47.40378 Inf Inf
[21,] -122.2108  47.25336 Inf Inf
[22,] -122.2291  47.63880 Inf Inf
[23,] -122.2419  47.76870 Inf Inf
[24,] -122.2722  48.04803 Inf Inf
[25,] -122.2732  47.87700 Inf Inf
[26,] -122.2804  47.77620 Inf Inf
[27,] -122.2839  47.82103 Inf Inf
[28,] -122.2890  47.86899 Inf Inf
[29,] -122.2993  47.67306 Inf Inf
[30,] -122.3180  47.38217 Inf Inf
[31,] -122.3270  47.40378 Inf Inf
[32,] -122.3474  47.43884 Inf Inf
[33,] -122.3484  47.53083 Inf Inf
[34,] -122.3581  47.27678 Inf Inf
[35,] -122.3618  47.76735 Inf Inf
[36,] -122.3700  47.56567 Inf Inf
[37,] -122.3908  47.54938 Inf Inf
[38,] -122.4128  47.64622 Inf Inf
[39,] -122.4293  47.17660 Inf Inf
[40,] -122.4621  47.44505 Inf Inf
[41,] -122.4904  47.27460 Inf Inf
[42,] -122.5515  46.93979 Inf Inf
[43,] -122.7348  42.37320 Inf Inf
[44,] -122.7827  47.31059 Inf Inf
[45,] -122.7987  47.23475 Inf Inf
[46,] -122.8385  42.35119 Inf Inf
[47,] -122.8537  42.34495 Inf Inf
[48,] -122.8904  42.39555 Inf Inf
[49,] -122.8927  42.33022 Inf Inf
[50,] -122.9451  47.37574 Inf Inf
[51,] -122.9594  42.30376 Inf Inf
[52,] -123.0641  47.16428 Inf Inf
[53,] -123.3413  42.44117 Inf Inf
Error in spTransform(xSP, CRSobj, ...) :
  failure in points 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53
In addition: Warning message:
In spTransform(xSP, CRSobj, ...) : 53 projected point(s) not finite

Here is the data:
dput(sample)
structure(list(ID = 1:53, Longitude = c(-119.733899, -119.766493, -119.779416, -121.0234, -122.004736, -122.013456, -122.0379, -122.0578, -122.132971, -122.150901, -122.170608, -122.18462, -122.184639, -122.185079, -122.195398, -122.198994, -122.201356, -122.202507, -122.20371, -122.209047, -122.210797, -122.229095, -122.2419, -122.27216, -122.273164, -122.280355, -122.28389, -122.289043, -122.299261, -122.318009, -122.326987, -122.347382, -122.34844, -122.358115, -122.361839, -122.37003, -122.390815, -122.41282, -122.429323, -122.462136, -122.490417, -122.551483, -122.734847, -122.782736, -122.798669, -122.838498, -122.853683, -122.8904, -122.89271, -122.94511, -122.959407, -123.064087, -123.341346), Latitude = c(39.53939, 39.396298, 39.287681, 39.205028, 47.192616, 47.188833, 47.5219, 47.609748, 47.13669, 47.559616, 47.155455, 47.234849, 48.15307, 47.448697, 47.684854, 47.516104, 47.447723, 47.698146, 47.6719, 47.403778, 47.253364, 47.638795, 47.768701, 48.048027, 47.876997, 47.776205, 47.821029, 47.868987, 47.673056, 47.382165, 47.403785, 47.438836, 47.530831, 47.276776, 47.76735, 47.565667, 47.549377, 47.646222, 47.176596, 47.445053, 47.274599, 46.939789, 42.373195, 47.310595, 47.234748, 42.351189, 42.344953, 42.395547, 42.33022, 47.375736, 42.303755, 47.164278, 42.441172)), class = "data.frame", row.names = c(NA, -53L))

Here is the routine:
require(sp)
require(rgdal)
#25*1609.34 = 40233.5     
dis <- 40233.5 #Distance threshold 25miles converted to meters

x <- tmp1b[,c(6)]
head(x)
y <- tmp1b[,c(5)]
head(y)
str(y)

xy <- SpatialPointsDataFrame(matrix(c(x,y), ncol=2), data.frame(ID=seq(1:length(x))),
                             proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))

str(xy)

xy <- spTransform(xy, CRS("+init=epsg:27700 +datum=WGS84"))#Error occurring here?

chc <- hclust(dist(data.frame(rownames=rownames(xy@data), x=coordinates(xy)[,1], #What is xy@data???? see str(xy)
                              y=coordinates(xy)[,2])), method="complete")
str(chc)

view(xy@data)#Look like 3 clusters

# Distance with a 25 Mile threshold
chc.dis <- cutree(chc, h=dis)
str(chc.dis)
view(chc.dis)

# Join results to meuse sp points
xy@data <- data.frame(xy@data, Clust=chc.dis)
str(xy@data)
view(xy@data)

# Plot results
plot(xy, col=factor(xy@data$Clust), pch=19)
box(col="black")
title(main="Clustering")
legend("topleft", legend=paste("Cluster", 1:3,sep=""),#Change from 4 in demo to 3 in my data
       col=palette()[1:3], pch=rep(19,3), bg="white")


Proprietary

NOTICE TO RECIPIENT OF INFORMATION:\ This e-mail may con...{{dropped:16}}

_______________________________________________
R-sig-Geo mailing list
mailto:[hidden email]
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dsig-2Dgeo&d=DwMFaQ&c=wluqKIiwffOpZ6k5sqMWMBOn0vyYnlulRJmmvOXCFpM&r=j7MrcIQm2xjHa8v-2mTpmTCtKvneM2ExlYvnUWbsByY&m=fDdQM1OwedGCkkG0UQTfAOUnp2_nUYnL-S_lSDHqxzM&s=kPefKeqQOlNKKPcGokf_XBbO51mavqj5WQOKbKof4ws&e=

Proprietary

NOTICE TO RECIPIENT OF INFORMATION:
This e-mail may contain confidential or privileged information. If you think you have received this e-mail in error, please advise the sender by reply e-mail and then delete this e-mail immediately.  
This e-mail may also contain protected health information (PHI) with information about sensitive medical conditions, including, but not limited to, treatment for substance use disorders, behavioral health, HIV/AIDS, or pregnancy. This type of information may be protected by various federal and/or state laws which prohibit any further disclosure without the express written consent of the person to whom it pertains or as otherwise permitted by law. Any unauthorized further disclosure may be considered a violation of federal and/or state law. A general authorization for the release of medical or other information may NOT be sufficient consent for release of this type of information.
Thank you. Aetna
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo