[R-sig-Geo] Issue reading ESRI polygon shapefiles with PBSMapping 'importShapefile'

Roger Bivand Roger.Bivand at nhh.no
Wed Jun 13 10:28:11 CEST 2007


On Tue, 12 Jun 2007, Rick Reeves wrote:

>
> Hello,
>
> Using R 2.5.0 with  PBSmapping package version 2.09:
>
> When I try to read in a polygon shapefile (eight polygons, the file was 
> written by the
> Feature Class to Shapefile command in ArcMap GIS 9.2) using the command:
>
> importShapefile("TriCountyPolyDD")
>
> The following error occurs:
>
> Error in x[[jj]][iseq] <- vjj : incompatible types (from NULL to integer) in 
> subassignment type fix


Please always (by reflex, don't even think why!) say traceback() after 
every error. The output of traceback() may not help you, but it certainly 
helps those who read the error report. Probably vjj is NULL, but vjj does 
not appear in importShapefile, so only traceback() would show where the 
error occurred.

>
> Using read.shape on the same file yields
>
>>  TriCounty <-read.shape("TriCountyPolyDD.shp") 
> Shapefile type: Polygon, (5), # of Shapes: 8
>> 
> Yet I wish to work with this shapefile using the PBSmapping tools.
>
> Has anyone else encountered and/or repaired this?
> Plan B would be to convert the Map object TriCounty into
> a PolySet or PolyData used by PBSmapping package, but
> so far I have not worked this out. Any suggestions?
>

To get to PolySet:

library(maptools)
library(PBSmapping)

# NC example shapefile included with maptools

xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1],
   IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
xx_PS <- SpatialPolygons2PolySet(xx)
class(xx_PS)

For PolyData, cast xx to data.frame:

xx_df <- as(xx, "data.frame")
xx_df1 <- cbind(PID=1:nrow(xx_df), xx_df)
xx_df1$col <- paste("grey", 100-(2*(xx_df1$SID74+1)), sep="")
xx_PD <- as.PolyData(xx_df1, projection=attr(xx_PS, "projection"))
plotMap(xx_PS, polyProps=xx_PD)

which corresponds to:

spplot(xx, "SID74", col.regions=grey(99:1/100))

Now this assumes that Arc hasn't done something odd to your shapefile, of 
course.

Hope this helps,

Roger

> Thanks, Rick Reeves
> NCEAS / UC Santa Barbara
>
>

-- 
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