shapeObj.getCentroid question - Mapscript_csharp
David Lowther
dlowther at COORDINATESOLUTIONS.COM
Thu Mar 29 14:12:04 PDT 2007
Sorry for the mass postings.
I've noticed that getCentroid behaves differently after projection of the
shapeObj based on whether you reproject the shape or a clone of the shape.
Not clear? No lie, I had a hard time typing the sentence.
In the following example you can see that I can get the right answer, I was
just wondering if someone could explain the difference in behavior.
Here's an example:
Partial Class ProjectPointGetCentroid
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'//project a shapeObj and getCentroid returns coordinates in
previous projection
TestProjectNOClone()
TestProjectClone()
End Sub
Private Sub TestProjectNOClone()
'//Incorrect Result
'//pCent will equal oCent
Dim albProj As String = "+proj=aea +lat_1=29.500000000
+lat_2=45.500000000 +lat_0=23.000000000 " _
& "+lon_0=-96.000000000 +x_0=0.000 +y_0=0.000 +datum=NAD83
+ellps=GRS80 +no_defs"
Dim llProj As String = "+proj=longlat +ellps=GRS80 + no_defs"
Dim shp As New shapeObj(MS_SHAPE_TYPE.MS_SHAPE_POLYGON)
Dim shp2 As New shapeObj(MS_SHAPE_TYPE.MS_SHAPE_POLYGON)
Dim line As New lineObj()
Dim pt As New pointObj(-100, 35, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-100, 36, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-101, 36, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-101, 35, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-100, 35, Nothing, Nothing)
line.add(pt)
shp.add(line)
Dim oCent As pointObj = shp.getCentroid()
Dim result As Integer
result = shp.project(New projectionObj(llProj), New
projectionObj(albProj))
Dim pCent As pointObj = shp.getCentroid()
End Sub
Private Sub TestProjectClone()
'//Correct Result
'//pCent will NOT equal oCent
Dim albProj As String = "+proj=aea +lat_1=29.500000000
+lat_2=45.500000000 +lat_0=23.000000000 " _
& "+lon_0=-96.000000000 +x_0=0.000 +y_0=0.000 +datum=NAD83
+ellps=GRS80 +no_defs"
Dim llProj As String = "+proj=longlat +ellps=GRS80 + no_defs"
Dim shp As New shapeObj(MS_SHAPE_TYPE.MS_SHAPE_POLYGON)
Dim shp2 As New shapeObj(MS_SHAPE_TYPE.MS_SHAPE_POLYGON)
Dim line As New lineObj()
Dim pt As New pointObj(-100, 35, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-100, 36, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-101, 36, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-101, 35, Nothing, Nothing)
line.add(pt)
pt = New pointObj(-100, 35, Nothing, Nothing)
line.add(pt)
shp.add(line)
Dim oCent As pointObj = shp.getCentroid()
Dim pShp As shapeObj
pShp = shp.clone()
Dim result As Integer
result = pShp.project(New projectionObj(llProj), New
projectionObj(albProj))
Dim pCent As pointObj = pShp.getCentroid()
End Sub
End Class
Thanks,
David Lowther
Coordinate Solutions, Inc.
501 N.E. 15th Street
Oklahoma City, OK 73104
405.246.9396 (Voice)
904.471.5548 (Fax)
www.coordinatesolutions.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20070329/9c5eef64/attachment.htm>
More information about the MapServer-users
mailing list