AnsweredAssumed Answered

Converting to map coordinates in 10.1

Question asked by oblique on Aug 29, 2012
Latest reply on Aug 30, 2012 by oblique
We have a bounding polygon in WGS 84 coordinates that we need to draw on the map.  The users map data could be anything.  The following code works in ArcMAP 10.0 (and prior) but does not work in 10.1 if the factory code is zero.  Unfortunately a lot of shape files our customers use seem to have valid projection files but no factory codes.  They show up in the dataframe properties a "custom" coordinate systems. 
In 10.1 is there anyway to create a coordinate system if you have a spatial reference but no factory code? 
Or be able to convert a WGS84 point to a "custom" coordinate?
Perhaps I should ask the high level generic question as well.  How can I convert a WGS84 coordinate into the maps coordinate system which can be anything ArcMAP supports.


 Public Function ConvertToMap(ByVal lat As Double, ByVal lon As Double, ByVal elev As Double, ByVal layer As ILayer) As IPoint         'Convert x and y to map units. m_pApp is set in ICommand_OnCreate.         Dim pMxApp As IMxApplication         Dim mapPoint As IPoint         Dim pPoint As Point      ' = m_mapPoint         Dim sMessage As String = ""         pMxApp = m_pApp          mapPoint = pMxApp.Display.DisplayTransformation.ToMapPoint(0, 0)         Dim pSpatialRefFactory As ISpatialReferenceFactory         pSpatialRefFactory = New SpatialReferenceEnvironment         Dim pGeographicCoordinateSystem As IGeographicCoordinateSystem         pGeographicCoordinateSystem = pSpatialRefFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)         pPoint = mapPoint          ' Set the Spacial Ref. to WGS 84         pPoint.Project(pGeographicCoordinateSystem)         pPoint.X = lon         pPoint.Y = lat         Dim code As Integer         Dim pProjectedCoordinateSystem As IProjectedCoordinateSystem         code = pMxApp.Display.DisplayTransformation.SpatialReference.FactoryCode()         ' Dont' know if map is in Geographic or Projected coordinate system so try both.        Try            pProjectedCoordinateSystem = pSpatialRefFactory.CreateProjectedCoordinateSystem(code)            pPoint.Project(pProjectedCoordinateSystem)        Catch ex As Exception            pGeographicCoordinateSystem = pSpatialRefFactory.CreateGeographicCoordinateSystem(code)            pPoint.Project(pGeographicCoordinateSystem)        End Try          Return pPoint     End Function