Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

 Subscribe to receive our newsletter. Subscribe Unsubscribe

## Addpolyline from a dataset

This is a discussion on Addpolyline from a dataset within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi everybody I have a dataset containing lat+lon: I would like to draw a polyline from those positions, but addpolyline ...

1. Junior Member Yellow Belt
Join Date
Jan 2007
Posts
16

## Addpolyline from a dataset

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

2. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433

## Re: Addpolyline from a dataset

Hi,

Code:
```Location[] loc = new Location[2];
loc[0] = MP.ActiveMap.GetLocation(lat1, lon1, 1);
loc[1] = MP.ActiveMap.GetLocation(lat2, lon2, 1);
or

Code:
`Shape s = MP.ActiveMap.Shapes.AddLine(Loc[0], Loc[1]);`

3. Junior Member Yellow Belt
Join Date
Jan 2007
Posts
16

## Re: Addpolyline from a dataset

Originally Posted by Wilfried
Hi,

Code:
```Location[] loc = new Location[2];
loc[0] = MP.ActiveMap.GetLocation(lat1, lon1, 1);
loc[1] = MP.ActiveMap.GetLocation(lat2, lon2, 1);
or

Code:
`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)

THANKS AGAIN

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 )

then:

Code:
```j := LatLonsDataset.RecordCount;
LatLonsDataset.First;
SetLength(Positions, j);
for i = 0 to j do
begin
Positions[i] := MP.ActiveMap.GetLocation(LatLonsDataset.FieldbyName('Lat').Value, LatLonsDataset.FieldbyName('Long').Value, 1);
LatLonsDataset.Next;
end
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

4. Senior Member Black Belt
Join Date
Nov 2004
Location
Belgium
Posts
2,433

## Re: Addpolyline from a dataset

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:

Code:
```LatLonsDatasetLat := TFloadField(LatLonsDataset.FieldbyName('Lat'));
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.

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•