Question

Creating shapeFile in arcEngine and adding to Globe control application

Asked by: Joeller

Hey guys; Sad to say I entered all of this before then pushed the wrong button and lost everything.  So i am entering it again, hoping I remembered everything.  

I am creating a shapefile in ArcObjects using code esri provided in one of their examples.  I used their code to create the workspace, create the IFields object, to create the the spatial reference of the shape field, create the feature class then add the polygon to the feature class and add the shape file as a layer to the globe control.  everything wokrs great except for the following, one the shape is displayed half a world away from where it is supposed to be.  and two, whe I use the UnitConverter.ConvertUnits method to convert meters to mapunit's I get a shape .0001 the size that it is supposed to be but if I just pass in meters then the shape is the correct size.  The shape is supposed to be located at 37.9166 N 86.0 W (or 37.9166, -86).  It actually ends up at 0 N .0001 W (0, -.0001)  so if anyone can give me a hand with this in a time sensitive manner I would be appreciative.  I am allocating what I believe is all my remaining points to this questions.  I need to know this fairly quickly as I will be out of the office for surgical recovery starting Wednesday.  "Help me Obi wan Kenobi. You're my only hope".

using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Analyst3D;
using System.Windows.Forms;
 
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SystemUI;
 
namespace TestDrapeApplication
{
    /// <summary>
    /// Command that works in ArcGlobe or GlobeControl
    /// </summary>
    [Guid("2d4a8248-b8d1-459f-aa4d-c73fdd4cde3b")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("TestDrapeApplication.AddShapeFileMemory")]
    public sealed class AddShapeFileMemory : BaseCommand
    {
        #region COM Registration Function(s)
        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryRegistration(registerType);
 
            //
            // TODO: Add any COM registration code here
            //
        }
 
        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryUnregistration(registerType);
 
