📄 form1.cs
字号:
}
if (point.Y > 89.891975) //fudge value to clip near poles
{
point.Y = point.Y - 179.78395;
}
else if (point.Y < -89.891975) //fudge value to clip near poles
{
point.Y = point.Y + 179.78395;
}
//Project the point onto the displays current spatial reference
//WHERE the point is going TO
point.Project(m_ProjectedCoordinateSystem);
element.Geometry = point;
}
element = m_GraphicsContainer.Next();
}
//Refresh the graphics
m_MapControl.Refresh(esriViewDrawPhase.esriViewGraphics,Type.Missing,Type.Missing);
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)
{
//If left mouse button then zoom in
if (e.button == 1)
{
m_MapControl.Extent = m_MapControl.TrackRectangle();
}
else
{
//Create a point and get the IPoint interface
IPoint point = new PointClass();
//Set points coordinates
point.PutCoords(e.mapX, e.mapY);
//QI for ITopologicalOperator interface through IPoint interface
ITopologicalOperator topologicalOperator = (ITopologicalOperator) point;
//Create a polygon by buffering the point and get the IPolygon interface
IPolygon polygon = (IPolygon) topologicalOperator.Buffer(m_MapControl.Extent.Width * 0.02);
//QI for IRelationalOperator interface through IPolygon interface
IRelationalOperator relationalOperator = (IRelationalOperator) polygon;
object o = null;
//Draw the polygon
m_MapControl.DrawShape(polygon, ref o);
//Loop through the elements in the GraphicContainer and get the IElement interface
m_GraphicsContainer.Reset();
IElement element = m_GraphicsContainer.Next();
while (element != null)
{
//If the polygon contains the point
if (relationalOperator.Contains(element.Geometry) == true)
{
//QI for IMarkerElement interface through IElement interface
IMarkerElement markerElement = (IMarkerElement) element;
markerElement.Symbol = GetMarkerSymbol(true);
//QI for the IElementProperties interface through IElement interface
IElementProperties elementProperties = (IElementProperties) element;
elementProperties.Name = true.ToString();
}
element = m_GraphicsContainer.Next();
}
if (chkTracking.CheckState == CheckState.Unchecked)
//Refresh the graphics
m_MapControl.Refresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, Type.Missing);
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//Release COM objects
ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
}
private void chkTracking_Click(object sender, System.EventArgs e)
{
//Turn the timer on or off
if (chkTracking.CheckState == CheckState.Checked)
{
timer1.Start();
}
else if (chkTracking.CheckState == CheckState.Unchecked)
{
timer1.Stop();
}
}
private IRgbColor GetRGBColor(int red,int green, int blue)
{
//Create rgb color and grab hold of the IRGBColor interface
IRgbColor rGB = new RgbColorClass();
//Set rgb color properties
rGB.Red = red;
rGB.Green = green;
rGB.Blue = blue;
return rGB;
}
private void SymbolizeData(ILayer layer, double dWidth, IRgbColor colorLine, IRgbColor colorFill)
{
//Create a line symbol and get the ILineSymbol interface
ILineSymbol lineSymbol = new SimpleLineSymbolClass();
//Set the line symbol properties
lineSymbol.Width = dWidth;
lineSymbol.Color = colorLine;
//Create a fill symbol and get the IFillSymbol interface
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
//Set the fill symbol properties
fillSymbol.Outline = lineSymbol;
fillSymbol.Color = colorFill;
//Create a simple renderer and get the ISimpleRenderer interface
ISimpleRenderer simpleRenderer = new SimpleRendererClass();
//Set the simple renderer properties
simpleRenderer.Symbol = (ISymbol) fillSymbol;
//QI for the IGeoFeatureLayer interface from the ILayer2 interface
IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer) layer;
//Set the GeoFeatureLayer properties
geoFeatureLayer.Renderer = (IFeatureRenderer) simpleRenderer;
}
private void MakeCoordinateSystems()
{
//Create a spatial reference environment and get theISpatialReferenceFactory2 interface
ISpatialReferenceFactory2 spatRefFact = new SpatialReferenceEnvironmentClass();
//Create a geographic coordinate system and get the IGeographicCoordinateSystem interface
m_GeographicCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984);
//Create a projected coordinate system and get the IProjectedCoordinateSystem interface
m_ProjectedCoordinateSystem = spatRefFact.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_World_Mollweide);
//Set the map controls spatial reference property
m_MapControl.SpatialReference = m_ProjectedCoordinateSystem;
}
private ICharacterMarkerSymbol GetMarkerSymbol(bool bLocated)
{
//Create a new system draw font
System.Drawing.Font drawFont = new System.Drawing.Font("ESRI Crime Analysis", 21);
//Create a new CharacterMarkerSymbol and get the ICharacterMarkerSymbol interface
ICharacterMarkerSymbol charMarker = new CharacterMarkerSymbolClass();
//Set the marker symbol properties
charMarker.Font = (stdole.IFontDisp) OLE.GetIFontDispFromFont(drawFont);
if (bLocated == true)
{
charMarker.CharacterIndex = 56;
charMarker.Color = GetRGBColor(255, 0, 0);
charMarker.Size = 30;
}
else
{
charMarker.CharacterIndex = 46;
charMarker.Color = GetRGBColor(0, 0, 0);
charMarker.Size = 30;
}
return charMarker;
}
private void DisplayAgentLocation(AGENT_IN_FIELD agent)
{
//Create a point and get the IPoint interface
IPoint point = new PointClass();
//Set the points x and y coordinates
point.PutCoords(agent.Longitude, agent.Latitude);
//Set the points spatial reference - WHERE the point is coming FROM
point.SpatialReference = m_GeographicCoordinateSystem;
//Project the point onto the displays current spatial reference - WHERE the point is going TO
point.Project(m_ProjectedCoordinateSystem);
//Create a marker element and get the IElement interface
IElement element = new MarkerElementClass();
//Set the elements geometry
element.Geometry = point;
//QI for the IMarkerElement interface from the IElement interface
IMarkerElement markerElement = (IMarkerElement) element;
//Set the marker symbol
markerElement.Symbol = GetMarkerSymbol(agent.Located);
//QI for the IElementProperties interface from the IMarkerElement interface
IElementProperties elementProperties = (IElementProperties) markerElement;
elementProperties.Name = agent.Located.ToString();
//Add the element to the graphics container
m_GraphicsContainer.AddElement(element, 0);
}
private void LoadAgentArray()
{
//Populate an array of agent locations and id's. The locations are in decimal degrees,
//based on the WGS1984 geographic coordinate system. [ie unprojected].
//Obviously, these values could be read directly from a GPS unit.
agentArray[0].CodeNumber = "001";
agentArray[0].Latitude = 56.185128983308;
agentArray[0].Longitude = 37.556904400607;
agentArray[0].Located = false;
agentArray[1].CodeNumber = "002";
agentArray[1].Latitude = 48.3732928679818;
agentArray[1].Longitude = 6.91047040971168;
agentArray[1].Located = false;
agentArray[2].CodeNumber = "003";
agentArray[2].Latitude = 32.1487101669196;
agentArray[2].Longitude = 39.3596358118361;
agentArray[2].Located = false;
agentArray[3].CodeNumber = "004";
agentArray[3].Latitude = 29.7450682852807;
agentArray[3].Longitude = 71.2078907435508;
agentArray[3].Located = false;
agentArray[4].CodeNumber = "005";
agentArray[4].Latitude = 38.7587253414264;
agentArray[4].Longitude = 138.509863429439;
agentArray[4].Located = false;
agentArray[5].CodeNumber = "006";
agentArray[5].Latitude = 35.1532625189681;
agentArray[5].Longitude = -82.0242792109256;
agentArray[5].Located = false;
agentArray[6].CodeNumber = "007";
agentArray[6].Latitude = -26.1396054628225;
agentArray[6].Longitude = 28.5432473444613;
agentArray[6].Located = true;
agentArray[7].CodeNumber = "008";
agentArray[7].Latitude = 33.9514415781487;
agentArray[7].Longitude = 3.90591805766313;
agentArray[7].Located = false;
agentArray[8].CodeNumber = "009";
agentArray[8].Latitude = 29.7450682852807;
agentArray[8].Longitude = 16.5250379362671;
agentArray[8].Located = false;
agentArray[9].CodeNumber = "010";
agentArray[9].Latitude = 45.9696509863429;
agentArray[9].Longitude = 23.1350531107739;
agentArray[9].Located = false;
agentArray[10].CodeNumber = "011";
agentArray[10].Latitude = 48.9742033383915;
agentArray[10].Longitude = 14.1213960546282;
agentArray[10].Located = false;
agentArray[11].CodeNumber = "012";
agentArray[11].Latitude = 29.7450682852807;
agentArray[11].Longitude = 79.0197268588771;
agentArray[11].Located = false;
agentArray[12].CodeNumber = "013";
agentArray[12].Latitude = 43.5660091047041;
agentArray[12].Longitude = 125.289833080425;
agentArray[12].Located = false;
agentArray[13].CodeNumber = "014";
agentArray[13].Latitude = 7.5113808801214;
agentArray[13].Longitude = -68.2033383915023;
agentArray[13].Located = false;
agentArray[14].CodeNumber = "015";
agentArray[14].Latitude = 9.31411229135053;
agentArray[14].Longitude = -79.6206373292868;
agentArray[14].Located = false;
agentArray[15].CodeNumber = "016";
agentArray[15].Latitude = 8.71320182094082;
agentArray[15].Longitude = -9.31411229135053;
agentArray[15].Located = true;
agentArray[16].CodeNumber = "017";
agentArray[16].Latitude = 22.5341426403642;
agentArray[16].Longitude = 53.7814871016692;
agentArray[16].Located = false;
agentArray[17].CodeNumber = "018";
agentArray[17].Latitude = 42.3641881638847;
agentArray[17].Longitude = 45.9696509863429;
agentArray[17].Located = false;
agentArray[18].CodeNumber = "019";
agentArray[18].Latitude = 39.3596358118361;
agentArray[18].Longitude = 27.9423368740516;
agentArray[18].Located = false;
agentArray[19].CodeNumber = "020";
agentArray[19].Latitude = 22.5341426403642;
agentArray[19].Longitude = 104.257966616085;
agentArray[19].Located = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -