Copying point location into new feature class

409
2
12-04-2012 03:30 AM
KevinYanuk
Occasional Contributor
Hello;

I am trying to grab point features from an existing point layer (feature class), and add a new point feature into a different feature class at that location (based on irrelevant criterion).


What I have creates new features, however, It puts all the features on top of each other at a single location, far away from the actual points I got the geometry from.  My code:


IFeature newConflict = fc.CreateFeature(); //feature class to create feature

newConflict.Shape = mFeat.Shape;  //mFeat is where I am pulling data from into newConflict

newConflict.Shape.SpatialReference = mFeat.Shape.SpatialReference;

//check for field, then add values
if (newConflict.Fields.FindField(FieldName) != -1)
{
    if (Value != null) Feature.set_Value(newConflict.Fields.FindField(FieldName), Value);
    else Feature.set_Value(newConflict.Fields.FindField(FieldName), DBNull.Value);
}
newConflict.Store();


Does feature.Shape not have contain location?  I thought it was complete geometry.

Do I need to manually store the Shape into the Shape field?


Thank you
0 Kudos
2 Replies
MarcinDruzgala
Occasional Contributor
As I understand this you just set the value for an empty feature in newConflict , you don't copy the feature.
Can't you just use Append? I really depends in what conditions you want to copy the feature(is it selected? etc).
Does feature.Shape not have contain location? I thought it was complete geometry.
(lest assume we have declared IFeature feature and it is point feature, I will skip few things just to show you example)

IPoint point = (IPoint)feature.Shape;
//now you can get the x,y and z values from it

double x = point.X;
double y = point.Y;
double z = point.Z;


Use Append Class form DataManagementTools to append feature into new featurelayer(the attributes will be copied as well).

tip - > it's easier to read the code this way:
if (newConflict.Fields.FindField(FieldName) != -1)
{
    if (Value != null)
          Feature.set_Value(newConflict.Fields.FindField(FieldName), Value);
    else 
          Feature.set_Value(newConflict.Fields.FindField(FieldName), DBNull.Value);
}


0 Kudos
SteveFang
New Contributor III
From what you're describing make sure you destination featureclass has the same spatial domain and coordinate system is the same as your source featureclass.  I don't know if you need the spatialreference line.
0 Kudos