Skip to content
Prev 2582 / 29559 Next

problem on converting the coordinates into interval [0, 1]?

Dear Zhijie Zhang,
On Sun, 23 Sep 2007, zhijie zhang wrote:

            
I think that you need to explain why. If it is just because the 
coordinates "explode" because they are large, then simply scaling like 
this:

library(rgdal)
guichi <- readOGR(".", "guichi")
plot(guichi, axes=TRUE)
bbox(guichi)
proj4string(guichi)
t1 <- paste("+proj=tmerc +lat_0=0 +lon_0=117 +k=1.000000 +x_0=0",
   "+y_0=-3348000 +a=6378140 +b=6356755.288157528 +units=km")
t2 <- spTransform(guichi, CRS(t1))
plot(t2, axes=TRUE)
bbox(t2)
#          min      max
# r1 10.148541 79.88203
# r2  0.834946 61.90978

gets down to 70 by 80, which is not such a numerical risk (if need be, use 
+units=kmi to get nautical miles, which reduces the numbers even more). It 
has the key advantage that you can always get back to the true coordinates 
by transforming back.

In the internal code, you will see that many packages guard by using [-1, 
+1] on both dimensions. In your case and if you know that you need this, 
you would have to work out the scaling factor on the longer axis, so that 
points on the shorter axis would be scaled correctly. But if you want to 
keep the dimensions' aspect, you could just shift the origin and the units 
as I show above.

Hope this helps,

Roger