Posted by plopesc on August 5, 2009 at 12:05pm
| Project: | Geo |
| Component: | Geo API |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
When you executes the geo_wkb_get_data() function, if you are using a non English system (i.e. Spanish), you have to use the number_format function to convert the double value to string, because if you are using other LOCALE, the decimal separator is "," instead of "." and the WKT format is not correct.
I have written this patch which solve this issue for me.
| Attachment | Size |
|---|---|
| patch-geo-wkt.patch | 1.77 KB |
Comments
#1
Can you show me a public/standard example of this type of format in use? I can't seem to find any information that supports a locale-based WKT format...
#2
Hello!
The problem is not the locale-based WKT format. The problem is produced if the Server's Language is not English, because when you transform directly the float value to String, it assumes the Spanish language and the decimal separator which appears is "," instead of ".". When I try to proccess that value, it fails because the "." separator is expected.
If you use the number_format method, you are sure that the decimal separator is always ".", independently of the Server's Language.
Thanks in advance!
#3
OK, cool - that makes much more sense to me!
I'm concerned about number_format's decimal parameter here. With this code, POINT(1 2) will become POINT(1.0000000000 2.0000000000) - which will get quite lengthy, especially for complex polygons. And data with more decimal places may potentially get lopped off.
Can you think of an alternative?
#4
Would a simple str_replace() work? For example:
<?phpstr_replace(',', '.', $data[x]);
?>
#5
Yes, I think that it would be a good solution for this problem, because in case of english notation, it doesn't affect to the float value, and in case of Spanish notation, itwill replace the separator value without adding 0's.
This method must be called before generate the whole WKT value, because in case of polygons, the "," value must appear between points.
I think that another option would be:
<?php$wkt_value = preg_replace('/(\d+),(\d+)/', '$1.$2', $wkt_value);
?>
In this way, you can format the whole WKT value.
Have a nice day
#6
Hi plopesc,
can you test this patch?
Thanks!
#7
Hi Allie!
I have tested the patch and there was a small problem, but I've solve it.
The new patch would be as follows.
Thanks!
#8
I have committed this. Thanks plopesc!
#9
Automatically closed -- issue fixed for 2 weeks with no activity.