Example #1
0
        private void MergeFeatures(IFeature featureToMergeTo, IFeature feature)
        {
            if (featureToMergeTo.Attributes[FeatureAttributes.ID].Equals(feature.Attributes[FeatureAttributes.ID]))
            {
                return;
            }
            if (featureToMergeTo.Geometry is GeometryCollection geometryCollection)
            {
                if (feature.Geometry is GeometryCollection geometryCollectionSource)
                {
                    featureToMergeTo.Geometry = _geometryFactory.CreateGeometryCollection(geometryCollection.Geometries.Concat(geometryCollectionSource.Geometries).ToArray());
                }
                else
                {
                    featureToMergeTo.Geometry = _geometryFactory.CreateGeometryCollection(geometryCollection.Geometries.Concat(new[] { feature.Geometry }).ToArray());
                }
            }
            else
            {
                featureToMergeTo.Geometry = _geometryFactory.CreateGeometryCollection(new[] { featureToMergeTo.Geometry, feature.Geometry });
            }

            if (featureToMergeTo.Attributes[FeatureAttributes.POI_CATEGORY].Equals(Categories.NONE))
            {
                featureToMergeTo.Attributes[FeatureAttributes.POI_CATEGORY] =
                    feature.Attributes[FeatureAttributes.POI_CATEGORY];
            }

            if (double.Parse(featureToMergeTo.Attributes[FeatureAttributes.SEARCH_FACTOR].ToString()) <
                double.Parse(feature.Attributes[FeatureAttributes.SEARCH_FACTOR].ToString()))
            {
                featureToMergeTo.Attributes[FeatureAttributes.SEARCH_FACTOR] =
                    feature.Attributes[FeatureAttributes.SEARCH_FACTOR];
            }

            if (string.IsNullOrWhiteSpace(featureToMergeTo.Attributes[FeatureAttributes.ICON].ToString()))
            {
                featureToMergeTo.Attributes[FeatureAttributes.ICON] =
                    feature.Attributes[FeatureAttributes.ICON];
                featureToMergeTo.Attributes[FeatureAttributes.ICON_COLOR] =
                    feature.Attributes[FeatureAttributes.ICON_COLOR];
            }

            // adding names of merged feature
            featureToMergeTo.MergeTitles(feature);

            if (!featureToMergeTo.Attributes[FeatureAttributes.POI_SOURCE]
                .Equals(feature.Attributes[FeatureAttributes.POI_SOURCE]) ||
                !feature.Attributes[FeatureAttributes.POI_SOURCE].Equals(Sources.OSM))
            {
                // do not merge OSM elements to each other since they won't exists in the database for fetching
                featureToMergeTo.AddIdToCombinedPoi(feature);
            }
            featureToMergeTo.MergeCombinedPoiIds(feature);
        }