issue with readOGR

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

issue with readOGR

Abdoulaye SARR
I am trying to read a shapefile using readOGR but keep getting error
messages:
map =
readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv =
use_iconv,  :
  Cannot open layer

What could be causing the problem? sp 1.3-2

Thanks
as

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: issue with readOGR

David Hine

Hi Abdoulaye

Perhaps its helpful to simplify the instruction so its easy to read in ordinary text. The example that Jeffrey Hollister gives at https://www.r-bloggers.com/things-i-forget-reading-a-shapefile-in-r-with-readogr/

is like this

myShapeInR<-readOGR("C:/data","myShapeFile") where the shapefile is called myShapeFile.shp, and its in C:/data.

If its in your current working directory (calling getwd() will tell you what your current working directory is) then you can use simply

myShapeInR<-readOGR(".","myShapeFile") as the full stop "." is a symbol for the current directory.

Hope that helps

David


On 9/11/2019 2:47 am, Abdoulaye Sarr wrote:
I am trying to read a shapefile using readOGR but keep getting error
messages:
map =
readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv =
use_iconv,  :
  Cannot open layer

What could be causing the problem? sp 1.3-2

Thanks
as

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Land and Water Management logo

David Hine
Land and Water Management PL
Level 7, 127 Creek St
Brisbane, Qld 4000
Australia

m: 0429 886 146 +61 429 886 146
t: (07) 4015 3470 +61 7 4015 3470

GeoPortal with example presentations of spatial data for horticulture users and others.
Land and Water Management PL



_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: issue with readOGR

Roger Bivand
Administrator
In reply to this post by Abdoulaye SARR
On Fri, 8 Nov 2019, Abdoulaye Sarr wrote:

> I am trying to read a shapefile using readOGR but keep getting error
> messages:
> map =
> readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
> Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv =
> use_iconv,  :
>  Cannot open layer

What is "/Volumes/DS2S/R_QGIS_codes//Data"? If a network drive, some OGR
drivers are known not to work with them (or that used to be the case).
Which OS/Platform is this? Is the repeated "//" correct? Can you see the
file running list.files("/Volumes/DS2S/R_QGIS_codes//Data") ?

Roger

>
> What could be causing the problem? sp 1.3-2
>
> Thanks
> as
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: issue with readOGR

Abdoulaye SARR
output from list.files:

     "dhaka_div.shx"        "dhaka_gazipur.cpg"
 "dhaka_gazipur.dbf"    "dhaka_gazipur.prj"    "dhaka_gazipur.qpj"
 "dhaka_gazipur.shp"
 "dhaka_gazipur.shx"    "dhaka.dbf"            "dhaka.prj"
 "dhaka.shp"
"dhaka.shx"            "indicator.csv"        "r_val.csv"

On Sat, Nov 9, 2019 at 5:07 PM Roger Bivand <[hidden email]> wrote:

> On Fri, 8 Nov 2019, Abdoulaye Sarr wrote:
>
> > I am trying to read a shapefile using readOGR but keep getting error
> > messages:
> > map =
> > readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
> > Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
> use_iconv =
> > use_iconv,  :
> >  Cannot open layer
>
> What is "/Volumes/DS2S/R_QGIS_codes//Data"? If a network drive, some OGR
> drivers are known not to work with them (or that used to be the case).
> Which OS/Platform is this? Is the repeated "//" correct? Can you see the
> file running list.files("/Volumes/DS2S/R_QGIS_codes//Data") ?
>
> Roger
>
> >
> > What could be causing the problem? sp 1.3-2
> >
> > Thanks
> > as
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > [hidden email]
> > 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; e-mail: [hidden email]
> https://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: issue with readOGR

Abdoulaye SARR
Platform is osx.

Thanks

On Sat, Nov 9, 2019 at 6:11 PM Abdoulaye Sarr <[hidden email]>
wrote:

> output from list.files:
>
>      "dhaka_div.shx"        "dhaka_gazipur.cpg"
>  "dhaka_gazipur.dbf"    "dhaka_gazipur.prj"    "dhaka_gazipur.qpj"
>  "dhaka_gazipur.shp"
>  "dhaka_gazipur.shx"    "dhaka.dbf"            "dhaka.prj"
>  "dhaka.shp"
> "dhaka.shx"            "indicator.csv"        "r_val.csv"
>
> On Sat, Nov 9, 2019 at 5:07 PM Roger Bivand <[hidden email]> wrote:
>
>> On Fri, 8 Nov 2019, Abdoulaye Sarr wrote:
>>
>> > I am trying to read a shapefile using readOGR but keep getting error
>> > messages:
>> > map =
>> > readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
>> > Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
>> use_iconv =
>> > use_iconv,  :
>> >  Cannot open layer
>>
>> What is "/Volumes/DS2S/R_QGIS_codes//Data"? If a network drive, some OGR
>> drivers are known not to work with them (or that used to be the case).
>> Which OS/Platform is this? Is the repeated "//" correct? Can you see the
>> file running list.files("/Volumes/DS2S/R_QGIS_codes//Data") ?
>>
>> Roger
>>
>> >
>> > What could be causing the problem? sp 1.3-2
>> >
>> > Thanks
>> > as
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > [hidden email]
>> > 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; e-mail: [hidden email]
>> https://orcid.org/0000-0003-2392-6140
>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: issue with readOGR

Roger Bivand
Administrator
On Sat, 9 Nov 2019, Abdoulaye Sarr wrote:

