Skip to content

Projections

🌐 WGS 84 to Web Mercator

Built-in coordinate projections (currently only between WGS84 and Web Mercator).

Here projected coordinates are metric coordinates with both x and y values having the valid value range of (-20037508.34, 20037508.34).

// Sample point as geographic coordinates.
const geographic = Geographic(lon: -0.0014, lat: 51.4778);
// Geographic (WGS 84 longitude-latitude) to Projected (WGS 84 Web Mercator).
final forward = WGS84.webMercator.forward;
final projected = geographic.project(forward);
// Projected (WGS 84 Web Mercator) to Geographic (WGS 84 longitude-latitude).
final inverse = WGS84.webMercator.inverse;
final unprojected = projected.project(inverse);
print('$unprojected <=> $projected');

🗺️ With proj4dart

Coordinate projections based on the external proj4dart package requires imports like:

// import the default geobase library
import 'package:geobase/geobase.dart';
// need also an additional import with dependency to `proj4dart`
import 'package:geobase/projections_proj4d.dart';

Then a sample to use coordinate projections:

// The projection adapter between WGS84 (CRS84) and EPSG:23700 (definition)
// (based on the sample at https://pub.dev/packages/proj4dart).
final adapter = Proj4d.init(
CoordRefSys.CRS84,
CoordRefSys.normalized('EPSG:23700'),
targetDef: '+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 '
'+k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 '
'+towgs84=52.17,-71.82,-14.9,0,0,0,0 +units=m +no_defs',
);
// The forward projection from WGS84 (CRS84) to EPSG:23700.
final forward = adapter.forward;
// A source geographic position.
const geographic = Geographic(lat: 46.8922, lon: 17.8880);
// Apply the forward projection returning a projected position in EPSG:23700.
final projected = geographic.project(forward);
// Prints: "561647.27300,172651.56518"
print(projected.toText(decimals: 5));

Please see the documentation of proj4dart package about it’s capabilities, and accuracy of forward and inverse projections.

🧩 Geometries and features

Geometry classes introduced in simple geometries and feature objects introduced in geospatial features have also project method that allow applying projections directly on them.

It’s also possible to implement your own custom projections by extending ProjectionAdapter mixin in your projection class. See Dart code of projections between WGS 84 (geographic) and Web Mercator (projected with metric coordinates) as an example. Custom projections can be applied to geometry and feature objects just like projections provided by packages discussed above.