proj4dart 1.0.1 copy "proj4dart: ^1.0.1" to clipboard
proj4dart: ^1.0.1 copied to clipboard

outdated

Proj4dart is a Dart library to transform point coordinates from one coordinate system to another, including datum transformations (Dart version of proj4js/proj4js).

PROJ4DART #

Proj4dart is a Dart library to transform point coordinates from one coordinate system to another, including datum transformations (Dart version of proj4js/proj4js).

Installing #

Add proj4dart to pubspec.yml (dependencies section), then run pub get to download the new dependencies.

dependencies:
  proj4dart: any # or the latest version on Pub

Using #

Predefined Projection #

There are 3 predefined Projections and 5 aliases by default:

  • EPSG:4326, which has the following alias:
    • WGS84
  • EPSG:4269
  • EPSG:3857, which has the following aliases:
    • EPSG:3785
    • GOOGLE
    • EPSG:900913
    • EPSG:102113

If you wish to use one of the predefined ones the signature is:

  var projection = Projection('EPSG:4326');

User-defined Projection #

Proj4dart supports Proj4 definition strings, OGC WKT definitions and ESRI WKT definitions. They can be obtained from epsg.io.

With Proj4 string definition

If you wish to define your own projection you can create it with a valid Proj4 string (here for EPSG:23700):

+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 signature is:

var projection = Projection.add('EPSG:23700',
      '+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');

For full example visit example/proj4dart_example.dart

With OGC WKT definition

If you wish to define your own projection you can create it with a valid OGC WKT string (here for EPSG:23700):

