[R-sig-Geo] Map labels

Roger Bivand Roger.Bivand at nhh.no
Mon Nov 23 20:23:01 CET 2009


On Mon, 23 Nov 2009, tom sgouros wrote:

>
> Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
>>> Being near the water, there are lots of islands, so each town is
>>> represented by a bunch of polygons.  How do I select only one to be
>>> labeled, and is there a convention for which one would be the best to
>>> use?  I see the labpt slot, in my SpatialPolygonsDataFrame object, but I
>>> don't see a mostAppropriateLabpt or primaryLabpt or anything like that.
>>>
>>> In addition to this, I get no errors when I follow the examples at
>>> http://r-spatial.sourceforge.net/gallery/ , but I see no labels, either.
>>>
>>> This is what I'm doing.  Are the colors covering my labels?
>>>
>>>  spplot(rep.map,zcol="vote02",at=breaks,col.regions=rg,
>>>        layout=list(list("sp.text",getSpPPolygonsLabptSlots(rep.map)[25,],"HERE I AM")))
>>>
>>
>> Thanks for the verbatim code. I think that you need to name the
>> argument sp.layout= rather than layout=. Because of the ... argument
>> list, layout= doesn't get rejected, but it doesn't get used
>
> Thank you, that works perfectly.
>
>> list("sp.text", coordinates(rep.map), row.names(rep.map))
>>
>> to put the FID value (feature ID) at the centroid of the largest
>> member polygon (Polygon object) of the entity (Polygons object), for
>> each entity of the data set.
>
> This doesn't, though.  When I read in my data, the IDvar is supposed to
> be the column that is unique for each record, correct?  But there are
> several records (closed polygons) for each town.  These are linked by
> another variable.  The coordinates(rep.map) gives me a list of 419
> coordinates for all the closed shapes, not 75 coordinates for all the
> towns.  How do I get the biggest polygons for each town?  I have an Area
> attribute, so I guess I can just calculate it.  Is that the right way to
> go, or is there some method already existing for this?
>
> I thought maybe my readSpatial... was done wrong, so I changed the IDvar
> to point to the iD for each town, but that gives me an error saying that
> duplicate row names are not allowed.  Is there a step I needed to take
> to link the polygons?

Yes, see the unionSpatialPolygons() function in maptools. It uses 
functions in gpclib to dissolve boundaries between member entities if they 
touch, so makes a Polygons object with possibly multiple member Polygon 
objects from multiple Polygons objects with the same ID values (towns for 
you). You then need to drop rows from the data.frame (as(rep.map, 
"data.frame")), and re-assemble using SpatialPolygonsDataFrame() with the 
row.names of the data.frame set to the town IDs used in 
unionSpatialPolygons().

The mess is caused by the underlying data being kept in OGC SFS (simple 
features) form, which does not store well in shapefiles (a similar remark 
could be made about SpatialPolygons objects, which are more like 
shapefiles than like SFS).

The gpclib package should not be used if its license conditions are
inappropriate. A free software alternative is being prepared.

Roger

>
> Thank you,
>
> -tom
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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