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

Optionally recursive $geometry->getComponents #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gregseb
Copy link
Contributor

@gregseb gregseb commented May 20, 2013

Altered getComponents so that it behaves in the normal manner if no parameters are provided, but has the option of specifying a geometry type or an array of geometry types and then recursively break down the geometry until all components comprise of the types provided.

The use case this is intended for is primarily to break down a complex geometry collection into points, lines, and polygons with a single function call.

ie:
$geometry->getComponents(array('Point', 'LineString', 'Polygon'));

@gregseb
Copy link
Contributor Author

gregseb commented May 21, 2013

This needs some things fixed still. It seems odd to check if parameters are included on every function call including recursive calls, so the recursive portion of the function could be separated into a private function called if parameters are included. The base case should check if the current geometry is of one of the specified types rather than immediately breaking it down into sub components and looping. In case no valid geometry types are provided the Point type should be added to the types array regardless of intention to prevent possible accidental infinite recursion.

- Split recursive functionality into a private method.
- Changed structure of recusive calls to avoid calling getComponents on points.
@gregseb
Copy link
Contributor Author

gregseb commented May 22, 2013

The last commit should address issues I brought up in the last comment. I don't imagine this is an important feature, but since I have needed this behaviour a number of times and have always ended up writing a function to retrieve points lines and polygons from a geometry it seemed like something that has no reason not to be included in geoPHP to start with.

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.

None yet

1 participant