Closed armantorkzaban closed 2 years ago
Should I already give a review?
Should I already give a review?
Would be nice if you could review the lineToPolygon and its test.
Just fyi, my incomplete implementation attempt for lineToPolygon. It does not contain "closing" of the polygon (first==last coord), etc.
import 'package:turf/helpers.dart';
import 'package:turf/meta.dart';
Feature lineToPolygon(GeoJSONObject geom) {
if (geom is Feature) {
return _toPolygonFeature(geom);
} else if (geom is FeatureCollection) {
return _toPolygonFeatureCollection(geom);
} else {
return _toPolygonSimple(geom);
}
}
Feature _toPolygonFeatureCollection(FeatureCollection coll) {
var multiPolygon = MultiPolygon(
coordinates: [],
);
geomEach(
coll,
(
GeometryType? currentGeometry,
int? featureIndex,
Map<String, dynamic>? featureProperties,
BBox? featureBBox,
dynamic featureId,
) {
if (currentGeometry is LineString) {
multiPolygon.coordinates.add([currentGeometry.coordinates]);
} else if (currentGeometry is MultiLineString) {
multiPolygon.coordinates.add(currentGeometry.coordinates);
} else {
throw Exception('unsupported type');
}
},
);
return Feature(geometry: multiPolygon);
}
Feature _toPolygonFeature(Feature feature) {
return _toPolygonSimple(feature.geometry);
}
Feature _toPolygonSimple(
GeoJSONObject? geom, [
Map<String, dynamic>? properties,
dynamic id,
]) {
if (geom is LineString) {
return Feature(
id: id,
properties: properties,
geometry: Polygon(coordinates: [geom.coordinates]),
);
} else if (geom is MultiLineString) {
return Feature(
id: id,
properties: properties,
geometry: Polygon(coordinates: geom.coordinates),
);
} else {
throw Exception('unsupported type');
}
}
BTW, once review requested, please change the PR from draft to a normal PR. @armantorkzaban
Let's narrow this PR down to just lineToPolygon
and polygonToLine
. This way we can merge faster, without having to implement the rest of the conversion methods here
@arman What is the status on this one? Looks to me also like an easy to finish thing. Let's finish this asap, so we can reduce the number of tasks that we work on at the same time.
Implements parts of #101