[R-sig-Geo] Quickest way to tell if an arbitrary file is a raster/vector?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Tue Jun 2 21:36:03 CEST 2015


Tricky, because OGR (at least) doesn't have a 1-1 mapping of "file" to
"data source"....

* I think any component of a shapefile can be used as a data source of
a single-layer. Command-line ogrinfo on my machine thinks so:

$ ogrinfo DSMW.dbf
INFO: Open of `DSMW.dbf'
      using driver `ESRI Shapefile' successful.
1: DSMW (Polygon)

As does rgdal::functions:

 > ogrListLayers("DSMW.shx")
[1] "DSMW"
attr(,"driver")
[1] "ESRI Shapefile"
attr(,"nlayers")
[1] 1


* Then a folder containing shapefiles can be used as a data source
where each shapefile is a layer...

I'd think about wrapping ogrInfo and GDALinfo in "try" clauses, and
then clearing up the duplicates...

Barry



On Tue, Jun 2, 2015 at 6:09 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
> r-sig-geo'ers:
>
> I'm working on a GIS cataloging function to add-in to spatial.tools, and
> one thing I'm struggling with is the quickest way to tell if a given file
> is a GDAL/OGR readable raster/vector.  Any ideas?
>
> --j
>
>         [[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



More information about the R-sig-Geo mailing list