[GRASS-stats] readVECT6 problem fo importing null data

Roger Bivand Roger.Bivand at nhh.no
Wed Dec 5 04:01:25 EST 2007


On Wed, 5 Dec 2007, Markus Neteler wrote:

>
> Dear Jarek,
>
> ok, I made again a test using out NC OSGeo data set
> but now PostgreSQL:
>
> db.connect driver=pg database="host=localhost,dbname=postgres"
> db.tables -p
> information_schema.sql_features
> ...
>
> # copy the map into your MAPSET and check for NULL
> g.copy vect=lakes,mylakes
> v.db.select mylakes
> v.db.select mylakes where="FTYPE IS NULL"
>
> # display the lakes, show undefined FTYPE lakes in red
> g.region swwake_10m
> d.mon x0
> d.erase
> d.vect mylakes where="FTYPE IS NOT NULL" type=area col=blue
> d.vect mylakes where="FTYPE IS NULL" type=area col=red
> # ... works.
>
> # Export test:
> v.out.ogr mylakes dsn=mylakes.shp type=area
>
> # Looking at it in openoffice:
> openoffice.org2.3 mylakes.dbf
> cat,N,11,0,area,N,24,15,perimeter,N,24,15,full_hydro,N,24,15,full_hydr2,N,24,15,ftype,C,80,fcode,N,11,0,name,C,80
> 8,5310.04,334.89,9,55660,LAKE/POND,39000,
> 33,21739.17,709.53,34,54836,LAKE/POND,39000,
> 63,469.77,105.84,64,0,,0,
> 84,10564.66,402.43,85,55595,ROCK/ISLAND,44100,
> 93,7655.72,344.71,94,53621,DAM/WEIR,34300,
> 94,1357.21,178.47,95,0,,0,
> 96,26382.58,1286.95,97,53957,ROCK/ISLAND,44100,
> ...

There is also the question of numerical fields, and please remember that 
an empty field is not NULL, it is a zero-length text string:

> a <- ""
> is.na(a)
[1] FALSE

so one needs to do:

> is.na(a) <- nchar(a) == 0
> is.na(a)
[1] TRUE

and remember that character fields are cast to factor - so use 
as.character(a) too. This means that the encoding for each field needs to 
be known and transferred *outside* the *.dbf file. I think that the DBF 
format is still the default for vector attribute data, isn't it? Maybe 
SQLite does a better job, then we could look at different OGR drivers, or 
ESRI Shapefile for the geometry and RSQLite for the data? Jarek had found 
that numerical NULL was being set to 0 if I remember.

Roger

>
> Also the expected empty fields here. I am using PG 8.2.5 and
> GRASS 6.3-CVS.
> Can you replicate this example?
>
> Markus
>
>
> Jarek Jasiewicz wrote:
>>
>> Dear Markus!
>>
>> The problem most probable concerns export only, when atributres are
>> stored in postgreSQL database and it happens when data during v.out.ogr
>> to shp with dbf table, in spite of NOT NULL in pgsql  is set
>> cheers
>> Jarek
>>
>
>

-- 
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 grass-stats mailing list