private void addGeocodeRequest(ref XLSType xLSType, string number, string street1, string street2, string city, string requestID) { RequestType requestType = xLSType.Request.Append(); requestType.methodName.Value = "GeocodeRequest"; GeocodeRequestType geocodeRequestType = requestType.GeocodeRequest.Append(); AddressType addressType = geocodeRequestType.Address.Append(); StreetAddressType streetAddressType = addressType.StreetAddress.Append(); if (number != null) { BuildingLocatorType buildingLocatorType = streetAddressType.Building.Append(); buildingLocatorType.number.Value = number; } StreetNameType streetNameType = streetAddressType.Street.Append(); streetNameType.Value = street1; if (street2 != null) { StreetNameType streetNameType2 = streetAddressType.Street.Append(); streetNameType2.Value = street2; } NamedPlaceType placeProvince = addressType.Place.Append(); placeProvince.type.Value = "CountrySubdivision"; placeProvince.Value = city; }
public static void addXlsHeader(ref XLSType xLSType) { RequestHeaderType requestHeaderType = xLSType.RequestHeader.Append(); requestHeaderType.clientName.Value = ServiceConfigProperties.clientUserName; requestHeaderType.clientPassword.Value = ServiceConfigProperties.clientPassword; }
public XLSType createXlsRequestTest(string number, string street1, string street2, string city, string requestID) { XlsDocument xLSDocument = XlsDocument.CreateDocument(); XLSType xLSType = xLSDocument.XLS.Append(); xLSType.lang.Value = ServiceConfigProperties.Language; // should be added one only RequestUtil.addXlsHeader(ref xLSType); addGeocodeRequest(ref xLSType, number, street1, street2, city, requestID); return(xLSType); }
// 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); } }
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); }
/// <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); }
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); }
public static XLSType perform(XLSType xLSTypeRequest) { XLSType xLSTypeResponse = null; WebClient webClient = new WebClient(); //webClient.Headers.Add("Content-Type", "text/xml"); //webClient.Encoding = Encoding.UTF8; webClient.Headers.Add("SOAPAction", "http://www.opengis.net/xls"); webClient.Encoding = System.Text.Encoding.UTF8; XlsDocument xLSDocument = XlsDocument.CreateDocument(); //xLSDocument.XLS. //xLSDocument.setXLS(xLSTypeRequest); string strRequest = getStringSoapMessage(xLSTypeRequest.Node.OuterXml); string strResponse = webClient.UploadString(ServiceConfigProperties.EndPointURL, "POST", strRequest); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(strResponse); XmlNodeList xlsNodeList = xmlDoc.GetElementsByTagName("XLS", "http://www.opengis.net/xls"); if (xlsNodeList.Count > 0) { XmlNode xlsNode = xlsNodeList.Item(0); xLSDocument = XlsDocument.LoadFromString(xlsNode.OuterXml); //xLSTypeResponse = XLSType.Factory.parse(xlsNode.OuterXml); xLSTypeResponse = xLSDocument.XLS.First; } return(xLSTypeResponse); }
// 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("*"); } }