geometries library
Features
Doing geospatial calculations requires feature types. This library provides a set of feature types for use in geospatial calculations, as well as a set of functions for working with them.
Geometry Types
The Feature class is the base class for all feature types.
Single Features
- The Point class is a feature type for points.
- The LineString class is a feature type for line strings.
- The Polygon class is a feature type for polygons.
Multi Features
- The MultiPoint class is a feature type for multi points.
- The MultiLineString class is a feature type for multi line strings.
- The MultiPolygon class is a feature type for multi polygons.
Geometry Collections
- The FeatureCollection class is a feature type for feature collections.
Coordinates
- The Coordinate class is a coordinate type for to denote one location with lat/long data.
- The LinearRing class is a coordinate type for linear rings, which is a geometry type for polygons.
- The BoundingBox class is a coordinate system for bounding boxes.
About Features
Each of the above feature classes has a toJson
method that returns a GeoJSON Map of the feature,
as well as a fromJson
method that creates a feature from a GeoJSON Map.
Each of the above feature classes also has a toWKT
method that returns a WKT String of the feature,
and a fromWKT
method that creates a feature from a WKT String.
Every feature has an explode
method that returns a List of Points used to create the feature.
Every Multi
feature type has an flatten
method that returns a List of the individual
features, as well as a union
method that returns a Feature of the union of the individual features.
Examples of how to use the above feature classes are shown below.
import 'package:geodart/geometries.dart';
// Create a point feature
Point point = Point(
Coordinate(1.0, 2.0)
properties: {
'name': 'Point',
'description': 'A point feature',
});
// Create a line string feature
LineString line = LineString([
Coordinate(1.0, 2.0),
Coordinate(3.0, 4.0),
Coordinate(5.0, 6.0),
Coordinate(7.0, 8.0),
Coordinate(9.0, 10.0),
],
properties: {
'name': 'LineString',
'description': 'A line string feature',
}
);
// Create a polygon feature
Polygon poly = Polygon([
LinearRing([
Coordinate(1.0, 2.0),
Coordinate(3.0, 4.0),
Coordinate(5.0, 6.0),
Coordinate(7.0, 8.0),
Coordinate(9.0, 11.0),
Coordinate(1.0, 2.0)
])],
properties: {
'name': 'Polygon',
'description': 'A polygon feature',
}
);
// Create a multi point feature
MultiPoint multiPoint = MultiPoint([
Coordinate(1.0, 2.0),
Coordinate(3.0, 4.0),
Coordinate(5.0, 6.0),
]),
properties: {
'name': 'MultiPoint',
'description': 'A multi point feature',
}
);
Classes
- BoundingBox
- A BoundingBox is a rectangular region in a coordinate system, generally used to define the extent of a Feature or FeatureCollection. A BoundingBox can be created from a Coordinate or a WKT String.
- Coordinate
- The base coordinate class, used by all feature types. It's used to represent a point in geographic coordinates.
- Feature
- The base class for all feature types.
- FeatureCollection
- A FeatureCollection is a collection of Features.
- LinearRing
- A LinearRing is a closed series of Coordinates. It is used in Polygons and MultiPolygons. Closed means the first and last Coordinates are the same.
- LineString
- A LineString is a Feature made up of connected Coordinates to form a line.
- MultiLineString
- A MultiLineString is a Feature made up of a List of LineString Coordinates.
- MultiPoint
- a MultiPoint is a collection of Coordinates that share properties.
- MultiPolygon
- A MultiPolygon is a collection of Polygon Geometries with shared properties.
- Point
- A Point is a single position in a coordinate system, with properties. A Point can be created from a Coordinate, from a WKT String, or from a GeoJSON Map. A Point can be converted to a WKT String or GeoJSON Map.
- Polygon
- A Polygon is a single closed path with shared properties. The first LinearRing defines the outer boundary of the Polygon, while the following LinearRings define holes within the Polygon.