pombreda / libkml

Automatically exported from code.google.com/p/libkml
Other
0 stars 0 forks source link

Change the file data of KmlFilePtr #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I use KmlFile::CreateFromParse() to get a KmlFilePtr.Then I use  
kmlengine::GetElementsById() to store every ElementPtr into a vector.I 
handle  one of the ElementPtr(infect it`s a LineStringPtr ), just add a 
coordinates in it. But when I use KmlFilePtr to print the KML file, the 
data do not change at all.

The main statements are :
kml_file = KmlFile::CreateFromParse(m_KMLFileData, &errors);
kmlengine::GetElementsById(m_KMLRoot, kmldom::Type_LineString, 
&lineStringVec);
kmldom::LineStringPtr linePtr = kmldom::AsLineString(lineStringVec[pNo]);

//cause I don`t find a function to insert a vec3 in a coorPt, so i clear 
the coordinates of the linePtr. Then i creat one as i need  and add it to 
the linePtr
linePtr->clear_coordinates();
kmldom::KmlFactory *kml_factory = kmldom::KmlFactory::GetFactory();
kmldom::CoordinatesPtr coorPtr = kml_factory->CreateCoordinates();
//then do something to evaluate the coorPtr, such as coorPtr->add_vec3() 
and so on 

linePtr->set_coordinates(coorPtr);
m_KMLFileData.clear();
kml_file->SerializeToString(&m_KMLFileData);

Original issue reported on code.google.com by jiangx...@gmail.com on 15 May 2009 at 4:02

GoogleCodeExporter commented 9 years ago
libkml is actually functioning as intended in this case.  libkml contains logic
to verify that a given element be in the same XmlFile (KmlFile) as its parent.
generally KmlFile is written to be quite strict in the handling of the dom
associated with the file.  The matter boils down to this code:

http://code.google.com/p/libkml/source/browse/trunk/src/kml/base/xml_element.h#9
1

This is to prevent one element from winding up in two different KmlFiles.
One could argue for an enhancement to first import a given element into
the KmlFile and from there attach it to a parent within that file.

Your work is better handled at a pure dom level.  Use kmldom::Parse() instead
of kmlengine::KmlFile().  Then both the parsed dom and any elements created
are both in the same file: the NULL file.

Original comment by kml.b...@gmail.com on 20 May 2009 at 11:02