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

Allow importing KML with empty geometries. #510 #511

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

paul121
Copy link
Member

@paul121 paul121 commented Mar 15, 2022

A simple fix for the bug identified in #510

Attaching a screenshot that shows the result of parsing the following placemark:

<Placemark>
	<name>Placemark name</name>
      <MultiGeometry></MultiGeometry>
  </Placemark>

Screenshot from 2022-03-15 16-50-57

@paul121
Copy link
Member Author

paul121 commented Mar 16, 2022

Force push to add fix to README.md

@@ -119,6 +119,11 @@ public function denormalize($data, $type, $format = NULL, array $context = []) {
// Load KML into a Geometry object.
$geometry = $this->geoPHP->load($placemark['xml'], 'kml');

// Create an empty collection if no geometry was loaded.
if (empty($geometry)) {
$geometry = new \GeometryCollection();
Copy link
Member

@mstenta mstenta Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to add use GeometryCollection; to the top of the file and change this to:

$geometry = new GeometryCollection();

Same effect, but feels like it would be more consistent to add a use statement in this case, even though phayes/GeometryCollection doesn't use namespaces.

I wonder if there's any benefit to consistency in this regard, like IDE integration, code sniffing, etc...

Curious your thoughts on this (very minor) thought @paul121 - doesn't need to be a blocker for merging this, I don't think, but worth considering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, yeah I don't see any problem with that, as long as it works! Normally PHPStorm would add that automatically for me but it's possible I typed it in differently without using any type helpers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I can make that change and amend your commit.

Create an empty collection if no geometry was loaded.
@mstenta
Copy link
Member

mstenta commented Mar 21, 2022

Pushed that change - do you want to give it one more test @paul121? I didn't test it, but PHPStorm recognizes GeometryCollection, so I assume it works.

@paul121
Copy link
Member Author

paul121 commented Mar 22, 2022

Great, tested & works great!

@mstenta mstenta merged commit 3c5b2c7 into farmOS:2.x Mar 23, 2022
@paul121 paul121 deleted the 2.x-kml-empty-import branch March 23, 2022 21:32
@paul121
Copy link
Member Author

paul121 commented Mar 23, 2022

I wonder if it makes sense to add use GeometryCollection; to the top of the file and change this to:

Hey @mstenta this change actually created a code sniffer violation:

see this failing action

FILE: .../profiles/farm/modules/core/kml/src/Normalizer/KmlNormalizer.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | ERROR | [x] Non-namespaced classes/interfaces/traits should not
   |       |     be referenced with use statements
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 6.38 secs; Memory: 26MB

@mstenta
Copy link
Member

mstenta commented Mar 24, 2022

Of course it did. 🙄

Should have left well enough alone...

mstenta added a commit that referenced this pull request Mar 24, 2022
@mstenta
Copy link
Member

mstenta commented Mar 24, 2022

Pushed a commit that changes this back to the way you had it originally @paul121 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants