[R-sig-Geo] Changing Shapefile's Coordinates

Wang, Kevin (SYD) kevinwang at kpmg.com.au
Thu Jul 21 08:59:57 CEST 2011


Thanks Barry, it worked!

By the way, is there a way to "rescale" the map (other than enlarge plotting window once the map is drawn)?  I'm asking this because there are a few local government areas that are too small (and hence I can't see the text (coordinates) plotted on it).

Cheers
Kevin

-----Original Message-----
From: b.rowlingson at googlemail.com [mailto:b.rowlingson at googlemail.com] On Behalf Of Barry Rowlingson
Sent: Wednesday, 20 July 2011 9:21 PM
To: Wang, Kevin (SYD)
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Changing Shapefile's Coordinates

On Wed, Jul 20, 2011 at 12:31 AM, Wang, Kevin (SYD) <kevinwang at kpmg.com.au> wrote:
> Hi,
>
>
>
> I'm just wondering if it's possible, in R, to modify a shapefile's 
> coordinates?
>
>
>
> I've shapefiles for each state/territory of Australia, and in them 
> there are local government areas coordinates.  Using readShapePoly(), 
> I am able to read them in and plot each state with its local 
> government areas.
>
>
>
> However, I also want to be able to "merge" local government areas into 
> roughly north-east-south-west - i.e. draw a state then divide it 
> roughly into four quadrants (or divide it in other ways by merging 
> various local government areas).   Is there any easy way that I can 
> manipulate the shapefile to do this?
>

 Another job for rgeos!

 Can do something with gUnionCascaded?:

library(maptools);library(rgeos)
xx <- readShapeSpatial(system.file("shapes/sids.shp",
package="maptools")[1],IDvar="FIPSNO", proj4string=CRS("+proj=longlat
+ellps=clrk66"))

# plot it, label it:

 plot(xx)
 text(coordinates(xx),as.character(1:nrow(xx)))

# now suppose we want to merge these regions:

 z1 = c(10,24,9,71)

# we do:
zx=gUnionCascaded(xx[z1,])


# which gives us a SpatialPolygons object with (in this case) one ring:

 plot(zx,add=TRUE,col="#80808080")


Repeat for each of your regions and splat everything together as a SpatialPolygonsDataFrame if thats what you need.

Look out for digitising errors which result in slivers and other junk where adjacent polygons dont match up.

Barry


******************************************************************

The information in this e-mail is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
e-mail by anyone else is unauthorised. If you have received this
communication in error, please notify us immediately by return
e-mail with the subject heading "Received in error" or telephone
+61 2 93357000, then delete the email and destroy any copies of it.
If you are not the intended recipient, any disclosure, copying,
distribution or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful. Any opinions or advice
contained in this e-mail are subject to the terms and conditions
expressed in the governing KPMG client engagement letter. Opinions,
conclusions and other information in this e-mail and any
attachments that do not relate to the official business of the firm
are neither given nor endorsed by it. 

KPMG cannot guarantee that e-mail communications are secure or
error-free, as information could be intercepted, corrupted,
amended, lost, destroyed, arrive late or incomplete, or contain
viruses. 

KPMG, an Australian partnership and a member firm of the KPMG
network of independent member firms affiliated with KPMG
International Cooperative (“KPMG International”), a Swiss entity. 
KPMG International provides no services to clients.  

Liability limited by a scheme approved under Professional Standards
Legislation. 

******************************************************************



More information about the R-sig-Geo mailing list