PROJCS["HD72 / EOV",GEOGCS["HD72",DATUM["Hungarian_Datum_1972",SPHEROID["GRS 1967",6378160,298.247167427,AUTHORITY["EPSG","7036"]],TOWGS84[52.17,-71.82,-14.9,0,0,0,0],AUTHORITY["EPSG","6237"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4237"]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",47.14439372222222],PARAMETER["longitude_of_center",19.04857177777778],PARAMETER["azimuth",90],PARAMETER["rectified_grid_angle",90],PARAMETER["scale_factor",0.99993],PARAMETER["false_easting",650000],PARAMETER["false_northing",200000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Y",EAST],AXIS["X",NORTH],AUTHORITY["EPSG","23700"]]

The signature is:

var projection = Projection.add('EPSG:23700',
      'PROJCS["HD72 / EOV",GEOGCS["HD72",DATUM["Hungarian_Datum_1972",SPHEROID["GRS 1967",6378160,298.247167427,AUTHORITY["EPSG","7036"]],TOWGS84[52.17,-71.82,-14.9,0,0,0,0],AUTHORITY["EPSG","6237"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4237"]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",47.14439372222222],PARAMETER["longitude_of_center",19.04857177777778],PARAMETER["azimuth",90],PARAMETER["rectified_grid_angle",90],PARAMETER["scale_factor",0.99993],PARAMETER["false_easting",650000],PARAMETER["false_northing",200000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Y",EAST],AXIS["X",NORTH],AUTHORITY["EPSG","23700"]]');

For full example visit example/proj4dart_ogc_wkt_example.dart

With ESRI WKT definition

If you wish to define your own projection you can create it with a valid ESRI WKT string (here for EPSG:23700):

PROJCS["HD72_EOV",GEOGCS["GCS_HD72",DATUM["D_Hungarian_1972",SPHEROID["GRS_1967",6378160,298.247167427]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",47.14439372222222],PARAMETER["longitude_of_center",19.04857177777778],PARAMETER["azimuth",90],PARAMETER["scale_factor",0.99993],PARAMETER["false_easting",650000],PARAMETER["false_northing",200000],UNIT["Meter",1]]

The signature is:

var projection = Projection.add('EPSG:23700',
      'PROJCS["HD72_EOV",GEOGCS["GCS_HD72",DATUM["D_Hungarian_1972",SPHEROID["GRS_1967",6378160,298.247167427]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Hotine_Oblique_Mercator_Azimuth_Center"],PARAMETER["latitude_of_center",47.14439372222222],PARAMETER["longitude_of_center",19.04857177777778],PARAMETER["azimuth",90],PARAMETER["scale_factor",0.99993],PARAMETER["false_easting",650000],PARAMETER["false_northing",200000],UNIT["Meter",1]]');

For full example visit example/proj4dart_esri_wkt_example.dart

Transform between Projections #

import 'package:proj4dart/proj4dart.dart';

void main() {
  // Define Point
  var pointSrc = Point(x: 17.888058560281515, y: 46.89226406700879);

  // Use built-in projection
  var epsgSrc = 'EPSG:4326';
  var projSrc = Projection(epsgSrc);

  // Define custom projection
  var epsgDst = 'EPSG:23700';
  var projDst = Projection.add(epsgDst,
      '+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');

  // Forward transform (lonlat -> projected crs)
  var pointForward = projSrc.transform(projDst, pointSrc);
  print(
      'FORWARD: Transform point [${pointSrc.x}, ${pointSrc.y}] from $epsgSrc to $epsgDst: [${pointForward.x}, ${pointForward.y}]');
  // FORWARD: Transform point [17.888058560281515, 46.89226406700879] from EPSG:4326 to EPSG:23700: [561651.8408065987, 172658.61998377228]

  // Inverse transform (projected crs -> lonlat)
  var pointInverse = projDst.transform(projSrc, pointForward);
  print(
      'INVERSE: Transform point [${pointForward.x}, ${pointForward.y}] from $epsgDst to $epsgSrc: [${pointInverse.x}, ${pointInverse.y}]');
  // INVERSE: Transform point [561651.8408065987, 172658.61998377228] from EPSG:23700 to EPSG:4326: [17.888058565574845, 46.89226406698969]
}

Accuracy #

Proj4dart was tested with

Forward and inverse transformations were both performed and checked in each case. The expected forward and inverse results were pre-calculated using proj4js (test/results/all_proj4_results.dart, test/results/all_proj4_ogc_wkt_results.dart, test/results/all_proj4_esri_wkt_results.dart).

Acceptance criteria was:

  • precision delta of 0.000001 in case of LonLat
  • precision delta of 0.00001 in case of projected CRS.

Example (using EPSG:4326 point of [17.888058560281515, 46.89226406700879] and transformed to EPSG:23700 defined with Proj4 definition string):

LIBRARY forward_x forward_y inverse_x inverse_y
proj4dart 561651.8408065987 172658.61998377228 17.888058565574845 46.89226406698969
proj4js 561651.8408065989 172658.61998377228 17.888058565574852 46.89226406698969
delta 0.0000000002 0.0 0.000000000000007 0.0

In some cases also manual PostGIS testing (PostgreSQL 12.1, PostGIS 3.0.0 r17983) was performed such as the following (using EPSG:4326 point of [17.888058560281515, 46.89226406700879] and transformed to EPSG:23700 defined with Proj4 definition string):

LIBRARY forward_x forward_y inverse_x inverse_y
proj4dart 561651.8408065987 172658.61998377228 17.888058565574845 46.89226406698969
PostGIS 561651.8408065987 172658.6199837724 17.88805856557482 46.8922640683514
delta 0.0 0.00000000012 0.000000000000025 0.00000000136171

Authors #

Proj4dart was ported from proj4js by @maRci002 and Gergely Padányi-Gulyás (@fegyi001) at Ulyssys Ltd, Budapest, Hungary.

38
likes
0
pub points
93%
popularity

Publisher

unverified uploader

Proj4dart is a Dart library to transform point coordinates from one coordinate system to another, including datum transformations (Dart version of proj4js/proj4js).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

mgrs_dart, wkt_parser

More

Packages that depend on proj4dart