[R-sig-Geo] Transportation Network Shapefile into a Raster

Robert J. Hijmans r.hijmans at gmail.com
Fri Jul 19 03:28:40 CEST 2013


Thiemo,
I think the plot does not show all the pixels. Simpler script:

tempr <- raster(USA.highway)
dim(tempr) <- c(4480, 2080)
USA.highwayraster <- rasterize(USA.highway, tempr, progress='text')

# high resolution plot (but how many pixels does your screen have?)
plot(USA.highwayraster, maxpixels=ncell(tempr))

# or try this
zoom(USA.highwayraster)  # now click twice on the previous plot

Robert


On Thu, Jul 18, 2013 at 5:23 PM, Thiemo Fetzer <thiemo.fetzer at gmail.com> wrote:
> Dear all,
>
> I have another question or problem -- this time it is related to the transformation of a Spatial Lines shapefile into a raster.
>
> Let me describe my problem: I want to construct a measure of travel distance from A<->B; I have obtained a shapefile of the highway network of the US; in order to compute the travel distance, I need to transform the shape into a raster -- at least that is what I have done in the past for a similar project, however, there the task was a lot simpler (computing maritime routes).
>
> I use the following code:
>
>
> #############LOAD USA HIGHWAY NETWORK
> USA.highway<-readShapeLines("Shapefiles/Highways/NHPNLine.shp")
>
>
> ###reproject to WGS 84
> proj4string(USA.highway)<- CRS("+init=epsg:4269"))
> USA.highway<-spTransform(USA.highway,CRS(proj4string(USA)))
>
>
> USA.highway
>
> ##spits out
> class       : SpatialLinesDataFrame
> nfeatures   : 176231
> extent      : -176.764, 17.93439, -65.59364, 71.31699  (xmin, xmax, ymin, ymax)
> coord. ref. : NA
> nvariables  : 42
>
> ###I reconed that -- in order to get crid-cells of roughly .less than ..1, I make the rast
>
> tempr<-raster(nrows=4480, ncols=2080)
>
> ###not sure if i need this
> setExtent(tempr, extent(USA.highway), keepres=FALSE, snap=FALSE)
> ###or this?
> extent(tempr) <- extent(USA.highway)
> ###this is the rasterize
> USA.highwayraster<- rasterize(USA.highway, tempr, progress='text')
>
>
> Well, it basically turns out that the raster picture looks nowhere near what the original shapefile looks like; even though I thought it should.
> To give you an impression, have a look at
>
> http://freigeist.devmag.net/wp-content/Screen-Shot-2013-07-19-at-02.19.31.png
>
> (I cropped out Alaska as it would otherwise be not so easily visible).
>
> I definately cant use that to compute routes as the grid basically does not have any connected roads at all!
>
> I appreciate your thoughts, ideas and comments on what I am doing wrong,
>
> thanks a lot
> best
> ----
> Thiemo Fetzer
> London School of Economics
> STICERD
> Houghton Street
> WC2A 2AE London
> United Kingdom
>
> office: 32L, 3.01 D
> tel: +44 7411 566845
> skype: thiemo.fetzer
> email: t.r.fetzer at lse.ac.uk
> web: www.trfetzer.com
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list