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

## Determine if a polyline is closed?

This is a discussion on Determine if a polyline is closed? within the MapPoint Desktop Discussion forums, part of the Map Forums category; Shapes.addPolyline method says "To add a closed polygon, use the same Location object for the first and last items in ...

1. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137

## Determine if a polyline is closed?

Shapes.addPolyline method says "To add a closed polygon, use the same Location object for the first and last items in the array." This works fine.

However, is there any way in the API to determine if a shape of type "geoFreeform" is closed or not?

The vertices property does not use the same Location object for the first and last items in the array even if it is closed.

2. You could compare the settings in the two Location objects.

Eg. is it a street address? If so, do they match?
Are they positioned by coordinates? If so, do they match?

You could also use Gilles code (on this website) that finds the longitude and latitude of any Location object. You will have to be careful with rounding errors and decide on a tolerance value for comparing - a simple, are they equal? does not working with floating point numbers.

Eg. is lat1 == lat2?
Should really use the check lat1>(lat2-EPS) AND lat1<(lat2+EPS)

EPS should be very small - this is your tolerance value.

Richard

3. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137
I'm not sure if I have explained the problem clearly based on your response.

Say you draw a closed triangle manually with the drawing tools. This means it has 3 vertices. This can easliy be done programatically as well. You create 3 location objects. Then use Shapes.AddPolyline, passing in the array of locations, which is size 4--the first location object is also repeated as the fourth location object. This tells mappoint to close the polygon (triangle). Easy enough. If you don't repeat the first location object in the fourth position, the triangle would not be closed.

Now, say you want programmatically determine in the code if this same triangle is closed:
1. Get the triangle from the Shapes Collection.
2. Get the array of location from the vertices property.
3. Here's the problem: The vertices array does not repeat the first location object if the polygon is closed. Therefore there is no way to distinguish this from a polygon that is open.

4. Sorry, I thought you meant the first and last location objects were physically different. It is possible for them to be different objects in different places in memory with the same internal contents - and my answer determines if that is the case.

Are these shapes drawn by your program? If so, you could name them and include a code in the name to say "open" or "closed". A bit kludgy but it would work.

Richard

5. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137
Originally Posted by Winwaed
Sorry, I thought you meant the first and last location objects were physically different. It is possible for them to be different objects in different places in memory with the same internal contents - and my answer determines if that is the case.

Are these shapes drawn by your program? If so, you could name them and include a code in the name to say "open" or "closed". A bit kludgy but it would work.

Richard
The shapes are drawn by the user. Then I need to pass the shape data (ie. the vertices and whether or not it forms a polygon) to another application for processing. I don't think there is a way around this problem other than assuming that it is either opened or closed.

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