poly 1.0.7+1 poly: ^1.0.7+1 copied to clipboard
A library for checking if given point(s) is present inside Polygon or not.
poly #
A library for checking if given point(s) is present inside Polygon or not.
Contents #
- Installation
- Examples
- Note: Instead of casting, use
toListNum()
&toListListNum()
- Function List
- Exceptions
- Detailed Index
Installation #
To install poly for your Dart project, simply add poly to your pub dependencies.
dependencies:
poly^ 1.0.5
Examples #
1. A very simple usage example #
- Creates 2 Polygons from
List<Point>
- Checks if 2
Polygon
have same vertices i.e.points
: usinghasSamePoint()
- Prints if given Points are inside Polygon
- Prints if all points in list are inside Polygon or not
- Prints list of result for List of points if they are inside Polygon or not
- Here
hasSamePoint()
,isPointInside(Point( ))
,contains(x,y)
,areAllPointsInsidePolygon_ListPoint()
&getList_IsListOfPointInside()
are used.
2. Example of Conversions List <=> Point
, List<Point> <=> List<List>
& other #
- Example of
toPoint()
&pointToList()
toPoint()
convertsList<num>
toPoint<num>
pointToList()
convertsPoint<num>
toList<num>
- Example of
toListOfPoint()
&pointsToList()
toListOfPoint()
convertsList<List<num>>
toList<Point<num>>
pointsToList()
convertsList<Point<num>>
toList<List<num>>
- Example of
toPolyFromListOfList()
&listOfList()
toPolyFromListOfList()
convertsList<List<num>>
toPolygon
listOfList()
returnsPolygon.points
asList<List<num>>
toPolyFromListOfList()
gives Polygon &backToListC2()
gives back List<List- Print status of List of List if they are inside our Polygon using
getList_IsListOfListInside
- Print if All points in List of List inside Polygon using
3. Examples of List<dynamic>
=> List<num>
and List<List<dynamic>>
=> List<List<num>>
#
toListNum()
returnsList<num>
from aList<dynamic>
toListListNum()
returnsList<List<num>>
from aList<List<dynamic>>
- Examples of
toListNum()
- without any optional parameters
- with
replaceWithZero: true
andsizeTwo: false
- with
sizeTwo: false
- Examples of
toListListNum()
- without any optional parameters
- with
swapXAndY: true
- with
replaceWithZero: true
- with
replaceWithZero: true
andswapXAndY: true
4. Simple CSV example #
- It contains examples of following functions -
-
Example of
IsInsideResultWithXY_ToCSVString
- Saving
ArePointsInside Results
to "IsInside.csv"- Headers row will be added, as
includeHeader
isnt passed as
false` - And as
diffNameThanIsInside:"Example String"
is passed, - Header row will be
latitude,longitude,Example String
- Headers row will be added, as
- Saving
-
Example of
toCSVString
- Saving
Polygon.points
to "Polygon.csv"- Headers row will be added, as
includeHeader
isnt passed as
false` - And as
useXY
is passed astrue
- Header row will be
x,y
- Headers row will be added, as
- Saving
-
Example of
csvToResult
- Display 1st row : 2nd element & 3rd element of "IsInside.csv"
- e.g. here "longitude" and "Example String"
- As, previously
xY_IsInside_ToCSVString
returned String with header - because optional parameter
header
was not set to false
- Display 1st row : 2nd element & 3rd element of "IsInside.csv"
-
Example of
csvToPoly
- Check if Point(18.507305, 73.806131) is inside Polygon readPolygon (Polygon from Polygon.csv)
5. Exception Handling Example #
- It contains examples of following exceptions & errors -
NeedsAtLeastThreePoints
is thrown ifPolygon.points
contains less than 3 pointsWrongSizeForPoint
is thrown iftoPoint()
has more or less than 2 element. Point has only x and y.TypeError
is thrown ifList<dynamic>
is passed instead ofList<num>
- Here, casting can be used to cast
List<dynamic>
toList<num>
- e.g.
print(toPoint([1,2]));
- Here, [1,2] has a type
List<dynamic>
- So, use
[1,2].cast<num>()
- Here, [1,2] has a type
- Here, casting can be used to cast
CastError example
- wrongly castingList<num>
toList<List<num>
6. Easy Casting Example #
- Without casting
List<dynamic>
toList<num>
TypeError
is thrown
-
Correct casting
- casting
List<dynamic>
toList<num>
- casting
List<dynamic>
toList<List<num>>
- casting
-
Passing
List
instead ofList<List>
- Passing
List
instead ofList<List>
& casting it : throwsCastError
as shown below :type
int
is not a subtype of typeList<num>
in type cast - Passing
List
instead ofList<List>
but, without casting it : throwsTypeError
as shown below :type
List<dynamic>
is not a subtype of typeList<List<num>>
- Note: currently casting
List<List<dynamic>>
toList<List<num>>
gives followingCastError
exception:- without
as List<List<num>>
-
type
List<dynamic>
is not a subtype of typeList<num>
in type cast- with
as List<List<num>>
-
type
List<List<dynamic>>
is not a subtype of typeList<List<num>>
in type cast - without
Note: Instead of casting, use toListNum()
& toListListNum()
#
- Use
toListNum()
forList<dynamic>
=>List<num>
- Use
toListListNum()
forList<List<dynamic>>
=>List<List<num>>
Function List #
Conversion Type #
List<num>
to Point(x,y)
: use toPoint()
- i.e.
[x,y]
->Point(x,y)
- Point can be created passing
List<num>
toPoint()
. - List must have exact 2 elements, else will throw
WrongSizeForPoint
exception
Point(x,y)
to List<num>
: use pointToList()
- i.e.
Point(x,y)
->[x,y]
- List can be created passing
Point(x,y)
pointToList()
.
List<List<num>>
to List<Point<num>>
: use toListOfPoint()
- i.e.
[ [x1,y1],[x2,y2],... ]
->[ Point(x1,y1), Point(x2,y2),... ]
- List of Points can be created from
List<List<num>>
by passing it totoListOfPoint()
List<Point<num>>
to List<List<num>>
: use pointsToList()
- i.e.
[ Point(x1,y1), Point(x2,y2),... ]
->[ [x1,y1],[x2,y2],... ]
- List can be created passing
List<Point<num>>
pointsToList()
.
List<List<num>>
to Polygon
: use toPolyFromListOfList()
- i.e.
[ [x1,y1],[x2,y2],... ]
->Polygon( Point(x1,y1), Point(x2,y2),... )
- Polygon can be returned from
List<List<num>>
by passing it totoPolyFromListOfList()
List<List<num>>
to Polygon
: use listOfList()
- i.e.
[ [x1,y1],[x2,y2],... ]
fromPolygon( Point(x1,y1), Point(x2,y2),... )
List<List<num>>
can be returned fromPolygon
by passing it tolistOfList()
List<dynamic>
to List<num>
: use toListNum()
- Returns
List<num>
from aList<dynamic>
- Can be used with [toPoly] as it accepts
List<num>
- Optional Parameters -
sizeTwo
- Default value
true
- When set
false
,Output List
can have more than 2 elements
- Default value
replaceWithZero
- Default value
false
- When set
true
, elements with typeString
orbool
will be replaced with 0, rather than being removed
- Default value
reverseIt
- Default value
false
- When set
true
,List
will be reversed
- Default value
List<List<dynamic>>
to List<List<num>>
: use toListListNum()
- Returns
List<List<num>>
from aList<List<dynamic>>
- Can be used with functions like [areAllPointsInsidePolygon_List] , [getList_IsListOfListInside] , [toPolyFromListOfList] , [toListOfPoint] which accepts
List<List<num>>
- Optional Parameters -
replaceWithZero
- Default value
false
- When set
true
, elements with typeString
orbool
will be replaced with 0, rather than being removed
- Default value
swapXAndY
- Default value
false
- When set
true
,xi
will be swapped withyi
- i.e.
[ [x1,y1], [x2,y2], ...]
->[ [y1,x1], [y2,x2], ...]
- i.e.
- Default value
is Point(s) inside #
Check if Single Point
is inside
Get Status by passing x
and y
to contains
- returns
true
if(x,y)
is present insidePolygon
Get Status by passing Point(x,y)
to isPointInside
- returns
true
ifPoint
is present insidePolygon
Check if Single Point
is inside Polygon with tolerance of T meter
Get Status by passing Point(x,y)
and Tolerance T
to isPointInside
Check if Multiple Points are inside given Polygon
Get Status of each Point
getList_IsListOfListInside(List<List<num>>)
returnsList<bool>
getList_IsListOfPointInside(List<Point<num>>)
returnsList<bool>
Check if all given Points are inside given Polygon
areAllPointsInsidePolygon_List((List<List<num>>)
returnstrue
orfalse
areAllPointsInsidePolygon_ListPoint(List<Point<num>>)
returnstrue
orfalse
Checks if 2 Polygon
have same vertices i.e. points
#
- use
hasSamePoints()
CSV #
Get result(s) along with lat, lang as a CSV String : IsInsideResultWithXY_ToCSVString()
- Returns result of
ArePointsInside
as CSV String which can be later saved or displayed - Output CSV String will by default contain a header row -
latitude,longitude,isInside
- Optional parameter:
bool useXY
- By passing, optional parameter:
useXY
as true, header will bex,y
instead oflatitude,longitude
- Default value of
useXY
isfalse
- By passing, optional parameter:
- Optional parameter:
String includeHeader
- if optional parameter -
includeHeader
is passed asfalse
, returning String will not contain header row
- if optional parameter -
- Optional Named parameter:
String diffNameThanIsInside
- Different name than Default name(
isInside
) will be used by passing optional parameter:diffNameThanIsInside
- Different name than Default name(
Get
Polygon as CSV String : toCSVString()
- Returns
Polygon
as CSV String which can be later saved or displayed - Output CSV String will by default contain a header row -
latitude,longitude
- Optional Named parameter:
bool useXY
- By passing, optional parameter:
useXY
as true, header will bex,y
instead oflatitude,longitude
- Default value of
useXY
isfalse
- By passing, optional parameter:
- Optional Named parameter:
String includeHeader
- if optional parameter -
includeHeader
is is passed asfalse
, returning String will not contain header row
- if optional parameter -
Get
Future
- Returns
Future<Polygon>
based oncsvString
csvString
may or may not contain header row- This function checks if
latitude,longitude
orx,y
are reversed- By checking Header row label
- i.e. By checking 1st row 1st element is neither "longitude" or "y"
- If they are reversed, Returned
Polygon
will bePolygon(latitude,longitude)
, instead ofPolygon(longitude,latitude)
- This can be manually set by passing optional parameter:
isReversed
astrue
- Optional parameter:
isReversed
isReversed
has default value =false
csvToListOfList()
- Returns
Future<List<List>>
based oncsvString
- which then can be used - convert that list into
Polygon
- which then can be used - convert that list into
- Optional parameter:
bool noHeader
- By passing optional parameter:
noHeader
astrue
, Resulting List will not contain header row - Default value
false
- By passing optional parameter:
Exceptions #
NeedsAtLeastThreePoints
is thrown ifPolygon.points
contains less than 3 pointsWrongSizeForPoint
is thrown iftoPoint()
has more or less than 2 element. Point has only x and y._TypeError
is thrown ifList<dynamic>
is passed instead ofList<num>
- Here, casting can be used to cast
List<dynamic>
toList<num>
- e.g.
print(toPoint([1,2]));
- Here, [1,2] has a type
List<dynamic>
- So, use
[1,2].cast<num>()
- Here, [1,2] has a type
- Here, casting can be used to cast
_CastError example
- castingList<num>
toList<List<num>
Index #
Features and bugs #
Please file feature requests and bugs at the issue tracker.
Licence #
Implemented contains
function logic from StageXL - A fast and universal 2D rendering engine for HTML5 and Dart
As, StageXL imports dart:html
, it can not be used in console application or in aqueduct back-end.
Also, function distanceInMeter
is implemented by using formulas for Algorithm & it's NOAA online calculator
Created from templates made available by Stagehand under a BSD-style license.