# SHAPEFILE.GetClosestSnapPosition returns wrong shapeindex

**URL:** <https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099>\
**Category:** MapWinGIS\
**Created:** [September 18, 2021, 5:37am UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099 "2021-09-18T05:37:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmoradpour](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@ahmoradpour](https://mapwindow.discourse.group/u/ahmoradpour)\
**Post date:** [September 18, 2021, 5:37am UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/1 "2021-09-18T05:37:49Z")

</div>

hi. i am using [vb.net](http://vb.net) and mapwingis 5.2. i need to know closest shape to a point and coordinate of nearest point on shape by using shapefile.GetClosestSnapPosition(x, y, MaxDistance,byref shapeindex, byref newX, byref newY, byref Distance). Distance & newX & newY works properly but ShapeIndex always returns -1.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [October 15, 2021, 6:04am UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/2 "2021-10-15T06:04:41Z")

</div>

Hello @ahmoradpour and welcome.

I’m sorry, but I looked at the source code, and this is a relatively new function that someone added, and is not fully implemented. It is returning -1 because it is initialized to -1 and never set to the resulting shape index. But there are other problems in this method as well, so it is not a one-line fix; I’ll have to do some debugging to resolve it.

Can you use [GetClosestVertex](https://www.mapwindow.org/documentation/mapwingis4.9/group __shapefile__ selection.html#ga43e6c5f88c8a0b1a01239b02acc8fa77)? I understand that this may not be what you’re looking for, but perhaps it will help in the interim.

Regards,  
Jerry.

---

<div class="post-metadata">

**Author:** ![ahmoradpour](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@ahmoradpour](https://mapwindow.discourse.group/u/ahmoradpour)\
**Post date:** [October 23, 2021, 10:48am UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/3 "2021-10-23T10:48:07Z")

</div>

shapefile.GetClosestVertex also returns Wrong ShapeIndex in first/last vertex of a PolyLine if polylines are sequentially attached.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [February 1, 2022, 3:59pm UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/4 "2022-02-01T15:59:54Z")

</div>

@jerryfaust and @ahmoradpour: Is this still an issue with the latest version: [MapWinGIS v5.3](https://github.com/MapWindow/MapWinGIS/releases)?

If so I will create a JIRA issue for this.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [February 1, 2022, 5:08pm UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/5 "2022-02-01T17:08:58Z")

</div>

Yes, this is still an issue. Thank you.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [February 2, 2022, 7:34am UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/6 "2022-02-02T07:34:54Z")

</div>

I created [[MWGIS-261] sf.GetClosestSnapPosition() returns wrong shapeindex](https://mapwindow.atlassian.net/browse/MWGIS-261) and [[MWGIS-262] sf.GetClosestVertex returns wrong ShapeIndex](https://mapwindow.atlassian.net/browse/MWGIS-262)

---

<div class="post-metadata">

**Author:** ![Clapter](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@Clapter](https://mapwindow.discourse.group/u/Clapter)\
**Post date:** [February 27, 2023, 12:55pm UTC](https://mapwindow.discourse.group/t/shapefile-getclosestsnapposition-returns-wrong-shapeindex/1099/7 "2023-02-27T12:55:10Z")

</div>

Hello all!  
It’s been a year, any news?
