Author Topic: GeoLocationData ScaleFactor returns wrong value  (Read 2137 times)

0 Members and 1 Guest are viewing this topic.

neyton

  • Newt
  • Posts: 68
GeoLocationData ScaleFactor returns wrong value
« on: September 26, 2015, 08:22:10 AM »
Hi,

I'm a Civil 3D user and I'm trying to implement this code to convert local coordinates (x,y) to UTM grid coordinates (north, east):

Dim gd As GeoLocationData = DB.GeoDataObject.GetObject(OpenMode.ForRead)

Dim m As Matrix3d = Matrix3d.Displacement(gd.DesignPoint.GetVectorTo(gd.ReferencePoint))

m = m * Matrix3d.Rotation(gd.NorthDirection, gd.UpDirection, gd.DesignPoint)

m = m * Matrix3d.Scaling(gd.ScaleFactor, gd.DesignPoint)

Dim ptUTM as Point3d = ptLOCAL.TransformBy(m)

But, gd.ScaleFactor always return 1, even if gd.ScaleEstimationMethod = ScaleEstimationMethod.ScaleEstMethodReferencePoint

Note: Civil 3D return correct value:
Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument.Settings.DrawingSettings.TransformationSettings.GridScaleFactor

What is wrong? Did I miss something?
Visit my website: http://tbn2.blogspot.com

Sheldon1874

  • Mosquito
  • Posts: 19
Re: GeoLocationData ScaleFactor returns wrong value
« Reply #1 on: October 08, 2015, 08:25:06 PM »
So I know nothing about the flavor of autoCAD you are using.  What I do know about is geomatics.  First thoughts are:  are you using enough precession.  Scale factors for a particular projection are often very close to 1, 0.997 is the starting point for my local circumstance.  Second: you can't scale and rotate using a point, you need vectors.  Like I said not sure how   "Matrix3d.Rotation" and "Matrix3d.Scaling" work but they must need vectors not points?

neyton

  • Newt
  • Posts: 68
Re: GeoLocationData ScaleFactor returns wrong value
« Reply #2 on: October 28, 2015, 02:37:59 PM »
Hello,
The precision is required for the calculation of UTM coordinates are equal to those that appear in traditional programs. Actually, I'm writing a program that creates  descriptive memorials of parcels and who will work within AutoCAD. In many cases, the user wants a memorial appear where the coordinates of the vertices of the lot, but the design generally is in local coordinates. Then the program must have the ability to convert, but should show correct results for the description.
See this program : http://tbn2net.appspot.com/download?pacid=C3DMEMO&lang=en

Visit my website: http://tbn2.blogspot.com

Gasty

  • Newt
  • Posts: 90
Re: GeoLocationData ScaleFactor returns wrong value
« Reply #3 on: October 31, 2015, 07:23:52 PM »
Hi,

What do you mean by "local coordinates", a local coordinate system may be anything, x,y (units?) means nothing without a global reference in a geographic sense.
As for the conversion, and given that you are in Civil 3D, a product that includes Map, you can use a query to transform from one system to another, assuming  that you have a well defined local system. A program to convert to UTM *must* know (or be able to infer from the local system definition) at least the UTM Zone number.

Gaston Nunez




neyton

  • Newt
  • Posts: 68
Re: GeoLocationData ScaleFactor returns wrong value
« Reply #4 on: November 04, 2015, 09:10:59 AM »
Local coordinate  are arbitrated. To calculate the area of a property, we use local coordinates because there is no distortion. The georeferencing is given in UTM coordinates or even geographic coordinates. But the area of the property can not be determined with UTM coordinates as there is distortion, so you need to convert

In general, it converts to a geocentric system, obtaining geocentric coordinates for the vertices to then calculate the area.
The GeoLocationData class does the conversion of geographical coordinates for local coordinates (autocad wcs) and vice versa, but does not to UTM coordinates
I implemented a code to do this:

Code: [Select]
<Extension()>
    Function TransformToUTM(gd As GeoLocationData, ByVal local As Point3d) As Point3d
        Dim geo As Point3d = gd.TransformToLonLatAlt(local)
        Dim latd = geo.Y
        Dim lngd = geo.X
        Dim drad = Math.PI / 180.0

        Dim xDoc As New XmlDocument
        xDoc.LoadXml(gd.CoordinateSystem)

        Dim SemiMajorAxis As Double = CDbl(xDoc.GetElementsByTagName("SemiMajorAxis").Item(0).InnerText)
        Dim b As Double = CDbl(xDoc.GetElementsByTagName("SemiMinorAxis").Item(0).InnerText)
        Dim k0 = 0.9996
        Dim e = Math.Sqrt(1 - (b / SemiMajorAxis) * (b / SemiMajorAxis))
        Dim phi = latd * drad
        Dim lng = lngd * drad
        Dim utmz = 1 + Math.Floor((lngd + 180) / 6)
        Dim zcm = 3 + 6 * (utmz - 1) - 180
        Dim e0 = e / Math.Sqrt(1 - e * e) 'Called e prime In reference
        Dim esq = (1 - (b / SemiMajorAxis) * (b / SemiMajorAxis)) ' e squared For use In expansions
        Dim e0sq = e * e / (1 - e * e) ' e0 squared - always even powers
        Dim N = SemiMajorAxis / Math.Sqrt(1 - Math.Pow(e * Math.Sin(phi), 2))
        Dim T = Math.Pow(Math.Tan(phi), 2)
        Dim C = e0sq * Math.Pow(Math.Cos(phi), 2)
        Dim A = (lngd - zcm) * drad * Math.Cos(phi)
        Dim M0 = 0
        Dim M = phi * (1 - esq * (1 / 4 + esq * (3 / 64 + 5 * esq / 256)))
        M = M - Math.Sin(2 * phi) * (esq * (3 / 8 + esq * (3 / 32 + 45 * esq / 1024)))
        M = M + Math.Sin(4 * phi) * (esq * esq * (15 / 256 + esq * 45 / 1024))
        M = M - Math.Sin(6 * phi) * (esq * esq * esq * (35 / 3072))
        M = M * SemiMajorAxis 'Arc length along standard meridian
        Dim x = k0 * N * A * (1 + A * A * ((1 - T + C) / 6 + A * A * (5 - 18 * T + T * T + 72 * C - 58 * e0sq) / 120)) 'Easting relative To CM
        x = x + 500000 'Easting standard
        Dim y = k0 * (M - M0 + N * Math.Tan(phi) * (A * A * (1 / 2 + A * A * ((5 - T + 9 * C + 4 * C * C) / 24 + A * A * (61 - 58 * T + T * T + 600 * C - 330 * e0sq) / 720)))) 'Northing from equator

        If (y < 0) Then y = 10000000 + y
        Return New Point3d(x, y, local.Z)
    End Function
Visit my website: http://tbn2.blogspot.com

neyton

  • Newt
  • Posts: 68
Re: GeoLocationData ScaleFactor returns wrong value
« Reply #5 on: November 04, 2015, 09:17:58 AM »
The function receives a 3dpoint as local coordinate (autocad wcs) and convert to UTM
Visit my website: http://tbn2.blogspot.com

Sheldon1874

  • Mosquito
  • Posts: 19
Re: GeoLocationData ScaleFactor returns wrong value
« Reply #6 on: December 08, 2015, 08:27:15 PM »
Interesting discussion.

When I hear "Local Grid Coordinates" I first think of a planner grid based on an arbitrary origin, something like 1000,2000,100 with north being selected to make design simple (front of a building square to the screen).  Probably from real world measurements. This then gives you the problem of generating vectors for a grid shift to the new grid.