> Platform is osx.
>
> Thanks
>
> On Sat, Nov 9, 2019 at 6:11 PM Abdoulaye Sarr <[hidden email]>
> wrote:
>
>> output from list.files:
>>
>>      "dhaka_div.shx"        "dhaka_gazipur.cpg"
>>  "dhaka_gazipur.dbf"    "dhaka_gazipur.prj"    "dhaka_gazipur.qpj"
>>  "dhaka_gazipur.shp"
>>  "dhaka_gazipur.shx"    "dhaka.dbf"            "dhaka.prj"
>>  "dhaka.shp"
>> "dhaka.shx"            "indicator.csv"        "r_val.csv"
>>

From this we see that "indicator.csv" is not (immediately) a file that has
an appropriate driver (it needs a *.vrt to say which columns are which,
see https://gdal.org/drivers/vector/csv.html). Valid layers should be
"dhaka" and "dhaka_gazipur", but not "dhaka_div", for which  only the
*.shx is shown.

Try ogrListLayers(path.expand("/Volumes/DS2S/R_QGIS_codes//Data")) to try
to detect valid layers. If you really meant "indicators", use
paste0("CSV:", file.path(path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),
"indicators.csv")) as per the GDAL vector driver help page.

Roger

>> On Sat, Nov 9, 2019 at 5:07 PM Roger Bivand <[hidden email]> wrote:
>>
>>> On Fri, 8 Nov 2019, Abdoulaye Sarr wrote:
>>>
>>>> I am trying to read a shapefile using readOGR but keep getting error
>>>> messages:
>>>> map =
>>>> readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
>>>> Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
>>> use_iconv =
>>>> use_iconv,  :
>>>>  Cannot open layer
>>>
>>> What is "/Volumes/DS2S/R_QGIS_codes//Data"? If a network drive, some OGR
>>> drivers are known not to work with them (or that used to be the case).
>>> Which OS/Platform is this? Is the repeated "//" correct? Can you see the
>>> file running list.files("/Volumes/DS2S/R_QGIS_codes//Data") ?
>>>
>>> Roger
>>>
>>>>
>>>> What could be causing the problem? sp 1.3-2
>>>>
>>>> Thanks
>>>> as
>>>>
>>>>       [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> [hidden email]
>>>> 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; e-mail: [hidden email]
>>> https://orcid.org/0000-0003-2392-6140
>>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>>>
>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: issue with readOGR

Abdoulaye SARR
Thank Roger, that solve the issue.

Best regards,
as

On Sun, Nov 10, 2019 at 1:34 PM Roger Bivand <[hidden email]> wrote:

> On Sat, 9 Nov 2019, Abdoulaye Sarr wrote:
>
> > Platform is osx.
> >
> > Thanks
> >
> > On Sat, Nov 9, 2019 at 6:11 PM Abdoulaye Sarr <[hidden email]>
> > wrote:
> >
> >> output from list.files:
> >>
> >>      "dhaka_div.shx"        "dhaka_gazipur.cpg"
> >>  "dhaka_gazipur.dbf"    "dhaka_gazipur.prj"    "dhaka_gazipur.qpj"
> >>  "dhaka_gazipur.shp"
> >>  "dhaka_gazipur.shx"    "dhaka.dbf"            "dhaka.prj"
> >>  "dhaka.shp"
> >> "dhaka.shx"            "indicator.csv"        "r_val.csv"
> >>
>
> From this we see that "indicator.csv" is not (immediately) a file that has
> an appropriate driver (it needs a *.vrt to say which columns are which,
> see https://gdal.org/drivers/vector/csv.html). Valid layers should be
> "dhaka" and "dhaka_gazipur", but not "dhaka_div", for which  only the
> *.shx is shown.
>
> Try ogrListLayers(path.expand("/Volumes/DS2S/R_QGIS_codes//Data")) to try
> to detect valid layers. If you really meant "indicators", use
> paste0("CSV:", file.path(path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),
> "indicators.csv")) as per the GDAL vector driver help page.
>
> Roger
>
> >> On Sat, Nov 9, 2019 at 5:07 PM Roger Bivand <[hidden email]>
> wrote:
> >>
> >>> On Fri, 8 Nov 2019, Abdoulaye Sarr wrote:
> >>>
> >>>> I am trying to read a shapefile using readOGR but keep getting error
> >>>> messages:
> >>>> map =
> >>>>
> readOGR(dsn=path.expand("/Volumes/DS2S/R_QGIS_codes//Data"),"indicator")
> >>>> Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
> >>> use_iconv =
> >>>> use_iconv,  :
> >>>>  Cannot open layer
> >>>
> >>> What is "/Volumes/DS2S/R_QGIS_codes//Data"? If a network drive, some
> OGR
> >>> drivers are known not to work with them (or that used to be the case).
> >>> Which OS/Platform is this? Is the repeated "//" correct? Can you see
> the
> >>> file running list.files("/Volumes/DS2S/R_QGIS_codes//Data") ?
> >>>
> >>> Roger
> >>>
> >>>>
> >>>> What could be causing the problem? sp 1.3-2
> >>>>
> >>>> Thanks
> >>>> as
> >>>>
> >>>>       [[alternative HTML version deleted]]
> >>>>
> >>>> _______________________________________________
> >>>> R-sig-Geo mailing list
> >>>> [hidden email]
> >>>> 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; e-mail: [hidden email]
> >>> https://orcid.org/0000-0003-2392-6140
> >>> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
> >>>
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > [hidden email]
> > 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; e-mail: [hidden email]
> https://orcid.org/0000-0003-2392-6140
> https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo