using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using AxMapWinGIS;
using MapWinGIS;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private List mapList = new List();
public Point MouseDowLocation;
private bool IsMouseDow = false;
private int m_Startx;
private int m_Starty;
private int m_Endx;
private int m_Endy;
private int m_CurX;
private int m_CurY;
private String Drawcase = “Circle”;
Point Point1 = new Point();
Point Point2 = new Point();
Point StartDowLocation = new Point();
public class Circle
{
}
public Form1()
{
InitializeComponent();
}
private void ToolStripButton9_Click(object sender, EventArgs e)
{
Application.Exit();
}
// <resumo>
// Cria um shapefile contendo polĂgonos com furos
// </summary>
private void toolStripButton1_Click(object sender, EventArgs e)
{
axMap1.Projection = tkMapProjection.PROJECTION_NONE;
var sf = new Shapefile();
bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON);
if (!result)
{
MessageBox.Show(sf.ErrorMsg[sf.LastErrorCode]);
}
else
{
double xMin = 0.0;
double yMin = 0.0;
double xMax = 5.0;
double yMax = 5.0;
Random rnd = new Random(DateTime.Now.Millisecond);
// builds 1 polygons
for (int i = 0; i < 1; i++)
{
double xCenter = xMin + (xMax - xMin) * rnd.NextDouble();
double yCenter = yMin + (yMax - yMin) * rnd.NextDouble();
// random radius from 10 to 100
double radius = 3 + rnd.NextDouble() * 1;
var shp = new Shape();
shp.Create(ShpfileType.SHP_POLYGON);
// o polĂgono deve ter a ordem dos pontos no sentido horário (primeiro argumento - true)
this.AddRing(true, xCenter, yCenter, radius, ref shp);
// os buracos devem ter a ordem dos pontos no sentido anti-horário (fale para o último argumento)
this.AddRing(false, xCenter, yCenter, radius / 2.0, ref shp);
for (int j = 0; j < shp.NumParts; j++)
{
Debug.Print("Part is clocwise: " + shp.PartIsClockWise[j]);
}
Debug.Print("Shape is valid: " + shp.IsValid);
if (!shp.IsValid)
Debug.Print("Reason: " + shp.IsValidReason);
sf.EditInsertShape(shp, ref i);
}
axMap1.AddLayer(sf, true);
axMap1.ZoomToLayer(0);
sf.SaveAs(@"c:\polygons.shp", null);
}
}
// <resumo>
// Adiciona um anel ao polĂgono
// </summary>
private void AddRing(bool clockWise, double x, double y, double radius, ref Shape shp)
{
int partIndex = shp.NumParts;
if (shp.numPoints > 0)
shp.InsertPart(shp.numPoints, ref partIndex);
int count = 0;
for (int j = 0; j < 38; j++)
{
double dx = radius * Math.Cos(j * Math.PI / 18);
double dy = radius * Math.Sin(j * Math.PI / 18);
//dx *= clockWise ? -1 : 1;
dy *= clockWise ? -1 : 1;
var pnt = new Point();
pnt.x = x + dx;
pnt.y = y + dy;
count = shp.numPoints;
shp.InsertPoint(pnt, ref count);
}
}
private void AxMap1_MouseDownEvent(object sender,_DMapEvents_MouseDownEvent e)
{
IsMouseDow = true;
m_Startx = e.x;
m_Starty = e.y;
m_CurX = e.x;
m_CurY = e.y;
StartDowLocation = e.`Location;`(At this point it is giving an error because the Polygon being created will not work because the Location Attribute does not exist in the AxMap1_MouseDownEvent(object sender,_DMapEvents_MouseDownEvent e) error CS1061 IT WAS NOT POSSIBLE TO FIND A DEFINITION FOR LOCATION INSIDE axMap 1 and no Method to insert in C# I need help.)
}
private void axMap1_MouseMoveEvent(object sender, _DMapEvents_MouseMoveEvent e)
{
}
private void axMap1_MouseUpEvent(object sender, _DMapEvents_MouseUpEvent e)
{
}
}
}