Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#5208 closed defect (fixed)

Syntetic field name considered as real

Reported by: strk Owned by: warmerdam
Priority: normal Milestone: 1.10.1
Component: OGR_SF Version: 1.10.0
Severity: normal Keywords: kml ogr2ogr
Cc:

Description

When converting an SQL query with a "Name" field to KML format, ogr2ogr renames the "Name" column to "name2" because (it says) a field named "name" already exists. But that field is really not in the query.

$ ogr2ogr -f kml /dev/stdout "PG:" -sql "SELECT 'a' as name"
Warning 1: Field 'name' already exists. Renaming it as 'name2'

The resulting KML has no "Name" described in the "ExtendedData?" schema in the placemark.

Full result:

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>sql_statement</name>
Warning 1: Field 'name' already exists. Renaming it as 'name2'
  <Placemark>
        <ExtendedData><SchemaData schemaUrl="#sql_statement">
                <SimpleData name="name2">a</SimpleData>
        </SchemaData></ExtendedData>
  </Placemark>
</Folder>
<Schema name="sql_statement" id="sql_statement">
        <SimpleField name="Name" type="string"></SimpleField>
        <SimpleField name="Description" type="string"></SimpleField>
        <SimpleField name="name2" type="string"></SimpleField>
</Schema>
</Document></kml>

It used to work differently in 1.9.2

This _may_ be a duplicate of #4988 but I'm not sure as there isn't enough information for me in that ticket

Change History (4)

comment:1 Changed 4 years ago by strk

This is the output from 1.9.2:

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>sql_statement</name>
<Schema name="sql_statement" id="sql_statement">
        <SimpleField name="Name" type="string"></SimpleField>
        <SimpleField name="Description" type="string"></SimpleField>
</Schema>
  <Placemark>
        <name>a</name>
        <ExtendedData><SchemaData schemaUrl="#sql_statement">
                <SimpleData name="Name">a</SimpleData>
        </SchemaData></ExtendedData>
  </Placemark>
</Folder></Document></kml>

Which is right and which is wrong ?

comment:2 Changed 4 years ago by Even Rouault

Keywords: kml ogr2ogr added
Milestone: 1.10.1
Resolution: fixed
Status: newclosed

Seen in the context of this ticket, but not directly the issue exposed :

trunk(r26346) and branches/1.10(r26347): "KML: in writing mode, avoid defining an extending schema for the name and description fields (related to #5208)"

trunk r26348 "ogr2ogr: check that detection of duplicated field names is case insensitive (#5208)" --> autotest only, since the fix itself existed in trunk since r26141

branches/1.10 r26349 "ogr2ogr: make detection of duplicated field names case insensitive (#5208)"

After those fixes, the output is now :

$ ogr2ogr -f kml /dev/stdout PG:dbname=autotest -sql "SELECT 'a' as name"
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>sql_statement</name>
  <Placemark>
	<name>a</name>
  </Placemark>
</Folder>
</Document></kml>

and

$ ogr2ogr -f kml /dev/stdout PG:dbname=autotest -sql "SELECT 'a' as name, 'b' as another_field"
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>sql_statement</name>
  <Placemark>
	<name>a</name>
	<ExtendedData><SchemaData schemaUrl="#sql_statement">
		<SimpleData name="another_field">b</SimpleData>
	</SchemaData></ExtendedData>
  </Placemark>
</Folder>
<Schema name="sql_statement" id="sql_statement">
	<SimpleField name="another_field" type="string"></SimpleField>
</Schema>
</Document></kml>

comment:3 Changed 4 years ago by strk

This still sounds bogus:

 ogr2ogr -f kml /dev/stdout PG: -sql "SELECT 'a' as name,  'b' as \"Name\""
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>sql_statement</name>
  <Placemark>
  </Placemark>
</Folder>
</Document></kml>

Needs another ticket ?

comment:4 Changed 4 years ago by strk

I've filed #5212 for the above problem

Note: See TracTickets for help on using tickets.