[R-sig-Geo] Plot street "Name" for city streets (lines) in a SpatialLinesDataFrame

Roger Bivand Roger.Bivand at nhh.no
Thu Sep 10 13:08:24 CEST 2015


On Wed, 9 Sep 2015, Roger Bivand wrote:

> On Wed, 9 Sep 2015, Jim Burke wrote:
>
>> Given a SpatialLinesDataFrame like below. How might I print the street
>> "Name" adjacent to these many streets in the SpatialLinesDataFrame? Just
>> what in the line class can I attach its "Name" to? I want to add this plot
>> as a layer to my other plots.
>> 
>
> Please no HTML mail. It is (much) bulkier, and can contain payloads, so all 
> the R lists strip HTML copies/markup, often leading to garbled content.
>
> Please provide a reproducible example, possibly with a small subset of OSM 
> data or similar (by URL). Guessing from the structure below with 125K Lines 
> objects would be hard, start small and scale up from there. Find a 
> representative point, possibly a midpoint, for each "street" - probably Lines 
> object - find its angle, and try to offset and rotate the inserted text.
>
> In regular cartography, the placement of labels is generally considered hard. 
> There are functions in the maptools package for label placement for point 
> support to avoid overlapping, but these do not accommodate rotation.

There is a good deal of code in src/library/graphics/src/plot3d.c, used in 
plotting labels when drawing contour plots.  That code is embedded in 
finding the contour locations, rather than being a general solution. It 
may, though, give some helpful ideas.

Roger

>
> Since you didn't say why you need this, it is hard to provide sensible 
> advice. An affiliation would give an indication of the motivation.
>
> Roger
>
>> And I cannot post an code snippet example because I don't get that far
>> here. This is more basic. I want some thoughts on how to plot a tiny street
>> name near each street in the SpatialLinesDataFrame.
>> 
>>> str(DC_Roads1_sp)
>> Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
>>  ..@ data       :'data.frame': 125059 obs. of  31 variables:
>>  .. ..$ DC_ID    : num [1:125059] 843772 843773 844139 844140 844141 ...
>>  .. ..$ Prefix   : chr [1:125059] NA NA NA "N" ...
>>  .. ..$ Pretype  : chr [1:125059] NA NA "STHY" NA ...
>>  .. ..$ Name     : chr [1:125059] "Freeport" "Freeport" "183" "Valley
>> View" ...
>> 
>> Then the line class looks like below (first two are shown)
>> 
>> ..@ lines      :List of 125059
>>  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
>>  .. .. .. ..@ Lines:List of 1
>>  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
>>  .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9
>>  .. .. .. ..@ ID   : chr "0"
>>  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
>>  .. .. .. ..@ Lines:List of 1
>>  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
>>  .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] -97 -97 32.9 32.9
>>  .. .. .. ..@ ID   : chr "1"
>> 
>> 
>> Any and all advice/suggestions/hints/examples is appreciated.
>> 
>> Thanks,
>> Jim Burke
>>
>> 	[[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
>> 
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list