public ESRI.ArcGIS.Geoprocessing.IGPFunction GetFunction(string Name)
        {
            switch (Name)
            {
            case m_DownloadDataName:
                IGPFunction osmGPDownloadFunction = new OSMGPDownload() as IGPFunction;
                return(osmGPDownloadFunction);

            case m_UploadDataName:
                IGPFunction osmGPUploadFunction = new OSMGPUpload() as IGPFunction;
                return(osmGPUploadFunction);

            case m_AttributeSelectorName:
                IGPFunction osmGPAttributeSelector = new OSMGPAttributeSelector() as IGPFunction;
                return(osmGPAttributeSelector);

            case m_FeatureSymbolizerName:
                IGPFunction osmGPSymbolizer = new OSMGPSymbolizer() as IGPFunction;
                return(osmGPSymbolizer);

            case m_AddExtensionName:
                IGPFunction osmGPAddExtension = new OSMGPAddExtension() as IGPFunction;
                return(osmGPAddExtension);

            case m_RemoveExtensionName:
                IGPFunction osmGPRemoveExtension = new OSMGPRemoveExtension() as IGPFunction;
                return(osmGPRemoveExtension);

            case m_FileLoaderName:
                IGPFunction osmGPFileLoader = new OSMGPFileLoader() as IGPFunction;
                return(osmGPFileLoader);

            case m_CombineLayersName:
                IGPFunction combineLayers = new GPCombineLayers() as IGPFunction;
                return(combineLayers);

            case m_CombineAttributesName:
                IGPFunction osmGPCombineAttributes = new OSMGPCombineAttributes() as IGPFunction;
                return(osmGPCombineAttributes);

            case m_CopyLayerExtensionName:
                IGPFunction gpCopyLayerExtensions = new GPCopyLayerExtensions() as IGPFunction;
                return(gpCopyLayerExtensions);

            case m_DiffLoaderName:
                IGPFunction osmGPDiffLoader = new OSMGPDiffLoader() as IGPFunction;
                return(osmGPDiffLoader);

            case m_Export2OSMName:
                IGPFunction osmGPExport2OSM = new OSMGPExport2OSM() as IGPFunction;
                return(osmGPExport2OSM);

            case m_FeatureComparisonName:
                IGPFunction osmGPFeatureComparison = new OSMGPFeatureComparison() as IGPFunction;
                return(osmGPFeatureComparison);

            case m_CreateNetworkDatasetName:
                IGPFunction osmGPCreateNetworkDataset = new OSMGPCreateNetworkDataset() as IGPFunction;
                return(osmGPCreateNetworkDataset);

            case m_MultiLoaderName:
                IGPFunction osmGPMultiLoader = new OSMGPMultiLoader() as IGPFunction;
                return(osmGPMultiLoader);

            case m_NodeLoaderName:
                IGPFunction osmGPNodeLoader = new OSMGPNodeLoader() as IGPFunction;
                return(osmGPNodeLoader);

            case m_WayLoaderName:
                IGPFunction osmGPWayLoader = new OSMGPWayLoader() as IGPFunction;
                return(osmGPWayLoader);

            case m_RelationLoaderName:
                IGPFunction osmGPRelationLoader = new OSMGPRelationLoader() as IGPFunction;
                return(osmGPRelationLoader);

            default:
                return(null);
            }
        }
