Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Detect if empty geometries
if (coordsIsNaN(buffered.coordinates)) return undefined;
// Unproject coordinates (convert to Degrees)
var result;
if (needsTransverseMercator) {
result = {
type: buffered.type,
coordinates: unprojectCoords(buffered.coordinates, defineProjection(geometry))
};
} else {
result = toWgs84(buffered);
}
return (result.geometry) ? result : feature(result, properties);
}
function lineIntersect<
G1 extends LineString|MultiLineString|Polygon|MultiPolygon,
G2 extends LineString|MultiLineString|Polygon|MultiPolygon
>(
line1: FeatureCollection | Feature | G1,
line2: FeatureCollection | Feature | G2,
): FeatureCollection {
const unique: any = {};
const results: any[] = [];
// First, normalize geometries to features
// Then, handle simple 2-vertex segments
if (line1.type === "LineString") { line1 = feature(line1); }
if (line2.type === "LineString") { line2 = feature(line2); }
if (line1.type === "Feature" &&
line2.type === "Feature" &&
line1.geometry !== null &&
line2.geometry !== null &&
line1.geometry.type === "LineString" &&
line2.geometry.type === "LineString" &&
line1.geometry.coordinates.length === 2 &&
line2.geometry.coordinates.length === 2) {
const intersect = intersects(line1, line2);
if (intersect) { results.push(intersect); }
return featureCollection(results);
}
// Handles complex GeoJSON Geometries
const tree = rbush();
function difference(polygon1, polygon2) {
var geom1 = getGeom(polygon1);
var geom2 = getGeom(polygon2);
var properties = polygon1.properties || {};
// Issue #721 - JSTS/Martinez can't handle empty polygons
geom1 = removeEmptyPolygon(geom1);
geom2 = removeEmptyPolygon(geom2);
if (!geom1) return null;
if (!geom2) return feature(geom1, properties);
var differenced = martinez.diff(geom1.coordinates, geom2.coordinates);
if (differenced.length === 0) return null;
if (differenced.length === 1) return polygon(differenced[0], properties);
else return multiPolygon(differenced, properties);
}
function lineIntersect<
G1 extends LineString|MultiLineString|Polygon|MultiPolygon,
G2 extends LineString|MultiLineString|Polygon|MultiPolygon
>(
line1: FeatureCollection | Feature | G1,
line2: FeatureCollection | Feature | G2,
): FeatureCollection {
const unique: any = {};
const results: any[] = [];
// First, normalize geometries to features
// Then, handle simple 2-vertex segments
if (line1.type === "LineString") { line1 = feature(line1); }
if (line2.type === "LineString") { line2 = feature(line2); }
if (line1.type === "Feature" &&
line2.type === "Feature" &&
line1.geometry !== null &&
line2.geometry !== null &&
line1.geometry.type === "LineString" &&
line2.geometry.type === "LineString" &&
line1.geometry.coordinates.length === 2 &&
line2.geometry.coordinates.length === 2) {
const intersect = intersects(line1, line2);
if (intersect) { results.push(intersect); }
return featureCollection(results);
}
// Handles complex GeoJSON Geometries
const tree = rbush();
tree.load(lineSegment(line2));
function createIntersectionGeometry(data:SharedStreetsIntersection) {
var point = turfHelpers.point([data.lon, data.lat]);
return turfHelpers.feature(point.geometry, {id: data.id});
}
break;
case 'MultiLineString':
geomType = 'LineString';
break;
case 'MultiPolygon':
geomType = 'Polygon';
break;
}
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {
type: geomType,
coordinates: coordinate
};
if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;
}
});
}
function createGeometry(data:SharedStreetsGeometry) {
var line = turfHelpers.lineString(lonlatsToCoords(data.lonlats));
return turfHelpers.feature(line.geometry, {id: data.id});
}