MapWindow 4 - ActiveX Control Programming : MapWindow Discussion Forum
Hi All I have added two layers to the map, and they are visibly overlapping. One layer of polygons (5) and one layer of points (~10000). Trying to determine which polygons contain each of the points, using the following code: Private Sub Button2_Click(ByVal sender
Point in polygon
Posted by:
jacksonmacd ()
Date: May 12, 2005 02:20PM
Hi All
I have added two layers to the map, and they are visibly overlapping. One layer of polygons (5) and one layer of points (~10000). Trying to determine which polygons contain each of the points, using the following code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sfPolygon As New MapWinGIS.Shapefile()
Dim sfPoints As New MapWinGIS.Shapefile()
Dim i As Integer
Dim pt As New MapWinGIS.Point()
Dim iShp As Int32
sfPoints = AxMap1.get_GetObject(0)
sfPolygon = AxMap1.get_GetObject(1)
For i = 0 To sfPoints.NumShapes - 1
pt = sfPoints.Shape(i).Point(0)
iShp = sfPolygon.PointInShapefile(pt.x, pt.y)
ListBox1.Items.Add(i & " " & pt.x.ToString & " " & pt.y.ToString & " " & iShp)
Next
End Sub
The iShp variable returns (-1, not within any shape) for all of the points. What am I doing wrong?
My plan is to populate one field of the Points datatable with the index of the polygon that it lies within -- the ListBox is just for testing. Is this the correct way to attack this problem (ie, looping through all the points)?
TIA
I have added two layers to the map, and they are visibly overlapping. One layer of polygons (5) and one layer of points (~10000). Trying to determine which polygons contain each of the points, using the following code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sfPolygon As New MapWinGIS.Shapefile()
Dim sfPoints As New MapWinGIS.Shapefile()
Dim i As Integer
Dim pt As New MapWinGIS.Point()
Dim iShp As Int32
sfPoints = AxMap1.get_GetObject(0)
sfPolygon = AxMap1.get_GetObject(1)
For i = 0 To sfPoints.NumShapes - 1
pt = sfPoints.Shape(i).Point(0)
iShp = sfPolygon.PointInShapefile(pt.x, pt.y)
ListBox1.Items.Add(i & " " & pt.x.ToString & " " & pt.y.ToString & " " & iShp)
Next
End Sub
The iShp variable returns (-1, not within any shape) for all of the points. What am I doing wrong?
My plan is to populate one field of the Points datatable with the index of the polygon that it lies within -- the ListBox is just for testing. Is this the correct way to attack this problem (ie, looping through all the points)?
TIA
Re: Point in polygon
Posted by:
jacksonmacd ()
Date: May 12, 2005 03:18PM
Found the answer to the first question -- a call to BeginPointInShapeFile made it work properly.
Re: Point in polygon
Posted by:
stevecaps47 ()
Date: January 03, 2011 02:52PM
Hi, I'm trying to do the exact same thing, how did you/how would someone solve this problem?
I have one layer that is a parcel map, the other point is lat/long points plotted on that map and I'd like to know what parcel each point lays on.
I have one layer that is a parcel map, the other point is lat/long points plotted on that map and I'd like to know what parcel each point lays on.
Sorry, only registered users may post in this forum.


