This code samples returns a list of attributes per matched location and the results of the complete path holding all matched segments.
Caution: The method is deprecated. Please use matchPositions() with the same result.
Add the obligatory url and add the given document style
CXF
The localhost which should be replaced by the dedicated host name and
the default port
50040
were used to define the obligatory
URL
which is obligatory to broadcast the request respectively the response
via Internet.
final String url = "http://localhost:50040/xmapmatch/ws/XMapmatch"; XMapmatchRemoteInterface client = (XMapmatchRemoteInterface) ClientFactory .createClient(XMapmatchRemoteInterface.class, RemoteType.DOCSTYLE_CXF, "", "", url);
XMapmatchWSService xMapMatchClient = new XMapmatchWSService();
The devices (e.g. GPS sensors) log the tracks in their specific format. Following parameters are going to be used in this sample:
Define a track.
h.addElement("1;251.065;5.00004;2011-07-06T07:57:03.000+0200;6.114670;49.626195"); ...
Define a track.
h.Add("1;251.065;5.00004;2011-07-06T07:57:03.000+0200;6.114670;49.626195"); ...
Please notice that the coordinate format
OG_GEODECIMAL
is mandatory obtaining your desired result.
Create object
CallerContext
and set the properties to define the attributes:
Profile
and
CoordFormat
.
CallerContext cxt = new CallerContext(); cxt.setLog1("Basic Map Matching"); CallerContextProperty props1 = new CallerContextProperty(); props1.setKey("Profile"); props1.setValue("default"); CallerContextProperty props2 = new CallerContextProperty(); props2.setKey("CoordFormat"); props2.setValue("OG_GEODECIMAL"); CallerContextProperty[] properties = new CallerContextProperty[] { props1, props2 }; cxt.setProperties(properties); client.setCallerContext(cxt);
Create object
CallerContext
and set the properties to define the attributes:
Profile
and
CoordFormat
.
CallerContext cxt = new CallerContext(); cxt.log1 = "Basic Map Matching"; CallerContextProperty props1 = new CallerContextProperty(); props1.key = "Profile"; props1.value = "default"; CallerContextProperty props2 = new CallerContextProperty(); props2.key = "CoordFormat"; props2.value = "OG_GEODECIMAL"; CallerContextProperty[] properties = new CallerContextProperty[] { props1, props2 }; cxt.wrappedProperties = properties;
Add the obligatory parameters such as id, heading, speed, time stamp, longitude and latitude as described above.
Create array trackPositions and the derived class trackPosition. Put all attributes in the corresponding elements.
TrackPosition[] trackPositions = new TrackPosition[max]; ... while (e.hasMoreElements()) { TrackPosition trackPosition = new TrackPosition(); ... trackPosition.setId(id); trackPosition.setHeading(heading); trackPosition.setSpeedInMps(speedInMps); trackPosition.setTimestamp(timestamp); trackPosition.setLon(x); trackPosition.setLat(y); ... }
Create array trackPositions and the derived class trackPosition. Put all attributes in the corresponding elements.
TrackPosition[] trackPositions = new TrackPosition[max]; for (int i = 0; i < gps.Count; i++) { String arg0 = gps[i]; String[] trackData = arg0.Split(';'); TrackPosition trackPosition = new TrackPosition(); int id = Convert.ToInt32(trackData[0]); trackPosition.id = id; float heading = Convert.ToSingle(trackData[1]); trackPosition.heading = heading; float speedInMps = Convert.ToSingle(trackData[2]); trackPosition.speedInMps = speedInMps; System.DateTime timestamp = Convert.ToDateTime(trackData[3]); trackPosition.timestamp = timestamp; double x = Convert.ToDouble(trackData[4]); trackPosition.lon = x; double y = Convert.ToDouble(trackData[5]); trackPosition.lat = y; trackPosition.latSpecified = true; trackPosition.lonSpecified = true; trackPosition.timestampSpecified = true; trackPositions[i] = trackPosition; }
Use the method matchTrack() including the corresponding arguments.
Call method matchTrack() and add the necessary argument "trackPositions" and the optional map name "lux_d".
matchTrack = client.matchTrack(trackPositions, "lux_d");
Call method matchTrack() and add the necessary argument "trackPositions" and the optional map name "lux_d".
matchTrack = xMapMatchClient.matchTrackExtended(trackPositions, "lux_d", cxt);
The match result contains following properties:
Discover the API to get experienced with all relevant parameters.
// Overall length and time: System.out.println("Total distance: " + (int) matchTrack.getOverallLength() + "m"); System.out.println("Total time : " + matchTrack.getOverallTime() + "s"); ... // Matched segments: rows[index][0] = matchedSegment.getTileId(); rows[index][1] = matchedSegment.getRtgSegIdx(); rows[index][2] = matchedSegment.getNetworkClass(); ... // Matched locations: rows[index][0] = String.format("%.2f", matchedLocation.getAngleDifference()); rows[index][1] = String.format("%.2f", matchedLocation.getCoveredDistance()); rows[index][2] = String.format("%.2f", matchedLocation.getDrivenDistance()); ...
foreach (MatchedSegment matchedSegment in matchedLocation.wrappedPath) { String endXYN = ""; foreach (int i in matchedSegment.wrappedEndXYN) { endXYNendXYN = endXYN + i + ";"; } String startXYN = ""; foreach (int i in matchedSegment.wrappedStartXYN) { startXYNstartXYN = startXYN + i + ";"; } // create table entry TableEntryMapMathchingCompletePath row = new TableEntryMapMathchingCompletePath() { tileID = matchedSegment.tileId, rtgSegIdx = matchedSegment.rtgSegIdx, networkClass = matchedSegment.networkClass, speedLimitBackward = matchedSegment.speedLimitBackward, speedLimitForward = matchedSegment.speedLimitForward, length = matchedSegment.length, countryCode = matchedSegment.countryCode, endXYNendXYN = endXYN, startXYNstartXYN = startXYN }; rows.Add(row); index++; } ... TableEntryMapMathchingResult row = new TableEntryMapMathchingResult { AngleDiff = String.Format("{0}", matchedLocation.angleDifference), CovDist = String.Format("{0}", matchedLocation.coveredDistance), DrivenDist = String.Format("{0}", matchedLocation.drivenDistance), Heading = String.Format("{0}", matchedLocation.heading), LinkingDist = String.Format("{0}", matchedLocation.linkingDistance), LocalMatching = matchedLocation.localMatching, LocalRating = String.Format("{0}", matchedLocation.localRating), Prob = String.Format("{0}", matchedLocation.probability * 100), Stable = matchedLocation.stable, Timestamp = matchedLocation.timestamp, TransRating = String.Format("{0}", matchedLocation.transitionRating), InputID = matchedLocation.inputId, Pos = lat + ";" + lon, TileID = tileID, NetClass = networkClass }; rows[index] = row; ...
The following graphical depictions exemplarily illustrate the given output.
Copyright © 2024 PTV Logistics GmbH All rights reserved. | Imprint