## DEV Community π©βπ»π¨βπ» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Dmitry Matuzko

Posted on

# Creation and validation of geometry in Aspose.GIS

Aspose.GIS handles geospatial data in a common way regardless of storage format, as all the GIS data formats store, in principle, the same kind of data. As such, methods to create and check geometric data are not coupled to format and can be used in any case. In this article I will overview how to create geometric data in Aspose.GIS and check its validity.

## Creation of Point, LineString and Polygon

Point is just a point, LineString is a polyline - a series of connected points, ang Polygon is basically an area enclosed by closed polyline. As such, Point can be instantiated with default values, from another point, or by passing X, Y and optional Z and M coordinates. LineString can be created by instantiating it and then adding points to it - either passing a Point to AddPoint, or just passing coordinates.

Here is an example of creation of Point and LineString:

``````Point point = new Point(40.7128, -74.006);

LineString line = new LineString();

``````

Polygon is a bit more complex. It has outer boundary, a closed polyline represented as LinearRing instance - this class is a LineString that ensures it's closed and doesn't self-intersect -, and it can have multiple inner boundaries, essentially "holes" in its geometry. These are also represented by LinearRing instances. External boundary is placed at ExteriorRing property, while interior rings are accessed by AddInteriorRing and GetInteriorRing methods, with only total count represented as InteriorRingsCount property. Look at the example on creating a polygon with a hole:

``````Polygon polygon = new Polygon();

LinearRing ring = new LinearRing();

LinearRing hole = new LinearRing();

polygon.ExteriorRing = ring;
``````

## Creation of geometry collection

Geometry collection is created in obvious way, create a collection and add elements to it:

``````Point point = new Point(40.7128, -74.006);

LineString line = new LineString();

GeometryCollection geometryCollection = new GeometryCollection();
``````

## Typed geometry collections

There are special collections that only accept the corresponding kind of geometry element: MultiLineString, MultiPoint and MultiPolygon. These only accept LineString, Point and Polygon accordingly:

``````MultiPoint multipoint = new MultiPoint();

LineString firstLine = new LineString();

LineString secondLine = new LineString();

MultiLineString multiLineString = new MultiLineString();

LinearRing firstRing = new LinearRing();
Polygon firstPolygon = new Polygon(firstRing);

LinearRing secondRing = new LinearRing();
Polygon secondPolygon = new Polygon(secondRing);

MultiPolygon multiPolygon = new MultiPolygon();
``````

As you can see, creating geometry is easy.

## Geometry validation

Validation checks wether geometric data in an geometry instance is correct for the type of that instance, i.e. a polygon has an external boundary, a LinearRing is enclosed, etc. It is performed automatically and result is availible at IsValid property. Take a look:

``````LinearRing linearRing = new LinearRing();
bool valid = linearRing.IsValid; // valid == false , as ring is not enclosed
valid = linearRing.IsValid; // valid == true, as ring is now enclosed
``````

Additionally, there is a check for simplicity, in terms of - like no self-intersections, etc. It works same way as validation and availible at IsSimple property.:

``````            LineString lineString = new LineString();
bool simple = lineString.IsSimple; // simple == true
simple = lineString.IsSimple; // simple == true