[R-sig-Geo] error in readShapePoly

Hurlbert, Allen H. (Biology) Hurlbert at bio.unc.edu
Wed Jun 10 20:02:06 CEST 2009


Is there an equivalent argument in readOGR() to read in a shapefile with
a NULL geometry, or can this only be done with readShapePoly?

Thanks,
Allen

-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Wednesday, June 10, 2009 12:44 PM
To: Hurlbert, Allen H. (Biology)
Cc: r-sig-geo at stat.math.ethz.ch
Subject: RE: [R-sig-Geo] error in readShapePoly

On Wed, 10 Jun 2009, Hurlbert, Allen H. (Biology) wrote:

> Thanks Roger!
>
> Are there any instances in which one would want delete_null_obj=FALSE?

Well, they shouldn't be there, really. When I release maptools, with 
default delete_null_obj=FALSE, it will report which one, and then:

library(foreign)
tip <- read.dbf("trin_inca_pl.dbf")
tip[134,]

would show the contents of the DBF for the offending NULL geometry. 
Setting it to TRUE by default wouldn't warn the user that there was 
anything untoward. In this case, the file originator might want to know 
that a geometry has gone away, perhaps. In an earlier case, Statistics 
Australia was squirrelling data with no spatial position away in a NULL 
geometry, which is OK for the DBF, but not OK if the files are (as they 
are) intended to contain geometries with attributes.

Roger

>
> -----Original Message-----
> From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> Sent: Wednesday, June 10, 2009 10:36 AM
> To: Hurlbert, Allen H. (Biology)
> Subject: RE: [R-sig-Geo] error in readShapePoly
>
> On Wed, 10 Jun 2009, Hurlbert, Allen H. (Biology) wrote:
>
>> Hi Roger,
>>
>> Here is the result of the traceback():
>>
>> 4: .shp2srsI(shapes[[belongs[[i]][j]]],
>> .nParts.shpI(shapes[[belongs[[i]][j]]]),
>>       force_ring = force_ring)
>> 3: .asSpatialPolygonsShapes(Map$Shapes, IDs, proj4string =
> proj4string,
>>       force_ring = force_ring)
>> 2: .Map2PolyDF(Map, IDs = IDvar, proj4string = proj4string,
force_ring
> =
>> force_ring,
>>       delete_null_obj = delete_null_obj, retrieve_ABS_null =
>> retrieve_ABS_null)
>> 1:
>>
>
readShapePoly(paste("\\\\Bioark.bio.unc.edu\\hurlbertallen\\GIS\\BirdRan
>> geMaps\\NatureServe3.0\\",
>>       as.character(families[f]), "\\", as.character(spp.list[s2,
>>           1]), sep = ""), proj4string = CRS("+proj=latlong
>> +datum=NAD83"))
>>
>> The shapefiles are bird range maps available online from NatureServe
>> here: http://www.natureserve.org/getData/birdMaps.jsp. The problem
> file
>> is trin_inca_pl.shp which is included in the zipped 'Scolopacidae'
> file
>> on that page.
>>
>> Unfortunately, I am unfamiliar with the syntax of readOGR() and can't
>> quite figure out how I'm supposed to use it to read in a shapefile.
>
> It is a bit more revealing:
>
>> trin_inca_pl <- readOGR("Scolopacidae", "trin_inca_pl")
> Error in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding =
> input_field_name_encoding) :
>   NULL geometry found
>
> and suggests using the fix in:
>
>> trin_inca_pl <- readShapePoly("Scolopacidae/trin_inca_pl.shp",
> +  delete_null_obj=TRUE)
> Warning message:
> In .Map2PolyDF(Map, IDs = IDvar, proj4string = proj4string, force_ring
=
>
> force_ring,  :
>   Null objects with the following indices deleted: 134
>
> So the data provider has inserted a NULL geometry into the data - they
> shouldn't do it, but it has been seen before. Could you summarise to
the
>
> list, please? I'll see if I can add a test in readShapePoly to point
> users
> to the optional argument.
>
> Roger
>
>>
>> Thanks!
>> Allen
>>
>> -----Original Message-----
>> From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
>> Sent: Wednesday, June 10, 2009 9:38 AM
>> To: Hurlbert, Allen H. (Biology)
>> Cc: r-sig-geo at stat.math.ethz.ch
>> Subject: Re: [R-sig-Geo] error in readShapePoly
>>
>> On Wed, 10 Jun 2009, Hurlbert, Allen H. (Biology) wrote:
>>
>>> Hello list,
>>>
>>>
>>>
>>> I'm new to GIS in R, so I appreciate any pointers with my problem.
>>>
>>>
>>>
>>> I have code that uses readShapePoly to read in shapefiles in a loop
>> and
>>> does some basic operations. This code appeared to be working great
> for
>>> twenty or so files, but then on one shapefile bonked with the
>> following
>>> error:   Error in from[j]:to[j] : NA/NaN argument.
>>>
>>>
>>>
>>> The problem shapefile opens fine in ArcGIS and there is nothing
>> readily
>>> different about its attribute table or source information that I can
>> see
>>> (and furthermore, all shapefiles are from the same standardized
>> source,
>>> although of course that doesn't mean one of them didn't get messed
up
>>> somewhere along the way). I am running 2.7.2 on Windows XP x64.
>>>
>>
>> Could you 1) try readOGR() in rgdal instead of readShapePoly() in
>> maptools
>> if possible, and see if the problem is repeated; 2) post either the
>> output
>> of traceback() run immediately after the error occurs (will show
> where,
>> more or less, the problem is in code) here and/or the shapefile(s)
all
>> 3-4
>> files in a zip archive on a website and post the URL here so that
> others
>>
>> can debug this? The problem seems to be a shot Pstart vector putting
> an
>> invalid value into the range from which to extract ring coordinates,
> but
>>
>> the question is why it is shot.
>>
>> If you can say something about the origin of the file, this may also
>> help
>> (what software wrote it), some have broken *.shx files.
>>
>> Roger
>>
>>>
>>>
>>> Thanks in advance,
>>>
>>> Allen
>>>
>>>
>>> 	[[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list