Select to view content in your preferred language

Problem / Question on projections

4042
12
09-29-2010 09:57 AM
BobPokorny
Emerging Contributor
Hi all:

I have spent countless hours trying to understand projections and conversions, etc...

I think I have a fairly simple an common question, although trying to weed through the code examples and documentation, I have been unsuccessful in finding a solution.

A little background:

I have a map that appears to be displaying x/y in Virginia State Plane (ex: 3367638.0705937, 11241037.076929).  It appears to be in feet.??

I have a coordinate of 42.234234, -79.234234 for example, which is WGS-1984?  When I try to perform a map.putcoords(x,y), it puts me in the middle of the ocean somewhere.

I'm not 100% exactly sure what I am looking for, but I know I need to do the following:
Take the example coordinates (show above), convert them to Virginia State Plane?
Move or Pan the map to that location and put a point on the map.

Sounds easy, right?!  Here is some [incomplete] example code that I have done so far. 

            Dim pSpatRefFact As ISpatialReferenceFactory2
            pSpatRefFact = New SpatialReferenceEnvironmentClass

            m_pGeographicCoordinateSystem = pSpatRefFact.CreateGeographicCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)

            m_pProjectedCoordinateSystem = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_NAD1983HARNSPCS_VANorth)

        Dim p As IPoint
        p = New Point

        p.PutCoords(-79.23452, 42.231123)
        p.SpatialReference = m_pGeographicCoordinateSystem
        p.Project(m_pProjectedCoordinateSystem)

Couple issues:
I'm not sure I am using or understand the PCS is the correct one.  That should be what projections my map is currently in - right?
Secondly, when I enter the code: pSpatRefFact = New SpatialReferenceEnvironmentClass, I get an error telling me 'Interop type 'SpatialReferenceEnvironmentClass' cannot be embedded.  Use the applicable interface instead.'

This is code taken directly from an example.  I am using VS2010 .Net 4.0 w/ArcEngine 10.0 if that matters at all.

Coule someone please provide me an accurate, working example of how to convert WGS1984 to Virginia State Plane, pan the map to the appropriate coordinate and place a simple point on the map?  This is becoming very frustrating and time consuming.

Lastly, are there webinars, videos, etc... that can shed some light on these issues?

Thanks for your help.
Bob
bobp@group1inc.com
0 Kudos
12 Replies
KonstantinosMeintanis
Emerging Contributor
Hi Melita,

Thank you for your response. Yes, I have tried the suggestions provided in the earlier posts and the ESRI webpage. What do you mean "setting the licensing information"? What I basically do is that I bind the ArcGIS runtime (it works fine), then check if the product is available (using esriLicenseProductCodeEngine) and finally initialize the license using the ESRI.ArcGIS.esriSystem.IAoInitialize class (this step returns "esriLicenseCheckedOut" - a confirmation that the initialization was successful). Again, the part that fails is the code that creates an instance of the ISpatialReferenceFactory3. I'm referencing libraries from the ArcObjects .NET SDK, do I need to do any COM registration? Running out of ideas ...

Thanks,
K.
0 Kudos
KonstantinosMeintanis
Emerging Contributor
Hi again,

After some testing I have realized that the instantiation of any of the classes in the Esri.ArcGIS.Geometry.dll throws the same exception. So, it's not a problem with the class (ISpatialReferenceFactory3) but with the whole library. Other ESRI dlls work fine (e.g. Esri.ArcGIS. Geodatabase). I never had problems with any of the dlls when I was using the v.9.3. Are there any dependencies of the Geometry.dll with other libraries that I'm not aware of? Is the ArcGIS engine license sufficient for using the Geometry.dll? Please provide help.

Thanks,
K.
0 Kudos
JustinWilliams
Emerging Contributor
Try this,

SpatialReferenceEnvironment spatialRefEnv = SpatialReferenceEnvironment();
ISpatialReferenceFactory2 spatialRefFactory = (ISpatialReferenceFactory2)spatialRefEnv;

As an alternative, if you have a class from an assembly that cannot embed you can set the 'Embed interop types' property
on the assembly reference in your solution explorer to false and that should be another option for you.

Justin
GIS Developer
Indiana Dept. of Homeland Security
0 Kudos