How create shapefile from another shapefile

668
3
08-12-2011 02:29 AM
FilippaFideria
New Contributor
Hi forum,

I would like to create a tool command to ArcMap 9.3.1 (language C#) that create a new shape file from a list of FID of another shapefile.
Can you suggest me how can I do it, please?

Thanks in advance!!!
0 Kudos
3 Replies
DubravkoAntonic
New Contributor III
Tool expects interaction, input, from user. Command doesn't expect any interaction but does the job.
If you have somewhere predefined FID-s then you create command and do action in the OnClick method.

get sourceFeature from original FID list.
in target IFeatureClass.Create - create feature
to created feature assign shape from sourceFeature
do some attribute update with IFeature.setValue(field index);
if you don't know field index you can use IFeature.Fields.FindField("fieldName") which returns fields index.
set targetsFeature.SaptialReference = Map.SpatialReference or GeoDataset.SpatialReference
save changes to the created feature createdFeature.Store()

If you would like to use undo / redo then You have to inert code from above into try block IEditor.StartOperation and IEditor.StopOperation("operation name tool tip"), and IEditor.AbortOperation int catch block.

These are some logic steps you should implement. For unknown interfaces use SDK before using to see if there are some examples or description.

Code long and prosper :cool:
0 Kudos
FilippaFideria
New Contributor
Hi dubravko.antonic,

sorry but my english is poor and I don't understand very well  what should I do!
Can you post some code, plese?

I create a query tha get lthe list of FID of the row shape that I would like to export to the nwe shape.
Can you suggest me the code that I could use, please?

Thanks for the prompt response!!!
0 Kudos
DubravkoAntonic
New Contributor III
I think this should work, use some time to get through, it is a must to consult SDK, there are a lot examples that are just waiting to be used.


IDataset pDataset = destinationFeatureClass as IDataset;
IEditWorkspace pEditWorkspace = pDataset.Workspace as IEditWorkspace;
//Open Edit Session
try{
pEditWorksapce.StartEditing();

If you got list of FID-s you do as follow:

// spatialreference
IGeoDataset pDestGeoDataset = destinationFeatureClass as IGeoDataset;
foreach(int fid in FIDlist)
{[INDENT]IFeature pFeature = sourceFeatureClass.GetFeature(fid);
IFeature pNewFeature = destinationFeatureClass.Create();
pNewFeature.shape = pFeature.ShapeCopy;
pNewFeature.spatialreference = pDestGeoDataset.SpatialReference;

//set some attribute
int fieldIdx = pFeature.Fields.FindField("attributeName");
pNewFeature.SetValue(pFeature.getValue(fieldIdx));

pNewFeature.Store();
[/INDENT]}
pEditWorksapce.StopEditing(true);// save edits
}
catch(Exception ex)
{
[INDENT] //some alert, log ... 
MessageBox.Show(ex.message);
[/INDENT] }
Hope it works if not please let me where you got error. Use try/catch
0 Kudos