Requirements raised by a customer in the transportation industry: for example, if there are highway center lines and many equipment points, these equipment points are not online (because the map is reduced, it cannot be too clear ), the offset direction and distance between the device point and the line are irregular. Now you need to move these points online. Here I write a program for Processing Based on the engine.
Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using ESRI. ArcGIS. CARTO;
Using ESRI. ArcGIS. Geodatabase;
Using ESRI. ArcGIS. geometry;
Using ESRI. ArcGIS. display;
Namespace pointbatchoffset
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
// Start execution
Private void button#click (Object sender, eventargs E)
{
// Query the Buffer Layer
Ifeaturelayer ptlayer = queryfeaturelayer ("pointz ");
// Obtain the closest point on the feature closest to the point on the specified layer.
Ifeatureclass ptfeatclass = ptlayer. featureclass;
Ifeaturecursor featurecursor = ptfeatclass. Search (null, false );
Ifeature feature = featurecursor. nextfeature ();
Ipoint point = new pointclass ();
While (feature! = NULL)
{
Point = feature. Shape as ipoint;
// Find the line closest to the vertex
Ifeature nearfea = getnearestfeature (point, 1.2 );
Ipoint neapoint = getnearestpoint (point, nearfea );
Neapoint. z = point. Z;
// Move the vertex
Movetoneapoint (feature, point, neapoint );
If (featurecursor = NULL | feature = NULL)
{
Return;
}
Feature = featurecursor. nextfeature ();
}
MessageBox. Show ("OK --");
}
// Query the layer with the given name
Private ifeaturelayer queryfeaturelayer (string name)
{
For (INT I = 0; I <axmapcontrol1.layercount; I ++)
{
Ilayer layer = axmapcontrol1.get _ layer (I );
If (layer. Name. Equals (name ))
{
Return (ifeaturelayer) layer;
}
}
Return NULL;
}
//// Obtain the closest point of the feature closest to the point on the specified layer.
Public ipoint getnearestpoint (ipoint point, ifeature nearfea)
{
Iproximityoperator proximity = (iproximityoperator) point;
Ifeaturelayer fealyr = queryfeaturelayer ("medianroadz ");
Ifeatureclass feacls = fealyr. featureclass;
Iqueryfilter queryfilter = NULL;
Itopologicaloperator topoator = (itopologicaloperator) point;
Igeometry GEO = topoodle. buffer (1.2 );
Ispatialfilter Sf = new spatialfilterclass ();
SF. Geometry = GEO;
SF. geometryfield = feacls. shapefieldname;
SF. spatialrel = esrispatialrelenum. esrispatialrelcrosses;
Ifeaturecursor feacur = feacls. Search (queryfilter, false );
Ifeature FEA = nearfea = feacur. nextfeature ();
Double mindistince, distance;
If (FEA = NULL)
Return NULL;
Mindistince = distance = proximity. returndistance (igeometry) FEA. Shape); // The nearest distance.
// Save the nearest feature
FEA = feacur. nextfeature ();
While (FEA! = NULL)
{
Distance = proximity. returndistance (igeometry) FEA. Shape );
If (distance <mindistince)
{
Mindistince = distance;
Nearfea = FEA;
}
FEA = feacur. nextfeature ();
} // End while
Proximity = (iproximityoperator) nearfea. shape;
Return proximity. returnnearestpoint (point, esrisegmentextension. esrinoextension );
}
// Find the nearest line
Public ifeature getnearestfeature (ipoint P, double rongcha)
{
Ifeature nearfea;
Iproximityoperator proximity = (iproximityoperator) P;
Ifeaturelayer fealyr = queryfeaturelayer ("medianroadz ");
Ifeatureclass feacls = fealyr. featureclass;
Iqueryfilter queryfilter = NULL;
Ifeaturecursor feacur = feacls. Search (queryfilter, false );
Ifeature FEA = nearfea = feacur. nextfeature ();
Double mindistince, distance;
If (FEA = NULL)
Return NULL;
Mindistince = distance = proximity. returndistance (igeometry) FEA. Shape); // The nearest distance.
// Save the nearest feature
FEA = feacur. nextfeature ();
While (FEA! = NULL)
{
Distance = proximity. returndistance (igeometry) FEA. Shape );
If (distance <mindistince)
{
Mindistince = distance;
Nearfea = FEA;
}
FEA = feacur. nextfeature ();
} // End while
Return nearfea;
}
Private void movetoneapoint (ifeature feature, ipoint point, ipoint neapoint)
{
Igeometry togeometry = NULL;
Ipoint geomtype = new pointclass ();
Feature. Shape = neapoint as igeometry;
Feature. Store ();
}
}
}