Exemplo n.º 1
1
        private IEnumerable<OSMTurnInfo> EnumerateOsmTurnRestrictions(IFeatureWorkspace fws)
        {
            OSMUtility osmUtility = new OSMUtility();
            ITable tableRelation = fws.OpenTable(_osmDataset.Name + "_osm_relation");
            try
            {
                TaskManager.StartProgress(tableRelation.RowCount(null));

                using (ComReleaser cr = new ComReleaser())
                {
                    ICursor cursor = tableRelation.Search(null, false);
                    cr.ManageLifetime(cursor);

                    int idxTags = cursor.FindField("osmTags");
                    int idxMembers = cursor.FindField("osmMembers");

                    IRow row = null;
                    while ((row = cursor.NextRow()) != null)
                    {
                        tag[] tags = osmUtility.retrieveOSMTags(row, idxTags, _osmDataset.Workspace);
                        var tagsRestriction = tags.Where(t => t.k.Equals("restriction", StringComparison.CurrentCultureIgnoreCase));

                        foreach (tag tagRestrict in tagsRestriction)
                        {
                            OSMTurnInfo turn = new OSMTurnInfo();

                            turn.TurnType = tagRestrict.v;

                            foreach (member m in osmUtility.retrieveMembers(row, idxMembers))
                            {
                                if (m.role.Equals("from", StringComparison.CurrentCultureIgnoreCase))
                                    turn.From = m;
                                else if (m.role.Equals("to", StringComparison.CurrentCultureIgnoreCase))
                                    turn.To = m;
                                else if (m.role.Equals("via", StringComparison.CurrentCultureIgnoreCase))
                                    turn.Via = m;
                            }

                            if (turn.HasValidMembers())
                            {
                                turn.FromFeature = FindEdgeFeature(turn.From.@ref);
                                turn.ToFeature = FindEdgeFeature(turn.To.@ref);
                                turn.ViaFeature = FindJunctionFeature(turn.Via.@ref);

                                if (turn.HasValidFeatures())
                                    yield return turn;
                            }
                        }

                        TaskManager.StepProgress();
                    }
                }
            }
            finally
            {
                TaskManager.EndProgress();
            }
        }
Exemplo n.º 2
0
        private IEnumerable <OSMTurnInfo> EnumerateOsmTurnRestrictions(IFeatureWorkspace fws)
        {
            OSMUtility osmUtility    = new OSMUtility();
            ITable     tableRelation = fws.OpenTable(_osmDataset.Name + "_osm_relation");

            try
            {
                TaskManager.StartProgress(tableRelation.RowCount(null));

                using (ComReleaser cr = new ComReleaser())
                {
                    ICursor cursor = tableRelation.Search(null, false);
                    cr.ManageLifetime(cursor);

                    int idxTags    = cursor.FindField("osmTags");
                    int idxMembers = cursor.FindField("osmMembers");

                    IRow row = null;
                    while ((row = cursor.NextRow()) != null)
                    {
                        tag[] tags            = osmUtility.retrieveOSMTags(row, idxTags, _osmDataset.Workspace);
                        var   tagsRestriction = tags.Where(t => t.k.Equals("restriction", StringComparison.CurrentCultureIgnoreCase));

                        foreach (tag tagRestrict in tagsRestriction)
                        {
                            OSMTurnInfo turn = new OSMTurnInfo();

                            turn.TurnType = tagRestrict.v;

                            foreach (member m in osmUtility.retrieveMembers(row, idxMembers))
                            {
                                if (m.role.Equals("from", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    turn.From = m;
                                }
                                else if (m.role.Equals("to", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    turn.To = m;
                                }
                                else if (m.role.Equals("via", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    turn.Via = m;
                                }
                            }

                            if (turn.HasValidMembers())
                            {
                                turn.FromFeature = FindEdgeFeature(turn.From.@ref);
                                turn.ToFeature   = FindEdgeFeature(turn.To.@ref);
                                turn.ViaFeature  = FindJunctionFeature(turn.Via.@ref);

                                if (turn.HasValidFeatures())
                                {
                                    yield return(turn);
                                }
                            }
                        }

                        TaskManager.StepProgress();
                    }
                }
            }
            finally
            {
                TaskManager.EndProgress();
            }
        }
Exemplo n.º 3
0
        private relation ConvertRowToOSMRelation(IRow currentRow, IWorkspace featureWorkspace, int tagsFieldIndex, int osmIDFieldIndex, int changesetIDFieldIndex, int osmVersionFieldIndex, int userIDFieldIndex, int userNameFieldIndex, int timeStampFieldIndex, int visibleFieldIndex, int membersFieldIndex, int extensionVersion)
        {

            if (currentRow == null)
                throw new ArgumentNullException("currentRow");

            relation osmRelation = new relation();
            object featureValue = DBNull.Value;
            List<object> relationItems = new List<object>();

            if (membersFieldIndex != -1)
            {
                member[] members = _osmUtility.retrieveMembers(currentRow, membersFieldIndex);
                relationItems.AddRange(members);
            }

            if (osmIDFieldIndex != -1)
            {
                osmRelation.id = Convert.ToString(currentRow.get_Value(osmIDFieldIndex));
            }

            if (changesetIDFieldIndex != -1)
            {
                featureValue = currentRow.get_Value(changesetIDFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmRelation.changeset = Convert.ToString(currentRow.get_Value(changesetIDFieldIndex));
                }
            }

            if (osmVersionFieldIndex != -1)
            {
                featureValue = currentRow.get_Value(osmVersionFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmRelation.version = Convert.ToString(featureValue);
                }
            }

            if (userIDFieldIndex != -1)
            {
                featureValue = currentRow.get_Value(userIDFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmRelation.uid = Convert.ToString(featureValue);
                }
            }

            if (userNameFieldIndex != -1)
            {
                featureValue = currentRow.get_Value(userNameFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmRelation.user = Convert.ToString(featureValue);
                }
            }

            if (timeStampFieldIndex != -1)
            {
                featureValue = currentRow.get_Value(timeStampFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmRelation.timestamp = Convert.ToDateTime(featureValue).ToUniversalTime().ToString("u");
                }
            }

            if (visibleFieldIndex != -1)
            {
                featureValue = currentRow.get_Value(visibleFieldIndex);

                if (featureValue != DBNull.Value)
                {
                    osmRelation.visible = Convert.ToString(featureValue);
                }
            }

            if (tagsFieldIndex > -1)
            {
                tag[] tags = null;
                tags = _osmUtility.retrieveOSMTags((IRow)currentRow, tagsFieldIndex, featureWorkspace);

                //// if the row is of type IFeature and a polygon then add the type=multipolygon tag
                //if (currentRow is IFeature)
                //{
                //    IFeature currentFeature = currentRow as IFeature;

                //    if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                //    {
                //        tag mpTag = new tag();
                //        mpTag.k = "type";
                //        mpTag.v = "multipolygon";

                //        relationItems.Add(mpTag);
                //    }
                //}

                if (tags.Length != 0)
                {
                    relationItems.AddRange(tags);
                }
            }

            // add all items (member and tags) to the relation element
            osmRelation.Items = relationItems.ToArray();

            return osmRelation;
        }