Does ThinkGeo have the ability to perform interpolation like the MapInfo Inverse Distance Weighting (IDW) Interpolator?
If so, do you have an example?
Does ThinkGeo have the ability to perform interpolation like the MapInfo Inverse Distance Weighting (IDW) Interpolator?
If so, do you have an example?
I should say I’m trying to create a IDW interpolated grid layer based on points. I’d rather not create a grid file using another library and load it using ThinkGeo if all possible.
Actually, we have a blog that shows how to create a GRID from some sample points using the IDW interpolation.
gis.thinkgeo.com/Support/Discussion...fault.aspx
As you can see, this is for 2.x and in 3.x, we don't have the API yet for creating a GRID. We currently can also display one as you can see in the sample app of "How Do I" Load a GridFileFeatureLayer in the DataProviders section.
Now, I don't know in what context, you want to use the IDW interpolation. Using a GRID or something else. In any case, you can see that you can get the IDW interpolation algorithm as the code for it can be found in the CalculatecellValueHandlerIDW in the blog.
Private Sub CalculateCellValueHandlerIDW(ByVal CellExtent As StraightRectangle, ByRef CellValue As Double)
Dim CellULx As Double = CellExtent.UpperLeftPoint.X
Dim CellULy As Double = CellExtent.UpperLeftPoint.Y
Dim CellLRx As Double = CellExtent.LowerRightPoint.X
Dim CellLRy As Double = CellExtent.LowerRightPoint.Y
Dim xp As Double = CellExtent.Center.X
Dim yp As Double = CellExtent.Center.Y
Dim CellCenterPointShape As New PointShape(xp, yp)
Dim CenterRecords() As Integer = Map1.Layers(0).QueryByDistance(CellExtent, 15, MapLengthUnits.metres, Map1.MapUnit)
If CenterRecords.GetLength(0) = 1 Then
Dim NearestRecords() As Integer = Map1.Layers(1).QueryByDistance(CellCenterPointShape, 200, MapLengthUnits.metres, Map1.MapUnit)
If NearestRecords.GetLength(0) > 0 Then
Dim NearestPointShapes() As PointShape = CType(Map1.Layers(1).GetShapes(NearestRecords), PointShape())
Dim NearestValues(NearestRecords.GetLength(0) - 1) As String
For i As Integer = 0 To NearestRecords.GetLength(0) - 1
NearestValues(i) = Map1.Layers(1).DataQuery(NearestRecords(i), "pH")
Next i
'This is the algorithm for IDW interpolation
Dim Power As Double = 2
Dim Zi, Zx1, Zx2, Zx, Di As Double
For i As Integer = 0 To NearestValues.GetLength(0) - 1
Zi = CDbl(NearestValues(i))
Di = CellCenterPointShape.DistanceTo(NearestPointShapes(i), Map1.MapUnit, MapLengthUnits.metres, DistanceTypes.Shortest)
Zx1 = Zx1 + (Math.Pow((1 / Di), Power) * (Zi))
Zx2 = Zx2 + ((Math.Pow((1 / Di), Power)))
Next
Zx = Zx1 / Zx2
CellValue = Zx
Else
CellValue = -9999
End If
Else
CellValue = -9999
End If
End Sub
This is what I was looking for. Thanks.
Peter,
I am glad that it’s working with you, Thank Val very much.
If you don’t mind, I will close this post.
James
Peter,
I want to let you know that we posted a new sample in the Code Community for creating GRID using the IDW interpolation interpolation. You may want to check it if you are interested, Create GRID: wiki.thinkgeo.com/wiki/Map_Suite_De...reate_GRID
Thank you.