A geographical application can host the control as its map surface. Survey points, parcel boundaries and labels are ordinary drawing entities, and the X and Y of the drawing are the map coordinates: an easting and a northing, or a local survey grid. The application reads the survey, identifies the boundary under the pointer, measures the parcel and writes the map back as a DXF or DWG.

Survey files

ReadGEO

ReadGEO replaces the current drawing with a GEO file. The file must start with the record #~1. Points, lines, arcs, circles, text and dimensions become drawing entities. Precision is stored as the linear-unit precision of the drawing. The default is 2.

GEO recordEntity in the drawing
P A survey point. Later records refer to it by index
LIN A line between two points
ARC, FIL An arc. FIL is a fillet
CIR A circle
TXT A text label, with its height and rotation
ATT A dimension. Type 11 is a diameter. Types 12 and 13 are linear dimensions, horizontal or vertical
#~331 … #~KONT_END One contour. With ContoursToPolylines the lines and arcs of the contour become a single polyline

Each GEO layer number is placed on a named layer: 0 Black, 1 White, 2 Red, 3 Yellow, 4 Green, 5 Cyan, 6 Blue, 7 Magenta. Dimensions are placed on the Cyan layer. After the read, ZoomCenter frames the survey in the view.

dxfReaderNETControl1.ReadGEO(@"C:\survey\site.geo", true, 3);
dxfReaderNETControl1.ZoomCenter();

Map drawings

ReadDXF and ReadDWG

Cadastral maps, site plans and contour drawings that are already DXF or DWG files are opened with ReadDXF and ReadDWG. The DXF property exposes the entities and the layers, so the application can show or hide a layer, such as boundaries, buildings or text. WriteDXF and WriteDWG save the map for another program.

dxfReaderNETControl1.ReadDXF(@"C:\maps\parcels.dxf");
Layer boundaries = dxfReaderNETControl1.DXF.Layers["BOUNDARIES"];
boundaries.IsVisible = true;

Coordinates

CoordsToWorld and WorldToCoords

CoordsToWorld converts a pixel of the control into the map point under the pointer. The values are the X and Y of the drawing, so they are the easting and the northing when the file was stored in a projected grid. WorldToCoords places a computed point back on the screen. DXF.ToFormattedUnit formats a coordinate with the precision of the drawing.

Vector2 mapPoint = dxfReaderNETControl1.CoordsToWorld(e.X, e.Y);
string easting = dxfReaderNETControl1.DXF.ToFormattedUnit(mapPoint.X);
string northing = dxfReaderNETControl1.DXF.ToFormattedUnit(mapPoint.Y);

Parcels

Boundaries, area and the entity under the pointer

GetEntity returns the boundary, the building or the label nearest to a click. GetEntities returns everything inside a rectangle. MathHelper.FindClosedAreaData returns the outer perimeter, the outer area, the length and area of the holes, and the number of inner contours. The parcel area is the outer area minus the inner area.

A new parcel is a closed polyline. AddHatch fills it. AddText writes the parcel number at a point on the map.

Vector2 point = dxfReaderNETControl1.CoordsToWorld(e.X, e.Y);
EntityObject boundary = dxfReaderNETControl1.GetEntity(point);
double externalLength, externalArea, internalLength, internalArea; int holes; MathHelper.FindClosedAreaData( dxfReaderNETControl1.DXF.Entities, out externalLength, out externalArea, out internalLength, out internalArea, out holes);
dxfReaderNETControl1.AddText("12", labelPoint, labelPoint, 2.5);

Background map

AddImage and AddPDFUnderlay

AddImage places a raster, such as an orthophoto or a scanned sheet, at a position of the drawing and at a given width and height, so the picture shares the coordinates of the vectors. AddPDFUnderlay places a PDF page the same way. Transparency keeps the vectors readable on top of the picture.

dxfReaderNETControl1.AddImage( @"C:\maps\orthophoto.jpg", origin, width, height, 0, 40);

Precise corners

ObjectOsnapMode

ObjectSnap locks the pointer to the geometry while the user traces a boundary or places a label. Endpoint catches a parcel corner, Intersection the crossing of two boundaries, Insertion the insertion point of a text or a block, and Nearest a point along a line. Modes are combined with a bitwise OR.

dxfReaderNETControl1.ObjectSnap = true;
dxfReaderNETControl1.ObjectOsnapMode = ObjectOsnapTypeFlags.Endpoint | ObjectOsnapTypeFlags.Intersection | ObjectOsnapTypeFlags.Insertion;

Print and exchange

Plot, Image and WriteDXF

Plot prints the current view. PlotPreview draws it into a PrintPreviewControl, and ShowPlotSettings opens the plot dialog. The Image property is the bitmap of the map currently on screen. WriteDXF and WriteDWG hand the survey to a CAD or GIS program. PlotRendering chooses color, gray scale or monochrome output.

dxfReaderNETControl1.PlotRendering = PlotRenderingType.Color;
dxfReaderNETControl1.Plot();
dxfReaderNETControl1.WriteDXF(@"C:\maps\site.dxf");