Select to view content in your preferred language

Trying to create a spatial reference - crashing

2840
10
Jump to solution
12-09-2013 08:46 AM
deleted-user-VeC5jUIlNXtq
Deactivated User
Hey folks,

I'm at a loss as to what's going on. This code (from what I can remember) was working before I left on Friday, yet this morning during testing I'm getting a crash.

Quick explanation, it's part of a larger program to convert a GPX file into a feature class in a file geodatabase. Everything is great except when I try to determine the point's UTM coordinates. For those familiar, I'm in Canada where we use the dominion land survey. Long story short W4M = UTM Zone 12, W5M (and part of 6) is Zone 11. The code loops through the point and determines a bunch of locational information such as decimal degrees, the LSD-SEC-TWP ... etc...

Here's the troublesome code:

             Dim pPCS As IProjectedCoordinateSystem             Dim pSRFactory As ISpatialReferenceFactory2             Dim pSpatialReference As ISpatialReference             Dim pGeometry As IGeometry             Dim pGeogPoint As IPoint              pSRFactory = New SpatialReferenceEnvironment              If iMer = 4 Then                 pPCS = pSRFactory.CreateProjectedCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_NAD1983UTM_12N)                 sZone = "12U"             ElseIf iMer = 5 Or iMer = 6 Then                 pPCS = pSRFactory.CreateProjectedCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N)                 sZone = "11U"             Else                 pPCS = Nothing                 sZone = "xxx"             End If              pSpatialReference = pPCS             pSpatialReference.SetFalseOriginAndUnits(200000, 4000000, 100)              pGeogPoint = pFreshPoint             pGeometry = pGeogPoint             pGeometry.Project(pSpatialReference)


From what I can see, it makes it to my If statement, then crashes. I think the problem is the "pPCS = pSRFactory.CreateProjectedCoordinateSystem" line.

I can't see what I'm doing wrong, all the snippets I've seen, have similar code setup. Any sort of help is much appreciated.

Edit: pFreshPoint is a point feature (we're currently in a larger Do loop to run through the points and perform this to each point). Let me know if more info is required.
0 Kudos
10 Replies
deleted-user-VeC5jUIlNXtq
Deactivated User
I put the code from above into a try block with:

             Try                 Dim pPCS As IProjectedCoordinateSystem                 Dim pSRFactory As ISpatialReferenceFactory2                 Dim pSpatialReference As ISpatialReference                 Dim pGeometry As IGeometry                 Dim pGeogPoint As IPoint                  pSRFactory = New SpatialReferenceEnvironment                  If iMer = 4 Then                     pPCS = pSRFactory.CreateProjectedCoordinateSystem(26911)                     sZone = "12U"                 ElseIf iMer = 5 Or iMer = 6 Then                     pPCS = pSRFactory.CreateProjectedCoordinateSystem(26912)                     sZone = "11U"                 Else                     pPCS = Nothing                     sZone = "xxx"                 End If                  pGeogPoint = pFreshPoint                 pSpatialReference = pPCS                 pSpatialReference.SetFalseOriginAndUnits(200000, 4000000, 100)                  pGeometry = pFreshPoint                 pGeometry.Project(pSpatialReference)             Catch ex As Exception                 ' Print generic exception messages.                 Console.WriteLine(ex.Message)              End Try


and it essentially 'skips' the entire try block and proceeds with the remainder of the program.

It finishes the program successfully (no more crash), but no message is printed.

Any thoughts?

Edit: ok I'm successfully able to create a projected coordinate system in a different part of the module (the main sub).

There must be something limiting me within the sub I'm working in...somehow.

Edit 2: Some success finally. I decided to create a simple function of type spatial reference, pass my integer (for Meridian) and create the spatial reference, then return it. This appears to have worked...fingers crossed!
0 Kudos