[R-sig-Geo] Error in converting SpatialPointsDataFrame object to ESRI shape file using writeOGR from rgdal package

Danlin Yu yud at mail.montclair.edu
Tue Jun 17 02:26:45 CEST 2008


Dear Debarchana Ghosh:

It may be me, but when I put a double quotation on [place] (I assume 
that's the layer's name?], writeOGR generates a folder with shapefiles 
in it. If that doesn't work or my understanding is not correct, you can 
still generate a shapefile by exporting the SDF object as an ASCII file 
(.csv is one of my favorite), since it does contain coordinates, you can 
then create a shapefile using GeoDa [Tools->Shape->Points from ASCII...].

Hope this helps.

Danlin

Debarchana Ghosh wrote:
> Hi,
>
> I am using R 2.7 on windows with 4GB ram.
>
> I am trying to convert the SpatialPointsDataFrame object (SDF) from the
> "gwr" output ( spgwr package) to ESRI shapefile using the writeOGR function
> from the rgdal package. The function is able to write the shape file with
> correct geometry but showing errors when trying to view the attribute table.
> The attribute table is empty. But the data slot of the
> SpatialPointsDataFrame object has values for all the columns. Below I paste
> my codes:
>
> # packages spgwr, maptool, sp, foreign
> # Finding the bandwidth by the AIC method
> test500.bw.aic<-gwr.sel(yimp00~ english + slope30 + mac95d + mdinc_t +
> musa00
>   + popden_t + dissewer + dismcd + diswater + ag04 + c1dishwy + c1dipark +
> tccost1 + soil1 + soil2,
>   data=base500vars, coords = cbind(base500vars$longx, base500vars$laty),
> method = "aic", longlat=TRUE)
>
> # gauss gwr function
> test500.gwr<-gwr(yimp00~ english + slope30 + mac95d + mdinc_t + musa00 +
> popden_t + dissewer + dismcd + diswater
>   + ag04 + c1dishwy + c1dipark + tccost1 + soil1 + soil2, data=base500vars,
>   coords = cbind(base500vars$longx, base500vars$laty), longlat=TRUE,
> bandwidth = test500.bw.aic,
>   hatmatrix=TRUE, se.fit=TRUE)
>
> # output of gwr
> names(test500.gwr)
> [1] "SDF"       "lhat"      "lm"        "results"   "bandwidth" "adapt"
> "hatmatrix" "gweight"   "this.call"
>
> class(test500.gwr$SDF)
> [1] "SpatialPointsDataFrame"
> attr(,"package")
> [1] "sp"
>
>   
>> names(test500.gwr$SDF)
>>     
>  [1] "sum.w"          "(Intercept)"    "english"        "slope30"
> "mac95d"         "mdinc_t"        "musa00"         "popden_t"
>  [9] "dissewer"       "dismcd"         "diswater"       "ag04"
> "c1dishwy"       "c1dipark"       "tccost1"        "soil1"
> [17] "soil2"          "R2"             "gwr.e"          "(Intercept)_se"
> "english_se"     "slope30_se"     "mac95d_se"      "mdinc_t_se"
> [25] "musa00_se"      "popden_t_se"    "dissewer_se"    "dismcd_se"
> "diswater_se"    "ag04_se"        "c1dishwy_se"    "c1dipark_se"
> [33] "tccost1_se"     "soil1_se"       "soil2_se"
>
> # I changed the names of column 2 and 20 to "Intercept" and "Intercept_se"
> because ESRI shapefiles does not like brackets
>   
>> names(test500.gwr$SDF)[2]<-"Intercept"
>> names(test500.gwr$SDF)[20]<-"Intercept_se"
>> names(test500.gwr$SDF)
>>     
>  [1] "sum.w"        "Intercept"    "english"      "slope30"
> "mac95d"       "mdinc_t"      "musa00"       "popden_t"     "dissewer"
> [10] "dismcd"       "diswater"     "ag04"         "c1dishwy"
> "c1dipark"     "tccost1"      "soil1"        "soil2"        "R2"
> [19] "gwr.e"        "Intercept_se" "english_se"   "slope30_se"
> "mac95d_se"    "mdinc_t_se"   "musa00_se"    "popden_t_se"  "dissewer_se"
> [28] "dismcd_se"    "diswater_se"  "ag04_se"      "c1dishwy_se"
> "c1dipark_se"  "tccost1_se"   "soil1_se"     "soil2_se"
>
> # Converting a "SpatialPointsDataFrame" object to ESRI shape file
> # packages rgdal
> writeOGR(test500.gwr$SDF, place, "test500gwr", driver="ESRI Shapefile")
>
> I cannot seem to find the error. Is there any other way to write the
> 'SpatialPointsDataFrame' object to ESRI shapefiles?
>
> Any pointers will be very helpful.
>
>   

-- 
___________________________________________
Danlin Yu, Ph.D.
Assistant Professor
Department of Earth & Environmental Studies
Montclair State University
Montclair, NJ, 07043
Tel: 973-655-4313
Fax: 973-655-4072
email: yud at mail.montclair.edu
webpage: csam.montclair.edu/~yu




More information about the R-sig-Geo mailing list