Example #1
0
        public static IPosition ToGeometry(this DirectPositionType pos)
        {
            IPosition position;

            int dim;

            string[] coord = pos.Text.Trim().Replace("  ", " ").Split(' ');
            if (string.IsNullOrEmpty(pos.srsDimension))
            {
                dim = 2; /* We assume that we are in 2D */
            }
            else
            {
                dim = int.Parse(pos.srsDimension);
                if (dim < 2 || dim > 3)
                {
                    throw new InvalidFormatException("invalid GML representation: gml:pos dimension equals " + dim);
                }
            }

            if (dim == 2)
            {
                position = new GeographicPosition(coord[0], coord[1]);
            }
            else
            {
                position = new GeographicPosition(coord[0], coord[1], coord[2]);
            }
            return(position);
        }
Example #2
0
        public static IPosition ToGeometry(this DirectPositionType pos)
        {
            IPosition position;

            int dim;

            var whitespaceSplitter = new Regex(@"\s+");

            string[] coord = whitespaceSplitter.Split(pos.Text.Trim());

            if (string.IsNullOrEmpty(pos.srsDimension))
            {
                dim = 2; /* We assume that we are in 2D */
            }
            else
            {
                dim = int.Parse(pos.srsDimension);
                if (dim < 2 || dim > 3)
                {
                    throw new FormatException("invalid GML representation: gml:pos dimension equals " + dim);
                }
            }

            if (dim == 2)
            {
                position = new Position(coord[0], coord[1]);
            }
            else
            {
                position = new Position(coord[0], coord[1], coord[2]);
            }
            return(position);
        }
