micheln
05-02-2007, 05:37 AM
Hi everybody
I have a dataset containing lat+lon: I would like to draw a polyline from those positions, but addpolyline accepts only an array of objects(location) : how can I draw the polyline with my positions? do I have to convert the dataset to an array? if yes: how do I do that?
Any Source code (delphi or C# .Net) would be REALLY appreciated.
Thanks for Your Help, any Help :)
Wilfried
05-03-2007, 06:49 AM
Hi,
Location[] loc = new Location[2];
loc[0] = MP.ActiveMap.GetLocation(lat1, lon1, 1);
loc[1] = MP.ActiveMap.GetLocation(lat2, lon2, 1);
MP.ActiveMap.Shapes.AddPolyline(loc);
or
Shape s = MP.ActiveMap.Shapes.AddLine(Loc[0], Loc[1]);
micheln
05-04-2007, 05:57 AM
Hi,
Location[] loc = new Location[2];
loc[0] = MP.ActiveMap.GetLocation(lat1, lon1, 1);
loc[1] = MP.ActiveMap.GetLocation(lat2, lon2, 1);
MP.ActiveMap.Shapes.AddPolyline(loc);or
Shape s = MP.ActiveMap.Shapes.AddLine(Loc[0], Loc[1]);
THANKS A LOT: that's very helpful: I'll always be amazed how easy and obvious the solutions seem to be when it's someone else that finds it (and share it) :lol:
THANKS AGAIN :D
I'm trying to draw the route (polyline) that some vehicle followed during a period of time.Is this code correct: (delphi)
var
j: integer;
Positions: array of locations; (locations is a record type having 2 fields: lat and long, or maybe a mappoint.location type: dunnow exactly :tongue:)
then:
j := LatLonsDataset.RecordCount;
LatLonsDataset.First;
SetLength(Positions, j);
for i = 0 to j do
begin
Positions[i] := MP.ActiveMap.GetLocation(LatLonsDataset.FieldbyNam e('Lat').Value, LatLonsDataset.FieldbyName('Long').Value, 1);
LatLonsDataset.Next;
end
MP.ActiveMap.Shapes.AddPolyline(Positions)
I dunnow if it works, but if it does: is it optimized? I mean, is there any better way to do it?
Is there any function in mappoint 2006 that, provided a (dataset) set of lat-longs, draws the polyline?
Thnx again :-)
Wilfried
05-04-2007, 06:49 AM
Hi,
No this is the way to go. You can speed it up by accessing the fields by object instead of by name which do a search + stringcomparisation at each iretate of the loop what you probably dont want. From the top of my head:
LatLonsDatasetLat := TFloadField(LatLonsDataset.FieldbyName('Lat'));
LatLonsDataSetLong := TFloadField(LatLonsDataset.FieldbyName('Long'));
for i = 0 to j do begin
Positions[i] := MP.ActiveMap.GetLocation(LatLonsDatasetLat.Value, LatLonsDatasetLong.Value, 1);
If the fieldobjects does not exists (depending on what kind of a Dataset it is or how you create them), then you can create them on the stack in that procedure.
Another thing that can speed up if this routine is called a lot, that is to set th e lengh of the dynamic array only if it must grow. Then of course the array must not be on the stack. Then there is only memory allocation / deallocation when needed. But this is only if this routine itself is called a lot.