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

IO GeoJSON Support #14

Merged
merged 45 commits into from
Jan 24, 2019
Merged

IO GeoJSON Support #14

merged 45 commits into from
Jan 24, 2019

Conversation

michaelcurry
Copy link
Contributor

@michaelcurry michaelcurry commented Jan 19, 2019

IO GeoJSON Support

Adding the ability to Read & Write GeoJson as an IO option.

GeoJSON Geometry Type Read Write
FeatureCollection
Feature N/A
Point
MultiPoint
LineString
MultiLineString
Polygon
MultiPolygon

NOTE: Z-Axis is supported

Michael Curry added 2 commits January 19, 2019 12:28
NOTE: Polygon Tests are running, but cirrently failing due to that type not being implemented yet.
@michaelcurry
Copy link
Contributor Author

Linked to Issue #13

@michaelcurry michaelcurry mentioned this pull request Jan 19, 2019
…n throwing an unsupported GeoJSON Type Exception
@BenMorel
Copy link
Member

BenMorel commented Jan 19, 2019

Thanks for the PR! 👍 First remarks:

  • You don't need to split the reader into AbstractGeoJSONReader and GeoJSONReader; I've done this for WKT as there are 2 very close formats (WKT and EWKT) that share the same base code, but in the case of GeoJSON there is only one format so this should never be necessary.
  • I would not create a GeoJSONParser either; WKT requires a parser because we need to go through the document "word by word", but in the case of GeoJSON, it's valid JSON, that we can read directly inside the GeoJSONParser class.
  • I don't like the fact that GeoJSONParser decodes the JSON, then later creates a new instance of GeoJSONParser with a re-encoded JSON, this is not efficient; the document should be parsed once with json_decode(), and the Reader class should work on nested arrays taken from this document.
  • I've seen that you expect uppercase attributes, e.g. $geojson_array['TYPE']; I've seen lowercase examples myself, therefore I assume that keys are not case-sensitive; as such, we would need to strtolower() or strtoupper() everything before each comparison.

@michaelcurry michaelcurry changed the title IO GeoJSON Support -- Work In Progress IO GeoJSON Support Jan 21, 2019
@BenMorel
Copy link
Member

This looks very good so far! 👍 I will provide my comments inline (mostly nitpicks).

src/IO/AbstractGeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/AbstractGeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONWriter.php Outdated Show resolved Hide resolved
src/IO/GeoJSONWriter.php Outdated Show resolved Hide resolved
@BenMorel
Copy link
Member

Something that would be nice also, it to provide an explanation to each "Invalid GeoJSON" exception, as there is no clue where the error lies at the moment.

@michaelcurry
Copy link
Contributor Author

Something that would be nice also, it to provide an explanation to each "Invalid GeoJSON" exception, as there is no clue where the error lies at the moment.

Resolved in Commit: a3eda38

@michaelcurry
Copy link
Contributor Author

@BenMorel All Review Items have been resolved. Please take another look at the Pull Request and let me know if there is anything else 👍

Copy link
Member

@BenMorel BenMorel left a comment

Choose a reason for hiding this comment

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

This should be the final review, if you can do this quickly I should be able to merge & release tomorrow!

These are only small fixes, apart maybe from the $hasM to remove from tests.

src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
tests/IO/GeoJSONReaderTest.php Outdated Show resolved Hide resolved
tests/IO/GeoJSONReaderTest.php Outdated Show resolved Hide resolved
tests/IO/GeoJSONReaderTest.php Outdated Show resolved Hide resolved
src/IO/GeoJSONWriter.php Show resolved Hide resolved
src/IO/GeoJSONReader.php Outdated Show resolved Hide resolved
@michaelcurry
Copy link
Contributor Author

@BenMorel I believe I hit all change requests. Please let me know if I missed anything and I will get a Commit in for change ASAP.

@BenMorel
Copy link
Member

Looks all right to me! 👍

Final thoughts:

  • just to confirm, you finally decided to be strict on case sensitivity of values, e.g. not accept "POLYGON" instead of "Polygon"? Something I had in mind could be to allow the parser to be lenient on case sensitivity, by a constructor configuration: __construct(bool $lenient = false)
  • something useful to add to GeoJSONWriter::write() would be an optional bool $prettyPrint = false parameter, that would set the JSON_PRETTY_PRINT flag in json_encode(), to get a human readable output?

Note that these are not mandatory and can be added later, but I'd like to have your thoughts on this.

@michaelcurry
Copy link
Contributor Author

just to confirm, you finally decided to be strict on case sensitivity of values, e.g. not accept "POLYGON" instead of "Polygon"? Something I had in mind could be to allow the parser to be lenient on case sensitivity, by a constructor configuration: __construct(bool $lenient = false)

Looking other a few of the implementations of GeoJSON, they seem to be pretty standard in Case Sensitivity. That being said, I do think there should be a way for the user to "opt-in" to case insensitive mode.

something useful to add to GeoJSONWriter::write() would be an optional bool $prettyPrint = false parameter, that would set the JSON_PRETTY_PRINT flag in json_encode(), to get a human readable output?

I agree! I could see where that would be useful. Did not cross my mind too be honest.

If these are not mandatory for the initial tag/release, I would like to complete these in a separate Pull Request. If you are ok with that, I can make new Issues and you can assign them to me?

@BenMorel BenMorel merged commit b86790f into brick:master Jan 24, 2019
@BenMorel
Copy link
Member

Excellent work here, thank you! 👍

Let's do this, you can open pull requests to add the features above. No need to open issues, you can open pull requests only, they're redundant!

@BenMorel
Copy link
Member

Released as 0.2.2 🎉

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

Successfully merging this pull request may close these issues.

2 participants