Ejemplo n.º 2
0
 public ESRI.ArcGIS.Geoprocessing.IGPFunction GetFunction(string Name)
 {
     switch (Name)
     {
         case m_DownloadDataName:
             IGPFunction osmGPDownloadFunction = new OSMGPDownload() as IGPFunction;
             return osmGPDownloadFunction;
         case m_UploadDataName:
             IGPFunction osmGPUploadFunction = new OSMGPUpload() as IGPFunction;
             return osmGPUploadFunction;
         case m_AttributeSelectorName:
             IGPFunction osmGPAttributeSelector = new OSMGPAttributeSelector() as IGPFunction;
             return osmGPAttributeSelector;
         case m_FeatureSymbolizerName:
             IGPFunction osmGPSymbolizer = new OSMGPSymbolizer() as IGPFunction;
             return osmGPSymbolizer;
         case m_AddExtensionName:
             IGPFunction osmGPAddExtension = new OSMGPAddExtension() as IGPFunction;
             return osmGPAddExtension;
         case m_RemoveExtensionName:
             IGPFunction osmGPRemoveExtension = new OSMGPRemoveExtension() as IGPFunction;
             return osmGPRemoveExtension;
         case m_FileLoaderName:
             IGPFunction osmGPFileLoader = new OSMGPFileLoader() as IGPFunction;
             return osmGPFileLoader;
         case m_CombineLayersName:
             IGPFunction combineLayers = new GPCombineLayers() as IGPFunction;
             return combineLayers;
         case m_CombineAttributesName:
             IGPFunction osmGPCombineAttributes = new OSMGPCombineAttributes() as IGPFunction;
             return osmGPCombineAttributes;
         case m_CopyLayerExtensionName:
             IGPFunction gpCopyLayerExtensions = new GPCopyLayerExtensions() as IGPFunction;
             return gpCopyLayerExtensions;
         case m_DiffLoaderName:
             IGPFunction osmGPDiffLoader = new OSMGPDiffLoader() as IGPFunction;
             return osmGPDiffLoader;
         case m_Export2OSMName:
             IGPFunction osmGPExport2OSM = new OSMGPExport2OSM() as IGPFunction;
             return osmGPExport2OSM;
         case m_FeatureComparisonName:
             IGPFunction osmGPFeatureComparison = new OSMGPFeatureComparison() as IGPFunction;
             return osmGPFeatureComparison;
         case m_CreateNetworkDatasetName:
             IGPFunction osmGPCreateNetworkDataset = new OSMGPCreateNetworkDataset() as IGPFunction;
             return osmGPCreateNetworkDataset;
         case m_MultiLoaderName:
             IGPFunction osmGPMultiLoader = new OSMGPMultiLoader() as IGPFunction;
             return osmGPMultiLoader;
         case m_NodeLoaderName:
             IGPFunction osmGPNodeLoader = new OSMGPNodeLoader() as IGPFunction;
             return osmGPNodeLoader;
         case m_WayLoaderName:
             IGPFunction osmGPWayLoader = new OSMGPWayLoader() as IGPFunction;
             return osmGPWayLoader;
         case m_RelationLoaderName:
             IGPFunction osmGPRelationLoader = new OSMGPRelationLoader() as IGPFunction;
             return osmGPRelationLoader;
         default:
             return null;
     }
 }
