Beispiel #1
0
        /// <inheritdoc />
        public Dictionary <string, List <Feature> > Preprocess(Dictionary <string, List <ICompleteOsmGeo> > osmNamesDictionary)
        {
            _logger.LogInformation("Preprocessing OSM data to GeoJson, total distict names: " + osmNamesDictionary.Keys.Count);
            var geoJsonNamesDictionary = new Dictionary <string, List <Feature> >();

            foreach (var pair in osmNamesDictionary)
            {
                var osmList = MergeOsmElements(pair.Value)
                              .Select(e => _osmGeoJsonConverter.ToGeoJson(e))
                              .Where(f => f != null)
                              .ToList();
                if (osmList.Any())
                {
                    geoJsonNamesDictionary[pair.Key] = osmList;
                }
            }

            geoJsonNamesDictionary.Values.SelectMany(v => v).ToList().ForEach(g =>
            {
                var isValidOp = new NetTopologySuite.Operation.Valid.IsValidOp(g.Geometry);
                if (!isValidOp.IsValid)
                {
                    _logger.LogError($"{g.Geometry.GeometryType} with ID: {g.Attributes[FeatureAttributes.ID]} {isValidOp.ValidationError.Message} ({isValidOp.ValidationError.Coordinate.X},{isValidOp.ValidationError.Coordinate.Y})");
                }
            });

            _logger.LogInformation("Finished converting OSM data to GeoJson, Starting GeoJson preprocessing");
            var containers = geoJsonNamesDictionary.Values.SelectMany(v => v).Where(f =>
                                                                                    !(f.Geometry is MultiLineString) &&
                                                                                    !(f.Geometry is LineString) &&
                                                                                    !(f.Geometry is MultiPoint) &&
                                                                                    !(f.Geometry is Point)).ToList();

            _logger.LogInformation("Total possible containers: " + containers.Count);
            var counter = 0;

            foreach (var features in geoJsonNamesDictionary.Values)
            {
                PreprocessGeoJson(features, containers);
                counter++;
                if (counter % 5000 == 0)
                {
                    _logger.LogInformation($"Finished processing {counter} names of {geoJsonNamesDictionary.Values.Count}");
                }
            }
            _logger.LogInformation("Finished GeoJson preprocessing");
            return(geoJsonNamesDictionary);
        }
        /// <inheritdoc />
        public List <Feature> Preprocess(Dictionary <string, List <ICompleteOsmGeo> > osmNamesDictionary)
        {
            _logger.LogInformation("Preprocessing OSM data to GeoJson, total distinct names: " + osmNamesDictionary.Keys.Count);
            var geoJsonNamesDictionary = new Dictionary <string, List <Feature> >();

            foreach (var pair in osmNamesDictionary)
            {
                var features = MergeOsmElements(pair.Value)
                               .Select(e =>
                {
                    var feature = _osmGeoJsonConverter.ToGeoJson(e);
                    if (feature == null)
                    {
                        _logger.LogError("Unable to convert " + e.ToString());
                    }
                    return(feature);
                })
                               .Where(f => f != null)
                               .ToList();
                if (!features.Any())
                {
                    continue;
                }
                AddAttributes(features);
                geoJsonNamesDictionary[pair.Key] = features;
            }

            geoJsonNamesDictionary.Values.SelectMany(v => v).ToList().ForEach(g =>
            {
                var isValidOp = new IsValidOp(g.Geometry);
                if (!isValidOp.IsValid)
                {
                    _logger.LogError($"{g.Geometry.GeometryType} with ID: {g.Attributes[FeatureAttributes.ID]} {isValidOp.ValidationError.Message} ({isValidOp.ValidationError.Coordinate.X},{isValidOp.ValidationError.Coordinate.Y})");
                }
                if (g.Geometry.IsEmpty)
                {
                    _logger.LogError($"{g.Geometry.GeometryType} with ID: {g.Attributes[FeatureAttributes.ID]} is an empty geometry - check for non-closed relations.");
                }
            });
            _logger.LogInformation("Finished GeoJson conversion");
            var featuresToReturn = geoJsonNamesDictionary.SelectMany(v => v.Value).ToList();

            ChangeLwnHikingRoutesToNoneCategory(featuresToReturn);
            return(featuresToReturn);
        }