shapeObj.getCentroid question - Mapscript_csharp

Umberto Nicoletti umberto.nicoletti at GMAIL.COM
Thu Mar 29 23:34:52 PDT 2007


Which one do you find to be correct: the centroid of the clone or of
the original shape? It *could* be that the clone function is not
entirely correct.

Umberto

On 3/29/07, David Lowther <dlowther at coordinatesolutions.com> wrote:
>
>
>
>
> 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



More information about the MapServer-users mailing list