コード例 #1
0
        private ESRI.ArcGIS.OSM.OSMClassExtension.node CreateNodeRepresentation(IFeatureClass pointFeatureClass, string action, long osmID, string osmChangeSetID, int osmVersion, IPoint deletePoint, int extensionVersion)
        {
            node nodeRepresentation = new node();

            // let's find all the rows that have a different status than 200 - meaning success
            IQueryFilter queryFilter = new QueryFilterClass();
            queryFilter.WhereClause = pointFeatureClass.WhereClauseByExtensionVersion(osmID, "OSMID", extensionVersion);

            using (ComReleaser comReleaser = new ComReleaser())
            {
                IFeatureCursor searchCursor = pointFeatureClass.Search(queryFilter, false);
                comReleaser.ManageLifetime(searchCursor);

                IFeature pointFeature = searchCursor.NextFeature();

                int osmTagsFieldIndex = pointFeatureClass.Fields.FindField("osmTags");
                int osmIDFieldIndex = pointFeatureClass.Fields.FindField("osmID");
                int osmUserFieldIndex = pointFeatureClass.Fields.FindField("osmuser");
                int osmUIDFieldIndex = pointFeatureClass.Fields.FindField("osmuid");
                int osmVisibleFieldIndex = pointFeatureClass.Fields.FindField("osmvisible");
                int osmVersionFieldIndex = pointFeatureClass.Fields.FindField("osmversion");

                IPoint pointGeometry = null;

                if (pointFeature != null)
                {
                    switch (action)
                    {
                        case "create":
                            // the newly created node needs to carry the changeset info, the coordinate and the tags
                            nodeRepresentation.changeset = osmChangeSetID;

                            pointGeometry = pointFeature.Shape as IPoint;
                            pointGeometry.Project(m_wgs84);

                            nodeRepresentation.lat = Convert.ToString(pointGeometry.Y, new CultureInfo("en-US"));
                            nodeRepresentation.lon = Convert.ToString(pointGeometry.X, new CultureInfo("en-US"));

                            tag[] tags = null;
                            if (osmTagsFieldIndex > -1)
                            {
                                tags = _osmUtility.retrieveOSMTags((IRow)pointFeature, osmTagsFieldIndex, ((IDataset)pointFeatureClass).Workspace);
                            }

                            List<tag> valueOnlyTags = new List<tag>();

                            for (int index = 0; index < tags.Length; index++)
                            {
                                if (!String.IsNullOrEmpty(tags[index].v))
                                {
                                    valueOnlyTags.Add(tags[index]);
                                }
                            }

                            nodeRepresentation.tag = valueOnlyTags.ToArray();

                            if (osmIDFieldIndex > -1)
                            {
                                nodeRepresentation.id = Convert.ToString(pointFeature.get_Value(osmIDFieldIndex), new CultureInfo("en-US"));
                            }

                            break;
                        case "modify":
                            // for an update the complete (full) node needs to be returned
                            nodeRepresentation.changeset = osmChangeSetID;

                            pointGeometry = pointFeature.Shape as IPoint;
                            pointGeometry.Project(m_wgs84);

                            nodeRepresentation.lat = Convert.ToString(pointGeometry.Y, new CultureInfo("en-US"));
                            nodeRepresentation.lon = Convert.ToString(pointGeometry.X, new CultureInfo("en-US"));

                            if (osmIDFieldIndex > -1)
                            {
                                nodeRepresentation.id = Convert.ToString(pointFeature.get_Value(osmIDFieldIndex), new CultureInfo("en-US"));
                            }

                            if (osmUserFieldIndex > -1)
                            {
                                nodeRepresentation.user = Convert.ToString(pointFeature.get_Value(osmUserFieldIndex));
                            }

                            if (osmUIDFieldIndex > -1)
                            {
                                nodeRepresentation.uid = Convert.ToString(pointFeature.get_Value(osmUIDFieldIndex), new CultureInfo("en-US"));
                            }

                            if (osmVisibleFieldIndex > -1)
                            {
                                try
                                {
                                    nodeRepresentation.visible = (nodeVisible)Enum.Parse(typeof(nodeVisible), Convert.ToString(pointFeature.get_Value(osmVisibleFieldIndex)));
                                }
                                catch
                                {
                                    nodeRepresentation.visible = nodeVisible.@true;
                                }
                            }

                            if (osmVersionFieldIndex > -1)
                            {
                                nodeRepresentation.version = Convert.ToString(pointFeature.get_Value(osmVersionFieldIndex));
                            }

                            tags = null;
                            if (osmTagsFieldIndex > -1)
                            {
                                tags = _osmUtility.retrieveOSMTags((IRow)pointFeature, osmTagsFieldIndex, ((IDataset)pointFeatureClass).Workspace);
                            }

                            valueOnlyTags = new List<tag>();

                            for (int index = 0; index < tags.Length; index++)
                            {
                                if (!String.IsNullOrEmpty(tags[index].v))
                                {
                                    valueOnlyTags.Add(tags[index]);
                                }
                            }

                            nodeRepresentation.tag = valueOnlyTags.ToArray();

                            break;
                        case "delete":

                            nodeRepresentation.changeset = osmChangeSetID;
                            nodeRepresentation.id = Convert.ToString(osmID);
                            nodeRepresentation.version = Convert.ToString(osmVersion);

                            pointGeometry = pointFeature.Shape as IPoint;
                            pointGeometry.Project(m_wgs84);

                            nodeRepresentation.lat = Convert.ToString(pointGeometry.Y, new CultureInfo("en-US"));
                            nodeRepresentation.lon = Convert.ToString(pointGeometry.X, new CultureInfo("en-US"));

                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    if (action.Equals("delete", StringComparison.InvariantCultureIgnoreCase))
                    {
                        nodeRepresentation.changeset = osmChangeSetID;
                        nodeRepresentation.id = Convert.ToString(osmID);
                        nodeRepresentation.version = Convert.ToString(osmVersion);

                        if (deletePoint != null)
                        {
                            deletePoint.Project(m_wgs84);

                            nodeRepresentation.lat = Convert.ToString(deletePoint.Y, new CultureInfo("en-US"));
                            nodeRepresentation.lon = Convert.ToString(deletePoint.X, new CultureInfo("en-US"));
                        }
                        else
                        {
                            nodeRepresentation = null;
                        }
                    }
                }
            }

            return nodeRepresentation;
        }
コード例 #2
0
        private node ConvertPointFeatureToOSMNode(IFeature currentFeature, IWorkspace featureWorkspace, int tagsFieldIndex, int osmIDFieldIndex, int changesetIDFieldIndex, int osmVersionFieldIndex, int userIDFieldIndex, int userNameFieldIndex, int timeStampFieldIndex, int visibleFieldIndex, int extensionVersion)
        {

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

            node osmNode = new node();
            object featureValue = DBNull.Value;

            if (currentFeature.Shape.IsEmpty == false)
            {
                IPoint wgs84Point = currentFeature.Shape as IPoint;
                wgs84Point.Project(m_wgs84);

                NumberFormatInfo exportCultureInfo = new CultureInfo("en-US", false).NumberFormat;
                exportCultureInfo.NumberDecimalDigits = 6;

                osmNode.lat = wgs84Point.Y.ToString("N", exportCultureInfo);
                osmNode.lon = wgs84Point.X.ToString("N", exportCultureInfo);

                Marshal.ReleaseComObject(wgs84Point);
            }

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

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

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

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

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

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

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

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

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

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

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

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

                if (featureValue != DBNull.Value)
                {
                    try
                    {
                        osmNode.visible = (nodeVisible)Enum.Parse(typeof(nodeVisible), Convert.ToString(featureValue));
                    }
                    catch
                    {
                        osmNode.visible = nodeVisible.@true;
                    }
                }
            }

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

                if (tags.Length != 0)
                {
                    osmNode.tag = tags;
                }
            }

            return osmNode;
        }