-
Notifications
You must be signed in to change notification settings - Fork 942
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
Revamp grid modules #1029
Revamp grid modules #1029
Conversation
@DenisCarriere I noticed all the grid have projection distortion because of the way the grid elements are created: Should we modify that and have Mercator-projected grids or we consider these correct outputs? |
👍 Yes I think we should make it Mercator friendly since 98% of users will be using a Leaflet type map to display their geojson. |
🤔 ... @stebogit might be best to use a new branch.. lots of conflicts and might be just easier to start a new PR based on the master branch. I think these conflicts are caused from the |
@DenisCarriere I'm not sure what's the correct type definition for |
@stebogit Sorry been busy the past days, I'm in Boulder at SOTM now. The difference between
{
type: "Polygon",
coordinates: Array<number>
}
You can always look at the
import {Polygon, Feature} from '@turf/helpers' |
packages/turf-point-grid/types.ts
Outdated
import pointGrid from './'; | ||
|
||
const cellSide = 50; | ||
const bbox: BBox = [-95, 30, -85, 40]; | ||
const poly: Polygon = polygon([[[20, 30], [10, 10], [20, 20], [20, 30]]]); |
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.
@stebogit This is my bad... Polygon
was short for Feature<Polygon>
, however now Polygon
from @turf/helpers
is now equivalent to Geometry<Polygon>
.
The reason for the error is because mask
doesn't handle adding Geometry<Polygon>
(which should be a valid input, both Geometry & Feature).
packages/turf-point-grid/index.d.ts
Outdated
cellSide: number, | ||
options?: { | ||
units?: Units, | ||
properties?: Properties, | ||
bboxIsMask?: boolean; | ||
mask?: Polygon|MultiPolygon; |
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.
The correct definition would be:
To support both
Geometry<Polygon|MultiPolygon>
&Feature<Polygon|MultiPolygon>
export default function pointGrid(
bbox: BBox,
cellSide: number,
options?: {
units?: Units,
properties?: Properties,
mask?: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon;
}
): FeatureCollection<Point>;
packages/turf-point-grid/index.js
Outdated
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.units="kilometers"] used in calculating cellSide, can be degrees, radians, miles, or kilometers | ||
* @param {number} [options.bboxIsMask=false] if true, and bbox is a Polygon or MultiPolygon, the grid Point will be created | ||
* @param {Feature<Polygon|MultiPolygon>} [options.mask=undefined] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it |
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.
No need to define the option as undefined
, [options.mask]
is perfectly fine.
packages/turf-point-grid/index.js
Outdated
var cellWidth = xFraction * (east - west); | ||
var yFraction = cellSide / (distance(point([west, south]), point([west, north]), options)); | ||
var cellHeight = yFraction * (north - south); | ||
var xFraction = cellSide / (distance(point([west, south]), point([east, south]), units)); |
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.
Distance no longer requires the input data to be Point, it can be an Array of numbers.
distance([west, south], [east, south], options)
Also, all modules have changed to the options
param syntax, even the ones with 1 param.
packages/turf-point-grid/index.js
Outdated
var properties = options.properties || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var units = options.units; | ||
var maskIsPoly = options.mask && (getType(options.mask) === 'Polygon' || getType(options.mask) === 'MultiPolygon'); |
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.
I wouldn't use a maskIsPoly
approach, instead add some type validation for the input and call it mask
.
packages/turf-point-grid/index.js
Outdated
if (inside(pt, bboxMask)) { | ||
var pt = point([currentX, currentY], properties); | ||
if (maskIsPoly) { | ||
if (inside(pt, options.mask)) { |
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.
For all optional parameters, you should use the param name mask
instead of options.mask
.
Thanks @DenisCarriere! I'll work on Mercator friendly outputs 👍
How's it goin'? |
|
👍 Nice! |
|
@stebogit Woot 🎉 First passing commit. Next thing to implement is the Mercator outputs and then I think we are ready to merge this PR. |
@stebogit Going to merge this PR, we can do the mercator part on a different PR. |
Ref #1019
@turf/square-grid
completelyWithin
parametercellDiameter
tocellSide
in all grid modules (Question: what does 'cellSize' geometrically measure in the resulting hex_grid #460)@turf/square-grid
and@turf/hex-grid
properties
parameter (passed to the output) to@turf/square-grid
and@turf/hex-grid
@turf/hex-grid
@turf/point-grid
(isobands documentation clarity #1021 (comment))New⚠️
Array<number>
.options.mask
=>mask
options.mask
should have (Multi)Polygon geometry type validation.@turf/truncate
to output test results to prevent any precision decimal errors.New - Improvements⚠️
options.properties
)options.mask
)@turf/boolean-within
or@turf/intersect
foroptions.mask
Update fixtures for
@turf/interpolate
@turf/transform-scale