private void GeocodeAddress(IPropertySet addressProperties)
        {
            // Match the Address
            IAddressGeocoding addressGeocoding = m_locator as IAddressGeocoding;
            IPropertySet      resultSet        = addressGeocoding.MatchAddress(addressProperties);

            // Print out the results
            object names, values;

            resultSet.GetAllProperties(out names, out values);
            string[] namesArray  = names as string[];
            object[] valuesArray = values as object[];
            int      length      = namesArray.Length;
            IPoint   point       = null;

            for (int i = 0; i < length; i++)
            {
                if (namesArray[i] != "Shape")
                {
                    this.ResultsTextBox.Text += namesArray[i] + ": " + valuesArray[i].ToString() + "\n";
                }
                else
                {
                    if (point != null && !point.IsEmpty)
                    {
                        point = valuesArray[i] as IPoint;
                        this.ResultsTextBox.Text += "X: " + point.X + "\n";
                        this.ResultsTextBox.Text += "Y: " + point.Y + "\n";
                    }
                }
            }

            this.ResultsTextBox.Text += "\n";
        }
コード例 #2
0
        public override void OnClick()
        {
            if (m_pAOIPanel.CurrentJob != null)
            {
                //show form
                AddressDialog pAddressDialog = new AddressDialog();

                if (pAddressDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ILocatorManager   pLocatorMgr = new LocatorManagerClass();
                    ILocatorWorkspace pLocatorWS  = pLocatorMgr.GetLocatorWorkspaceFromPath(m_strWorkspace);

                    IAddressGeocoding pLocator = (IAddressGeocoding)pLocatorWS.GetLocator(m_strLocator);

                    IPropertySet addressProperties = new PropertySetClass();
                    addressProperties.SetProperty("Street", pAddressDialog.street);

                    IPropertySet matchProperties = pLocator.MatchAddress(addressProperties);

                    if (pLocator.MatchFields.FieldCount == 0)
                    {
                        System.Windows.Forms.MessageBox.Show("No address found");
                        return;
                    }

                    IPoint pPoint = null;
                    for (int i = 0; i < pLocator.MatchFields.FieldCount; i++)
                    {
                        if (pLocator.MatchFields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            object pObject = matchProperties.GetProperty(pLocator.MatchFields.get_Field(i).Name);
                            if (pObject is IPoint)
                            {
                                pPoint = (IPoint)pObject;
                            }
                        }
                    }
                    //calculate AOI

                    ITopologicalOperator pTopo = (ITopologicalOperator)pPoint;
                    IGeometry            pGeom = pTopo.Buffer(100);

                    IEnvelope pMyAOI = pGeom.Envelope;

                    m_pAOIPanel.CurrentAOI = CreatePolyFromEnv(pMyAOI);
                    IEnvelope pEnv = pGeom.Envelope;
                    pEnv.Expand(2, 2, true);
                    m_hookHelper.ActiveView.Extent = pEnv;
                    m_hookHelper.ActiveView.Refresh();
                }
            }
        }
コード例 #3
0
        private void GeocodeAddress()
        {
            // Get the locator
            System.Object     obj              = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"));
            ILocatorManager2  locatorManager   = obj as ILocatorManager2;
            ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath(@"C:\California_fgdb.gdb");
            ILocator          locator          = locatorWorkspace.GetLocator("California_city_state_zip_94_new");

            // Set up the address properties
            IAddressInputs addressInputs     = locator as IAddressInputs;
            IFields        addressFields     = addressInputs.AddressFields;
            IPropertySet   addressProperties = new PropertySetClass();

            addressProperties.SetProperty(addressFields.get_Field(0).Name, this.AddressTextBox.Text);
            addressProperties.SetProperty(addressFields.get_Field(1).Name, this.CityTextBox.Text);
            addressProperties.SetProperty(addressFields.get_Field(2).Name, this.StateTextBox.Text);
            addressProperties.SetProperty(addressFields.get_Field(3).Name, this.ZipTextBox.Text);

            // Match the Address
            IAddressGeocoding addressGeocoding = locator as IAddressGeocoding;
            IPropertySet      resultSet        = addressGeocoding.MatchAddress(addressProperties);

            // Print out the results
            object names, values;

            resultSet.GetAllProperties(out names, out values);
            string[] namesArray  = names as string[];
            object[] valuesArray = values as object[];
            int      length      = namesArray.Length;
            IPoint   point       = null;

            for (int i = 0; i < length; i++)
            {
                if (namesArray[i] != "Shape")
                {
                    this.ResultsTextBox.Text += namesArray[i] + ": " + valuesArray[i].ToString() + "\n";
                }
                else
                {
                    if (point != null && !point.IsEmpty)
                    {
                        point = valuesArray[i] as IPoint;
                        this.ResultsTextBox.Text += "X: " + point.X + "\n";
                        this.ResultsTextBox.Text += "Y: " + point.Y + "\n";
                    }
                }
            }

            this.ResultsTextBox.Text += "\n";
        }