Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:50:29+00:00 2026-06-18T04:50:29+00:00

I have a matrix data with spatial coordinates and one variable. The spatial resolution

  • 0

I have a matrix data with spatial coordinates and one variable. The spatial resolution is 1000 meters.

> str(dat1)
> List of 3
> $ x: num [1:710] 302340 303340 304340 305340 306340 ...
> $ y: num [1:1241] 5431470 5432470 5433470 5434470 5435470 ...
> $ z: num [1:710, 1:1241] 225 225 225 225 225 ...

I want to convert it into raster format.

> dat1$x[1:10]
> [1] 302339.6 303339.6 304339.6 305339.6 306339.6 307339.6 308339.6 309339.6 310339.6 311339.6
> dat1$y[1:10]
>  [1] 5431470 5432470 5433470 5434470 5435470 5436470 5437470 5438470 5439470 5440470

I used the following code to do it. But the resolution I get is not the same with that I have. Any better way to get the same resolution with my real data?

> r <-raster(
             dat1$z,
             xmn=range(dat1$x)[1], xmx=range(dat1$x)[2],
             ymn=range(dat1$y)[1], ymx=range(dat1$y)[2], 
             crs=CRS("+proj=utm +zone=11 +datum=NAD83")
            )
> r

class       : RasterLayer 
dimensions  : 710, 1241, 881110  (nrow, ncol, ncell)
resolution  : 571.3135, 1746.479  (x, y)
extent      : 302339.6, 1011340, 5431470, 6671470  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=11 +datum=NAD83 
data source : in memory
names       : layer 
values      : 13.65059, 248.6229  (min, max)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:50:30+00:00Added an answer on June 18, 2026 at 4:50 am

    Try reading the help for raster. When creating a raster from a matrix, the sense of rows and columns isn’t what you think it is. You were feeding it a 1241×710 matrix but taking the max and min from the wrong vectors.

    Try the following:

    > # small version of your test set
    > dat1=list()
    > dat1$x=seq(302339.6,by=1000,len=71)
    > dat1$y=seq(5431470,by=1000,len=124)
    > dat1$z=matrix(runif(71*124),71,124)
    > str(dat1)
    List of 3
     $ x: num [1:71] 302340 303340 304340 305340 306340 ...
     $ y: num [1:124] 5431470 5432470 5433470 5434470 5435470 ...
     $ z: num [1:71, 1:124] 0.765 0.79 0.185 0.461 0.421 ...
    > image(dat1,asp=1)
    

    Nice square pixels. Now create your raster:

    r <-raster(
                 dat1$z,
                 xmn=range(dat1$x)[1], xmx=range(dat1$x)[2],
                 ymn=range(dat1$y)[1], ymx=range(dat1$y)[2], 
                 crs=CRS("+proj=utm +zone=11 +datum=NAD83")
                )
    plot(r)
    

    Totally NON-square pixels. And if you look carefully, the matrix is rotated 90 degrees from the image plot. Or transposed or something.

    Solution: just create the raster from the x,y,z list:

     > r=raster(dat1);plot(r)
    

    Square pixels, same way round as image plot, and resolution is now what you expect:

    > r
    class       : RasterLayer 
    dimensions  : 124, 71, 8804  (nrow, ncol, ncell)
    resolution  : 1000, 1000  (x, y)
    extent      : 301839.6, 372839.6, 5430970, 5554970  (xmin, xmax, ymin, ymax)
    coord. ref. : NA 
    data source : in memory
    names       : layer 
    values      : 7.738103e-05, 0.9995497  (min, max)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one matrix data like that: 1 2 3 1: 1.0 2.0 5.0
I have the following matrix (actually a data frame) in R: > str(x2) 'data.frame':
I have a matrix of data (the columns represent time, and the rows spectrum
I have a matrix of data, m : 12345 12348 2011-05-13 NA 0.18001079 2011-05-16
Suppose I have a matrix of weights, and another matrix of data values. Can
I have a matrix of objects that contains data in this form: name A,2,name
I have a matrix A which I want to convert into a data.frame of
I have a data set which consists of an ID and a matrix (n
I have a std::istream which refers to matrix data, something like: 0.0 1.0 2.0
I'm trying to create a matrix data structure in C. I have a struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.