Home > Net >  Arcgisengine c # in some new layer, add elements and give assignment
Arcgisengine c # in some new layer, add elements and give assignment

Time:09-24

 
Int bz=0;
Private IWorkspace2 pWorkspace2;
Private IWorkspaceFactory wf.
Private IFeatureWorkspace FWS;
Private IFields pFields;
Private IFieldsEdit pFieldsEdit;
Private IFeatureClass pFeatClass;
Private void button9_Click (object sender, EventArgs e)
{

The object text=this.com boBox1. Text;
//IWorkspaceFactory wf=new ShapefileWorkspaceFactoryClass ();
//IWorkspaceName wname=wf. Create (" C: \ \ temp \ \ ", "biaozhu", null, 0).
//IName name_=wname as IName;
//IWorkspace workspace=(IWorkspace) name_. The Open ();
If (bz==0)
{
Wf=new ShapefileWorkspaceFactoryClass ();
IWorkspaceName wName=wf. Create (Application. StartupPath, "bz", null, 0).
FWS=(IFeatureWorkspace) wf. OpenFromFile (Application. StartupPath + "\ " bz, 0).
PWorkspace2=FWS as IWorkspace2;
//set the field set
PFields=new FieldsClass ();
PFieldsEdit=(IFieldsEdit pFields);

//set the field
IField pField=new FieldClass ();
IFieldEdit pFieldEdit=(IFieldEdit pField);

//create a type of geometry type of field
PFieldEdit. Name_2="shape";
PFieldEdit. Type_2=esriFieldType. EsriFieldTypeGeometry;

////set the projection coordinate system of 51 n
//ISpatialReferenceFactory spatialReferenceFactory=new SpatialReferenceEnvironmentClass ();
//IProjectedCoordinateSystem PCS=spatialReferenceFactory. CreateProjectedCoordinateSystem ((int) esriSRProjCSType. EsriSRProjCS_WGS1984UTM_51N);

//set the geographic coordinates to WGS84
ISpatialReferenceFactory spatialReferenceFactory=new SpatialReferenceEnvironmentClass ();
IGeographicCoordinateSystem PCS=spatialReferenceFactory. CreateGeographicCoordinateSystem ((int) esriSRGeoCSType. EsriSRGeoCS_WGS1984);

//set the geometry types to point type, coordinate system for the
IGeometryDef pGeoDef=new GeometryDefClass ();
IGeometryDefEdit pGeoDefEdit=(IGeometryDefEdit pGeoDef);
PGeoDefEdit. GeometryType_2=esriGeometryType. EsriGeometryPoint;
PGeoDefEdit. SpatialReference_2=PCS;
//pGeoDefEdit. SpatialReference_2=geographicCoordinateSystem;
PFieldEdit. GeometryDef_2=pGeoDef;
PFieldsEdit. AddField (pField);

//add other fields
PField=new FieldClass ();
PFieldEdit=(IFieldEdit pField);
PFieldEdit. Name_2="biaozhu";
PFieldEdit. Type_2=esriFieldType. EsriFieldTypeString;
PFieldsEdit. AddField (pField);

//create a shapefile
PFeatClass=FWS. CreateFeatureClass (bz, pFields, null, null, esriFeatureType. EsriFTSimple, "shape", "");
Bz=1;
}



IWorkspaceEdit wedit;
//IFeatureCursor featurecursor;
Wedit=pWorkspace2 as IWorkspaceEdit;
Wedit. StartEditing (false);
Wedit. StartEditOperation ();
.//IFeature pFeature=pFeatClass CreateFeature ();
IFeatureBuffer featureBuffer=pFeatClass. CreateFeatureBuffer ();
IFeatureCursor featurecursor=pFeatClass. Insert (true);
IPoint pt=new PointClass ();
Pt. X=the Convert. ToDouble (this) textBox2) Text);
Pt. Y=the Convert. ToDouble (this) textBox1) Text);
Pt. PutCoords (pt) X, pt. Y);
Int fieldIndex=pFields. FindField (" biaozhu ");
The object featureOID;
FeatureBuffer. Shape=pt;
featureBuffer. Set_Value (fieldIndex, text);
FeatureOID=featurecursor. InsertFeature (featureBuffer);
Featurecursor. Flush ();
Wedit. StopEditOperation ();
Wedit. StopEditing (true);
System. The Runtime. InteropServices. Marshal. ReleaseComObject (pFields);
System. The Runtime. InteropServices. Marshal. ReleaseComObject (pFieldsEdit);
System. The Runtime. InteropServices. Marshal. ReleaseComObject (FWS);
System. The Runtime. InteropServices. Marshal. ReleaseComObject (wf);


}

CodePudding user response:

Setvalue () has been an error, not out for a long time, who can help me

CodePudding user response:

Bosses, look, it is a new layer, add some elements to the layer, assign attributes

CodePudding user response:

Bosses 6666666!

CodePudding user response:

To what's wrong?
Have a look at fieldIndex value of interrupt
  •  Tags:  
  • C#
  • Related