Ejemplo n.º 3
0
        public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message)
        {
            try
            {
                IGPUtilities3 execute_Utilities = new GPUtilitiesClass();
                OSMUtility    osmUtility        = new OSMUtility();

                if (TrackCancel == null)
                {
                    TrackCancel = new CancelTrackerClass();
                }

                IGPParameter inputOSMParameter = paramvalues.get_Element(in_osmFeatureClassNumber) as IGPParameter;
                IGPValue     inputOSMGPValue   = execute_Utilities.UnpackGPValue(inputOSMParameter);

                IGPParameter  tagFieldsParameter   = paramvalues.get_Element(in_attributeSelectorNumber) as IGPParameter;
                IGPMultiValue tagCollectionGPValue = execute_Utilities.UnpackGPValue(tagFieldsParameter) as IGPMultiValue;

                if (tagCollectionGPValue == null)
                {
                    message.AddError(120048, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), tagFieldsParameter.Name));
                    return;
                }


                IFeatureClass osmFeatureClass = null;
                ITable        osmInputTable   = null;
                IQueryFilter  osmQueryFilter  = null;

                try
                {
                    execute_Utilities.DecodeFeatureLayer(inputOSMGPValue, out osmFeatureClass, out osmQueryFilter);
                    osmInputTable = osmFeatureClass as ITable;
                }
                catch { }

                try
                {
                    if (osmInputTable == null)
                    {
                        execute_Utilities.DecodeTableView(inputOSMGPValue, out osmInputTable, out osmQueryFilter);
                    }
                }
                catch { }

                if (osmInputTable == null)
                {
                    return;
                }

                // find the field that holds tag binary/xml field
                int osmTagCollectionFieldIndex = osmInputTable.FindField("osmTags");


                // if the Field doesn't exist - wasn't found (index = -1) get out
                if (osmTagCollectionFieldIndex == -1)
                {
                    message.AddError(120005, resourceManager.GetString("GPTools_OSMGPAttributeSelector_notagfieldfound"));
                    return;
                }

                // set up the progress indicator
                IStepProgressor stepProgressor = TrackCancel as IStepProgressor;

                if (stepProgressor != null)
                {
                    int featureCount = osmInputTable.RowCount(osmQueryFilter);

                    stepProgressor.MinRange  = 0;
                    stepProgressor.MaxRange  = featureCount;
                    stepProgressor.Position  = 0;
                    stepProgressor.Message   = resourceManager.GetString("GPTools_OSMGPCombineAttributes_progressMessage");
                    stepProgressor.StepValue = 1;
                    stepProgressor.Show();
                }

                String illegalCharacters = String.Empty;

                ISQLSyntax sqlSyntax = ((IDataset)osmInputTable).Workspace as ISQLSyntax;
                if (sqlSyntax != null)
                {
                    illegalCharacters = sqlSyntax.GetInvalidCharacters();
                }

                // establish the list of field indexes only once
                Dictionary <string, int> fieldIndexes = new Dictionary <string, int>();
                for (int selectedGPValueIndex = 0; selectedGPValueIndex < tagCollectionGPValue.Count; selectedGPValueIndex++)
                {
                    // find the field index
                    int fieldIndex = osmInputTable.FindField(tagCollectionGPValue.get_Value(selectedGPValueIndex).GetAsText());

                    if (fieldIndex != -1)
                    {
                        string tagKeyName = osmInputTable.Fields.get_Field(fieldIndex).Name;

                        tagKeyName = OSMGPAttributeSelector.convert2OSMKey(tagKeyName, illegalCharacters);

                        fieldIndexes.Add(tagKeyName, fieldIndex);
                    }
                }

                ICursor updateCursor = null;
                IRow    osmRow       = null;

                using (ComReleaser comReleaser = new ComReleaser())
                {
                    updateCursor = osmInputTable.Update(osmQueryFilter, false);
                    comReleaser.ManageLifetime(updateCursor);

                    osmRow = updateCursor.NextRow();
                    int progressIndex = 0;

                    while (osmRow != null)
                    {
                        // get the current tag collection from the row
                        ESRI.ArcGIS.OSM.OSMClassExtension.tag[] osmTags = osmUtility.retrieveOSMTags(osmRow, osmTagCollectionFieldIndex, ((IDataset)osmInputTable).Workspace);

                        Dictionary <string, string> tagsDictionary = new Dictionary <string, string>();
                        for (int tagIndex = 0; tagIndex < osmTags.Length; tagIndex++)
                        {
                            tagsDictionary.Add(osmTags[tagIndex].k, osmTags[tagIndex].v);
                        }

                        // look if the tag needs to be updated or added
                        bool tagsUpdated = false;
                        foreach (var fieldItem in fieldIndexes)
                        {
                            object fldValue = osmRow.get_Value(fieldItem.Value);
                            if (fldValue != System.DBNull.Value)
                            {
                                if (tagsDictionary.ContainsKey(fieldItem.Key))
                                {
                                    if (!tagsDictionary[fieldItem.Key].Equals(fldValue))
                                    {
                                        tagsDictionary[fieldItem.Key] = Convert.ToString(fldValue);
                                        tagsUpdated = true;
                                    }
                                }
                                else
                                {
                                    tagsDictionary.Add(fieldItem.Key, Convert.ToString(fldValue));
                                    tagsUpdated = true;
                                }
                            }
                        }

                        if (tagsUpdated)
                        {
                            List <ESRI.ArcGIS.OSM.OSMClassExtension.tag> updatedTags = new List <ESRI.ArcGIS.OSM.OSMClassExtension.tag>();

                            foreach (var tagItem in tagsDictionary)
                            {
                                ESRI.ArcGIS.OSM.OSMClassExtension.tag newTag = new ESRI.ArcGIS.OSM.OSMClassExtension.tag();
                                newTag.k = tagItem.Key;
                                newTag.v = tagItem.Value;
                                updatedTags.Add(newTag);
                            }

                            // insert the tags back into the collection field
                            if (updatedTags.Count != 0)
                            {
                                osmUtility.insertOSMTags(osmTagCollectionFieldIndex, osmRow, updatedTags.ToArray(), ((IDataset)osmInputTable).Workspace);

                                updateCursor.UpdateRow(osmRow);
                            }
                        }

                        progressIndex++;
                        if (stepProgressor != null)
                        {
                            stepProgressor.Position = progressIndex;
                        }

                        if (osmRow != null)
                        {
                            Marshal.ReleaseComObject(osmRow);
                        }

                        osmRow = updateCursor.NextRow();
                    }

                    if (stepProgressor != null)
                    {
                        stepProgressor.Hide();
                    }
                }
            }
            catch (Exception ex)
            {
                message.AddError(120007, ex.Message);
            }
        }