Select to view content in your preferred language

Problem / Question on projections

3666
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
NeilClemmons
Honored Contributor
You're using the HARN PCS which probably isn't the VA State Plane that you want.  Since you're needing to project your coordinates into the PCS of the map, then just get the spatial reference of the map instead of creating it using the spatial reference environment.  This will make your code work no matter what spatial reference the map is in.  You'll still need to create the GCS according to whatever system your input coordinates are in.  Unless, of course, you're getting those from a feature class or something that also has a spatial reference (in which case, just get the SR from that instead of creating it).  As for your error, try using SpatialReferenceEnvironment (without the Class on the end).
0 Kudos
MelitaKennedy
Esri Notable Contributor
You're using the HARN PCS which probably isn't the VA State Plane that you want.  Since you're needing to project your coordinates into the PCS of the map, then just get the spatial reference of the map instead of creating it using the spatial reference environment.  This will make your code work no matter what spatial reference the map is in.  You'll still need to create the GCS according to whatever system your input coordinates are in.  Unless, of course, you're getting those from a feature class or something that also has a spatial reference (in which case, just get the SR from that instead of creating it).  As for your error, try using SpatialReferenceEnvironment (without the Class on the end).


If the sample projected point is in Pittsylvania or Danville area, then the pcs is Virginia South, using US survey feet. Could be based on NAD83 or NAD83 HARN. The 11 million value is the easting or X value. The PCS you have below is using meters, rather than feet. Try

esriSRProjCS_NAD1983SPCS_VASouthFT

or

esriSRProjCS_NAD1983HARN_StatePlane_Virginia_South_FIPS_4502_Ft

However, the lat/lon you have (42.234234, -79.234234) is in west New York state. Latitude values for very southern Virginia should be around 36.6.

Some possible references are:

Hitchhiker's Guide to coordinate systems
http://edn.esri.com/index.cfm?fa=media.detail&media=54

2010 Esri Developer's Summit: Understanding and using the geometry ...
http://proceedings.esri.com/library/userconf/devsummit10/tech/tech_58.html

Understanding map projections and coordinate systems ($145, no programming)
http://training.esri.com/acb2000/showdetl.cfm?DID=6&Product_ID=697

Melita
0 Kudos
BobPokorny
Emerging Contributor
Thanks for all the comments, feedback and help.

I removed 'Class' from SpatialReferenceEnvironment and receive another COM exception:

Retrieving the COM class factory for component with CLSID {7B5B7020-C4F6-11D1-BC92-0000F875BCCE} failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).

I'm not a COM developer, so this is a little foreign to me.

A bit more on the map I am using.  I was handed a MXD file that has Virginia's map data (Danville area), and in order to track across the US, ESRI's North America Street Map data was also added.  The map as previously indicated should be projected in the Virginia State Plane.  I did change by PCS to esriSRProjCSType.esriSRProjCS_NAD1983SPCS_VASouthFT, but as I mentioned, I get the error mentioned above.

If I can get past that error, that would be great.  Is there something I have to do to put a wrapper around Arc Objects COM object?

Thanks for the help.
Bob
0 Kudos
MelitaKennedy
Esri Notable Contributor
Thanks for all the comments, feedback and help.

I removed 'Class' from SpatialReferenceEnvironment and receive another COM exception:

Retrieving the COM class factory for component with CLSID {7B5B7020-C4F6-11D1-BC92-0000F875BCCE} failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).

I'm not a COM developer, so this is a little foreign to me.

A bit more on the map I am using.  I was handed a MXD file that has Virginia's map data (Danville area), and in order to track across the US, ESRI's North America Street Map data was also added.  The map as previously indicated should be projected in the Virginia State Plane.  I did change by PCS to esriSRProjCSType.esriSRProjCS_NAD1983SPCS_VASouthFT, but as I mentioned, I get the error mentioned above.

If I can get past that error, that would be great.  Is there something I have to do to put a wrapper around Arc Objects COM object?

Thanks for the help.
Bob


Hi Bob,

I tell people that I'm barely a programmer (I do enough for testing, but it sure isn't 'elegant') so I can't tell if you're using VB6 or VB.Net code, or maybe something else.

For VB6, try

   Dim pSpatRefFact As SpatialReferenceEnvironment
   Set pSpatRefFact = New SpatialReferenceEnvironment

and you also need to use

   Set pGCS = pSpatRefFact.CreateGeographicCoordinateSystem(enum)

For VB.Net, try

        Dim t As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
        Dim obj As System.Object = Activator.CreateInstance(t)
        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 = obj


Melita
0 Kudos
WeiChen
Deactivated User
Hi Bob,

