<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using Mapsui.Extensions;
using Mapsui.Geometries;
using Mapsui.GeometryLayer;
using Mapsui.Projection;

namespace Mapsui.Utilities
{
    public static class ProjectionHelper
    {
        public const string EpsgPrefix = "EPSG:";
        public const string EsriStringPrefix = "ESRISTRING:";
        public const string Proj4StringPrefix = "PROJ4STRING:";


        private static bool IsTransformationSupported(IGeometryTransformation geometryTransformation, string fromCRS, string toCRS)
        {
            return geometryTransformation.IsProjectionSupported(fromCRS, toCRS) == true;
        }

        public static BoundingBox? Transform(BoundingBox? extent,
            IGeometryTransformation geometryTransformation, string fromCRS, string toCRS)
        {
            if (extent == null) return null;

            if (!CrsHelper.IsTransformationNeeded(fromCRS, toCRS)) return extent;

            if (!CrsHelper.IsCrsProvided(fromCRS, toCRS))
                throw new NotSupportedException($"CRS is not provided. From CRS: {fromCRS}. To CRS {toCRS}");

            if (!IsTransformationSupported(geometryTransformation, fromCRS, toCRS))
                throw new NotSupportedException($"Transformation is not supported. From CRS: {fromCRS}. To CRS {toCRS}");

            var copiedExtent = extent.Copy();
            geometryTransformation.Transform(fromCRS, toCRS, copiedExtent);
            return copiedExtent;
        }

        public static IEnumerable<GeometryFeature>? Transform(IEnumerable<GeometryFeature>? features,
            IGeometryTransformation geometryTransformation, string fromCRS, string toCRS)
        {
            if (features == null) return null;

            if (!CrsHelper.IsTransformationNeeded(fromCRS, toCRS)) return features;

            if (!CrsHelper.IsCrsProvided(fromCRS, toCRS))
                throw new NotSupportedException($"CRS is not provided. From CRS: {fromCRS}. To CRS {toCRS}");

            if (!IsTransformationSupported(geometryTransformation, fromCRS, toCRS))
                throw new NotSupportedException($"Transformation is not supported. From CRS: {fromCRS}. To CRS {toCRS}");

            var copiedFeatures = features.Copy().ToList();
            foreach (var copiedFeature in copiedFeatures)
            {
                if (copiedFeature.Geometry == null) continue;
                var copiedGeometry = copiedFeature.Geometry.Copy();
                geometryTransformation.Transform(fromCRS, toCRS, copiedGeometry);
                copiedFeature.Geometry = copiedGeometry;
            }
            return copiedFeatures;
        }
    }
}<commit_msg>Simplify feature copy in ProjectionHelper<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using Mapsui.Extensions;
using Mapsui.Geometries;
using Mapsui.GeometryLayer;
using Mapsui.Projection;

namespace Mapsui.Utilities
{
    public static class ProjectionHelper
    {
        public const string EpsgPrefix = "EPSG:";
        public const string EsriStringPrefix = "ESRISTRING:";
        public const string Proj4StringPrefix = "PROJ4STRING:";


        private static bool IsTransformationSupported(IGeometryTransformation geometryTransformation, string fromCRS, string toCRS)
        {
            return geometryTransformation.IsProjectionSupported(fromCRS, toCRS) == true;
        }

        public static BoundingBox? Transform(BoundingBox? extent,
            IGeometryTransformation geometryTransformation, string fromCRS, string toCRS)
        {
            if (extent == null) return null;

            if (!CrsHelper.IsTransformationNeeded(fromCRS, toCRS)) return extent;

            if (!CrsHelper.IsCrsProvided(fromCRS, toCRS))
                throw new NotSupportedException($"CRS is not provided. From CRS: {fromCRS}. To CRS {toCRS}");

            if (!IsTransformationSupported(geometryTransformation, fromCRS, toCRS))
                throw new NotSupportedException($"Transformation is not supported. From CRS: {fromCRS}. To CRS {toCRS}");

            var copiedExtent = extent.Copy();
            geometryTransformation.Transform(fromCRS, toCRS, copiedExtent);
            return copiedExtent;
        }

        public static IEnumerable<GeometryFeature>? Transform(IEnumerable<GeometryFeature>? features,
            IGeometryTransformation geometryTransformation, string fromCRS, string toCRS)
        {
            if (features == null) return null;

            if (!CrsHelper.IsTransformationNeeded(fromCRS, toCRS)) return features;

            if (!CrsHelper.IsCrsProvided(fromCRS, toCRS))
                throw new NotSupportedException($"CRS is not provided. From CRS: {fromCRS}. To CRS {toCRS}");

            if (!IsTransformationSupported(geometryTransformation, fromCRS, toCRS))
                throw new NotSupportedException($"Transformation is not supported. From CRS: {fromCRS}. To CRS {toCRS}");

            var copiedFeatures = features.Copy().ToList();
            foreach (var copiedFeature in copiedFeatures)
            {
                geometryTransformation.Transform(fromCRS, toCRS, copiedFeature.Geometry);
            }
            return copiedFeatures;
        }
    }
}
{'fraction_non_alphanumeric': 0.08243114909781576, 'fraction_numerical': 0.0007597340930674264, 'mean_word_length': 2.8607038123167157, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5984867', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1381, 'n_words': 359}