Decimal separator is not always "."

plopesc - August 5, 2009 - 12:05
Project:Geo
Version:6.x-1.x-dev
Component:Geo API
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

AttachmentSize
patch-geo-wkt.patch1.77 KB

#1

Allie Micka - November 9, 2009 - 17:50
Status:needs review» postponed (maintainer needs more info)

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

plopesc - November 10, 2009 - 08:03
Status:postponed (maintainer needs more info)» needs review

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

Allie Micka - November 10, 2009 - 18:09
Status:needs review» needs work

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

Allie Micka - November 11, 2009 - 01:20

Would a simple str_replace() work? For example:

<?php
str_replace
(',', '.', $data[x]);
?>

#5

plopesc - November 11, 2009 - 08:18

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

Allie Micka - November 12, 2009 - 18:41
Status:needs work» needs review

Hi plopesc,

can you test this patch?

Thanks!

AttachmentSize
geo.wkb_.inc_.patch 583 bytes

#7

plopesc - November 16, 2009 - 08:03
Status:needs review» reviewed & tested by the community

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!

AttachmentSize
patch-geo-comma.patch 1006 bytes

#8

Allie Micka - November 16, 2009 - 21:08
Status:reviewed & tested by the community» fixed

I have committed this. Thanks plopesc!

#9

System Message - November 30, 2009 - 21:10
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.