-
Notifications
You must be signed in to change notification settings - Fork 32
Coords opts #7
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
Coords opts #7
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from numpy import asarray, array, ndarray, vstack, newaxis, nonzero, concatenate, transpose, atleast_2d, size, isscalar | ||
|
||
from numpy import asarray, array, ndarray, vstack, newaxis, nonzero, concatenate, transpose, atleast_2d, size, isscalar, meshgrid, where | ||
from matplotlib.path import Path | ||
|
||
def add_property(d, prop, name): | ||
|
||
|
@@ -206,4 +206,27 @@ def list_to_regions(reg): | |
checkthree = all(map(lambda x: len(x) == 3, reg)) | ||
if not (checktwo or checkthree): | ||
raise Exception("All region names must be two letters (for US) or three letters (for world)") | ||
return reg | ||
return reg | ||
|
||
def get_points_from_polygon(coords): | ||
""" | ||
Given a list of pairs of points which define a polygon, return a list of points interior to the polygon | ||
""" | ||
|
||
bounds = array(coords).astype('int') | ||
|
||
bMax = bounds.max(0) | ||
bMin = bounds.min(0) | ||
|
||
path = Path(bounds) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break |
||
grid = meshgrid(range(bMin[0],bMax[0]+1),range(bMin[1],bMax[1]+1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and elsewhere put spaces after commas within function argument lists |
||
|
||
gridFlat = zip(grid[0].ravel(),grid[1].ravel()) | ||
|
||
inside = path.contains_points(gridFlat).reshape(grid[0].shape).astype('int') | ||
inside = where(inside) | ||
inside = vstack([inside[0],inside[1]]).T + bMin[-1::-1] | ||
inside.tolist() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return inside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace
array
withasarray