/// <summary>
		/// Set solver settings
		/// </summary>
		/// <param name="strNAClassName">NAClass name</param>
		/// <param name="inputFC">Input feature class</param>
        /// <param name="maxSnapTolerance">Max snap tolerance</param>
        public void LoadNANetworkLocations(string strNAClassName, IFeatureClass inputFC, double maxSnapTolerance)
        {
			INamedSet classes = m_NAContext.NAClasses;
			INAClass naClass = classes.get_ItemByName(strNAClassName) as INAClass;

			// Delete existing locations from the specified NAClass
			naClass.DeleteAllRows();

			// Create a NAClassLoader and set the snap tolerance (meters unit)
            INAClassLoader classLoader = new NAClassLoader();
            classLoader.Locator = m_NAContext.Locator;
            if (maxSnapTolerance > 0) ((INALocator3)classLoader.Locator).MaxSnapTolerance = maxSnapTolerance;
            classLoader.NAClass = naClass;

			// Create field map to automatically map fields from input class to NAClass
			INAClassFieldMap fieldMap = new NAClassFieldMapClass();
			fieldMap.CreateMapping(naClass.ClassDefinition, inputFC.Fields);
            classLoader.FieldMap = fieldMap;

			// Avoid loading network locations onto non-traversable portions of elements
			INALocator3 locator = m_NAContext.Locator as INALocator3;
			locator.ExcludeRestrictedElements = true;
			locator.CacheRestrictedElements(m_NAContext);

			// Load network locations
			int rowsIn = 0;
			int rowsLocated = 0;
            classLoader.Load((ICursor)inputFC.Search(null, true), null, ref rowsIn, ref rowsLocated);

			// Message all of the network analysis agents that the analysis context has changed.
            ((INAContextEdit)m_NAContext).ContextChanged();
        }
Beispiel #2
0
        public void LoadNANetworkLocations(string strNAClassName, IFeatureClass pInputFC, double SnapTolerance)
        {
            INAClass class2 = this.m_pNAContext.NAClasses.get_ItemByName(strNAClassName) as INAClass;

            class2.DeleteAllRows();
            INAClassLoader loader = new NAClassLoaderClass
            {
                Locator = this.m_pNAContext.Locator
            };

            if (SnapTolerance > 0.0)
            {
                loader.Locator.SnapTolerance = SnapTolerance;
            }
            loader.NAClass = class2;
            INAClassFieldMap map = new NAClassFieldMapClass();

            map.CreateMapping(class2.ClassDefinition, pInputFC.Fields);
            loader.FieldMap = map;
            int            rowsInCursor = 0;
            int            rowsLocated  = 0;
            IFeatureCursor cursor       = pInputFC.Search(null, true);

            loader.Load((ICursor)cursor, null, ref rowsInCursor, ref rowsLocated);
        }
Beispiel #3
0
        private bool LoadLocations(IFeatureWorkspace featureWorkspace)
        {
            IFeatureClass inputFeatureClass = null;

            try
            {
                inputFeatureClass = featureWorkspace.OpenFeatureClass(txtInputFacilities.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Specified input feature class does not exist");
                return(false);
            }

            INamedSet classes = m_naContext.NAClasses;
            INAClass  naClass = classes.get_ItemByName("Facilities") as INAClass;

            // delete existing locations, except barriers
            naClass.DeleteAllRows();

            // Create a NAClassLoader and set the snap tolerance (meters unit)
            INAClassLoader naClassLoader = new NAClassLoaderClass();

            naClassLoader.Locator = m_naContext.Locator;
            naClassLoader.Locator.SnapTolerance = 100;
            naClassLoader.NAClass = naClass;

            // Create field map to automatically map fields from input class to NAClass
            INAClassFieldMap naClassFieldMap = new NAClassFieldMapClass();

            naClassFieldMap.CreateMapping(naClass.ClassDefinition, inputFeatureClass.Fields);
            naClassLoader.FieldMap = naClassFieldMap;

            // Avoid loading network locations onto non-traversable portions of elements
            INALocator3 locator = m_naContext.Locator as INALocator3;

            locator.ExcludeRestrictedElements = true;
            locator.CacheRestrictedElements(m_naContext);

            // load network locations
            int rowsIn      = 0;
            int rowsLocated = 0;

            naClassLoader.Load(inputFeatureClass.Search(null, true) as ICursor, null, ref rowsIn, ref rowsLocated);

            if (rowsLocated <= 0)
            {
                MessageBox.Show("Facilities were not loaded from input feature class");
                MessageBox.Show("没有导入任何结果!");
                return(false);
            }

            // Message all of the network analysis agents that the analysis context has changed
            INAContextEdit naContextEdit = m_naContext as INAContextEdit;

            naContextEdit.ContextChanged();

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Load the input table and create field map to map fields from input table to NAClass
        /// </summary>
        /// <param name="strNAClassName">NAClass name</param>
        /// <param name="inputTable">Input table</param>
        public void LoadNANetworkLocations(string strNAClassName, ITable inputTable)
        {
            INamedSet classes = m_NAContext.NAClasses;
            INAClass  naClass = classes.get_ItemByName(strNAClassName) as INAClass;

            // Delete existing rows from the specified NAClass
            naClass.DeleteAllRows();

            // Create a NAClassLoader and set the snap tolerance (meters unit)
            INAClassLoader loader = new NAClassLoader();

            loader.Locator = m_NAContext.Locator;
            loader.Locator.SnapTolerance = 100;
            loader.NAClass = naClass;

            // Create field map to automatically map fields from input table to NAclass
            INAClassFieldMap fieldMap = new NAClassFieldMapClass();

            fieldMap.CreateMapping(naClass.ClassDefinition, inputTable.Fields);
            loader.FieldMap = fieldMap;


            // Avoid loading network locations onto non-traversable portions of elements
            INALocator3 locator = m_NAContext.Locator as INALocator3;

            locator.ExcludeRestrictedElements = true;
            locator.CacheRestrictedElements(m_NAContext);

            // Load input table
            int rowsIn      = 0;
            int rowsLocated = 0;

            loader.Load(inputTable.Search(null, true), null, ref rowsIn, ref rowsLocated);

            // Message all of the network analysis agents that the analysis context has changed.
            INAContextEdit naContextEdit = m_NAContext as INAContextEdit;

            naContextEdit.ContextChanged();
        }