terraformer
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "terraformer", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Terraformer GIS Tools", | ||
@@ -5,0 +5,0 @@ "main": "terraformer.js", |
@@ -1,2 +0,2 @@ | ||
/*! Terraformer JS - 0.0.1 - 2013-02-02 | ||
/*! Terraformer JS - 0.0.1 - 2013-02-03 | ||
* https://github.com/geoloqi/Terraformer | ||
@@ -473,2 +473,23 @@ * Copyright (c) 2013 Environmental Systems Research Institute, Inc. | ||
function polygonContainsPoint(polygon, point) { | ||
if (polygon && polygon.length) { | ||
if (polygon.length === 1) { // polygon with no holes | ||
return coordinatesContainPoint(polygon[0], point); | ||
} else { // polygon with holes | ||
if (coordinatesContainPoint(polygon[0], point)) { | ||
for (var i = 1; i < polygon.length; i++) { | ||
if (coordinatesContainPoint(polygon[i], point)) { | ||
return false; // found in hole | ||
} | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
/* | ||
@@ -789,19 +810,3 @@ Internal: An array of variables that will be excluded form JSON objects. | ||
if (primitive.coordinates && primitive.coordinates.length) { | ||
if (this.coordinates && this.coordinates.length === 1) { // polygon with no holes | ||
return coordinatesContainPoint(this.coordinates[0], primitive.coordinates); | ||
} else { // polygon with holes | ||
if (coordinatesContainPoint(this.coordinates[0], primitive.coordinates)) { | ||
for (var i = 1; i < this.coordinates.length; i++) { | ||
if (coordinatesContainPoint(this.coordinates[i], primitive.coordinates)) { | ||
return false; // found in hole | ||
} | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
return polygonContainsPoint(this.coordinates, primitive.coordinates); | ||
}; | ||
@@ -845,3 +850,16 @@ | ||
}; | ||
MultiPolygon.prototype.contains = function(primitive) { | ||
if (primitive.type !== "Point") { | ||
throw new Error("Only points are supported"); | ||
} | ||
for (var i = 0; i < this.coordinates.length; i++) { | ||
if (polygonContainsPoint(this.coordinates[i], primitive.coordinates)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/* | ||
@@ -1067,2 +1085,3 @@ GeoJSON Feature Class | ||
exports.Tools.coordinatesContainPoint = coordinatesContainPoint; | ||
exports.Tools.polygonContainsPoint = polygonContainsPoint; | ||
exports.Tools.convexHull = convexHull; | ||
@@ -1069,0 +1088,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34063
927