Example #3
0
        internal protected void AddLine(double x, double y, double?z)
        {
            // Bug in LinqToXsd: serialization is culture dependent...
            // lowerCorner.TypedValue[0]=x;
            // lowerCorner.TypedValue[1]=y;

            IList <double> lc = null;

            if (lowerCorner == null)
            {
                lowerCorner = new DirectPositionType();
                lc          = new double[] { x, y };
            }
            else
            {
                lc = new List <double>(lowerCorner.TypedValue);

                if (lc[0] > x)
                {
                    lc[0] = x;
                }
                if (lc[1] > y)
                {
                    lc[1] = y;
                }
            }

            IList <double> uc = null;

            if (upperCorner == null)
            {
                upperCorner = new DirectPositionType();
                uc          = new double[] { x, y };
            }
            else
            {
                uc = new List <double>(upperCorner.TypedValue);

                if (uc[0] < x)
                {
                    uc[0] = x;
                }
                if (uc[1] < y)
                {
                    uc[1] = y;
                }
            }

            lowerCorner.Untyped.Value = string.Join(
                " ",
                lc.Select <double, string>(d => d.ToString(CultureInfo.InvariantCulture))
                );
            upperCorner.Untyped.Value = string.Join(
                " ",
                uc.Select <double, string>(d => d.ToString(CultureInfo.InvariantCulture))
                );
        }
        // route service
        public List <ServiceGeo> doTestRouteService(double VDStart, double KDStart, double VDEnd, double KDEnd)
        {
            List <ServiceGeo> lstInfo         = new List <ServiceGeo>();
            XLSType           xLSTypeRequest  = createRouteServiceRequest(VDStart, KDStart, VDEnd, KDEnd);
            XLSType           xLSTypeResponse = RequestUtil.perform(xLSTypeRequest);

            if (xLSTypeResponse.Response.Exists)
            {
                ResponseType responseType = xLSTypeResponse.Response.First;
                DetermineRouteResponseType determineRouteResponseType = responseType.DetermineRouteResponse.First;
                if (determineRouteResponseType.RouteInstructionsList.Exists)
                {
                    RouteInstructionsListType routeInstructionsListType = determineRouteResponseType.RouteInstructionsList.First;

                    foreach (RouteInstructionType routeInstructionType in routeInstructionsListType.RouteInstruction)
                    {
                        ServiceGeo   Geo            = new ServiceGeo();
                        string       strInstruction = routeInstructionType.Instruction.First.Value;
                        string       strDescription = routeInstructionType.description.Value;
                        DistanceType distanceType   = routeInstructionType.distance.First;
                        string       strUnit        = distanceType.uom.Value;
                        string       strDistance    = distanceType.value2.Value.ToString();

                        RouteGeometryType  routeGeometryType = routeInstructionType.RouteInstructionGeometry.First;
                        LineStringType     lineStringType    = routeGeometryType.LineString.First;
                        string             strX = "";
                        string             strY = "";
                        DirectPositionType directPositionType = lineStringType.pos.First;
                        string[]           xy = directPositionType.Value.Split(new string[] { " " }, StringSplitOptions.None);
                        strX = xy[1];
                        strY = xy[0];
                        // ListViewItem listViewItem = new ListViewItem(new string[] { strInstruction, strDescription, strDistance, strUnit, strX, strY });
                        // this.listViewRouteInstructionsList.Items.Add(listViewItem);
                        Geo.DonVi      = strUnit.ToLower();
                        Geo.ChiDan     = strInstruction;
                        Geo.MoTa       = strDescription;
                        Geo.KhoangCach = (float)Math.Round(double.Parse(strDistance), 1);
                        Geo.KinhDo     = strX;
                        Geo.ViDo       = strY;
                        lstInfo.Add(Geo);
                    }
                    return(lstInfo);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #5
0
 public static DirectPositionType ToGmlPos(this IPosition position)
 {
     if (position is GeographicPosition)
     {
         DirectPositionType gmlPos = new DirectPositionType();
         gmlPos.srsDimension = ((GeographicPosition)position).Altitude == null ? null : "3";
         GeographicPosition p = (GeographicPosition)position;
         if (p.Altitude != null)
         {
             gmlPos.Text = string.Format("{0} {1} {2}", p.Latitude, p.Longitude, p.Altitude);
         }
         else
         {
             gmlPos.Text = string.Format("{0} {1}", p.Latitude, p.Longitude);
         }
         return(gmlPos);
     }
     return(null);
 }
Example #6
0
        private void addReverseGeocodeRequest(ref XLSType xLSType, string strPoint, string requestID)
        {
            RequestType requestType = xLSType.Request.Append();

            requestType.methodName.Value = "ReverseGeocodeRequest";

            ReverseGeocodeRequestType reverseGeocodeRequestType = requestType.ReverseGeocodeRequest.Append();

            ReverseGeocodePreferenceTypeType reverseGeocodePreferenceType = reverseGeocodeRequestType.ReverseGeocodePreference.Append();

            reverseGeocodePreferenceType.Value = "StreetAddress";

            PositionType positionType = reverseGeocodeRequestType.Position.Append();
            PointType    pointType    = positionType.Point.Append();

            DirectPositionType directPositionType = pointType.pos.Append();

            directPositionType.Value = strPoint;
        }
        private XLSType createRouteServiceRequest(double VDStart, double KDStart, double VDEnd, double KDEnd)
        {
            XlsDocument xLSDocument    = XlsDocument.CreateDocument();
            XLSType     xLSTypeRequest = xLSDocument.XLS.Append();

            // should be added one only
            RequestUtil.addXlsHeader(ref xLSTypeRequest);

            RequestType requestType = xLSTypeRequest.Request.Append();

            requestType.methodName.Value = "DetermineRouteRequest";

            DetermineRouteRequestType determineRouteRequest = requestType.DetermineRouteRequest.Append();

            RoutePlanType           routePlanType           = determineRouteRequest.RoutePlan.Append();
            RoutePreferenceTypeType routePreferenceTypeType = routePlanType.RoutePreference.Append();

            routePreferenceTypeType.Value = "Shortest";
            WayPointListType wayPointListType = routePlanType.WayPointList.Append();

            // start
            WayPointType       wayPointTypeStartPoint       = wayPointListType.StartPoint.Append();
            PositionType       positionTypeStartPoint       = wayPointTypeStartPoint.Position.Append();
            PointType          pointTypeStartPoint          = positionTypeStartPoint.Point.Append();
            DirectPositionType directPositionTypeStartPoint = pointTypeStartPoint.pos.Append();

            directPositionTypeStartPoint.Value = VDStart.ToString() + " " + KDStart.ToString();

            // end
            WayPointType       wayPointTypeEndPoint       = wayPointListType.EndPoint.Append();
            PositionType       positionTypeEndPoint       = wayPointTypeEndPoint.Position.Append();
            PointType          pointTypeEndPoint          = positionTypeEndPoint.Point.Append();
            DirectPositionType directPositionTypeEndPoint = pointTypeEndPoint.pos.Append();

            directPositionTypeEndPoint.Value = VDEnd.ToString() + " " + KDEnd.ToString();
            determineRouteRequest.RouteGeometryRequest.Append();
            // add this if need the text instructions
            RouteInstructionsRequestType routeInstructionsRequestType = determineRouteRequest.RouteInstructionsRequest.Append();

            routeInstructionsRequestType.format.Value = "text/plain";
            return(xLSTypeRequest);
        }
 public static DirectPositionType ToGmlPos(this IPosition position)
 {
     if (position is GeographicPosition) {
         DirectPositionType gmlPos = new DirectPositionType();
         gmlPos.srsDimension = ((GeographicPosition)position).Altitude == null ? null : "3";
         GeographicPosition p = (GeographicPosition)position;
         if (p.Altitude != null)
             gmlPos.Text = string.Format("{0} {1} {2}", p.Latitude, p.Longitude, p.Altitude);
         else
             gmlPos.Text = string.Format("{0} {1}", p.Latitude, p.Longitude);
         return gmlPos;
     }
     return null;
 }
        // 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("*");
            }
        }
        /// <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);
        }
        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("*");
            }
        }
Example #12
0
        internal protected void AddLine(double x, double y, double? z)
        {
            // Bug in LinqToXsd: serialization is culture dependent...
            // lowerCorner.TypedValue[0]=x;
            // lowerCorner.TypedValue[1]=y;

            IList<double> lc=null;
            if (lowerCorner==null)
            {
                lowerCorner=new DirectPositionType();
                lc=new double[] { x, y };
            } else
            {
                lc=new List<double>(lowerCorner.TypedValue);

                if (lc[0]>x)
                    lc[0]=x;
                if (lc[1]>y)
                    lc[1]=y;
            }

            IList<double> uc=null;
            if (upperCorner==null)
            {
                upperCorner=new DirectPositionType();
                uc=new double[] { x, y };
            } else
            {
                uc=new List<double>(upperCorner.TypedValue);

                if (uc[0]<x)
                    uc[0]=x;
                if (uc[1]<y)
                    uc[1]=y;
            }

            lowerCorner.Untyped.Value=string.Join(
                " ",
                lc.Select<double, string>(d => d.ToString(CultureInfo.InvariantCulture))
            );
            upperCorner.Untyped.Value=string.Join(
                " ",
                uc.Select<double, string>(d => d.ToString(CultureInfo.InvariantCulture))
            );
        }