[R-sig-Geo] Filtering shapefile to come up with only one county

Yuster Ronoh yuster0 at gmail.com
Sat Apr 5 13:47:02 CEST 2014


Thanks rogers I figured out with the code
> writeOGR(Nakuru, dsn= "gis", layer="Nakuru". driver="ESRI Shapefile")

On 4/5/14, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Sat, 5 Apr 2014, Yuster Ronoh wrote:
>
>> Thanks Gordon and Kapo. Gordon I tried your code and it plot the whole
>> country  but for Kapo it work well and I manage to plot Nakuru county but
>> I
>> still have problem in exporting shapefile here in the error message:
>>
>> writeOGR(Nakuru,dsn="C://Users/symon/Desktop/gis/",layer="Nakuru",driver="ESRI
>> Shapefile")Error in writeOGR(Nakuru, dsn =
>> "C://Users/symon/Desktop/gis/", layer = "Nakuru",  :
>>  Creation of output file failed
>
> This is a known problem under Windows, the dsn should read:
>
> "C:/Users/symon/Desktop/gis"
>
> with no trailing directory separator. Can be replicated with:
>
> library(rgdal)
> td <- tempdir()
> dsn <- system.file("vectors", package = "rgdal")[1]
> cities <- readOGR(dsn=dsn, layer="cities")
> td
> writeOGR(cities, paste(td, "/", sep=""), "cities",
>   driver="ESRI Shapefile")
> # Error in writeOGR(cities, paste(td, "/", sep = ""), "cities",
> #  driver = "ESRI Shapefile") :
> #  Creation of output file failed
> writeOGR(cities, td, "cities", driver="ESRI Shapefile")
> # works
>
> Roger
>
>>
>>
>>
>>
>> On Sat, Apr 5, 2014 at 1:16 AM, Kapo Coulibaly <kmcoulib at gmail.com>
>> wrote:
>>
>>> Something like this works for me:
>>> counties<-readOGR(dsn=""C://Users/symon/Desktop/gis/",layer="counties")
>>> Nakuru<-subset(counties,COUNTY_NAM=="Nakuru") # make sure the name and
>>> the
>>> content of the columns are spelled correctly
>>> plot(Nakuru) # Plots the county map
>>>
>>>
>>> You can write the shapefile of Nakuru county with:
>>> writeOGR(Nakuru,dsn=""C://Users/symon/Desktop/gis/",layer="Nakuru",driver="ESRI
>>> Shapefile")
>>>
>>>
>>>
>>> On Fri, Apr 4, 2014 at 1:25 PM, Yuster Ronoh <yuster0 at gmail.com> wrote:
>>>
>>>> Dear List members
>>>> I have a Kenya shapefile with counties.I try to come up with Nakuru
>>>> county
>>>> map and I try with the below code and got an error.How do i  sub-set to
>>>> come up with Nakuru shapefile from the Kenya shapefile
>>>> here is my code:
>>>>
>>>>> library(maps)
>>>>
>>>>> library(maptools)
>>>>
>>>>> library(sp)
>>>>
>>>>> library(rgdal)
>>>>
>>>>> library(ggplot2)
>>>>
>>>>> counties<-readShapePoly("C://Users/symon/Desktop/gis/counties.shp")
>>>>
>>>>> str(counties)
>>>>
>>>>> Nakuru <- fortify(counties, region = "COUNTY_NAM")
>>>>> str(Nakuru)
>>>>> unique(counties at data$COUNTY_NAM)
>>>>
>>>>> class(counties)
>>>>
>>>>> counties at data = counties at data[counties at data$COUNTY_NAME != "NAKURU",]
>>>>
>>>>> plot(counties at data)Error in plot.window(...) : need finite 'xlim'
>>>> valuesIn addition: Warning messages:1: In min(x) : no non-missing
>>>> arguments
>>>> to min; returning Inf2: In max(x) : no non-missing arguments to max;
>>>> returning -Inf3: In min(x) : no non-missing arguments to min; returning
>>>> Inf4: In max(x) : no non-missing arguments to max; returning -Inf
>>>>
>>>>
>>>>         [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo at r-project.org
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>
>>>
>>>
>>
>> 	[[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics,
> Helleveien 30, N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
>
>



More information about the R-sig-Geo mailing list