Create FeatureClass doesn't draw point

482
4
03-04-2014 10:09 AM
ChrisBrannin__GISP
New Contributor
Hello

When I try to create a new featureClass I do not get the symbol created with the row(s) in the table. So I am trying to add the symbol as the featureClass is being created. Is this the right process or should the symbol be added on the creation of the featureClass? The coordinate flashes upon creation but does not stay!?

            IPoint makePoint = new PointClass();
            double xCoor = Convert.ToDouble(listVariants.SelectedItems[0].SubItems[6].Text);
            double yCoor = Convert.ToDouble(listVariants.SelectedItems[0].SubItems[7].Text);
            makePoint.PutCoords(xCoor, yCoor);

            IMxDocument drawDoc = (IMxDocument)ArcMap.Application.Document;
            IActiveView drawView = drawDoc.ActiveView;
            IScreenDisplay drawDisplay = drawView.ScreenDisplay;
            short screenCache = Convert.ToInt16(esriScreenCache.esriNoScreenCache);
            drawDisplay.StartDrawing(drawDisplay.hDC, screenCache);
            

            ESRI.ArcGIS.Display.RgbColorClass color = new ESRI.ArcGIS.Display.RgbColorClass();
            color.Red = 55; color.Green = 100; color.Blue = 66;

            ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
            simpleMarkerSymbol.Color = color;
            simpleMarkerSymbol.Size = 8;
            drawDisplay.SetSymbol(simpleMarkerSymbol as ISymbol);            
            drawDisplay.DrawPoint(makePoint);
            
            drawDisplay.FinishDrawing();        


Please, any suggestions are greatly appreciated!

Cheers
Chris
0 Kudos
4 Replies
AhmedEl-Sisi
Occasional Contributor III
You can try to Refresh your display after adding features to your featureclass.

pMap.PartialRefresh(esriViewGeography, pLayer, null);


for permanent Graphics on Map you can use AddGraphicToMap Snippet then Refresh your map.


Regards,
0 Kudos
ChrisBrannin__GISP
New Contributor
You can try to Refresh your display after adding features to your featureclass.

pMap.PartialRefresh(esriViewGeography, pLayer, null);


for permanent Graphics on Map you can use AddGraphicToMap Snippet then Refresh your map.


Regards,


Thanks for the suggestions. I am still getting the same results. I wonder... Do I need to open an editing session?

Cheers
Chris
0 Kudos
NeilClemmons
Regular Contributor III
I don't see anywhere in the code you posted where you are creating a feature class, or a feature for that matter.  Your code is drawing a point on the display.  Unless you put this code in the active view's AfterDraw event, it will simply draw once and then disappear on the next refresh of the display because it's simply a graphic and is not permanent.  If you want to create a new feature from the point and save it into a feature class then that is completely different than what you are doing in the code you posted.  There are examples that show how to create new features in the developer samples and here on the forums.
0 Kudos
ChrisBrannin__GISP
New Contributor
I don't see anywhere in the code you posted where you are creating a feature class, or a feature for that matter.  Your code is drawing a point on the display.  Unless you put this code in the active view's AfterDraw event, it will simply draw once and then disappear on the next refresh of the display because it's simply a graphic and is not permanent.  If you want to create a new feature from the point and save it into a feature class then that is completely different than what you are doing in the code you posted.  There are examples that show how to create new features in the developer samples and here on the forums.

*EDIT - WORKING*
I took a slightly different approach to this and it seems to be working in the dataview... Code is edited to reflect current working solution. Any suggestions to clean this up or make it better would still be greatly appreciated!


Hello and thanks for the reply. I tried to post all of the code but it told me it was too many characters. I only posted the drawing part to see if I was going about the drawing correctly and to get suggestions on where to place it within the featureClass creation method. Can you point me to these samples, because I am creating the FC just fine but not with the symbol. I thought I was doing something wrong with my drawing.

Simplified Code:

IFields fields = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            IField oidField = new FieldClass();
            IFieldEdit oidFieldEdit = (IFieldEdit)oidField;

            oidFieldEdit.Name_2 = "OID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.AddField(oidField);

            //create geometry definition and spatial reference for the featureclass
            IGeometryDef geometryDef = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass();

            int coordinateSystemID = (int)esriSRGeoCSType.esriSRGeoCS_WGS1984;
            ISpatialReference spatialReference = spatialRefFactory.CreateGeographicCoordinateSystem(coordinateSystemID);
IField geometryField = new FieldClass();
            IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;

            //field = new FieldClass();
            geometryFieldEdit.Name_2 = "Shape";
            geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            geometryFieldEdit.GeometryDef_2 = geometryDef;
            fieldsEdit.AddField(geometryField);

            //Create fields
            IField A2Field = new FieldClass();
            IFieldEdit A2FieldEdit = (IFieldEdit)A2Field;
            A2FieldEdit.Name_2 = "ISO_A2";
            A2FieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            A2FieldEdit.Length_2 = 254;
            fieldsEdit.AddField(A2Field);
// Use IFieldChecker to create a validated fields collection
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IEnumFieldError enumFieldError = null;
            IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (IWorkspace)fws;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

IFeatureClass featureClass = fws.CreateFeatureClass(fcName, validatedFields, null, null , esriFeatureType.esriFTSimple, "Shape", "");
MessageBox.Show(fcName + " Has been created successfully!");

IFeatureClass fc = fws.OpenFeatureClass(fcName); 

            IFeatureLayer fl = new FeatureLayerClass();
            fl.Name = fcName;
            fl.FeatureClass = fc;
            IMxDocument mxDoc = (IMxDocument)ArcMap.Application.Document;
            IMap map = mxDoc.FocusMap;
            map.AddLayer(fl);
            IEnumLayer enumLayer = map.Layers;


            
            ILayer layer = enumLayer.Next();
            IFeatureLayer2 pointLayer = null;
            while (layer != null)
            {
                if (layer.Name == fcName && layer is IFeatureLayer2)
                {
                    pointLayer = layer as IFeatureLayer2;
                }

                layer = enumLayer.Next();
            }

            if (pointLayer == null)
            {
                MessageBox.Show("No layer!");
                return;
            }

            try
            {
                //set coordinates
                double xCoor = Convert.ToDouble(listVariants.SelectedItems[0].SubItems[6].Text);
                double yCoor = Convert.ToDouble(listVariants.SelectedItems[0].SubItems[7].Text);


                IFeature newPoint = pointLayer.FeatureClass.CreateFeature();
                IPoint placePoint = new PointClass();
                placePoint.PutCoords(yCoor, xCoor);
                newPoint.Shape = placePoint;


                IFeatureClass pointFClass = pointLayer.FeatureClass;
int fieldCOUNTRY = pointFClass.Fields.FindField("COUNTRY");

newPoint.Value[fieldCOUNTRY] = listVariants.SelectedItems[0].SubItems[5].Text;

newPoint.Store();
            }
            catch (Exception ex)
            {
                new MessageDialogClass().DoModal(ex.Source, ex.Message, "", "", ArcMap.Application.hWnd);
            }


I'm very new to ArcObjects so any help suggestions are greatly appreciated!

Cheers
Chris
0 Kudos