[R-sig-Geo] sp package seems to round my coordinates
Roger Bivand
Roger.Bivand at nhh.no
Thu Sep 8 23:40:13 CEST 2011
On Thu, 8 Sep 2011, Pascal Title wrote:
> Hi
>
> I have a dataframe containing coordinates and metadata that I am converting
> to SpatialPointsDataFrame using the function from the sp package.
> However, I have noticed that the resulting coordinates have fewer decimal
> places than my original data. This is problematic for me because later on I
> will be using these coordinates to match them with the original records in
> order to retrieve other information.
>
> Is there any way I can have the function keep my coordinates as is?
This is a FAQ - you are mistaking the internal representation, which
retails precision, with the displayed representation, which uses the
default number of digits set by options() for all print() methods. So when
you print splisttemp, you are actually saying:
print(splisttemp)
and could say:
print(splisttemp, digits=4)
print(splisttemp, digits=12)
or equivalently set the option to another value, with different output.
See:
set.seed(1)
x <- rnorm(10)
print(x)
print(x, digits=4)
print(x, digits=14)
Hope this clarifies,
Roger
> Here is an example:
>
>> splisttemp
> DecimalLongitude DecimalLatitude SpAbbr InstitutionCode CatalogNumberText
> 1 -76.87271 3.6628163 BanRot EBIRD_COL OBS81997559
> 2 -76.97495 3.7168289 BanRot AUDCLO OBS89767945
> 3 -76.88397 3.6160872 BanRot AUDCLO OBS89769896
> 4 -77.51667 5.5166667 BanRot AMNH Skin-123476
> 5 -76.03337 4.8666900 BanRot LACM 34848
> 6 -78.43333 1.4333333 BanRot LSUMZ 38939
> 7 -78.55000 0.9500000 BanRot ANSP 182799
> 8 -79.21389 0.4719444 BanRot AUDCLO OBS58485973
> 9 -78.51036 0.8953493 BanRot AUDCLO OBS84822747
> 10 -78.37810 1.5102800 BanRot AUDCLO OBS67916517
> 11 -75.15000 7.0700000 BanRot 8110002317-09 4743-5160
>
>>
> SpatialPointsDataFrame(coords=splisttemp[,c("DecimalLongitude","DecimalLatitude")],data=splisttemp[,c("SpAbbr","InstitutionCode","CatalogNumberText")],proj4string=CRS("+proj=longlat
> +datum=WGS84"))->tempshp
>> tempshp
> coordinates SpAbbr InstitutionCode CatalogNumberText
> 1 (-76.8727, 3.66282) BanRot EBIRD_COL OBS81997559
> 2 (-76.9749, 3.71683) BanRot AUDCLO OBS89767945
> 3 (-76.884, 3.61609) BanRot AUDCLO OBS89769896
> 4 (-77.5167, 5.51667) BanRot AMNH Skin-123476
> 5 (-76.0334, 4.86669) BanRot LACM 34848
> 6 (-78.4333, 1.43333) BanRot LSUMZ 38939
> 7 (-78.55, 0.95) BanRot ANSP 182799
> 8 (-79.2139, 0.471944) BanRot AUDCLO OBS58485973
> 9 (-78.5104, 0.895349) BanRot AUDCLO OBS84822747
> 10 (-78.3781, 1.51028) BanRot AUDCLO OBS67916517
> 11 (-75.15, 7.07) BanRot 8110002317-09 4743-5160
>
> Thanks for your help!
>
> -Pascal
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list