I tell people that I'm barely a programmer (I do enough for testing, but it sure isn't 'elegant') so I can't tell if you're using VB6 or VB.Net code, or maybe something else.

For VB6, try

   Dim pSpatRefFact As SpatialReferenceEnvironment
   Set pSpatRefFact = New SpatialReferenceEnvironment

and you also need to use

   Set pGCS = pSpatRefFact.CreateGeographicCoordinateSystem(enum)

For VB.Net, try

        Dim t As Type = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
        Dim obj As System.Object = Activator.CreateInstance(t)
        Dim pSpatRefFact As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3 = obj


Melita


I have similar problem when I tried to migrate my 9.3 C# code to 10.0.
I got error message for
ISpatialReferenceFactory spatialReferenceFactory2 = new SpatialReferenceEnvironmentClass();
the error message is "Retrieving the COM class factory for component with CLSID {7B5B7020-C4F6-11D1-BC92-0000F875BCCE} failed due to the following error: 80040111."

Then I tried to use activator so I revised the code to following:
// Set up the SpatialReferenceEnvironment.
            // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
            System.Object object1 = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory2 spatialReferenceFactory2 = object1 as ISpatialReferenceFactory2;

However, I still got the same error message.

Can anyone help on this one?

Thanks a lot.

Wei
0 Kudos
MelitaKennedy
Esri Notable Contributor
I have similar problem when I tried to migrate my 9.3 C# code to 10.0.
I got error message for
ISpatialReferenceFactory spatialReferenceFactory2 = new SpatialReferenceEnvironmentClass();
the error message is "Retrieving the COM class factory for component with CLSID {7B5B7020-C4F6-11D1-BC92-0000F875BCCE} failed due to the following error: 80040111."

Then I tried to use activator so I revised the code to following:
// Set up the SpatialReferenceEnvironment.
            // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
            Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
            System.Object object1 = Activator.CreateInstance(factoryType);
            ISpatialReferenceFactory2 spatialReferenceFactory2 = object1 as ISpatialReferenceFactory2;

However, I still got the same error message.

Can anyone help on this one?

Thanks a lot.

Wei


Hi Wei,

Another post with a similar issue said that he needed to add this:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);

(or other licensing information).

Melita
0 Kudos
WeiChen
Deactivated User
Hi Wei,

Another post with a similar issue said that he needed to add this:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);

(or other licensing information).

Melita


Hello Melita,
Thanks for the reply.

I still got the same error message after adding the line. By the way, I am using ArcGIS Desktop 10 concurrent license. The code worked well with ArcGIS Desktop 9.3concurrent license. Then I realized that I should use ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop). It works this time.

For other people who may have similar problem like me, please refer to http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_migrate_ArcGIS_9... for "Migrating an ArcGIS 9.3 application to 10 using the LicenseControl".

Thanks a lot,
Wei
0 Kudos
KonstantinosMeintanis
Emerging Contributor
Hi,

I'm trying also to migrate my code from v9.3 (where it runs fine) to v10 but without any success. The error I'm getting is the same to what the other folks report here: "Retrieving the COM class factory for component with CLSID {7B5B7020-C4F6-11D1-BC92-0000F875BCCE} failed due to the following error: 80040111". I have followed all the instructions posted on the ESRI website about the migration. My code uses only the ArcGIS engine and debugging completes with no errors (C#, VS2008SP1). The binding to the appropriate ArcGIS runtime works fine, the license initialization the same but when I try to create a new instance of the SpatialReferenceEnvironment I get the exception above. In case you are wondering, the ArcGIS Migration Code Analyzer doesn't throw any errors when I test my projects (only a warning that I have to change the target CPU to x86). Can somebody help?

Thanks
K.
0 Kudos
MelitaKennedy
Esri Notable Contributor
Hi,

I'm trying also to migrate my code from v9.3 (where it runs fine) to v10 but without any success. The error I'm getting is the same to what the other folks report here: "Retrieving the COM class factory for component with CLSID {7B5B7020-C4F6-11D1-BC92-0000F875BCCE} failed due to the following error: 80040111". I have followed all the instructions posted on the ESRI website about the migration. My code uses only the ArcGIS engine and debugging completes with no errors (C#, VS2008SP1). The binding to the appropriate ArcGIS runtime works fine, the license initialization the same but when I try to create a new instance of the SpatialReferenceEnvironment I get the exception above. In case you are wondering, the ArcGIS Migration Code Analyzer doesn't throw any errors when I test my projects (only a warning that I have to change the target CPU to x86). Can somebody help?

Thanks
K.


Hi,

Are you setting the licensing information? See earlier posts in this thread, or this blog entry:

Migrating to Engine 10

Melita
0 Kudos