            //
            // TODO: Add any COM unregistration code here
            //
        }
 
        #region ArcGIS Component Category Registrar generated code
        /// <summary>
        /// Required method for ArcGIS Component Category registration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryRegistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            GMxCommands.Register(regKey);
            ControlsCommands.Register(regKey);
        }
        /// <summary>
        /// Required method for ArcGIS Component Category unregistration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryUnregistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            GMxCommands.Unregister(regKey);
            ControlsCommands.Unregister(regKey);
        }
 
        #endregion
        #endregion
 
        private IGlobeHookHelper m_globeHookHelper = null;
 
        public AddShapeFileMemory()
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "Add Shape File to map"; //localizable text
            base.m_caption = "Add Shape File";  //localizable text
            base.m_message = "Add shape File to Map";  //localizable text 
            base.m_toolTip = "Add Shape File to Map";  //localizable text
            base.m_name = "AddShapeFileMemory";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")
 
            try
            {
                //
                // TODO: change bitmap name if necessary
                //
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }
 
        #region Overriden Class Methods
 
        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            if (hook == null)
                return;
 
            try
            {
                m_globeHookHelper = new GlobeHookHelperClass();
                m_globeHookHelper.Hook = hook;
                if (m_globeHookHelper.ActiveViewer == null)
                {
                    m_globeHookHelper = null;
                }
            }
            catch
            {
                m_globeHookHelper = null;
            }
 
            if (m_globeHookHelper == null)
                base.m_enabled = false;
            else
                base.m_enabled = true;
 
            // TODO:  Add other initialization code
        }
 
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //This is run after adding document with elevation Raster layer
            IGlobeDisplay globeDisplay = new GlobeDisplayClass();
 
            globeDisplay = m_globeHookHelper.GlobeDisplay;
 
 
            double lon = -86.00;
            double lat = 37.9166;
            double alt = 100.0;
            double azimuth = 175.0;
            double range = 1000; //ConvertMetersToDatasetUnits((IGlobe2)globeDisplay.Globe, 1000.0);
            double fov = 60.0;
 
            m_globeHookHelper.GlobeDisplay.RefreshViewers();
            //Elevation present to here.
            AddElement(ref globeDisplay, azimuth, fov, range, lat, lon, alt);
            // still have elevation with polygon under elevated layer.
            m_globeHookHelper.GlobeDisplay.RefreshViewers();
 
        }
 
        #endregion
 
        private void AddElement(ref IGlobeDisplay globeDisplay, double azimuth, double fov, double range, double lat, double lon, double alt)
        {
            //Depending on the ASCII file type set a variable which will control the flow of the application
            string shapeType = null;
            string sensorID = "Sim.Trip1";
            //shapeType = "points";
            //    shapeType = "polylines";
            shapeType = "polygons";
 
            string datasetType = "Shapefile";
            IWorkspace workSpace = null;
            workSpace = this.CreateWorkspace();
            IFields fields = CreateFields(shapeType);
            //Create the Feature Class 
            IFeatureClass featureClass = CreateFeatureClass(workSpace, null, shapeType, fields, null, null, "");
 
            AddShape(ref featureClass, ref workSpace, azimuth, fov, range, lat, lon, alt, sensorID);
 
            //Create a Feature Layer to display the data in ArcMap
            IFeatureLayer featureLayer = new FeatureLayerClass();
            featureLayer.FeatureClass = featureClass;
            featureLayer.Name = featureClass.AliasName;
            featureLayer.Visible = true;
            IGeoFeatureLayer lyr = (IGeoFeatureLayer)featureLayer;
            IRgbColor lyrColor = new RgbColorClass();
            lyrColor.Red = 255;
            lyrColor.Green = 0;
            lyrColor.Blue = 0; 
            ISimpleFillSymbol sfSymbol = new SimpleFillSymbolClass();
            sfSymbol.Color = lyrColor;
            sfSymbol.Outline.Width = 0.4;
            sfSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
            ISimpleRenderer lyrSimRend = new SimpleRendererClass();
            lyrSimRend.Symbol = (ISymbol)sfSymbol;
 
            lyr.Renderer = (IFeatureRenderer)lyrSimRend;
 
            ((IScene)globeDisplay.Globe).AddLayer(featureLayer, true);
            ILayer lyrCreated = featureLayer;
            
            ((IActiveView)globeDisplay.Globe).Extent = lyrCreated.AreaOfInterest;
        }
        private IWorkspace CreateWorkspace()
        {
            try
            {
 
                IWorkspaceFactory workspaceFactory = null;
                // Instantiate a Shapefile workspace factory
                //workspaceFactory = new ShapefileWorkspaceFactoryClass();
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
                workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
 
                //Create a directory hierarchy to seperate out datasets created for Points, Polylines, and Polygons
 
                IWorkspaceName workspaceName = workspaceFactory.Create(Application.StartupPath + @"\ShapeFile", "Shapefile", null, 0);
                IName Name = (IName)workspaceName;
                IWorkspace workspace = (IWorkspace)(Name.Open());
                return workspace;
            }
            catch (Exception ex)
            {
                String mess = ex.Message;
                MessageBox.Show(mess);
                return null;
            }
 
 
        }
 
        private IFields CreateFields(string shapeType)
        {
 
            // Create a new fields collection.
            IFields fields = new FieldsClass();
 
            // Cast to IFieldsEdit to modify the properties of the fields collection.
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
 
            // Set the number of fields the collection will contain.
            fieldsEdit.FieldCount_2 = 5;
 
            // Create the ObjectID field.
            IField oidField = new FieldClass();
            IFieldEdit oidFieldEdit = (IFieldEdit)oidField;
            oidFieldEdit.Name_2 = "ObjectID";
            oidFieldEdit.AliasName_2 = "FID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.set_Field(0, oidField);
 
            // Create the myID field.
            IField myIDField = new FieldClass();
            IFieldEdit myIDFieldEdit = (IFieldEdit)myIDField;
            myIDFieldEdit.Name_2 = "SensorID";
            myIDFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(1, myIDField);
 
            // Create the text field.
            IField textField = new FieldClass();
            IFieldEdit textFieldEdit = (IFieldEdit)textField;
            textFieldEdit.Length_2 = 30; // Only string fields require that you set the length.
            textFieldEdit.Name_2 = "Str_Att1";
            textFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(2, textField);
 
            // Create the numeric field.
            IField numericField = new FieldClass();
            IFieldEdit numericFieldEdit = (IFieldEdit)numericField;
            numericFieldEdit.Name_2 = "Num_Att1";
            numericFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.set_Field(3, numericField);
 
            //Create the SHAPE field.
            IField shapeField = new FieldClass();
            IFieldEdit shapeFieldEdit = (IFieldEdit)shapeField;
            shapeFieldEdit.Name_2 = "SHAPE";
            shapeFieldEdit.IsNullable_2 = true;
            shapeFieldEdit.Required_2 = true;
 
            IGeometryDef geometryDef = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
            geometryDefEdit.AvgNumPoints_2 = 1;
            geometryDefEdit.GridCount_2 = 0;
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;
 
            //Depending on the feature type (ie. Point, Polyline, or Polygon)
            //set the appropriate .Type_2 and .GeometryType_2 Properties.
            if (shapeType == "points")
            {
                shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            }
            else if (shapeType == "polylines")
            {
                shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            }
            else if (shapeType == "polygons")
            {
                shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            }
 
            //Generate a default Spatial Reference
            ISpatialReference spatialReference = MakeSpatialReference(esriSRProjCSType.esriSRProjCS_Sphere_AzimuthalEquidistant);
            geometryDefEdit.SpatialReference_2 = spatialReference;
 
            shapeFieldEdit.GeometryDef_2 = (GeometryDef)geometryDefEdit;
            fieldsEdit.set_Field(4, shapeFieldEdit);
 
            return fields;
 
        }
 
 
        ///<summary>Helper to create a Feature Class.</summary>
        public IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset, System.String featureClassName, IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID, ESRI.ArcGIS.esriSystem.UID CLSEXT, System.String strConfigKeyword)
        {
 
            if (featureClassName == "")
            {
                return null; // name was not passed in
            }
            featureClassName = "newShapeFile";
            IFeatureClass featureClass = null;
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; // Explicit Cast
 
            // assign the class id value if not assigned
            if (CLSID == null)
            {
                CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }
 
            System.String strShapeField = "";
 
            // locate the shape field
            //for (Int32 j = 0; j < fields.FieldCount; j++)
            //{
            //    if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
            //    {
            //        strShapeField = fields.get_Field(j).Name;
            //    }
            //}
            strShapeField = "SHAPE";
            // finally create and return the feature class
 
            // no feature dataset passed in, create at the workspace level
            try
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, CLSID, CLSEXT, esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            catch (Exception ex)
            {
                String mess = ex.Message;
                MessageBox.Show(mess);
            }
                return featureClass;
 
        }
 
        public ISpatialReference MakeSpatialReference(esriSRProjCSType coordinateSystem)
        {
 
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
 
            //Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
            ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(System.Convert.ToInt32(coordinateSystem)) as ISpatialReferenceResolution;
            spatialReferenceResolution.ConstructFromHorizon();
            ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
            spatialReferenceTolerance.SetDefaultXYTolerance();
            ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
 
            return spatialReference;
 
        }
 
        private void AddShape(ref IFeatureClass FeatureClass, ref IWorkspace workspace, double azimuth, double fov, double range, double lat, double lon, double alt, String sensorID)
        {
            // Start an edit session and edit operation.
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
 
            int IDAttributeFieldIndex = FeatureClass.FindField("SensorID");
            int StringAttributeFieldIndex = FeatureClass.FindField("Str_Att1");
            int NumericAttributeFieldIndex = FeatureClass.FindField("Num_Att1");
 
            ComReleaser comReleaser = new ComReleaser();
            // Create a new insert cursor with buffering.
            IFeatureCursor featureCursor = FeatureClass.Insert(true);
            comReleaser.ManageLifetime(featureCursor);
 
            // Create a feature buffer. This will store the values common to every
            // feature to be installed.
            IFeatureBuffer featureBuffer = FeatureClass.CreateFeatureBuffer();
            comReleaser.ManageLifetime(featureBuffer);
 
 
            IPolygon polygon = makePolygon(azimuth, fov, range, lat, lon, alt);
            featureBuffer.Shape = (IGeometry)polygon;
            featureBuffer.set_Value(IDAttributeFieldIndex, sensorID);
            featureBuffer.set_Value(StringAttributeFieldIndex, "Try this");
            featureBuffer.set_Value(IDAttributeFieldIndex, 2);
            featureCursor.InsertFeature(featureBuffer);
 
            // Flush the cursor.
            featureCursor.Flush();
 
            // All of the features were successfully inserted; stop the edit operation
            // and stop the edit session, saving the changes made in edit operations.
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
        }
        #region "Build Polygon"
 
        /// <summary>
        /// Takes input of azimuth field of view and range with position and altitude
        /// to make a circular arc polygon to add as a symbol for element in layer.
        /// </summary>
        /// <param name="azimuth"></param>
        /// <param name="fov"></param>
        /// <param name="range"></param>
        /// <param name="lat"></param>
        /// <param name="lon"></param>
        /// <param name="alt"></param>
        /// <returns>IPolygon polygon</returns>
        private IPolygon makePolygon(double azimuth, double fov, double range, double lat, double lon, double alt)
        {
            object missing = System.Reflection.Missing.Value;
            //IZAware zAware;
            IPolygon polygon = new PolygonClass();
 
            IPoint centerPoint = new PointClass();
            IPoint startPoint = new PointClass();
            IPoint endPoint = new PointClass();
            Boolean isCCW = true;
            Boolean isMinor = false;
            centerPoint.SpatialReference = MakeSpatialReference(esriSRProjCSType.esriSRProjCS_Sphere_AzimuthalEquidistant);
            startPoint.SpatialReference = centerPoint.SpatialReference;
            endPoint.SpatialReference = centerPoint.SpatialReference;
            //zAware = centerPoint as IZAware;
            ////zAware.ZAware = true;
 
            //zAware = startPoint as IZAware;
            ////zAware.ZAware = true;
 
            //zAware = endPoint as IZAware;
            ////zAware.ZAware = true;
 
            centerPoint.PutCoords(lon, lat);
            ////centerPoint.Z = alt;
            double Xray = centerPoint.X;
            double Yankee = centerPoint.Y;
 
            ICircularArc circularArc = new CircularArcClass();
 
 
            ISegmentCollection ring1 = new RingClass();
            ring1.AddSegment(circularArc as ISegment, ref missing, ref missing);
            double fovRadian = 0.0;
            fovRadian = (fov * 2 * Math.PI) / 360;
            circularArc.PutCoordsByAngle(centerPoint, GetFromAngle(azimuth, fov), fovRadian, range);
 
            circularArc.QueryCoords(centerPoint, startPoint, endPoint, ref isCCW, ref isMinor);
 
            ILine lineOut = new LineClass();
            ILine lineIn = new LineClass();
            lineOut.PutCoords(centerPoint, startPoint);
            lineIn.PutCoords(endPoint, centerPoint);
 
            ISegmentCollection segColl = new PolygonClass();
            segColl.AddSegment((ISegment)lineOut, ref missing, ref missing);
            segColl.AddSegment((ISegment)circularArc, ref missing, ref missing);
            segColl.AddSegment((ISegment)lineIn, ref missing, ref missing);
            polygon = segColl as IPolygon;
            //IGeometryCollection geometryCollection = polygon as IGeometryCollection;
            //geometryCollection.AddGeometry(segColl as IGeometry, ref missing, ref missing);
 
            //geometryCollection.GeometriesChanged();
            return polygon;
 
        }
 
        /// <summary>
        /// Converts Azimuth and Field of View width to geometric 
        /// start angle of circular arc.
        /// </summary>
        /// <param name="azimuth"></param>
        /// <param name="FOV"></param>
        /// <returns>Double startAngle</returns>
        private double GetFromAngle(double azimuth, double FOV)
        {
            double startAngle = 0.0;
            double fovRadian = 0.0;
            fovRadian = (FOV * 2 * Math.PI) / 360;
            startAngle = AzimuthToAngle(azimuth) - (.5 * fovRadian);
            return startAngle;
        }
        /// <summary>
        /// Converts Azimuth to geometric angle of arc.
        /// </summary>
        /// <param name="azimuth"></param>
        /// <returns>double angle</returns>
        private double AzimuthToAngle(double azimuth)
        {
            double angle = 0.0;
            double angleRadian = 0.0;
 
            angleRadian = (azimuth * 2 * Math.PI) / 360;
            angle = (2 * Math.PI) - (angleRadian - Math.PI / 2);
            if (angle >= 2 * Math.PI)
            {
                angle -= 2 * Math.PI;
            }
            return angle;
        }
 
        private double ConvertMetersToDatasetUnits(IGlobe2 globe, double meters)
        {
            try
            {
                esriUnits units = globe.GlobeUnits;
                IUnitConverter cvtr = new UnitConverter();
                double mapUnits = cvtr.ConvertUnits(meters, esriUnits.esriMeters, units);
                return mapUnits;
            }
            catch (Exception ex)
            {
                String mess = ex.Message;
                return -1.0;
            }
 
        }
 
 
        #endregion
 
    }
}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-31 at 09:40:41ID24695317
Tags

