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
merged 1 commit into from Jul 21, 2014

Conversation

@amenadiel
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

<Placemark>
      <ExtendedData>
          <Data name='abernant'>
            <displayName><![CDATA[abernant]]></displayName>
            <value><![CDATA[ALLGOOD]]></value>
          </Data>
          <Data name='alabama'>
            <displayName><![CDATA[alabama]]></displayName>
            <value><![CDATA[Alabama]]></value>
          </Data>
          <Data name='geoscore'>
            <displayName><![CDATA[Geocode Score]]></displayName>
            <value><![CDATA[0.889]]></value>
          </Data>
          <Data name='geoprecision'>
            <displayName><![CDATA[Geocode Precision]]></displayName>
            <value><![CDATA[zip]]></value>
          </Data>
      </ExtendedData>
      <Point>
        <coordinates>-86.508321,33.92621</coordinates>
      </Point>
</Placemark>
$decoder = new Symm\Gisconverter\Decoders\KML();
$kmltext=file_get_contents('alabama.kml');
$placemark= $decoder->geomFromText( $kmltext );

var_dump($placemark->attributes);
# 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
Details
continuous-integration/travis-ci The Travis CI build passed
Details
@symm

This comment has been minimized.

Copy link
Owner

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();
$kmltext=file_get_contents('alabama.kml');
$placemark= $decoder->geomFromText( $kmltext );
$placemark ->getAttributes()

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

@amenadiel

This comment has been minimized.

Copy link
Author

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
Projects
None yet
2 participants
You can’t perform that action at this time.