Adam Wachowski
Bu B ui il ld d C Co oo or rd di in na at te e Sy S ys st te em m Ob O bj je ec ct t fr f ro om m WK W KT T St S tr ri in ng g
http://69.17.46.171/Site/Thread.aspx?id=28108&ti=632947930186770000 mdsumner on 9/25/2006 2:56 PM (#28109)
Sub Main
Set comps = Document.ComponentSet Set cs = App
ication.NewCoordinateSystemFromTextWKT("PROJCS[""unnamed"",GEOGCS[""GCS_WGS_1984"",DAT UM[""D_WGS_1984"",SPHEROID[""WGS_1984"",6378137.000000,298.257224]],PRIMEM[""Greenwich
"",0.0],UNIT[""Degree"",0.0174532925199433]],PROJECTION[""Orthographic""],PARAMETER[""
Fa
se_Easting"",0.0],PARAMETER[""Fa se_Northing"",0.0],PARAMETER[""
ongitude_Of_Center"",0.0],PARAMETER[""
atitude_Of_Center"",0.0],UNIT[""Meter"",1.0]]") End Sub
Co C on nv ve er rt t a a Po P oi in nt t fr f ro om m Dr D ra aw w in i ng g Co C oo or rd di in na at te e Sy S ys st te em m t to o La L at t/ /L Lo on n
http://69.17.46.171/Site/Thread.aspx?id=166&ti=632079515400000000 adamw on 11/25/2003 8:00 AM (#213)
' Here is the example code that converts a point ' from drawing coordinate system to lat/lon.
{code - temp tag to be replaced}
Option Explicit Sub Main
Dim Pt, Drwg, Converter
Set Pt = Application.NewPoint(1000, 1000) Set Drwg = Document.ComponentSet("Drawing")
Set Converter = Application.NewCoordinateConverter() Converter.Prepare Drwg.CoordinateSystem, _
Application.DefaultCoordinateSystemLatLon
' Following line converts (1000, 1000) from drawing ' coordinate system to lat/lon.
Converter.Convert Pt
Application.Messagebox Pt.X & ":" & Pt.Y End Sub
{/code - temp tag to be replaced}
' Goal is to create a bounding rectangle for each component and store it in a lat/long ' drawing component.
'
' Speaking of drawings, you can project each drawing object to lat/lon and compute ' common bounding box of the projected objects.
'
' Speaking of images and surfaces, while you can project each pixel to lat/lon and ' compute common bounding box of the projected pixels, it might be better to project ' a, say, 10x10 grid that covers the entire component and compute a bounding box of
' that area (in many cases, projecting just the corners will not work).
'
' Case "majorAxis", "eccentricity", "centerX", "centerY", "centerZ"
'
' ignore these cause I don't have a clue as to what they do '
' These are the datum:
' ~~~~~~~~~~~~~~~~~~~
' parameters.majorAxis = size of the major axis in meters.
' eccentricity = square root from (1- (minor*minor)/(major*major)) ' centerX, centerY, and centerZ = offsets to the center of the ellipsoid
relative to WGS 84 in meters.
Ex E xt tr ra ac ct t Ma M ap p La L ay ye er r Co C oo or rd di in na at te e S S ys y st te em m In I nf fo or r ma m at ti io on n to t o Ta T ab bl le e Co C ol lu um mn ns s
' ****************************************************************
' * THE FOLLOWING MANIFOLD-L THREAD GIVES THE BACKGROUND. * ' * THIS IS ADAM'S SUGGESTION IN A SCRIPTED FORM. *
' * L. Ketch - April 9, 2006 *
' ****************************************************************
'
' Sent: Thu 04/06/2006 5:19 PM
' From: David Weinschrott [[email protected]]
' To: [email protected] ' Subject: [Manifold-l] Finding the bad apple '
' I have a map I have been adding stuff to for a couple of weeks. All of a ' sudden things have slowed down a lot. My guess is that one of those layers ' has an odd projection. In my understand, In order to find the bad apple I ' have to find each of those layers in the project mnanager and check its ' projection. Is there any other quicker way -- it would be cool to be able ' to put up a table that would list projections of each layer. One could have ' a button that would change all layers to a selected projection, but that is ' a bit drastic when you don't know which one might need specific projection ' attention.
'
' David J. Weinschrott, PhD '
' ---'
' Sent: Fri 04/07/2006 10:06 AM ' From: [email protected]
' To: [email protected] ' Subject: RE: [Manifold-l] Finding the bad apple '
' > ... it would be cool to be able to put up a table that ' > would list projections of each layer.
'
' Here is what you could do:
'
' Create a table named "Data" with a text column named "Name". Open the table ' and add a record for each component you are interested in. Create a new query ' and set its text to:
'
' SELECT [Name], CoordSys([Name] AS COMPONENT) [CoordSys] INTO [CoordSystems] FROM [Data];
'
' Run the query. Open the resulting table. Right click the "CoordSys" column, ' select Format, set formatting style to "XML" and click OK. Resize the column.
' You should see the name of the coordinate system preset in the first 50 or ' so characters of the XML (between <name> and </name>).
' '
--' Adam Wachowski
' Manifold Development Team
' **************************************************************************
Option Explicit Sub Main()
' Author: Lorne Ketch
' Email: LKetch[at]hfx{dot}eastlink(.)ca Dim Comp
Dim CoordSys_Table Dim Cols, Col Dim Rcrd, Rcrds Dim Active_Window
Dim Coord_Sys, CoordSys_ParmSet Dim Map_Layer, Map_Layers
Set Active_Window = Application.WindowSet.ActiveWindow If Active_Window.Component.Type <> ComponentMap Then
Application.MessageBox "The Active Window must be a Map"
Exit Sub End If
Set Map_Layers = Active_Window.Component.LayerSet Delete_Component("Layer_CoordSystems")
Set CoordSys_Table = Document.NewTable("Layer_CoordSystems") Set Cols = CoordSys_Table.ColumnSet
' NOTE: following 4 lines do not work if run under the Debugger.
' The column name is not changed and the type is not set. You ' get an error later when the code trys to find column "MapLayer"
' Code works fine if not run through the Debugger.
Set Col = Cols.Item(0) Col.Name = "MapLayer"
Col.Type = ColumnTypeWText Col.Size = 100
Set Col = Cols.NewColumn Col.Name = "CoordSys_Name"
Col.Type = ColumnTypeWText Col.Size = 100
Cols.Add(Col)
Set Col = Cols.NewColumn
Col.Name = "Datum"
Col.Type = ColumnTypeWText Col.Size = 100
Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "EllipsoidName"
Col.Type = ColumnTypeWText Col.Size = 100
Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "CoordSys_Unit"
Col.Type = ColumnTypeWText Col.Size = 50
Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "localOffsetX"
Col.Type = ColumnTypeFloat32 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "localOffsetY"
Col.Type = ColumnTypeFloat32 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "localScaleX"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "localScaleY"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "ScaleCorrectionX"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "ScaleCorrectionY"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "FalseEasting"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "FalseNorthing"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "majorAxis"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "Eccentricity"
Col.Type = ColumnTypeFloat64 Cols.Add(Col)
Set Col = Cols.NewColumn Col.Name = "CoordSys_XML"
Col.Type = ColumnTypeWText
Col.Size = 2000 ' >1000 required here or the script fails Cols.Add(Col)
Set Rcrds = CoordSys_Table.RecordSet For Each Map_Layer in Map_Layers
Set Comp = Map_Layer.Component
Set Coord_Sys = Comp.CoordinateSystem
Set CoordSys_ParmSet = Coord_Sys.ParameterSet Rcrds.AddNew()
Set Rcrd = Rcrds.LastAdded
Rcrd.Data("MapLayer") = Comp.Name
Rcrd.Data("CoordSys_Name") = Coord_Sys.Name
Rcrd.Data("Datum") = Coord_Sys.Datum.Name
Rcrd.Data("EllipsoidName") = Coord_Sys.Datum.Ellipsoid.Name Rcrd.Data("CoordSys_Unit") = Coord_Sys.Unit.Name
Rcrd.Data("localOffsetX") = CoordSys_ParmSet.Item("localOffsetX").Value Rcrd.Data("localOffsetY") = CoordSys_ParmSet.Item("localOffsetY").Value Rcrd.Data("localScaleX") = CoordSys_ParmSet.Item("localScaleX").Value Rcrd.Data("localScaleY") = CoordSys_ParmSet.Item("localScaleY").Value Rcrd.Data("ScaleCorrectionX") = CoordSys_ParmSet.Item("ScaleX").Value Rcrd.Data("ScaleCorrectionY") = CoordSys_ParmSet.Item("ScaleY").Value Rcrd.Data("FalseEasting") = CoordSys_ParmSet.Item("FalseEasting").Value Rcrd.Data("FalseNorthing") = CoordSys_ParmSet.Item("FalseNorthing").Value Rcrd.Data("majorAxis") = CoordSys_ParmSet.Item("majorAxis").Value
Rcrd.Data("Eccentricity") = CoordSys_ParmSet.Item("Eccentricity").Value Rcrd.Data("CoordSys_XML") = Coord_Sys.ToXML()
Next
CoordSys_Table.Open() End Sub
' **************************************************************************