shapeObj.getCentroid question - Mapscript_csharp

David Lowther dlowther at COORDINATESOLUTIONS.COM
Fri Mar 30 07:08:45 EDT 2007


I find TestProjectClone to be correct. TestProjectNOClone returns .bounds in
a different projection than .getCentroid.

David Lowther
 
 

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of Umberto Nicoletti
Sent: Friday, March 30, 2007 2:35 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] shapeObj.getCentroid question -
Mapscript_csharp

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