示例#1
0
        private List <MatchedAddress> ConvertToMatchedAddresses(Geocode geocode)
        {
            List <MatchedAddress> matchedAddresses = new List <MatchedAddress>();

            if (geocode.GcCount != null && geocode.GcCount.Count > 0)
            {
                foreach (Feature feature in geocode.Features)
                {
                    MatchedAddress matchedAddress = new MatchedAddress();

                    foreach (Field field in feature.Fields)
                    {
                        switch (field.Name)
                        {
                        case "ADDRESSFOUND":
                            matchedAddress.Address = field.FieldValue.ValueString;
                            break;

                        case "SCORE":
                            matchedAddress.Score = Convert.ToInt32(field.FieldValue.ValueString);
                            break;

                        case "SHAPEFIELD":
                            matchedAddress.Location = field.FieldValue.Point.Coordinate;
                            break;
                        }

                        matchedAddresses.Add(matchedAddress);
                    }
                }
            }

            return(matchedAddresses);
        }
示例#2
0
        public override List <MatchedAddress> FindAddressCandidates(params AddressValue[] values)
        {
            ValidateAddressValues(values);
            RecordSet recordSet = GeocodeServer.FindAddressCandidates(ConvertAddressValuesToProperties(values), GetModifiedLocatorProperties());

            List <MatchedAddress> matchedAddresses = new List <MatchedAddress>();

            if (recordSet != null && recordSet.Records != null)
            {
                var select = recordSet.Fields.FieldArray.Select((field, index) => new { field, index });

                var result       = select.FirstOrDefault(o => o.field.Name == "Match_addr");
                int addressIndex = result == null ? -1 : result.index;

                result = select.FirstOrDefault(o => o.field.Name == "Score");
                int scoreIndex = result == null ? -1 : result.index;

                result = select.FirstOrDefault(o => o.field.Name == "Shape");
                int shapeIndex = result == null ? -1 : result.index;

                foreach (Record record in recordSet.Records)
                {
                    MatchedAddress matchedAddress = new MatchedAddress();

                    if (addressIndex > -1)
                    {
                        matchedAddress.Address = record.Values[addressIndex].ToString();
                    }

                    if (scoreIndex > -1)
                    {
                        matchedAddress.Score = Convert.ToInt32(record.Values[scoreIndex]);
                    }

                    if (shapeIndex > -1)
                    {
                        matchedAddress.Location = ((AppGeo.Clients.Ags.Proxy.Geometry)record.Values[shapeIndex]).ToCommon().Centroid.Coordinate;
                    }

                    matchedAddresses.Add(matchedAddress);
                }
            }

            return(matchedAddresses);
        }
示例#3
0
        public override MatchedAddress GeocodeAddress(params AddressValue[] values)
        {
            ValidateAddressValues(values);
            PropertySet propertySet = GeocodeServer.GeocodeAddress(ConvertAddressValuesToProperties(values), GetModifiedLocatorProperties());

            MatchedAddress matchedAddress = null;

            if (propertySet != null && propertySet.PropertyArray != null || propertySet.PropertyArray.Length > 0)
            {
                PropertySetProperty prop = propertySet.PropertyArray.FirstOrDefault(o => o.Key == "Status");

                if (prop != null && prop.Value.ToString() == "M")
                {
                    matchedAddress = new MatchedAddress();

                    prop = propertySet.PropertyArray.FirstOrDefault(o => o.Key == "Match_addr");

                    if (prop != null)
                    {
                        matchedAddress.Address = prop.Value.ToString();
                    }

                    prop = propertySet.PropertyArray.FirstOrDefault(o => o.Key == "Score");

                    if (prop != null)
                    {
                        matchedAddress.Score = Convert.ToInt32(prop.Value);
                    }

                    prop = propertySet.PropertyArray.FirstOrDefault(o => o.Key == "Shape");

                    if (prop != null)
                    {
                        matchedAddress.Location = ((AppGeo.Clients.Ags.Proxy.Geometry)prop.Value).ToCommon().Centroid.Coordinate;
                    }
                }
            }

            return(matchedAddress);
        }