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

ArcGIS Engine Forums

ArcGIS Engine: ArcObjects .NET API forum

Convert coordinate system for a shapefile   Grant Yang Jun 20, 2006
Re: Convert coordinate system for a shapefi...   Melita Kennedy Jun 20, 2006
Re: Convert coordinate system for a shapefi...   Grant Yang Jun 22, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Convert coordinate system for a shapefile 
Author Grant Yang 
Date Jun 20, 2006 
Message I am stuck on converting the coordinate system for a shapefile. The function I am doing is like bool ProjectFile(fromShapeFile, toShapeFile) . I am converting any given shapefile to a percific coordinate system, which is
esriSRProjectionType.esriSRProjection_LambertConformalConic. Any opinion is appreciated! 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert coordinate system for a shapefile 
Author Melita Kennedy 
Date Jun 20, 2006 
Message Check out FeatureDataConverter. The input 'featureclass' must have its coordinate system/spatial reference defined. The same for the output geometrydef (which includes a spatial reference).

If at all possible, you do not want to have to create a coordinate system from scratch. Instead figure out a way to get the complete coordinate system information--which probably has an enumeration already. esriSRProjectionType has enumerations for map projections--the math, not complete projected coordinate systems.

If the input/output coordinate systems do not share the same geographic coordinate system (its part of a projected coordsys too), you will also need to decide what geographic/datum transformation to use.

You may want to take a look at the Hitchhiker's Guide to projections and spatial references.

http://edn.esri.com/index.cfm?fa=media.gateway

Melita 
  Melita Kennedy
ESRI Product Specialist 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Convert coordinate system for a shapefile 
Author Grant Yang 
Date Jun 22, 2006 
Message Thanks Melita for your answer. Here I have used your suggestion to make conversion as in code below below, in C#. When it runs it popup error when convert at pFConverter.ConvertFeatureClass(pFeatureClassNameInput, null, null,pFCNameout, pGeomDef, myfieldsout, "", 1000, 0);
I am wonder that the dataset I have given here may be wrong. Any ieda will be great helpful.
Note: CreateShapeFileForProjection(...) is another class to create a shapefile with exact same fields as above.
Thanks!

 
 
//pFeatureClassNameInput
 IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
 IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile("C:\\gisdata", 0) as IFeatureWorkspace;
 IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass("ramshape");
IFeatureClassName pFeatureClassNameInput = (IFeatureClassName)((IDataset)pFeatureClass).FullName;


//Output
IFields myfieldsout = new FieldsClass();
IFieldsEdit myfiedseditout= (IFieldsEdit)myfieldsout;
IFeatureClass pFCout = CreateShapeFileForProjection("c:\\gisdata\\", "newshpname", out myfiedseditout);
IFeatureClassName pFCNameout = (IFeatureClassName)((IDataset)pFCout).FullName;
IDataset pDout = (IDataset)pFCout;
IGeometryDef pGeomDef = new GeometryDefClass();
IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;
ISpatialReference pSR = axMapControlMain.SpatialReference;
pGeomDefEdit.GeometryType_2 = pFeatureClass.ShapeType;
pGeomDefEdit.SpatialReference_2 = pSR;

//Convert
IFeatureDataConverter pFConverter = new FeatureDataConverterClass();
pFConverter.ConvertFeatureClass(pFeatureClassNameInput, null, null,pFCNameout, pGeomDef, myfieldsout, "", 1000, 0);