ArcGIS Engine ArcGlobe ArcGIS ESRI

Topics

GIS & GPS Programming

,

Miscellaneous Programming

Participating Experts
0
Points
0
Comments
2

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Internet globe icon and browsers
    How do I link a browser to the internet globe icon? Internet Explorer is linked automatically by Microsoft but I would like to know how to change it so I can start Netscape automatically when I log on to the internet. My ISP said all I had to do was logon with the dialer on...
  2. Boston Globe Title Font
    What is the Boston Globe Title font and is it available
  3. Boston Globe Title Font
    What is the Boston Globe's Title font and is it available? See it at bostonglobe.com
  4. Required a Font with Globes
    Hello Everyone, I am looking for a dingbat font that has various forms of globes like wireframe globes, normal globes, wireframe circle etc. I am sure there are fonts like this but have not been successful in finding one. If you have any suhc font, please upload it to some ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: JoellerPosted on 2009-08-31 at 12:49:58ID: 25225790

OK resolved issue. First off putcoords is x,y not necessarily lon, lat. It is dependent upon the spatial reference of your point.
If you are using a spatial reference that utilizes meters instead of decimal degrees like esriSRProjCSType.esriSRProjCS_Sphere_AzimuthalEquidistant then x, y is in meters from the point of origin which is Lat 0 Long 0.
So when I set my point's spatial reference to that determined by that projected coordinate system, then I was specifying 86 meters west of the prime meridian and 37.9166 meters north of the equator. Everything else worked properly from that.
What I needed to do was to set spatial reference of the point to that returned by CreateGeographicCoordinateSystem of the
Spatialreference factory for the GCS constant esriSRGeoCSType.esriSRGeoCS_WGS1984 like in the function below. Then use the project method of that point to set the spatial reference to the projected coord syst used by the shapefile like so:

