[R-sig-Geo] Proj4 - latitude or longitude exceeded limits

Roger Bivand Roger.Bivand at nhh.no
Wed Jan 18 10:17:07 CET 2017


On Tue, 17 Jan 2017, Michael Sumner wrote:

> Watch out with proj4 btw, it has an obscure bug where a 2 row matrix input
> is transposed, mixing longitude and latitude in a way that triggers an out
> of bounds error for latitude, only when the mixed abs(longitude) is greater
> than 90.

You mean:

> library(rgdal)
> crds <- rbind(c(90, 1), c(91, 2))
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
          [,1]     [,2]
[1,] 833927.9 110682.8
[2,] 945193.9 221604.0
> crds <- rbind(c(90, 1), c(91, 2), c(92, 3))
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
           [,1]     [,2]
[1,]  833927.9 110682.8
[2,]  945193.9 221604.0
[3,] 1056324.8 332866.1
> crds <- matrix(c(91, 2), nrow=1)
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
          [,1]   [,2]
[1,] 945193.9 221604

and

> library(proj4)
> crds <- rbind(c(90, 1), c(91, 2))
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
Error in project(crds, "+proj=utm +zone=45 +ellps=WGS84") :
   latitude or longitude exceeded limits
> crds <- rbind(c(90, 1), c(90, 2))
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
Error in project(crds, "+proj=utm +zone=45 +ellps=WGS84") :
> crds <- rbind(c(90, 1), c(91, 2), c(92, 3))
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
           [,1]     [,2]
[1,]  833927.9 110682.8
[2,]  945193.9 221604.0
[3,] 1056324.8 332866.1
> crds <- matrix(c(91, 2), nrow=1)
> project(crds, "+proj=utm +zone=45 +ellps=WGS84")
          [,1]   [,2]
[1,] 945193.9 221604

right?

I'll take a look and if I see the bug, send a patch to Simon. Please 
confirm that this is what you see.

Best wishes,

Roger

>
> Use the sf package, or rgdal, or mapproj.
>
> Cheers, Mike
>
> On Wed, Jan 18, 2017, 05:51 Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
>> On Tue, 17 Jan 2017, aurelie.tschopp at vetsuisse.unibe.ch wrote:
>>
>>> Dear all,
>>>
>>> I am analysing GPS Data from Chad. I need to first project the latitude
>>> and longitudes. I use the package Proj4, the function project for this.
>>> I have 2 devices and with the data of the 1st device, the projection
>>> worked perfectly. But with the data from the other device, I got this
>>> error message: "Error in project(loc, "+proj=utm +zone=33 +ellps=WGS84
>>> +datum=WGS84 +units=m +no_defs") : latitude or longitude exceeded
>>> limits"
>>>
>>> I found that Chad was UTM 33P (Wikipedia UTM:
>>>
>> https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system
>>> ), but some people could use the notification 33N: 33 for the zone and N
>>> for the North hemisphere.
>>>
>>> My code is:
>>> loc <- dat[,c("Longitude","Latitude")
>>> loc_Zone33 <- project(loc, "+proj=utm +zone=33 +ellps=WGS84 +datum=WGS84
>>> +units=m +no_defs")
>>>
>>> Does anybody know where my problem could be?
>>
>> Well, the error message is coming from inside the proj.4 library: did you
>> look at the input object? If one device was returning decimal geographical
>> coordinates and the other a string with degrees, minutes and seconds in
>> one "number":
>>
>> library(rgdal)
>> project(matrix(c(19.0, 15.0), nrow=1), "+proj=utm +zone=33 +ellps=WGS84")
>> project(matrix(c(1900, 1500), nrow=1), "+proj=utm +zone=33 +ellps=WGS84")
>>
>> In this setting I get:
>>
>>> project(matrix(c(19.0, 15.0), nrow=1), "+proj=utm +zone=33
>> +ellps=WGS84")
>>           [,1]    [,2]
>> [1,] 930334.7 1662218
>>> project(matrix(c(1900, 1500), nrow=1), "+proj=utm +zone=33
>> +ellps=WGS84")
>>       [,1] [,2]
>> [1,]  Inf  Inf
>> Warning message:
>> In project(matrix(c(1900, 1500), nrow = 1), "+proj=utm +zone=33
>> +ellps=WGS84") :
>>    1 projected point(s) not finite
>>
>> but not your error. I suspect that the matrix you are passing contains
>> non-geographical coordinates. If you are using the proj4 package (odd
>> choice but there you are):
>>
>>> library(proj4)
>>> project(matrix(c(19.0, 15.0), nrow=1), "+proj=utm +zone=33
>> +ellps=WGS84")
>>           [,1]    [,2]
>> [1,] 930334.7 1662218
>>> project(matrix(c(1900, 1500), nrow=1), "+proj=utm +zone=33
>> +ellps=WGS84")
>> Error in project(matrix(c(1900, 1500), nrow = 1), "+proj=utm +zone=33
>> +ellps=WGS84") :
>>    latitude or longitude exceeded limits
>>
>> confirming that it doesn't handle exceptions other than by a hard fail.
>>
>> Roger
>>
>>
>>> Thank you
>>> Aurélie
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> 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: Roger.Bivand at nhh.no
>> http://orcid.org/0000-0003-2392-6140
>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>> http://depsy.org/person/434412
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>> University of Tasmania Electronic Communications Policy (December, 2014).
>> This email is confidential, and is for the intended recipient only.
>> Access, disclosure, copying, distribution, or reliance on any of it by
>> anyone outside the intended recipient organisation is prohibited and may be
>> a criminal offence. Please delete if obtained in error and email
>> confirmation to the sender. The views expressed in this email are not
>> necessarily the views of the University of Tasmania, unless clearly
>> intended otherwise.
>> .
>>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412


More information about the R-sig-Geo mailing list