Http://www.cnblogs.com/bpcbcm/archive/2009/05/16/bpc.html
The GIS of the distribution network is used as an example to import the collected grid data GPS data to the SDE database. Taking the tower line as an example, the tower data is automatically connected after being drawn, and the network relationship is maintained at the same time.
/// <Summary>
/// Obtain all the line names of all towers to be added to the file
/// // </Summary>
///
Public void getlinenames ()
{
// Gpsedit. currentlayer =
Ifeatureworkspace pfeatws;
Iworkspacefactory pworkspacefactory;
Pworkspacefactory = new shapefileworkspacefactoryclass ();
If (fileworkspacestring = NULL) return;
Pfeatws = pworkspacefactory. openfromfile (fileworkspacestring, 0) as ifeatureworkspace;
Foreach (string file in listnames)
{
// Create a picturebox.
If (file = "export_output.shp ")
{
Try
{
Iqueryfilter queryfilter = new queryfilterclass ();
Queryfilter. subfields = "xlmc, zlmc ";
Ifeatureclass pfeatureclass = pfeatws. openfeatureclass (File );
Iselectionset selectionset = pfeatureclass. Select (null, esriselectiontype. esriselectiontypeidset, esriselectionoption. esriselectionoptionnormal, null );
Ienumids enumids = selectionset. IDS;
Int fieldindex = pfeatureclass. findfield ("xlmc ");
Int fieldindex1 = pfeatureclass. findfield ("zlmc ");
Ifeature feature;
Int id = enumids. Next ();
Xlname XL = new xlname ();
Int isfirst = 0;
While (ID! =-1) //-1 is reutned after the last valid ID has been reached
{
If (isfirst = 0)
{
Feature = pfeatureclass. getfeature (ID );
XL. xlmc = feature. get_value (fieldindex). tostring ();
XL. zlmc = feature. get_value (fieldindex1). tostring ();
Xlnames. Add (XL );
Isfirst = 1;
}
Else
{
Feature = pfeatureclass. getfeature (ID );
XL. xlmc = feature. get_value (fieldindex). tostring ();
XL. zlmc = feature. get_value (fieldindex1). tostring ();
Bool iscz = true;
Foreach (xlname xlmc in xlnames)
{
If (xlmc. xlmc = XL. xlmc) & (xlmc. zlmc = XL. zlmc ))
{
Iscz = false; // whether it exists
}
}
If (iscz = true) // Add if it does not exist
{
Xlnames. Add (XL );
}
}
Id = enumids. Next ();
}
Int dd = xlnames. count;
}
Catch (exception E)
{
Console. writeline (E. Message. tostring ());
}
}
}
}
/// <Summary>
/// Draw a point Device
/// </Summary>
/// <Param name = "iflayer"> </param>
/// <Param name = "Ppoint"> </param>
Private void drawpoint (ilayer iflayer, ipoint Ppoint)
{
Try
{
If (iflayer = NULL) return;
If (! (Iflayer is igeofeaturelayer) return;
Ifeaturelayer pfeaturelayer = (ifeaturelayer) iflayer;
Ifeatureclass mfeatureclass = pfeaturelayer. featureclass;
Idataset pdataset = (idataset) pfeaturelayer. featureclass;
If (pdataset = NULL) return;
// Start editing and set Undo/Redo to available
Iworkspaceedit pworkspaceedit = (iworkspaceedit) pdataset. workspace;
If (! Pworkspaceedit. isbeingedited ())
{
Pworkspaceedit. startediting (true );
Pworkspaceedit. enableundoredo ();
Ifeature myfeature;
Ifeatureclasswrite Fr = mfeatureclass as ifeatureclasswrite; // draw Tower
Pworkspaceedit. starteditoperation ();
Myfeature = mfeatureclass. createfeature ();
Myfeature. Shape = Ppoint;
Myfeature. Store ();
Fr. writefeature (myfeature );
Pworkspaceedit. stopeditoperation ();
Pworkspaceedit. stopediting (true );
M_pmap.clearselection ();
Iactiveview pactiveview = (iactiveview) m_pmap;
Pactiveview. Refresh ();
}
}
Catch (exception E)
{
Console. writeline (E. Message. tostring ());
}
}
/// <Summary>
/// Draw a line
/// </Summary>
Public void drawline (ilayer iflayer, ipointcollection pointcollection)
{
Try
{
If (iflayer = NULL) return;
If (! (Iflayer is igeofeaturelayer) return;
Ifeaturelayer pfeaturelayer = (ifeaturelayer) iflayer;
Ifeatureclass mfeatureclass = pfeaturelayer. featureclass;
Idataset pdataset = (idataset) pfeaturelayer. featureclass;
If (pdataset = NULL) return;
// Start editing and set Undo/Redo to available
Iworkspaceedit pworkspaceedit = (iworkspaceedit) pdataset. workspace;
If (! Pworkspaceedit. isbeingedited ())
{
Pworkspaceedit. startediting (true );
Pworkspaceedit. enableundoredo ();
Ifeature myfeature;
Ifeatureclasswrite Fr = mfeatureclass as ifeatureclasswrite; // draw Tower
Pworkspaceedit. starteditoperation ();
Myfeature = mfeatureclass. createfeature ();
Pworkspaceedit. starteditoperation ();
Myfeature = mfeatureclass. createfeature ();
// Igeometry ggeometry = (igeometry) pointcollection;
Ipolympus line ppolyline = pointcollection as ipolympus line;
Myfeature. Shape = ppolyline;
Myfeature. Store ();
Fr. writefeature (myfeature );
Icomplexedgefeature ccomplexedte = myfeature as icomplexedgefeature; // establish connectivity
Ccomplexedte. connectatintermediatevertices ();
Pworkspaceedit. stopeditoperation ();
Pworkspaceedit. stopediting (true );
M_pmap.clearselection ();
Iactiveview pactiveview = (iactiveview) m_pmap;
Pactiveview. Refresh ();
}
}
Catch (exception E)
{
Console. writeline (E. Message. tostring ());
}
}
/// <Summary>
/// Draw GPS data, Tower, line
/// </Summary>
Public void draw ()
{
Ifeatureworkspace pfeatws;
Iworkspacefactory pworkspacefactory;
Pworkspacefactory = new shapefileworkspacefactoryclass ();
If (fileworkspacestring = NULL) return;
Pfeatws = pworkspacefactory. openfromfile (fileworkspacestring, 0) as ifeatureworkspace;
Foreach (string file in listnames)
{
If (file = "export_output.shp") // layout Tower
{
Foreach (xlname xlmc in xlnames)
{
Ifeature featurepoint;
Int idline = getlayerid (m_pmap, "GIS. Lines"); // obtain the line layer.
Ilayer ilayerline = m_pmap.get_layer (idline );
Int idpoint = getlayerid (m_pmap, "GT"); // obtain the vertex layer.
Ilayer iflayer = m_pmap.get_layer (idpoint );
Ipolympus mypolylin = new polylineclass ();
Ipointcollection pointcollection = mypolylin as ipointcollection;
Object missingval = system. reflection. Missing. value;
Iqueryfilter queryfilter = new queryfilterclass ();
Queryfilter. whereclause = "xlmc = '" + xlmc. xlmc + "'" + "and zlmc = '" + xlmc. zlmc + "'";
Ifeatureclass pfeatureclass = pfeatws. openfeatureclass (File );
// Iqueryfilterdefinition queryfilterdefinition = (iqueryfilterdefinition) queryfilter;
// Queryfilterdefinition. postfixclause = "order by GH ";
Ifields Ffield = pfeatureclass. fields;
For (INT fieldindex = 0; fieldindex <Ffield. fieldcount; fieldindex ++)
{
String dd = Ffield. get_field (fieldindex). Name;
String DDD = pfeatureclass. shapefieldname;
}
Iselectionset selectionset = pfeatureclass. Select (queryfilter, esriselectiontype. esriselectiontypeidset, esriselectionoption. esriselectionoptionnormal, null );
Int fieldindexgh = pfeatureclass. findfield ("GH ");
Int fieldindexzjgh = pfeatureclass. findfield ("zjgh ");
Int fieldindexxlmc = pfeatureclass. findfield ("xlmc ");
Int fieldindexzlmc = pfeatureclass. findfield ("zlmc ");
Int fieldindextjxl = pfeatureclass. findfield ("tjxl ");
Int fieldindextjgh = pfeatureclass. findfield ("tjgh ");
Ienumids enumids = selectionset. IDS;
For (Int J = 1; j <= selectionset. Count; j ++)
{
Bool istjgh = false;
Enumids. Reset ();
Int id = enumids. Next ();
While (ID! =-1) //-1 is reutned after the last valid ID has been reached
{
Featurepoint = pfeatureclass. getfeature (ID );
Igeometry geometrygt = featurepoint. shape; // get the object in the SHP File
Ipoint pointgt = geometrygt as ipoint;
Gtzb gtxx = new gtzb ();
Gtxx. GH = featurepoint. get_value (fieldindexgh). tostring ();
Gtxx. xlmc = featurepoint. get_value (fieldindexxlmc). tostring ();
Gtxx. zlmc = featurepoint. get_value (fieldindexzlmc). tostring ();
Gtxx. zjgh = featurepoint. get_value (fieldindexzjgh). tostring ();
If (gtxx. GH = J. tostring () & gtxx. zjgh. tostring (). Trim () = "")
{
Drawpoint (iflayer, pointgt); // draw objects in the SHP file to the database
Pointcollection. addpoint (pointgt, ref missingval, ref missingval );
}
Else if (gtxx. GH = J. tostring () & gtxx. zjgh. tostring (). Trim ()! = "")
{
Istjgh = true;
}
Id = enumids. Next ();
}
If (istjgh)
{
Iqueryfilter queryfiltersub = new queryfilterclass ();
Queryfiltersub. whereclause = "xlmc = '" + xlmc. xlmc + "'" + "and zlmc ='" + xlmc. zlmc + "'and zjgh ='" + J + "'";
Iselectionset selectionsetsub = pfeatureclass. Select (queryfiltersub, esriselectiontype. esriselectiontypeidset, esriselectionoption. esriselectionoptionnormal, null );
For (INT subj = 1; subj <= selectionsetsub. Count; subj ++)
{
Ienumids enumsubids = selectionsetsub. IDS;
Enumsubids. Reset ();
Int idsub = enumsubids. Next ();
While (idsub! =-1) //-1 is reutned after the last valid ID has been reached
{
Featurepoint = pfeatureclass. getfeature (idsub );
Igeometry geometrygt = featurepoint. shape;
Ipoint pointgt = geometrygt as ipoint;
Gtzb gtxx = new gtzb ();
Gtxx. longpolling = pointgt. X;
Gtxx. Latitude = pointgt. Y;
Gtxx. elevation = pointgt. Z;
Gtxx. GH = featurepoint. get_value (fieldindexgh). tostring ();
Gtxx. zjgh = featurepoint. get_value (fieldindexzjgh). tostring ();
Gtxx. xlmc = featurepoint. get_value (fieldindexxlmc). tostring ();
Gtxx. zlmc = featurepoint. get_value (fieldindexzlmc). tostring ();
If (gtxx. zjgh = subj. tostring ())
{
Drawpoint (iflayer, pointgt );
Pointcollection. addpoint (pointgt, ref missingval, ref missingval );
}
Idsub = enumsubids. Next ();
}
}
}
}
// Draw a line
Drawline (ilayerline, pointcollection );
}
}
}