You are here: > ESRI Forums > arcgis engine forums > Thread Replies

ArcGIS Engine Forums

ArcGIS Engine: ArcObjects .NET API forum

Convert lat/long to Map X/Y then center it   Matthew Yip Dec 27, 2006
Re: Convert lat/long to Map X/Y then center...   Neil Clemmons Dec 28, 2006
Re: Convert lat/long to Map X/Y then center...   Matthew Yip Dec 28, 2006
Re: Convert lat/long to Map X/Y then center...   Neil Clemmons Dec 28, 2006
Re: Convert lat/long to Map X/Y then center...   Matthew Yip Jan 08, 2007
Re: Convert lat/long to Map X/Y then center...   Neil Clemmons Jan 08, 2007
Re: Convert lat/long to Map X/Y then center...   Matthew Yip Jan 08, 2007
Re: Convert lat/long to Map X/Y then center...   Neil Clemmons Jan 08, 2007
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Convert lat/long to Map X/Y then center it 
Author Matthew Yip 
Date Dec 27, 2006 
Message Anyone knows how to convert decimal lat/long to map X/Y units and center it on the map?

Thanks. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Neil Clemmons 
Date Dec 28, 2006 
Message Using ArcObjects, you must create a Point object with the correct geographic coordinate system as its spatial reference. You then project that point into whatever projected coordinate system you want. There are also 3rd party tools that will do this. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Matthew Yip 
Date Dec 28, 2006 
Message Thanks for the reply...
I actually have the following code but doesn't seem going to the correct location. I create a Point then project it NAD83 and center it. It is off from the location 100+ miles for some reason.

All shape files are all in NAD83 format.

Thanks. 
 
IPoint pPoint = new PointClass();
pPoint.X = -80.743;
pPoint.Y = 39.95477;

IProjection pProjection = new ProjectionClass();
ISpatialReferenceFactory pSpatialRefFactory = new SpatialReferenceEnvironmentClass();
pProjection = pSpatialRefFactory.CreateProjection((int)esriSRProjectionType.esriSRProjection_TransverseMercator);
IGeographicCoordinateSystem pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);
pPoint.SpatialReference = pGeographicCoordSys as ISpatialReference;
pPoint.Project(pGeographicCoordSys as ISpatialReference);

axMapControl1.CenterAt(pPoint);
axMapControl1.Refresh();
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Neil Clemmons 
Date Dec 28, 2006 
Message You use the geographic coordinate system to set the point's spatial reference. You then project it into the projected coordinate system. Your code is projecting the point into the same coordinate system. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Matthew Yip 
Date Jan 08, 2007 
Message I'm kind of confused of those projections. Would you try to modify the code I posted? No matter how I change the projection, I am still getting the same wrong location on the map.
Thanks. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Neil Clemmons 
Date Jan 08, 2007 
Message In order to project any geometry (point, polyline, polygon, etc), it must first have an initial spatial reference. If the geometry doesn't have a spatial reference, then you can't project it because the "from" spatial reference is unknown and there is no way for it to know what conversion algorithm to use. You set the spatial reference by setting the geometry's SpatialReference property. Once this is done, you can project it to any projected coordinate system by calling Project and passing in the desired spatial reference.

The code you last posted does not set the initial spatial reference. Explaining it in terms that are more easily understood, it's like converting a length in feet to meters. If I ask you to convert 100 feet to meters, you know how to do that because it's a simple matter of applying a conversion factor. But if I asked you to convert 100 to meters, you can't do that because you don't know what the initial units are. 100 what? You need to know the original units in order to determine what conversion factor to apply.

The code below shows the general way to do this. In this code, fromSpatialReference should be the geographic coordinate system and toSpatialReference should be the projected coordinate system.

The developer help topic for IGeometry::Project also has an example. 
 
Dim point As IPoint
point.SpatialReference = fromSpatialReference
point.PutCoords (x, y)
point.Project(toSpatialReference)
 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Matthew Yip 
Date Jan 08, 2007 
Message Thanks for your valuable input. It's really helpful! I got it working now. Thanks a lot.
Here is the change: 
 
private IGeographicCoordinateSystem m_GeographicCoordinateSystem; 
private IProjectedCoordinateSystem m_ProjectedCoordinateSystem;

....

ISpatialReferenceFactory2 spatRefFact = new SpatialReferenceEnvironmentClass();
m_GeographicCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984);
m_ProjectedCoordinateSystem = spatRefFact.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_World_Mollweide);
axMapControl1.SpatialReference = m_ProjectedCoordinateSystem as ISpatialReference;

....

IPoint pPoint = new PointClass();
//Sample Lat/Lon
double longitude = -81.1538;
double latitude = 39.4421;
pPoint.PutCoords(longitude,latitude);
pPoint.SpatialReference = m_GeographicCoordinateSystem;
pPoint.Project(m_ProjectedCoordinateSystem);
axMapControl1.CenterAt(pPoint);
.....
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert lat/long to Map X/Y then center it 
Author Neil Clemmons 
Date Jan 08, 2007 
Message please mark the question as answered, thanks. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/