[R-sig-Geo] write/readOGR issue with date / time strings
MacQueen, Don
macqueen1 at llnl.gov
Mon Nov 14 17:10:32 CET 2011
You don't truly have a date/time field, even though it looks like it. You
have a factor.
So the first thing I would try is to convert the date/time field from
factor to character using format() or as.character() before writing the
shapefile. (That is, do the conversion myself rather than relying on
writeOGR's internal conversion; see the help page for writeOGR).
I'm a little bothered by the fact that Lat and Lon are factors; they
shouldn't be. This suggests that somewhere in your data is at least one
row where lat or long is not a valid number. But writeOGR doesn't use
these particular Lat and Lon columns to write coordinates to the
shapefile, so maybe it doesn't matter.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 11/11/11 12:54 PM, "Corrie Curtice" <corrie.curtice at duke.edu> wrote:
>Hello,
>
>Apologies if this has already been addressed somewhere, I did a brief
>search
>of archives but didn't find quite this issue.
>
>I'm writing out an ESRI shapefile. My spdf has a date/time field. Looks
>like this:
>
>> head(spdfUTM at data)
> krillGMTtime Lat Lon
>1 2010-05-12 12:34:21 -64.67655969 -62.15040195
>21 2010-05-12 12:35:12 -64.6771229 -62.1519511
>38 2010-05-12 12:36:02 -64.67775863 -62.15340614
>57 2010-05-12 12:36:53 -64.67838269 -62.15494829
>78 2010-05-12 12:37:43 -64.67901497 -62.15647203
>100 2010-05-12 12:38:37 -64.67973667 -62.15773224
>
>All three fields are reported to be "factors" by str. writeOGR appears
>happy:
>
>> writeOGR(spdfUTM,dd,layer="krillPoints-UTM",driver="ESRI
>Shapefile",verbose=TRUE,overwrite=TRUE)
>$object_type
>[1] "SpatialPointsDataFrame"
>$output_dsn
>[1] "/users/corriecurtice/documents/Data_2010/Shapefiles/"
>$output_layer
>[1] "krillPoints-UTM"
>$output_diver
>[1] "ESRI Shapefile"
>$output_n
>[1] 11179
>$output_nfields
>[1] 3
>$output_fields
>[1] "krillGMTtime" "Lat" "Lon"
>$output_fclasses
>[1] 4 4 4
>$dataset_options
>NULL
>$layer_options
>NULL
>Warning message:
>In writeOGR(spdfUTM, dd, layer = "krillPoints-UTM", driver = "ESRI
>Shapefile", :
> existing layer removed
>
>When I read it right back in again, the date/time field is NAs. This is
>also true if I load the shapefile into ArcMap.
>
>> foo <- readOGR(dd,layer="krillPoints-UTM",verbose=TRUE)
>OGR data source with driver: ESRI Shapefile
>Source: "/users/corriecurtice/documents/Data_2010/Shapefiles/", layer:
>"krillPoints-UTM"
>with 11179 features and 3 fields
>Feature type: wkbPoint with 2 dimensions
>
>> head(foo at data)
> krillGMTti Lat Lon
>1 <NA> -64.67655969 -62.15040195
>2 <NA> -64.6771229 -62.1519511
>3 <NA> -64.67775863 -62.15340614
>4 <NA> -64.67838269 -62.15494829
>5 <NA> -64.67901497 -62.15647203
>6 <NA> -64.67973667 -62.15773224
>
>Thoughts? Am I missing something obvious?
>
>I can break it up into separate date and time fields, but since the field
>is
>simply a factor anyways I'm not sure how that would help.
>
>Cheers,
>
>Corrie
>
>---
>Corrie Curtice
>Research Analyst
>Marine Geospatial Ecology Lab
>Nicholas School of the Environment, Duke University
>http://mgel.env.duke.edu
>em: corrie.curtice at duke.edu
>ph: 252-504-7538
>
>
>
>
> [[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