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

Generate random geojson #59

Closed
rowanwins opened this issue Jun 27, 2015 · 8 comments
Closed

Generate random geojson #59

rowanwins opened this issue Jun 27, 2015 · 8 comments

Comments

@rowanwins
Copy link
Contributor

Hey everyone,

Thanks for a great python library. Just wondering if you'd be interested in extending it to support generating random features? eg create me a linestring.

>>> from geojson import LineString

>>> Random_LineString() 
{"coordinates": [[8.91..., 44.407...], [8.92..., 44.407...]], "type": "LineString"}

I'd be happy to attempt to make a start even though I dont entriely know what Im getting myself in for!

Cheers,
Rowan

@groteworld
Copy link
Contributor

I'm not against the idea. Though I think it should look like:

>>> from geojson import LineString
>>> from geojson.utils import generate_example  # not in love with this function name

>>> my_linestring = generate_example(LineString)  # or the string 'LineString' maybe
{"coordinates": [[8.91..., 44.407...], [8.92..., 44.407...]], "type": "LineString"}

@frewsxcv
Copy link
Collaborator

Just wondering if you'd be interested in extending it to support generating random features?

Sounds good to me! I think it would be good to use @grotewold's suggestions:

  • Make it a single function that takes an argument specifying which GeoJSON object type
  • Put it in geojson.utils

Let us know if you need any help

@rowanwins
Copy link
Contributor Author

Gday @grotewold & @frewsxcv

Thanks for the advice, certainly happy for it to sit within geojson.utils . If all goes well I might have a few extra arguments around things like number of vertices, number of features etc.

Anyway I'll keep you posted, Im no python guru so this is a fun little project to test my skills and contribute something useful at the same time.

Cheers
Rowan

@groteworld
Copy link
Contributor

Excited! Good luck and welcome!

On Sat, Jun 27, 2015 at 11:52 PM, Rowan Winsemius
notifications@github.com wrote:

Gday @grotewold & @frewsxcv
Thanks for the advice, certainly happy for it to sit within geojson.utils . If all goes well I might have a few extra arguments around things like number of vertices, number of features etc.
Anyway I'll keep you posted, Im no python guru so this is a fun little project to test my skills and contribute something useful at the same time.
Cheers

Rowan

Reply to this email directly or view it on GitHub:
#59 (comment)

@rowanwins
Copy link
Contributor Author

Well @grotewold and @frewsxcv I think I'm making some good progress. I've got my function setup which accepts the following params so far

  • featureType
  • numberFeatures
  • numberVertices

Mostly fairly self-explanatory, ask for a point get a point, if you ask for 20 points then you get a geometry collection of points, or you can ask for a line with 10 vertices.

The trickiest thing Im running into is generating meaningful polygons that aren't whacky and full of topological errors. There is a library with some python bindings so I might see if I can find anything interesting in it that could help.

Another setting I'd like to explore is setting a bounding box to contain the features or the vertices, eg give me a line with 10 vertices all within this extent that I've set.

Anyway I'll create a fork for you guys to check out hopefully in the next few days, if you have any other ideas let me know.

Cheers
Rowan

@rowanwins
Copy link
Contributor Author

Hi @grotewold & @frewsxcv ,

Well I've had some success and so have forked your repo and made a branch for you to look at.

For example

from geojson import utils
blah = utils.generate_random(featureType = 'Point', numberFeatures = 3, boundingBox = [-50, -50, 50,50])

>>>{"geometries": [{"coordinates": [-30, 16], "type": "Point"}, {"coordinates": [-6, -2], "type": "Point"}, {"coordinates": [48, 19], "type": "Point"}], "type": "GeometryCollection"}

It's perhaps not entirely optimised for those multi-feature collections yet but its at least returning valid geojson.

My biggest issue is around the polygon creation, its kind of working by not quite. My theory is that if I can sort all my lats and all my lons in order and then the poly should be fine, however my sorting skills are going that well, Im just kind of guessing at what I should be doing and its not sorting properly.

Anyway it's certainly shaping up it seems, would love any feedback as Im a python newb :)

Cheers
Rowan

@frewsxcv
Copy link
Collaborator

Awesome! I'll check this out later today after work. It might be helpful to open a pull request so we can comment on it directly. If you need help with that let us know. Thanks again!

@frewsxcv
Copy link
Collaborator

Completed in #60

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

No branches or pull requests

3 participants