[prev in list] [next in list] [prev in thread] [next in thread]
List: postgis-users
Subject: Re: [postgis-users] pgsql2shp: date field
From: Peter Hopfgartner <peter.hopfgartner () r3-gis ! com>
Date: 2009-11-30 12:01:00
Message-ID: 4B13B3FC.5010803 () r3-gis ! com
[Download RAW message or body]
I've tried to fix the problem with the left padding, too.
The resulting shape files open cleanly in ArcGIS and gvSIG. Also
inspection with a tool from Borland, ("Database Desktop") has no
complaints about those files.
This patch inclued your fix about the rapprsentation of tha NULL date.
Regards,
Peter
Paul Ramsey wrote:
> I've placed a ticket on this with a patch
>
> http://trac.osgeo.org/postgis/ticket/321
>
> If you would try and patch and see if it creates files that are more
> broadly usable, that would be nice.
>
> Thanks,
>
> Paul
>
> On Fri, Nov 27, 2009 at 5:28 AM, Peter Hopfgartner
> <peter.hopfgartner@r3-gis.com> wrote:
>
>> Hi,
>>
>> we currently have some interoperability problems with pgsql2shp generated
>> shapes. Basically, if a date field is NULL, pgsql2shp writes all zeros to
>> the file. This file can not be opened with gvSIG and OpenOffice, whereas it
>> can be opened with ArcGIS and MS-Excel 2003 (showing the zeros).
>>
>> If I overwrite these zeros (from the hex editor) with spaces, all of the
>> above programs do open and interpret the NULL value correctly.
>>
>> I've attached a dump of the database and the generated shape file and the
>> version with the zeros replaced with spaces.
>>
>> I have not found any spec how dBase III should represent NULL data values
>> and forward this problem to the ML, but the files written in ArcGIS use
>> spaces, too.
>>
>> Another issue: pgsql2shp writes the integer field "ID" aligned to the left,
>> when written from ArcGIS it is aligned to the right. Indeed, some tools
>> seem to have problems in interpreting the value written.
>>
>> Regards,
>>
>> Peter
>>
>> --
>>
>> Dott. Peter Hopfgartner
>>
>> R3 GIS Srl - GmbH
>> Via Johann Kravogl-Str. 2
>> I-39012 Meran/Merano (BZ)
>> Email: peter.hopfgartner@r3-gis.com
>> Tel. : +39 0473 494949
>> Fax : +39 0473 069902
>> www : http://www.r3-gis.com
>>
>> ================================================================================
>> Venite a trovarci all'ASITA, dal 1 al 4 dicembre a Bari www.asita.it
>> Besuchen Sie uns bei der Messe ASITA vom 1. bis 4. Dezember in Bari
>> www.asita.it
>> Visit us at ASITA, from 1st to 4th December in Bari www.asita.it
>> ================================================================================
>>
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users@postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>>
>>
> _______________________________________________
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>
--
Dott. Peter Hopfgartner
R3 GIS Srl - GmbH
Via Johann Kravogl-Str. 2
I-39012 Meran/Merano (BZ)
Email: peter.hopfgartner@r3-gis.com
Tel. : +39 0473 494949
Fax : +39 0473 069902
www : http://www.r3-gis.com
================================================================================
Venite a trovarci all'ASITA, dal 1 al 4 dicembre a Bari www.asita.it
Besuchen Sie uns bei der Messe ASITA vom 1. bis 4. Dezember in Bari www.asita.it
Visit us at ASITA, from 1st to 4th December in Bari www.asita.it
================================================================================
["pgsql2shp.c.patch" (text/x-patch)]
--- pgsql2shp.c.orig 2009-05-03 05:16:42.000000000 +0200
+++ pgsql2shp.c 2009-11-26 18:03:40.000000000 +0100
@@ -64,6 +64,7 @@
char temptablename[256];
char *geo_col_name, *table, *shp_file, *schema, *usrquery;
int type_ary[256];
+int type_ary_len[256];
char *main_scan_query;
DBFHandle dbf;
SHPHandle shp;
@@ -110,7 +111,7 @@
* Might return untouched input or pointer to static private
* buffer: use return value right away.
*/
-static const char * goodDBFValue(const char *in, char fieldType);
+static const char * goodDBFValue(const char *in, char fieldType, int filedLen);
/** @brief Binary to hexewkb conversion function */
char *convert_bytes_to_hex(uchar *ewkb, size_t size);
@@ -852,7 +853,7 @@
else
{
val = PQgetvalue(res, residx, j);
- val = goodDBFValue(val, type_ary[j]);
+ val = goodDBFValue(val, type_ary[j], type_ary_len[j]);
}
LWDEBUG(3, "s");
@@ -1514,6 +1515,7 @@
return 0;
}
type_ary[mainscan_nflds]=FTInteger;
+ type_ary_len[mainscan_nflds]=6;
mainscan_flds[mainscan_nflds++] = fname;
continue;
}
@@ -1529,11 +1531,12 @@
if ( DBFAddField(dbf, field_name, FTInteger,
11, 0) == -1 )
{
- printf( "Error - Ingeter field could not "
+ printf( "Error - Integer field could not "
"be created.\n");
return 0;
}
type_ary[mainscan_nflds]=FTInteger;
+ type_ary_len[mainscan_nflds]=11;
mainscan_flds[mainscan_nflds++] = fname;
continue;
}
@@ -1554,6 +1557,7 @@
return 0;
}
type_ary[mainscan_nflds]=FTInteger;
+ type_ary_len[mainscan_nflds]=20;
mainscan_flds[mainscan_nflds++] = fname;
continue;
}
@@ -1576,6 +1580,7 @@
return 0;
}
type_ary[mainscan_nflds]=FTDouble;
+ type_ary_len[mainscan_nflds]=32;
mainscan_flds[mainscan_nflds++] = fname;
continue;
}
@@ -1593,6 +1598,7 @@
return 0;
}
type_ary[mainscan_nflds]=FTLogical;
+ type_ary_len[mainscan_nflds]=2;
mainscan_flds[mainscan_nflds++] = fname;
continue;
}
@@ -1610,6 +1616,7 @@
return 0;
}
type_ary[mainscan_nflds]=FTDate;
+ type_ary_len[mainscan_nflds]=8;
mainscan_flds[mainscan_nflds++] = fname;
continue;
}
@@ -1668,6 +1675,7 @@
return 0;
}
type_ary[mainscan_nflds]=FTString;
+ type_ary_len[mainscan_nflds]=size;
mainscan_flds[mainscan_nflds++] = fname;
}
@@ -1994,8 +2002,8 @@
return "****************";
case FTDate:
- /* NULL date fields have value "00000000" */
- return "00000000";
+ /* NULL date fields have value " " */
+ return " ";
case FTLogical:
/* NULL boolean fields have value "?" */
@@ -2013,7 +2021,7 @@
* buffer: use return value right away.
*/
static const char *
-goodDBFValue(const char *in, char fieldType)
+goodDBFValue(const char *in, char fieldType, int fieldLen)
{
/*
* We only work on FTLogical and FTDate.
@@ -2021,7 +2029,8 @@
* We allocate space for 9 bytes to take
* terminating null into account
*/
- static char buf[9];
+ static char buf[32+1]; // size of float + \0
+ int rv;
switch (fieldType)
{
@@ -2040,6 +2049,13 @@
buf[7]=in[9]; /* D */
buf[8]='\0';
return buf;
+ case FTInteger:
+ case FTDouble:
+ rv = snprintf(buf, sizeof(buf), "%*s", fieldLen, in);
+ if (rv >= sizeof(buf)) {
+ printf("error(integer) - Value too long\n");
+ }
+ return buf;
default:
return in;
}
_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic