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
Results 1 to 4 of 4

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. #1
    micheln is offline 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. #2
    Wilfried is offline 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);
    MP.ActiveMap.Shapes.AddPolyline(loc);
    or

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

  3. #3
    micheln is offline Junior Member Yellow Belt
    Join Date
    Jan 2007
    Posts
    16

    Re: Addpolyline from a dataset

    Quote Originally Posted by Wilfried View Post
    Hi,

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

    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
    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

  4. #4
    Wilfried is offline 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'));
    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.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. AddPolyLine (s) array problem
    By FreddyD in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-20-2006, 01:45 PM
  2. Shapes.AddPolyline is very slow
    By tdaffin in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 01-27-2006, 08:08 AM
  3. Addpolyline , Array , Visual Basic and Other languages
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 08-26-2004, 04:58 AM
  4. addpolyline
    By Anonymous in forum Wish List
    Replies: 2
    Last Post: 04-25-2003, 04:50 PM
  5. If I have one dataset with 300 pushpins, how do i ....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 02-26-2002, 01:52 PM

Tags for this Thread

Posting Permissions

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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66