jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
908 stars 120 forks source link

Generate random geojson #59

Closed rowanwins closed 9 years ago

rowanwins commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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:

Let us know if you need any help

rowanwins commented 9 years ago

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 commented 9 years ago

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: https://github.com/frewsxcv/python-geojson/issues/59#issuecomment-116189975

rowanwins commented 9 years ago

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

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

Completed in #60