phayes/geoPHP

Parsing additional information from KML

NickStallman opened this issue · 2 comments

I'm unsure if this would be classified as out of scope for this project or not, however it could be useful to myself and likely others to extract additional details from KML file (and other formats).

For example I'm extracting a set of polygons, however the source file also has a 'name' tag which would be useful to my purposes.

The geometry class could simply have an attributes array added to it, and in KML.class.php: geomFromXML() it just needs to append any non-supported XML nodes to the attributes array if they can be parsed as text.
The library shouldn't make any assumption of what the fields actually are since they could differ from user to user.

@NickStallman - I just now implemented geoPHP + kml + name/description.

While it would be nice for geoPHP to support KML attributes "out of the box" - the way kml is setup - it allows for meta data to exist on BOTH placemarks and "folders". Therefore geoPHP wouldn't be really able to expose all the meta data (at least not directly on the geometry objects). In which case, I would prefer to keep the two separate.

However, I did see a recent PR that included additional attributes from the KML parser. I would take a look around the recent PRs if I were you.

--

Here is how I implemented meta data on KML import:

  • Load kml file as a simplexml_load_string()
  • Loop through each folder; loop through each placemark
  • Extract meta data
  • Use geoPHP to import the geometry. You don't have to pass in a full xml file into geoPHP for it parse your kml! Passing just the polygon/point/geometry: $xmlPlacemark->asXml() works!

@gsolak do you mean this PR?
#141

I did end up writing the code to handle attributes, looks like at least one other person found it useful.

It's still not in the core so this issue is still relevant.