Skip to content

Commit

Permalink
Fix multiPOlygon
Browse files Browse the repository at this point in the history
  • Loading branch information
BilelJegham committed May 15, 2020
1 parent cdc793e commit 2d3c7fa
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const booleanPointInPolygon = require('@turf/boolean-point-in-polygon').default;
*
*/
function randomPositionInPolygon(polygon) {
if(!polygon || !polygon.type || polygon.type !== 'Feature' || ['Polygon','MutliPolygon'].indexOf(polygon.geometry.type) === -1) {
if(!polygon || !polygon.type || polygon.type !== 'Feature' || ['Polygon','MultiPolygon'].indexOf(polygon.geometry.type) === -1) {
throw new Error('param polygon must be a Feature<(Polygon|MultiPolygon)>')
}
let position;
Expand Down
88 changes: 87 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,90 @@ test('Square', () => {
i++;
}

});
});

test('Square', () => {

const polygon = ` {
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-47.900390625,
-14.944784875088372
],
[
-51.591796875,
-19.91138351415555
],
[
-41.11083984375,
-21.309846141087192
],
[
-43.39599609375,
-15.390135715305204
],
[
-47.900390625,
-14.944784875088372
]
],
[
[
-46.6259765625,
-17.14079039331664
],
[
-47.548828125,
-16.804541076383455
],
[
-46.23046874999999,
-16.699340234594537
],
[
-45.3515625,
-19.31114335506464
],
[
-46.6259765625,
-17.14079039331664
]
],
[
[
-44.40673828125,
-18.375379094031825
],
[
-44.4287109375,
-20.097206227083888
],
[
-42.9345703125,
-18.979025953255267
],
[
-43.52783203125,
-17.602139123350838
],
[
-44.40673828125,
-18.375379094031825
]
]
]
]}
}`

const position = randomPositionInPolygon(JSON.parse(polygon))

expect(position).toBeDefined();


});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "random-position-in-polygon",
"version": "1.0.1",
"version": "1.0.2",
"description": "Return random position inside geoJson Polygon or MultiPolygon",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2d3c7fa

Please sign in to comment.