Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parses possible element attributes #3

merged 1 commit into from Jul 21, 2014


Copy link

amenadiel commented Jul 21, 2014

Since KML files can contain not only Placemark geometries but also custom attributes for each placemark, I added a parser to store those properties in an $attributes public class property

Case of use:

alabama.kml file

          <Data name='abernant'>
          <Data name='alabama'>
          <Data name='geoscore'>
            <displayName><![CDATA[Geocode Score]]></displayName>
          <Data name='geoprecision'>
            <displayName><![CDATA[Geocode Precision]]></displayName>
$decoder = new Symm\Gisconverter\Decoders\KML();
$placemark= $decoder->geomFromText( $kmltext );

# array (size=4)
#   'abernant' => string 'ALLGOOD' (length=7)
#   'alabama' => string 'Alabama' (length=7)
#   'Geocode Score' => string '0.889' (length=5)
#   'Geocode Precision' => string 'zip' (length=3)

var_dump($placemark->toWKT() );
# string 'POINT(-86.508321 33.92621)' (length=26)

The parser tries to cover every possible case, since placemark attributes can come in the form of children nodes, or children nodes of the ExtendedData node. The attribute name can come from several sources as well. In my case, I was parsing the kml already and it was sub optimal to do that twice for each placemark.

Parses possible element attributes
@symm symm merged commit 1e4b937 into symm:master Jul 21, 2014
2 checks passed
2 checks passed
ci/scrutinizer Scrutinizer: 21 new issues, 10 updated code elements — Tests: passed
continuous-integration/travis-ci The Travis CI build passed

This comment has been minimized.

Copy link

symm commented Jul 21, 2014

@amenadiel Thank you, I've added a test and updated this to set the attributes as a private property on the Geometry base class instead of public and added a Getter for it so it's now:

$decoder = new Symm\Gisconverter\Decoders\KML();
$placemark= $decoder->geomFromText( $kmltext );
$placemark ->getAttributes()

Merged and tagged, so should be available in v1.0.3.


This comment has been minimized.

Copy link

amenadiel commented Jul 21, 2014

This made my day 👍 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.