Exemple #1
0
        public List <Feature> Render(List <Node> nodes)
        {
            var features = new List <Feature>();

            foreach (var node in nodes)
            {
                // Probably doesn't need to be rendered
                if (node.Parent != null &&
                    !node.IsReferencedByARelation &&
                    !node.HasInterestingTags)
                {
                    continue;
                }
                if (!node.Lat.HasValue || !node.Lon.HasValue)
                {
                    continue;
                }
                if (node.IsBounds || node.IsAGeometryNode)
                {
                    continue;
                }
                var point   = new Point(new GeographicPosition(node.Lat.Value, node.Lon.Value));
                var feature = new Feature(point, _featurePropertyBuilder.GetProperties(node), string.Format("{0}/{1}", node.Type, node.Id));
                if (node.IsCentrePlaceHolder)
                {
                    feature.Properties["geometry"] = "center";
                }
                features.Add(feature);
            }
            return(features);
        }
        public List <Feature> Render(List <Way> ways)
        {
            var features = new List <Feature>();

            foreach (var way in ways.OrderBy(x => x.Id))
            {
                if ((way.Nodes == null || way.Nodes.Count == 0) ||
                    (way.IsAnInnerWithoutAnOuter && !way.HasInterestingTags) ||
                    ((way.HasParent && ((Relation)way.Parent).HasBeenRendered) &&
                     ((way.HasParent && ((Relation)way.Parent).IsSimpleMultiPolygon) ||
                      (way.HasParent && way.IsGeometryIncomplete) ||
                      (way.IsMultipolygonOutline && !way.HasInterestingTags) ||
                      (way.HasParent && !way.HasInterestingTags))))
                {
                    continue;
                }
                //way.IsGeometryIncomplete = false;

                var coordinates = new List <Coordinates>();
                foreach (var nodeId in way.Nodes)
                {
                    if (!way.ResolvedNodes.ContainsKey(nodeId))
                    {
                        continue;
                    }
                    var node = way.ResolvedNodes[nodeId];
                    coordinates.Add(new Coordinates {
                        Lat = node.Lat.Value, Lon = node.Lon.Value
                    });
                }
                if (coordinates.Count <= 1 && way.Center == null)
                {
                    Debug.WriteLine("Way {0}/{1} ignored because it contains too few nodes", way.Type, way.Id);
                    continue;
                }

                IGeometryObject geometry = null;
                if (coordinates.Count == 1)
                {
                    geometry = GetPointFor(way.ResolvedNodes.Values.First());
                }
                else
                {
                    geometry = GetGeometryForCoordinates(coordinates, way);
                }


                var feature = new Feature(geometry, _featurePropertyBuilder.GetProperties(way));
                feature.Id = string.Format("{0}/{1}", way.Type, way.Id);
                features.Add(feature);
            }
            return(features);
        }
Exemple #3
0
        private Feature ConstructMultiPolygon(Element element, IEnumerable <Way> ways)
        {
            var multiPolygonGeoemtryType = element is Way ? "way" : "relation";
            var validWays  = ways.Where(x => x.IsGeometryIncomplete == false).ToList();
            var outerRings = _ringOrganiser.AssignToRings(validWays.Where(w => w.RoleInRelation == "outer").ToList());
            var innerRings = _ringOrganiser.AssignToRings(validWays.Where(w => w.RoleInRelation == "inner").ToList());
            var clusters   = new List <Cluster>();

            outerRings.ToList().ForEach(x => clusters.Add(new Cluster(new [] { x })));

            foreach (var innerRing in innerRings)
            {
                var matchingOuterIndex = FindOuterIndex(innerRing, outerRings);
                if (matchingOuterIndex != -1)
                {
                    clusters[matchingOuterIndex].Add(innerRing);
                }
                else
                {
                    Debug.WriteLine("Multipolygon{0}/{1} contains an inner ring with no container outer", multiPolygonGeoemtryType, element.Id);
                }
            }

            _clusterCleanser.SanitzeClusters(clusters);

            if (clusters.Count == 0 || clusters.All(c => !c.Any()))
            {
                Debug.WriteLine("Multipolygon{0}/{1} contains no coordinates", multiPolygonGeoemtryType, element.Id);
                return(null);
            }

            IGeometryObject geometryObject = clusters.Count == 1 ? ConvertToPolygon(clusters[0]) : ConvertToMultiPolygon(clusters);
            var             properties     = _featurePropertyBuilder.GetProperties(element);

            return(new Feature(geometryObject, properties)
            {
                Id = string.Format("{0}/{1}", multiPolygonGeoemtryType, element.Id)
            });
        }