Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="DuLieu"></param>
        /// <returns></returns>
        public XLSType CreateRequest(List <PointF> DuLieu)
        {
            XlsDocument xLSDocument = XlsDocument.CreateDocument();
            XLSType     xLSType     = xLSDocument.XLS.Append();

            xLSType.lang.Value = ServiceConfigProperties.Language;

            if (DuLieu.Count == 0)
            {
                return(xLSType);
            }
            RequestUtil.addXlsHeader(ref xLSType);

            for (int i = 0; i < DuLieu.Count; i++)
            {
                string strPoint  = DuLieu[i].X + " " + DuLieu[i].Y;
                string requestId = "request_" + i.ToString();
                addReverseGeocodeRequest(ref xLSType, strPoint, requestId);
            }

            return(xLSType);
        }
Esempio n. 2
0
        public XLSType createXlsRequestTest(double x, double y)
        {
            XlsDocument xLSDocument = XlsDocument.CreateDocument();
            XLSType     xLSType     = xLSDocument.XLS.Append();

            xLSType.lang.Value = ServiceConfigProperties.Language;
            // should be added one only
            RequestUtil.addXlsHeader(ref xLSType);

            // can be added more than one
            //double x = 105.81783721316403;
            //double y = 21.028330217040492;
            //Random random = new Random();
            //for (int i = 0; i < 100; i++)
            //{
            //    double x1 = x + random.NextDouble() / 100;
            //    double y1 = y + random.NextDouble() / 100;
            //string strPoint = y1 + " " + x1;
            //string requestId = "request_" + i;
            addReverseGeocodeRequest(ref xLSType, y + " " + x, "request_0");
            //}

            return(xLSType);
        }
        /// <summary>
        /// lay nhieu ket qua
        /// </summary>
        /// <param name="xLSTypeResponse"></param>
        public ArrayList GetArrDiaChi(List <PointF> Data)
        {
            ReverseGeocoderTest reverseGeocoderTest = new ReverseGeocoderTest();
            XLSType             xLSTypeRequest      = reverseGeocoderTest.CreateRequest(Data);
            XLSType             xLSTypeResponse     = RequestUtil.perform(xLSTypeRequest);
            ArrayList           result = new ArrayList();

            if (xLSTypeResponse.Response.Exists)
            {
                string Duong = "", Xa = "", Huyen = "", Tinh = "";
                for (int i = 0; i < xLSTypeResponse.Response.Count; i++)
                {
                    ResponseType responseType = xLSTypeResponse.Response[i];
                    ReverseGeocodeResponseType reverseGeocodeResponseType = responseType.ReverseGeocodeResponse.First;

                    if (reverseGeocodeResponseType.ReverseGeocodedLocation.Exists)
                    {
                        ReverseGeocodedLocationType reverseGeocodedLocationType = reverseGeocodeResponseType.ReverseGeocodedLocation.First;
                        PointType          pointType          = reverseGeocodedLocationType.Point.First;
                        DirectPositionType directPositionType = pointType.pos.First;
                        AddressType        addressType        = reverseGeocodedLocationType.Address.First;
                        StreetAddressType  streetAddressType  = addressType.StreetAddress.First;


                        string strStreetName   = "";
                        string buildingNumber  = "";
                        string strCommuneName  = "";
                        string strDistrictName = "";
                        string strProvinceName = "";

                        if (streetAddressType.Building.Exists)
                        {
                            BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;
                            buildingNumber = buildingLocatorType.number.Value.Trim();
                        }

                        if (streetAddressType.Street.Exists)
                        {
                            StreetNameType streetNameType = streetAddressType.Street.First;
                            strStreetName = streetNameType.Value.Trim();
                        }

                        for (int j = 0; j < addressType.Place.Count; j++)
                        {
                            NamedPlaceType namedPlaceType = addressType.Place.At(j);
                            if (namedPlaceType.type.Value == "Municipality")
                            {
                                strCommuneName = namedPlaceType.Value.Trim();
                            }
                            else if (namedPlaceType.type.Value == "CountrySecondarySubdivision")
                            {
                                strDistrictName = namedPlaceType.Value.Trim();
                            }
                            else if (namedPlaceType.type.Value == "CountrySubdivision")
                            {
                                strProvinceName = namedPlaceType.Value.Trim();
                            }
                        }

                        string[] latlong = directPositionType.Value.Split(new string[] { " " }, StringSplitOptions.None);

                        string KetQua = "";
                        strStreetName   = strStreetName.Trim();
                        strCommuneName  = strCommuneName.Trim();
                        strDistrictName = strDistrictName.Trim();
                        strProvinceName = strProvinceName.Trim();
                        if (strStreetName != "")
                        {
                            if (Duong != strStreetName)
                            {
                                KetQua += "Đường " + strStreetName + ", ";
                                if (Xa != strCommuneName)
                                {
                                    if (strCommuneName != "")
                                    {
                                        KetQua += strCommuneName + ", ";
                                    }
                                    if (Huyen != strDistrictName)
                                    {
                                        if (strDistrictName != "")
                                        {
                                            KetQua += strDistrictName + ", ";
                                        }
                                        if (Tinh != strProvinceName)
                                        {
                                            if (strProvinceName != "")
                                            {
                                                KetQua += strProvinceName;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (Xa != strCommuneName)
                                {
                                    if (strCommuneName != "")
                                    {
                                        KetQua += strCommuneName + ", ";
                                    }
                                    if (Huyen != strDistrictName)
                                    {
                                        if (strDistrictName != "")
                                        {
                                            KetQua += strDistrictName + ", ";
                                        }
                                        if (Tinh != strProvinceName)
                                        {
                                            if (strProvinceName != "")
                                            {
                                                KetQua += strProvinceName;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (Huyen != strDistrictName)
                                    {
                                        if (strDistrictName != "")
                                        {
                                            KetQua += strDistrictName + ", ";
                                        }
                                        if (Tinh != strProvinceName)
                                        {
                                            if (strProvinceName != "")
                                            {
                                                KetQua += strProvinceName;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Xa != strCommuneName)
                            {
                                KetQua += strCommuneName + ", ";
                                if (Huyen != strDistrictName)
                                {
                                    if (strDistrictName != "")
                                    {
                                        KetQua += strDistrictName + ", ";
                                    }
                                    if (Tinh != strProvinceName)
                                    {
                                        if (strProvinceName != "")
                                        {
                                            KetQua += strProvinceName;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (Huyen != strDistrictName)
                                {
                                    if (strDistrictName != "")
                                    {
                                        KetQua += strDistrictName + ", ";
                                    }
                                    if (Tinh != strProvinceName)
                                    {
                                        if (strProvinceName != "")
                                        {
                                            KetQua += strProvinceName;
                                        }
                                    }
                                }
                            }
                        }

                        /*
                         * if (i == (xLSTypeResponse.Response.Count - 1))
                         * {
                         * // if (KetQua == "")
                         * // {
                         *  KetQua = "";
                         *      if (strStreetName != "") KetQua += "Đường " + strStreetName + ", ";
                         *      if (strCommuneName != "") KetQua += strCommuneName + ", ";
                         *      if (strDistrictName != "") KetQua += strDistrictName + ", ";
                         *      if (strProvinceName != "") KetQua += strProvinceName;
                         * // }
                         * }
                         */
                        Duong = strStreetName;
                        Xa    = strCommuneName;
                        Huyen = strDistrictName;
                        Tinh  = strProvinceName;
                        if (KetQua != "")
                        {
                            if (KetQua.Substring(KetQua.Length - 1) == " ")
                            {
                                KetQua = KetQua.Remove(KetQua.Length - 2);
                            }
                        }
                        result.Add(KetQua);
                    }
                }
            }
            return(result);
        }
        // toa do->dia chi
        public string doTestReverseGeocoderWithAddress(double kinhdo, double vido)
        {
            ReverseGeocoderTest reverseGeocoderTest = new ReverseGeocoderTest();
            XLSType             xLSTypeRequest      = reverseGeocoderTest.createXlsRequestTest(kinhdo, vido);
            XLSType             xLSTypeResponse     = RequestUtil.perform(xLSTypeRequest);

            if (xLSTypeResponse.Response.Exists)
            {
                ResponseType responseType = xLSTypeResponse.Response.First;
                ReverseGeocodeResponseType reverseGeocodeResponseType = responseType.ReverseGeocodeResponse.First;

                if (reverseGeocodeResponseType.ReverseGeocodedLocation.Exists)
                {
                    ReverseGeocodedLocationType reverseGeocodedLocationType = reverseGeocodeResponseType.ReverseGeocodedLocation.First;
                    PointType          pointType          = reverseGeocodedLocationType.Point.First;
                    DirectPositionType directPositionType = pointType.pos.First;
                    AddressType        addressType        = reverseGeocodedLocationType.Address.First;
                    StreetAddressType  streetAddressType  = addressType.StreetAddress.First;
                    //BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;
                    string strStreetName   = "";
                    string buildingNumber  = "";
                    string strCommuneName  = "";
                    string strDistrictName = "";
                    string strProvinceName = "";
                    if (streetAddressType.Building.Exists)
                    {
                        BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;
                        buildingNumber = buildingLocatorType.number.Value;
                    }
                    if (streetAddressType.Street.Exists)
                    {
                        StreetNameType streetNameType = streetAddressType.Street.First;
                        strStreetName = streetNameType.Value;
                    }

                    for (int j = 0; j < addressType.Place.Count; j++)
                    {
                        NamedPlaceType namedPlaceType = addressType.Place.At(j);
                        if (namedPlaceType.type.Value == "Municipality")
                        {
                            strCommuneName = namedPlaceType.Value;
                        }
                        else if (namedPlaceType.type.Value == "CountrySecondarySubdivision")
                        {
                            strDistrictName = namedPlaceType.Value;
                        }
                        else if (namedPlaceType.type.Value == "CountrySubdivision")
                        {
                            strProvinceName = namedPlaceType.Value;
                        }
                    }
                    if ((buildingNumber == "") && (strStreetName == "") && (strCommuneName == "") && (strDistrictName == "") && (strProvinceName == ""))
                    {
                        return("*");
                    }
                    //  string[] latlong = directPositionType.Value.Split(new string[] { " " } , StringSplitOptions.None);
                    string diachi;
                    if (buildingNumber == "0")
                    {
                        diachi = strStreetName + "," + strCommuneName + "," + strDistrictName + "," + strProvinceName;
                    }
                    else
                    {
                        diachi = buildingNumber + "," + strStreetName + "," + strCommuneName + "," + strDistrictName + "," + strProvinceName;
                    }
                    diachi = diachi.Replace(",,", ",");
                    return(diachi);
                }
                else
                {
                    return("*");
                }
            }
            else
            {
                return("*");
            }
        }
        public string doTestGeocoderByAddress(string numberBuild, string Street, string Province, string requestID)
        {
            GeocoderTest geocoderTest    = new GeocoderTest();
            XLSType      xLSTypeRequest  = geocoderTest.createXlsRequestTest(numberBuild, Street, null, Province, requestID);
            XLSType      xLSTypeResponse = RequestUtil.perform(xLSTypeRequest);

            if (xLSTypeResponse.Response.Exists)
            {
                ResponseType        responseType        = xLSTypeResponse.Response.First;
                GeocodeResponseType geocodeResponseType = responseType.GeocodeResponse.First;

                if (geocodeResponseType.GeocodeResponseList.Exists)
                {
                    GeocodeResponseListType geocodeResponseListType = geocodeResponseType.GeocodeResponseList.First;
                    if (geocodeResponseListType.GeocodedAddress.Exists)
                    {
                        GeocodedAddressType geocodedAddressType = geocodeResponseListType.GeocodedAddress.First;
                        PointType           pointType           = geocodedAddressType.Point.First;
                        DirectPositionType  directPositionType  = pointType.pos.First;
                        AddressType         addressType         = geocodedAddressType.Address.First;
                        StreetAddressType   streetAddressType   = addressType.StreetAddress.First;
                        BuildingLocatorType buildingLocatorType = streetAddressType.Building.First;

                        string buildingNumber  = buildingLocatorType.number.Value;
                        string strCommuneName  = "";
                        string strDistrictName = "";
                        string strProvinceName = "";
                        string strStreetName   = "";



                        if (streetAddressType.Street.Exists)
                        {
                            StreetNameType streetNameType = streetAddressType.Street.First;
                            strStreetName = streetNameType.Value;
                        }

                        foreach (NamedPlaceType namedPlaceType in addressType.Place)
                        {
                            if (namedPlaceType.type.Value == "Municipality")
                            {
                                strCommuneName = namedPlaceType.Value;
                            }
                            else if (namedPlaceType.type.Value == "CountrySecondarySubdivision")
                            {
                                strDistrictName = namedPlaceType.Value;
                            }
                            else if (namedPlaceType.type.Value == "CountrySubdivision")
                            {
                                strProvinceName = namedPlaceType.Value;
                            }
                        }
                        // string[] latlong = directPositionType.Value.Split(new string[] { " " } , StringSplitOptions.None);
                        return(directPositionType.Value.ToString());
                    }
                    else
                    {
                        return("*");
                    }
                }
                else
                {
                    return("*");
                }
            }
            else
            {
                return("*");
            }
        }