[gdal-dev] RE Python ogr GetFieldAsString problem
Even Rouault
even.rouault at spatialys.com
Thu May 14 06:46:32 PDT 2015
Selon Steve.Toutant at inspq.qc.ca:
> Thanks for your responses!
> We can't change the settings, Refused by the system admin, too many
> applications are using the database and the actual settings.
>
>
> The response of the WFS contains the comma, and it is in GML
> <gml:featureMember>
> <ms:SMDVDP_STAT_METE fid="SMDVDP_STAT_METE.2153">
> <ms:LONG_STAT>-64,2131</ms:LONG_STAT>
> </ms:SMDVDP_STAT_METE>
> </gml:featureMember>
>
> The comma and decimals are not truncated by an XML validator,
I've tested something similar and libxml2 does reject such GML file :
Element '{http://ogr.maptools.org/}AREA': '215229,266' is not a valid value of
the local atomic type., line 17
they are
> truncated by GetFieldAsDouble
>
> But Maybe, it thinks that there are 2 values...-64 and 2131.
> On my side, A patch would be to replace the , by ., use GetFieldAsDouble
> and replace . by , .....
>
> Many countries in the world are using a comma as decimal separator there
> must be a solution....
In GML/XML, decimal values should not be localized.
> What do you think, Does GetFieldAsDouble should be able to manage the ,''?
When the .gml file is accompanied by the .xsd, the GML reader can easily be
tweaked to recognize the , as decimal separator. But when operating without
.xsd, the detection of types would recognize such a value as a string, not a
real value. So I'm not sure if it is appropriate to apply. Anyway, if you want
it :
Index: ogr/ogrsf_frmts/gml/ogrgmllayer.cpp
===================================================================
--- ogr/ogrsf_frmts/gml/ogrgmllayer.cpp (revision 29190)
+++ ogr/ogrsf_frmts/gml/ogrgmllayer.cpp (working copy)
@@ -393,7 +393,7 @@
{
case GMLPT_Real:
{
- poOGRFeature->SetField( iDstField,
CPLAtof(psGMLProperty->papszSubProperties[0]) );
+ poOGRFeature->SetField( iDstField,
CPLAtofM(psGMLProperty->papszSubProperties[0]) );
}
break;
>
> thanks!
>
>
>
>
>
>
>
>
> Even Rouault <even.rouault at spatialys.com>
> 2015-05-13 17:02
>
> A
> Steve.Toutant at inspq.qc.ca
> cc
> gdal-dev at lists.osgeo.org
> Objet
> Re: [gdal-dev] RE Python ogr GetFieldAsString problem
>
>
>
>
>
>
>
>
> Steve,
>
> I believe comma as decimal separator is invalid for a XML double. Hence
> the GML
> driver only parses the value up to the comma. This could likely be
> improved to
> accept comma, but technically I believe a XML validator would reject this
> GML.
>
> Even
>
> > More info.....
> > ogr2ogr --version = GDAL 1.10.1, released 2013/08/26
> > python --version = Python 2.7.3
> >
> > I have modified my script to get the field type
> > while feat is not None:
> > feat_defn = layer.GetLayerDefn()
> > field_defn =
> > feat_defn.GetFieldDefn(feat_defn.GetFieldIndex(attribut))
> > print field_defn.GetType()
> > if field_defn.GetType() == ogr.OFTReal:
> > print "%.4f" % feat.GetFieldAsDouble(attribut)
> > output.add(feat.GetFieldAsString(attribut))
> > feat = layer.GetNextFeature()
> >
> > It detects that it is a real, But GetFieldAsDouble also truncate the
> value
> > at the comma
> >
> >
> >
> > Steve Toutant/INSPQ/SSSS
> > 2015-05-13 15:11
> >
> > A
> > gdal-dev at lists.osgeo.org
> > cc
> >
> > Objet
> > Python ogr GetFieldAsString problem
> >
> >
> >
> >
> >
> >
> >
> >
> > I'm trying to parse a GML and read all the values of an attribute.
> > Example
> > <gml:featureMember>
> > <ms:SMDVDP_STAT_METE fid="SMDVDP_STAT_METE.2153">
> > <ms:LONG_STAT>-64,2131</ms:LONG_STAT>
> > </ms:SMDVDP_STAT_METE>
> > </gml:featureMember>
> >
> > DescribeFeatureType for this layer returns
> > <element name="LONG_STAT" minOccurs="0" type="double"/>
> >
> > wfs_ds = ogr.Open(tmp_file.name) #tmp_file.name is the response of a
> WFS
> > getFeature request
> > layer = wfs_ds.GetLayerByName('SMDVDP_STAT_METE ')
> > feat = layer.GetNextFeature()
> > while feat is not None:
> > output.add(feat.GetFieldAsString('LONG_STAT'))
> > feat = layer.GetNextFeature()
> >
> > (At runtime, the WFs, layer and attribute can be anything of any type.
> And
> > decimal separator, can be ',' or '.')
> > The problem is that feat.GetFieldAsString('LONG_STAT') truncate the
> string
> > to the comma
> >
> > So instead of having -64,2131, I get -64 in the output
> >
> > What is the appropriate way to get the value of an attribute?
> >
> > thanks you!
> >
> >
> >
> >
> >
> >
>
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>
>
>
>
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list