Coder Social home page Coder Social logo

Comments (7)

Nowosad avatar Nowosad commented on June 5, 2024 3

The numbers are rounded when print, but they still have the same precision. See:

library(sf)

multipoint_matrix = rbind(c(1.0000005, 2), c(1, 3), c(3, 4), c(3, 2))
mp = st_multipoint(multipoint_matrix)

mpc = st_coordinates(mp)
mpc
#>             X Y L1
#> [1,] 1.000001 2  1
#> [2,] 1.000000 3  1
#> [3,] 3.000000 4  1
#> [4,] 3.000000 2  1

mpc[1,1]
#>        X 
#> 1.000001

formatC(mpc[1, 1], digits = 10)
#>             X 
#> "  1.0000005"

from geocompr.

mdsumner avatar mdsumner commented on June 5, 2024 2

bit easier with

op <- options(digits = 16)
## st_coordinates(mp) etc
options(op)

from geocompr.

JosiahParry avatar JosiahParry commented on June 5, 2024 1

When you read in the dataset that you exported into QGIS, do you still have the same number of decimals? Because we're reading in data using gdal and i don't expect it to drop an precision.

from geocompr.

Robinlovelace avatar Robinlovelace commented on June 5, 2024

Hi @sy5938 you could try st_set_precision() or after converting to numeric values with the round() function in base R. Does that help? If you have a reproducible example to show what you have tried and what you're trying to achieve that could help. Interesting we don't seem to mention st_precision() or related functions in the book: https://github.com/search?q=repo%3Ageocompx%2Fgeocompr+precision&type=code

from geocompr.

sy5938 avatar sy5938 commented on June 5, 2024

Hi Prof. @Robinlovelace .It doesn't look good.

Sorry I can't provide the original shpfile data, so I randomly sample 4 points (Uploaded as an attachment sample1.zip).
My code:

library(sf)
test_point <- read_sf("sample1.gpkg")
st_set_precision(test_point,0.001)
st_coordinates(test_point)

Using the sample data, the st_set_precision() also didn't work well. Did I miss something? Perhaps read_sf directly drop the decimal? If read_sf can set an argument, that will be good.

image

image

from geocompr.

sy5938 avatar sy5938 commented on June 5, 2024

Thanks a bunch! Very clear now.

from geocompr.

sy5938 avatar sy5938 commented on June 5, 2024

@mdsumner Wow! Thanks for your wisdom. I shouldn't forget the most basic R setting. My bad....

Guys in this issue, I appreciate all your time! Thanks a lot!🤘

from geocompr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.