[R-sig-Geo] Editing Shapefiles

Hisaji ONO hi_ono2001 at ybb.ne.jp
Wed Dec 14 16:29:09 CET 2005


Hello.

 Sorry I'm not "Dr."

 Here is my Non-Contiguous Area-based "Shrinking"
Cartogram script for maptools.

 This script doesn't support multi-parts polygon shape. 

 Please try this.

###############
require(maptools)

#
# Non Contiguous Area-based Cartogram
#
createNonContiguousAreaBasedCartogram<-function(mapObj,targetAttribute,areaAttribute){
  densities<- sqrt(targetAttribute/areaAttribute) #
calclulate given attribute value

  maxDensity<-max(densities) # get Maximum of densities
  
  k <- 1/maxDensity

  L <- k * densities

  centroidXY<-get.Pcent(mapObj) # get polygons' centroids
  
  mapObj2 <- mapObj[[1]]
  
  for(i in 1:length(mapObj2)){
    if(mapObj2[[i]]$nParts == 1){
      coords <- mapObj2[[i]]$verts
      newX<-L[i] * (coords[,1] -  centroidXY[i,1]) +
centroidXY[i,1] # new X coordinate
      newY<-L[i] * (coords[,2] -  centroidXY[i,2]) +
centroidXY[i,2] # new Y coordinate
      polygon(newX,newY,col="red") #draw polygon
    }
  }
}



columbus<-read.shape(system.file("shapes/columbus.shp",package="maptools"))
#load polygon shape file


plot(columbus)

createNonContiguousAreaBasedCartogram(columbus,columbus$att.data$CRIME,columbus$att.data$AREA)


> In the days when I had more time to work on this
> stuff I looked into
> programming continuous cartograms for maptools.

 There are  lots of arcscripts for contiguous codes in
following ESRI's arcscripts site.



http://arcscripts.esri.com/scripts.asp?eLang=&eProd=&perPage=10&eQuery=contiguous&Submit2=Search


 GeoDa(which will be opnssource) can display Doring's
circular cartogram which use Cellular Automata for good
performance.(https://geoda.uiuc.edu/pdf/geoda095i.pdf).


 Some Japanese GIS researcher has tried to employ some
optimisation method for Doring's and Contiguous one.


 Regards.




More information about the R-sig-Geo mailing list