On Fri, 2009-09-11 at 21:35 +0100, Jon Burgess wrote:
> On Fri, 2009-09-11 at 21:10 +0100, Jon Burgess wrote:
> > > to my map file, so that values would be displayed for tracts with
> > > avg_r_tax_val_0906 below 100000. I've attached the map that was
> > > rendered, adding an arrow pointing to an incorrect value. The value
> > > displayed is 17761.66, but it should be 170761.66. The 0 before the
> > > disimal has been dropped. It appears this is the case for other
> > > incorrect values. Weird!
> > >
> >
> > Losing digits in the middle of a number is indeed very weird. Are you
> > sure the field is stored correctly in the DB?
>
> What postgres data type does the avg_r_tax_val_0906 column use?
>
> Looking in the Mapnik postgis plugin source, the numeric2string function
> sticks out as possibly being relevant. You could try adding some debug
> in there.
>
> What machine is this running on, an x86 cpu or something else? Is the DB
> on the same machine as Mapnik or a remote connection?
I'm fairly confident this is due to an issue in numeric2string. Can you
try the attached patch?
It will spew a lot of debug to stderr describing how it builds the
string but hopefully it should get the right result. If you still see
problems then the output will be useful to help debug further.
The problem was occurring because the intermediate 'digits' of the
numeric type have to be padded with leading zeros to make them all 4
characters long. I won't try to describe the details, but each
postgresql digit can represent a number between 0000 & 9999, not the
normal 0-9 which you might expect.
Jon
Index: plugins/input/postgis/postgisfs.cpp
===================================================================
--- plugins/input/postgis/postgisfs.cpp (revision 1301)
+++ plugins/input/postgis/postgisfs.cpp (working copy)
@@ -60,12 +60,30 @@
int i = std::max(weight,int16_t(0));
int d = 0;
+
+ // NB. each "digit" is actually a value between 0 and 9999 stored in a 16 bit value
+
while ( i >= 0)
{
- if (i <= weight && d < ndigits)
- ss << digits[d++];
- else
- ss << '0';
+ if (i <= weight && d < ndigits) {
+ std::cerr << ss.str() << " adding '" << digits[d] << "' position " << d <<"\n";
+ // All digits after the first require leading zero's to be pre-pended to the value
+ if (d != 0) {
+ switch(digits[d]) {
+ case 0 ... 9:
+ ss << "000";
+ break;
+ case 10 ... 99:
+ ss << "00";
+ break;
+ case 100 ... 999:
+ ss << "0";
+ break;
+ }
+ }
+ ss << digits[d++];
+ } else
+ ss << "0000";
i--;
}
if (dscale > 0)
@@ -73,11 +91,26 @@
ss << '.';
while ( i >= -dscale)
{
- if (i <= weight && d < ndigits)
- ss << digits[d++];
+ if (i <= weight && d < ndigits) {
+ std::cerr << ss.str() << " adding '" << digits[d] << "'\n";
+ switch(digits[d]) {
+ case 0 ... 9:
+ ss << "000";
+ break;
+ case 10 ... 99:
+ ss << "00";
+ break;
+ case 100 ... 999:
+ ss << "0";
+ break;
+ }
+ ss << digits[d++];
+ }
i--;
}
}
+ std::cerr << "Result = " << ss.str() << "\n";
+
return ss.str();
}
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users