ISpatialReference projCoordSys = new ESRI.ArcGIS.Geometry.ProjectedCoordinateSystemClass();
projCoordSys = MakeSpatialReference(esriSRProjCSType.esriSRProjCS_Sphere_AzimuthalEquidistant);
tempPoint.Project(projCoordSys);
centerPoint = tempPoint;
and voila; Polygon is in northern Kentucky as it should be. Thanks due to my boss Mr. Bill Dollins.

public ISpatialReference MakeSpatialReferenceB(esriSRGeoCSType coordinateSystem)
        {
 
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
 
            //Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
            ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateGeographicCoordinateSystem(System.Convert.ToInt32(coordinateSystem)) as ISpatialReferenceResolution;
            spatialReferenceResolution.ConstructFromHorizon();
            ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
            spatialReferenceTolerance.SetDefaultXYTolerance();
            ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
 
            return spatialReference;
 
        }
 
//Original
public ISpatialReference MakeSpatialReference(esriSRProjCSType coordinateSystem)
        {
 
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
 
            //Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
            ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(System.Convert.ToInt32(coordinateSystem)) as ISpatialReferenceResolution;
            spatialReferenceResolution.ConstructFromHorizon();
            ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
            spatialReferenceTolerance.SetDefaultXYTolerance();
            ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
 
            return spatialReference;
 
        }

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

 

by: JoellerPosted on 2009-08-31 at 12:51:44ID: 25225804

That also explains why it was not necessary to convert from meters to map units as the map units are meters.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...