mirror of
https://github.com/Turfjs/turf.git
synced 2026-02-01 16:57:21 +00:00
refactored with @turf/projection
This commit is contained in:
parent
6aa812f358
commit
adee2d93de
@ -3,6 +3,10 @@ var jsts = require('jsts');
|
||||
var meta = require('@turf/meta');
|
||||
var center = require('@turf/center');
|
||||
var helpers = require('@turf/helpers');
|
||||
// var projection = require('@turf/projection');
|
||||
var projection = require('./../turf-projection');
|
||||
var toMercator = projection.toMercator;
|
||||
var toWgs84 = projection.toWgs84;
|
||||
var feature = helpers.feature;
|
||||
var geomEach = meta.geomEach;
|
||||
var featureEach = meta.featureEach;
|
||||
@ -95,25 +99,39 @@ function buffer(geojson, radius, units, steps) {
|
||||
|
||||
// Project GeoJSON to Transverse Mercator projection (convert to Meters)
|
||||
var distance = radiansToDistance(distanceToRadians(radius, units), 'meters');
|
||||
var projection = defineProjection(geojson);
|
||||
var projected = {
|
||||
type: geometry.type,
|
||||
coordinates: projectCoords(geometry.coordinates, projection)
|
||||
};
|
||||
// var projection = defineProjection(geojson);
|
||||
// var projected = {
|
||||
// type: geometry.type,
|
||||
// coordinates: projectCoords(geometry.coordinates, projection)
|
||||
// };
|
||||
|
||||
var mercator = toMercator(geojson);
|
||||
// JSTS buffer operation
|
||||
var reader1 = new jsts.io.GeoJSONReader();
|
||||
var geom1 = reader1.read(mercator.geometry || mercator);
|
||||
var buffered1 = geom1.buffer(distance);
|
||||
var writer1 = new jsts.io.GeoJSONWriter();
|
||||
buffered1 = writer1.write(buffered1);
|
||||
|
||||
|
||||
// JSTS buffer operation
|
||||
var reader = new jsts.io.GeoJSONReader();
|
||||
var geom = reader.read(projected);
|
||||
var buffered = geom.buffer(distance);
|
||||
var writer = new jsts.io.GeoJSONWriter();
|
||||
buffered = writer.write(buffered);
|
||||
// var reader = new jsts.io.GeoJSONReader();
|
||||
// var geom = reader.read(projected);
|
||||
// var buffered = geom.buffer(distance);
|
||||
// var writer = new jsts.io.GeoJSONWriter();
|
||||
// buffered = writer.write(buffered);
|
||||
|
||||
// Detect if empty geometries
|
||||
if (coordsIsNaN(buffered.coordinates)) return undefined;
|
||||
// if (coordsIsNaN(buffered.coordinates)) return undefined;
|
||||
if (coordsIsNaN(buffered1.coordinates)) return undefined;
|
||||
|
||||
// Unproject coordinates (convert to Degrees)
|
||||
buffered.coordinates = unprojectCoords(buffered.coordinates, projection);
|
||||
return feature(buffered, properties);
|
||||
// buffered.coordinates = unprojectCoords(buffered.coordinates, projection);
|
||||
|
||||
var result = toWgs84(buffered1);
|
||||
// result.properties = properties;
|
||||
return (result.geometry) ? result : feature(result, properties);
|
||||
// return feature(buffered, properties);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -45,6 +45,7 @@
|
||||
"dependencies": {
|
||||
"@turf/center": "^4.6.1",
|
||||
"@turf/helpers": "^4.6.0",
|
||||
"@turf/projection": "^4.6.0",
|
||||
"@turf/meta": "^4.6.0",
|
||||
"d3-geo": "^1.6.3",
|
||||
"jsts": "1.3.0"
|
||||
|
||||
273
packages/turf-buffer/test/in/issue-#900.geojson
Normal file
273
packages/turf-buffer/test/in/issue-#900.geojson
Normal file
@ -0,0 +1,273 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-86.85,
|
||||
21.025
|
||||
],
|
||||
[
|
||||
-86.53333,
|
||||
22.39167
|
||||
],
|
||||
[
|
||||
-86.45,
|
||||
22.765
|
||||
],
|
||||
[
|
||||
-86.35,
|
||||
23.21
|
||||
],
|
||||
[
|
||||
-86.15,
|
||||
24.04
|
||||
],
|
||||
[
|
||||
-85.33333,
|
||||
25.34167
|
||||
],
|
||||
[
|
||||
-85.26667,
|
||||
26.03
|
||||
],
|
||||
[
|
||||
-85.23333,
|
||||
26.38333
|
||||
],
|
||||
[
|
||||
-85.18333,
|
||||
26.5
|
||||
],
|
||||
[
|
||||
-84.78333,
|
||||
27.49333
|
||||
],
|
||||
[
|
||||
-83.41667,
|
||||
28
|
||||
],
|
||||
[
|
||||
-83.21667,
|
||||
28.175
|
||||
],
|
||||
[
|
||||
-82.63333,
|
||||
28.69
|
||||
],
|
||||
[
|
||||
-82.6,
|
||||
29.43
|
||||
],
|
||||
[
|
||||
-82.55,
|
||||
30.505
|
||||
],
|
||||
[
|
||||
-81.18333,
|
||||
32.14667
|
||||
],
|
||||
[
|
||||
-79.65,
|
||||
34.23333
|
||||
],
|
||||
[
|
||||
-79.48333,
|
||||
34.54333
|
||||
],
|
||||
[
|
||||
-78.93333,
|
||||
35.56667
|
||||
],
|
||||
[
|
||||
-78.78333,
|
||||
35.87333
|
||||
],
|
||||
[
|
||||
-78.53333,
|
||||
36.15833
|
||||
],
|
||||
[
|
||||
-78.16667,
|
||||
36.565
|
||||
],
|
||||
[
|
||||
-77.9,
|
||||
36.86167
|
||||
],
|
||||
[
|
||||
-77.31667,
|
||||
37.50167
|
||||
],
|
||||
[
|
||||
-76.83333,
|
||||
37.97
|
||||
],
|
||||
[
|
||||
-76.65,
|
||||
38.1
|
||||
],
|
||||
[
|
||||
-76.4,
|
||||
38.28833
|
||||
],
|
||||
[
|
||||
-76.01667,
|
||||
38.695
|
||||
],
|
||||
[
|
||||
-75.91667,
|
||||
38.80333
|
||||
],
|
||||
[
|
||||
-75.78333,
|
||||
38.94333
|
||||
],
|
||||
[
|
||||
-75.66667,
|
||||
39.06167
|
||||
],
|
||||
[
|
||||
-75.6,
|
||||
39.13833
|
||||
],
|
||||
[
|
||||
-75.51667,
|
||||
39.23167
|
||||
],
|
||||
[
|
||||
-74.41667,
|
||||
39.81667
|
||||
],
|
||||
[
|
||||
-73.7,
|
||||
40.205
|
||||
],
|
||||
[
|
||||
-72.31667,
|
||||
40.91833
|
||||
],
|
||||
[
|
||||
-71.56667,
|
||||
41.16667
|
||||
],
|
||||
[
|
||||
-70.01667,
|
||||
41.28167
|
||||
],
|
||||
[
|
||||
-67,
|
||||
42.63333
|
||||
],
|
||||
[
|
||||
-56.46667,
|
||||
45.60333
|
||||
],
|
||||
[
|
||||
-52,
|
||||
46.5
|
||||
],
|
||||
[
|
||||
-50.45,
|
||||
46.89
|
||||
],
|
||||
[
|
||||
-50,
|
||||
47
|
||||
],
|
||||
[
|
||||
-42.86667,
|
||||
47.805
|
||||
],
|
||||
[
|
||||
-40,
|
||||
48
|
||||
],
|
||||
[
|
||||
-38.03333,
|
||||
48.48
|
||||
],
|
||||
[
|
||||
-30,
|
||||
50
|
||||
],
|
||||
[
|
||||
-27.85,
|
||||
50.29
|
||||
],
|
||||
[
|
||||
-20,
|
||||
51
|
||||
],
|
||||
[
|
||||
-19.33333,
|
||||
51.01167
|
||||
],
|
||||
[
|
||||
-15,
|
||||
51
|
||||
],
|
||||
[
|
||||
-14,
|
||||
51
|
||||
],
|
||||
[
|
||||
-8.5,
|
||||
51
|
||||
],
|
||||
[
|
||||
-8.25,
|
||||
51
|
||||
],
|
||||
[
|
||||
-8,
|
||||
51
|
||||
],
|
||||
[
|
||||
-5.88333,
|
||||
50.935
|
||||
],
|
||||
[
|
||||
-3.98333,
|
||||
50.84333
|
||||
],
|
||||
[
|
||||
-2.65,
|
||||
50.76
|
||||
],
|
||||
[
|
||||
-2.51667,
|
||||
50.75
|
||||
],
|
||||
[
|
||||
-2.11667,
|
||||
50.675
|
||||
],
|
||||
[
|
||||
-1.6,
|
||||
50.575
|
||||
],
|
||||
[
|
||||
-0.93333,
|
||||
50.82
|
||||
],
|
||||
[
|
||||
-0.75,
|
||||
50.855
|
||||
],
|
||||
[
|
||||
-0.08333,
|
||||
50.88667
|
||||
],
|
||||
[
|
||||
-0.18333,
|
||||
50.985
|
||||
],
|
||||
[
|
||||
-0.18333,
|
||||
51.14833
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
1247
packages/turf-buffer/test/out/issue-#900.geojson
Normal file
1247
packages/turf-buffer/test/out/issue-#900.geojson
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user