Skip to content
Prev 16786 / 29559 Next

readOGR and PostGIS: "Error getting field 0"

On Fri, 30 Nov 2012, Mathieu Basille wrote:

            
The error message is from ogrReadColumn(), line 221 in src/ogrsource.cpp, 
for example here:

https://r-forge.r-project.org/scm/viewvc.php/pkg/src/ogrsource.cpp?view=markup&root=rgdal

What does ogrInfo() report? Does it make a difference if you add an extra 
field? I'm wondering whether in this case the GID is not being seen as a 
field as such, but the FID of the point. Possibly ogr2ogr steps round 
this. I don't have a PostGIS system running, so may need help debugging. 
If you debug(readOGR), what happens here:

         if (drop_unsupported_fields) {
              iflds <- as.integer((1:ogr_info$nitems)-1)
              iflds <- iflds[keep]
              fldnms <- ogr_info$iteminfo$name[keep]
              if (any(!keep)) warning(paste("Fields dropped:",
                  paste(ogr_info$iteminfo$name[!keep], collapse=" ")))
         } else {
              if (any(!keep)) stop(paste("Unsupported field type:",
                  paste(ogr_info$iteminfo$typeName[!keep], collapse=" ")))
              iflds <- as.integer((1:ogr_info$nitems)-1)
              fldnms <- ogr_info$iteminfo$name
         }

I think ogr_info$nitems is 1, so we get 0, but if ogr_info$nitems is 0, 
(0, -1).

Roger