GithubHelp home page GithubHelp logo

marci002 / proj4dart Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 2.0 3.08 MB

Proj4dart is a Dart library to transform point coordinates from one coordinate system to another, including datum transformations.

License: MIT License

Dart 99.96% JavaScript 0.04%
dart crs proj4js proj4 gis wkt srs

proj4dart's Introduction

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 use Named Projection which has the following signature:

  var projection = Projection.get('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 def = '+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';

// Named Projection signature, later find it from anywhere via Projection.get('EPSG:23700')
var namedProjection = Projection.add('EPSG:23700', def);
// Projection without name signature
var projection = Projection.parse(def);

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 def = '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"]]';

// Named Projection signature, later find it from anywhere via Projection.get('EPSG:23700')
var namedProjection = Projection.add('EPSG:23700', def);
// Projection without name signature
var projection = Projection.parse(def);

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 def = '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]]');

// Named Projection signature, later find it from anywhere via Projection.get('EPSG:23700')
var namedProjection = Projection.add('EPSG:23700', def);
// Projection without name signature
var projection = Projection.parse(def);

For full example visit example/proj4dart_esri_wkt_example.dart

Grid Based Datum Adjustments

To use +nadgrids= in a proj definition, first read your NTv2 .gsb file into an Uint8List, then pass to Projection.nadgrid. E.g:

Dart:

final bytes = await File(
  'assets/my_grid.gsb',
).readAsBytes();

Projection.nadgrid('key', bytes);

Flutter:

import 'package:flutter/services.dart' show rootBundle;
final bytes = (await rootBundle.load(fileName)).buffer.asUint8List();

Projection.nadgrid('key', bytes);

then use the given key in your definition, e.g. +nadgrids=@key,null. See Proj4 General Parameters.

Nadgrid example:

import 'package:flutter/services.dart' show rootBundle;

final bytes = (await rootBundle.load('assets/nzgd2kgrid0005.gsb')).buffer.asUint8List();
Projection.nadgrid('nzgd2kgrid0005.gsb', bytes);

var def = '+proj=longlat +datum=nzgd49 +towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993 +nadgrids=nzgd2kgrid0005.gsb +no_defs';
var namedProjection = Projection.add('EPSG:4272', def);

For full example visit example/proj4dart_shift_grid_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 projSrc = Projection.get('EPSG:4326')!;

  // Find Projection by name or define it if not exists
  var projDst = Projection.get('EPSG:23700') ??
      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',
      );

  // Forward transform (lonlat -> projected crs)
  var pointForward = projSrc.transform(projDst, pointSrc);
  print(
      'FORWARD: Transform point ${pointSrc.toArray()} from EPSG:4326 to EPSG:23700: ${pointForward.toArray()}');
  // 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.toArray()} from EPSG:23700 to EPSG:4326: ${pointInverse.toArray()}');
  // INVERSE: Transform point [561651.8408065987, 172658.61998377228] from EPSG:23700 to EPSG:4326: [17.888058565574845, 46.89226406698969]
}

Transform between Projections using ProjectionTuple

import 'package:proj4dart/proj4dart.dart';

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

  // Define ProjectionTuple which makes vice versa conversions even easier
  var tuple = ProjectionTuple(
    // Use built-in projection
    fromProj: Projection.get('EPSG:4326')!,
    // Define custom projection
    toProj: Projection.parse(
      '+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 = tuple.forward(pointSrc);
  print(
      'FORWARD: Transform point ${pointSrc.toArray()} from EPSG:4326 to EPSG:23700: ${pointForward.toArray()}');
  // FORWARD: Transform point [17.888058560281515, 46.89226406700879] from EPSG:4326 to EPSG:23700: [561651.8408065987, 172658.61998377228]

  // Inverse transform (projected crs -> lonlat)
  var pointInverse = tuple.inverse(pointForward);
  print(
      'INVERSE: Transform point ${pointForward.toArray()} from EPSG:23700 to EPSG:4326: ${pointInverse.toArray()}');
  // 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).

The following table shows the avarage deltas of different Projections (using EPSG:4326 point of [17.888058560281515, 46.89226406700879] and transformed to Custom CRS defined with Proj4 definition string which gave the forward result then transformed back the received forward result which gave the inverse result):

Projection No. tests avg delta forward_x avg delta forward_y avg delta inverse_x avg delta inverse_y
Albers Projection 58 2.8260822953849e-9 1.6378431484617036e-9 1.0719394720518753e-14 1.0903155772870503e-14
Azimuthal Equidistant Projection 12 7.761021455128987e-11 1.5522042910257974e-10 1.7763568394002505e-15 1.1842378929335002e-15
Cassini Projection 33 3.9510654680656665e-10 3.3866275440562856e-10 3.2297397080004555e-16 0.0
Central Cylindrical Projection 5 0.0 0.0 0.0 0.0
Equidistant Conic Projection 9 1.2935035758548312e-11 0.0 1.578983857244667e-15 0.0
Equidistant Cylindrical Projection 25 0.0 0.0 0.0 0.0
Geocentric Projection 196 0.0 0.0 9.06304509898087e-17 0.0
Gnomic Projection 2 0.0 0.0 3.552713678800501e-15 0.0
Hotine Oblique Mercator Projection 51 4.460304683330012e-9 8.017819959158991e-9 6.339155779820502e-15 3.901018941428001e-15
Krovak Projection 9 9.054525030983819e-10 1.448724004957411e-9 1.578983857244667e-15 3.157967714489334e-15
Lambert Azimuthal Equal-Area Projection 20 5.820766091346741e-11 0.0 5.329070518200751e-16 0.0
Lambert Conformal Conic Projection 2028 1.8960008225716005e-8 1.2588414830372427e-8 4.613097105712702e-14 8.064379757884726e-14
LongLat 1152 1.6961740653995446e-16 0.0 2.312964634635743e-16 2.7755575615628914e-16
Miller Cylindrical Projection 2 0.0 0.0 0.0 0.0
Mollweide Projection 2 0.0 0.0 0.0 0.0
New Zealand Map Grid Projection 1 0.0 0.0 0.000003294908452744494 0.000008533214440831216
Orthographic Projection 2 0.0 0.0 7.105427357601002e-15 3.552713678800501e-15
Polyconic Projection 10 0.0 0.0 1.1842378929335002e-15 0.0
Pseudo Mercator Projection 25 0.0 3.7252902984619143e-10 1.4210854715202004e-16 2.842170943040401e-16
Robinson Projection 2 0.0 0.0 0.0 0.0
Sinusoidal Projection 3 0.0 0.0 0.0 0.0
Stereographic North Projection 21 2.217434701465425e-11 2.993536846978324e-10 4.906128413581644e-15 1.3534147347811431e-15
Stereographic South Projection 44 2.43414258446509e-10 2.063731004268861e-10 1.3726393759001935e-15 0.0
Swiss Oblique Mercator Projection 5 4.656612873077393e-11 0.0 1.4210854715202005e-15 0.0
Transverse Mercator Projection 3445 7.527289676908484e-12 5.01819311793899e-12 3.966550829771659e-13 3.0942861377693824e-13
Universal Transverse Mercator Projection 1279 3.4847229055075836e-10 3.429655454604303e-10 3.4304936617033767e-15 2.4999548951684524e-15
Van der Grinten Projection 2 3.3760443329811096e-9 2.3283064365386963e-9 0.0 0.0

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

Used by

  • Proj4dart is currently the default projection handler of flutter_map.

Authors

Proj4dart was ported from proj4js by @maRci002 and Gergely Padányi-Gulyás (@fegyi001).

proj4dart's People

Contributors

marci002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

proj4dart's Issues

flutter_map - Proj4Crs (Custom CRS) not works

Even if this is happening in a flutter_map project, I feel that it makes sense to post the issue here.

I am trying to load a WMS layer with a defined CRS. What I am doing is more or less:

    final resolutions = <double>[
      134217728, // 20
      67108864,
      33554432,
      16777216,
      8388608,
      4194304, //15
      2097152,
      1048576,
      524288,
      262144,
      131072, // 10
      65536,
      32768, 
      16384,
      8192,
      4096, // 5
      2048,
      1024,
      512,
      256, 
      128, // 0
    ];
    var crs = Proj4Crs.fromFactory(
        code: 'EPSG:3857',
        proj4Projection: projection3857,
        resolutions: resolutions);

    List<LayerOptions> layers = [
      TileLayerOptions(
        opacity: 1,
        backgroundColor: Colors.transparent,
        wmsOptions: WMSTileLayerOptions(
          crs: crs,
          transparent: true,
          format: imageFormat,
          baseUrl: _getCapabilitiesUrl,
          layers: [_layerName],
        ),
      )
    ];

But on creation of the layer, I am getting:

The setter 'z=' was called on null.
Receiver: null
Tried calling: z=null

with the following stacktrace:

The relevant error-causing widget was
    FlutterMap 
lib/…/core/onlinesourcespage.dart:216
When the exception was thrown, this was the stack
#0      Object.noSuchMethod  (dart:core-patch/object_patch.dart:53:5)
#1      Projection.transform package:proj4dart/…/classes/projection.dart:171
#2      _Proj4Projection.project package:flutter_map/…/crs/crs.dart:452
#3      WMSTileLayerOptions.getUrl package:flutter_map/…/layer/tile_layer.dart:262
#4      TileProvider.getTileUrl package:flutter_map/…/tile_provider/tile_provider.dart:20
...

Am I missing something in the creation?

Just as info, if it helps:

On a sidenote: when removing the crs option it works.

Accuracy issue from EPSG:26716 to EPSG:4326

I'm trying to transform from EPSG:26716 to EPSG:4326, and the results I get with proj4dart are slightly off.

Here's the code:

    final tuple = proj4.ProjectionTuple(
      fromProj: proj4.Projection.parse('+proj=utm +zone=16 +datum=NAD27 +units=m +no_defs'),
      toProj: proj4.Projection.WGS84,
    );

    final pointSrc = proj4.Point(x: 444650, y: 4640510);
    final pointForward = tuple.forward(pointSrc);
    print('Transform point ${pointSrc.toArray()} from EPSG:26716 to EPSG:4326: ${pointForward.toArray()}');

proj4dart gives [-87.66744437695456, 41.9143951210944]
while epsg.io gives [-87.6674992, 41.9165563]
cf https://epsg.io/transform#s_srs=26716&t_srs=4326&x=444650.0000000&y=4640510.0000000

The difference in latitude is particularly noticeable. Am I misusing the library?

Custom CRS give the wrong result on Proj4Dart.

Now I am using Proj4Dart V2.0.0 & Flutter 3.0.4, found some big different of transform coordinates from my custom CRS. This is my code:

`import 'package:proj4dart/proj4dart.dart';

void main() {
var n1 = 1657193.5292;
var e1 = 834934.4417;
var ptSrc = Point(x: e1, y: n1);
var projSrc =
Projection.parse('+proj=utm +zone=47 +datum=WGS84 +units=m +no_defs');
var projDst = Projection.parse(
'+proj=tmerc +lat_0=0.0 +lon_0=102.25 +k_0=1.0 +x_0=500000 +y_0=0 +a=6378297.0 +b=6356911.77779 +towgs84=0.0,0.0,0.0,0,0,0,0 +units=m +no_defs type=crs');
var tuple = ProjectionTuple(fromProj: projSrc, toProj: projDst);
var ptDst = tuple.forward(ptSrc);
print(
'FORWARD: Transform point ${ptSrc.toArray()} from EPSG:32647 to custom projection: ${ptDst.toArray()}');
}
`
The console printed:
FORWARD: Transform point [834934.4417, 1657193.5292] from EPSG:32647 to custom projection: [485333.96880976285, 1655549.4642448912]

The correct answer must be [485333.9690, 1655549.7316].
This is very strange due to I used pyproj version of Python that derived from PROJ4 also but gave the correct coordinates.
This is my Python code with the same Proj4 strings:
`from pyproj import CRS, Transformer

projsrc = CRS.from_proj4('+proj=utm +zone=47 +datum=WGS84 +units=m +no_defs')
projdst = CRS.from_proj4('+proj=tmerc +lat_0=0.0 +lon_0=102.25 +k_0=1.0 +x_0=500000 +y_0=0 +a=6378297.0 +b=6356911.77779 +towgs84=0.0,0.0,0.0,0,0,0,0 +units=m +no_defs type=crs');
xx, yy = 834934.4417, 1657193.5292
transformer = Transformer.from_crs(projsrc, projdst)
ptdst = transformer.transform(xx=xx, yy=yy)
print(f'Source point x,y: {xx} {yy}')
print(f'Dest point x,y: {ptdst[0]} {ptdst[1]}')`

The console of Python printed:
Source point x,y: 834934.4417 1657193.5292
Dest point x,y: 485333.9689740725 1655549.7315796772

I am new to Dart/Flutter what I am doing wrong or is it Proj4Dart's bug? Please help me. I run this code on Windows 11.

3857 to 4326 issue

Hi, I am sure I am doing something wrong here, but I can't find what and how, so after hours of trial, I will ask you to see if there is an issue. :-)

I am converting a 3857 bbox to 4326.

      var originPrj = proj4dart.Projection.parse(wktPrj);
      var destPrj = proj4dart.Projection("EPSG:4326");

      var ll = proj4dart.Point(x: west, y: south);
      var llDest = originPrj.transform(destPrj, ll);

where wktPrj is read from a prj file. That one is read properly and recognises the projection correctly (PseudoMercatorProjection).

But the converted Y for some reason is off.
For example converting:
west: 1235116.6370151439
south: 5852571.412104731

should give me:
x: 11.0952417
y: 46.4488475

but the y I get is:
y: 46.6408787

Do you have any idea what that might happen?

Initializing x0, y0 in stere.dart

When running:

double lat = 0;
double lon = 0;
var pointSrc = Point(x: lon, y: lat);
var projSrc = Projection('EPSG:4326');
var projDst = Projection('Stere') ??
Projection.add('Stere', '+proj=stere +lat_0=90 +lon_0=0 +lat_ts=0 +ellps=WGS84 +x_0=0 y_0=0',
);
// Forward transform (lonlat -> Stereographic)
var pointForward = projSrc.transform(projDst, pointSrc);

I got the following error in line 107 of stere.dart (where x0 is first used):

Unhandled exception:
NoSuchMethodError: The method '+' was called on null.
Receiver: null
Tried calling: +(0.0)

Problem is solved in stere.dart by changing:

StereographicSouthProjection.init(ProjParams params)
: lat0 = params.lat0,
long0 = params.long0,
lat_ts = params.lat_ts ?? double.nan, // fix js behavior
x0 = params.x0,
y0 = params.y0,

to:

StereographicSouthProjection.init(ProjParams params)
: lat0 = params.lat0,
long0 = params.long0,
lat_ts = params.lat_ts ?? double.nan, // fix js behavior
x0 = params.x0 ?? 0,
y0 = params.y0 ?? 0,

+proj=longlat not working on transformation

void transform() {
  final latOffset = 0.04086; // degrees
  final lonOffset = 0.36427; // degrees
  final source = Projection.get('WGS84');
  final target = Projection.parse(
      '+proj=longlat +lon_0=$lonOffset +lat_0=$latOffset +ellps=WGS84 +units=m +no_defs');
  final transform = ProjectionTuple(fromProj: source!, toProj: target);
  final transformed = transform.forward(Point(x: 7.421, y: 79.546));
  print('${transformed}');
}

I need to shift some coordinates to the correct location. I used the above code but it does not seems to transform the coordinates and only output the same coordinates that I give.

[question] get the epsg code from a projection

Hi, I have the case in which I am reading the prj wkt from a file that is a sidecar file of a tiff file.

In the case the projection is not registered, I would like to advise the user that a certain epsg code needs to be added as definition.

Is there a way to get the epsg code from a projection object?
This would help a lot to keep a list of registered projections and handle them.

Is the ability to convert wgs84 coordinate system to tm128 coordinate system also supported?

Hello, I am trying to change the general latitude and longitude wgs84 coordinate system value to the TM128 coordinate system value.

I got the desired value by converting the wgs84 coordinate system to the Tm128 coordinate system in the proj4 package provided by node js.

const proj4 = require('proj4');
var from = 'WGS84'
var to = 'TM128'

proj4.defs('WGS84', "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
proj4.defs('TM128', '+proj=tmerc +lat_0=38 +lon_0=128 +k=0.9999 +x_0=400000 +y_0=600000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43');
var xy = [126.947937,37.375219];
var result = proj4(from, to, xy); 

console.log(result) 

But I need a conversion function in flutter. Can you guide me?

Custom crs for flutter_map wrong

Hello,
I have a problem with custom crs in flutter_map. Could you help me?

This is my code:

List<double> getResolutions(double maxX, double minX, int zoom, [double tileSize = 256.0]) {
  var size = (maxX - minX) / tileSize;
  return List.generate(zoom, (z) => size / math.pow(2, z));
}

int r = 6378137;
double _boundsD = r * math.pi;

final Bounds<double> _bounds = Bounds<double>(
  CustomPoint<double>(532687.840000, 1250489.697300),
  CustomPoint<double>(607009.080400, 1345845.903300),
);
final resolutions = getResolutions(607009.080400, 532687.840000, 19);
final maxZoom = (resolutions.length - 1).toDouble();

var def = '+proj=tmerc +lat_0=0 +lon_0=108.25 +k=0.9999 +x_0=500000 +y_0=0 +ellps=WGS84 +towgs84=-191.90441429,-39.30318279,-111.45032835,0.00928836,-0.01975479,0.00427372,0.252906278 +units=m +no_defs';

var epsg9217 = proj4.Projection.add('EPSG:9217', def);

var epsg9217CRS = Proj4Crs.fromFactory(
  code: 'EPSG:9217',
  proj4Projection: epsg9217,
  resolutions: resolutions,
  bounds: _bounds,
  origins: [CustomPoint(-5122600.0, 1.00011E7)],
);

In main FlutterMap:

FlutterMap(
  options: MapOptions(
    crs: Epsg3857(),
  ),
  children: [
                  TileLayerWidget(
                      options: TileLayerOptions(
                        backgroundColor: Colors.transparent,
                        wmsOptions: WMSTileLayerOptions(
                          crs: const Epsg3857()
                          version: '1.1.1',
                          transparent: true,
                          baseUrl: 'https://ows.terrestris.de/osm/service?',
                          layers: ["OSM-WMS"],
                        )
                      ))
  ],
  layers: [
    TileLayerOptions(
                          backgroundColor: Colors.transparent,
                          fastReplace: true,
                          wmsOptions: WMSTileLayerOptions(
                            crs: epsg9217CRS,
                            version: '1.3.0',
                            transparent: true,
                            baseUrl: <wms_server_url>,
                            layers: ['2,3'],
                          ),
                        ))
  ]
)

Layer 'OSM-WMS' is show on my application but layer ('2,3') is not.
I console url that generate by WMSTileLayerOptions but BBOX is not correct.
Log : 499804.8535484949, 10000988.210334396, 499804.8535484949, 10000988.210334396

In javascript project, I use proj4js and BBOX is correct.
Log in javascript: 582600.854078125, 1278053.6005968752, 583345.8244375, 1278798.5709562502
This is code of javascript:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/proj4-src.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.6.1/build/ol.js"></script>

const newProjCode = 'EPSG:9217';
const def = "+proj=tmerc +lat_0=0 +lon_0=108.25 +k=0.9999 +x_0=500000 +y_0=0 +ellps=WGS84 +towgs84=-191.90441429,-39.30318279,-111.45032835,0.00928836,-0.01975479,0.00427372,0.252906278 +units=m +no_defs";
proj4.defs(newProjCode, def);
ol.proj.proj4.register(proj4);
		
const projection = new ol.proj.Projection({
            code: 'EPSG:9217',
            extent: [532687.8399999999, 1250489.6973, 607009.0804000003, 1345845.9033000004], // [540286.530000, 1276528.530000, 585024.462000, 1318764.630000],
            units: 'm',
});

Thank you.

P/S: This is my WMS Capabilities:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<WMS_Capabilities xmlns="http://www.opengis.net/wms" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:esri_wms="http://www.esri.com/wms" version="1.3.0" xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd http://www.esri.com/wms https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?version=1.3.0%26service=WMS%26request=GetSchemaExtension">
<Service>
<Name>
<![CDATA[ WMS ]]>
</Name>
<Title>
<![CDATA[ Test_BD_BDN ]]>
</Title>
<Abstract>WMS</Abstract>
<KeywordList>
<Keyword>
<![CDATA[ ]]>
</Keyword>
</KeywordList>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?"/>
<ContactInformation>
<ContactPersonPrimary>
<ContactPerson>
<![CDATA[ ]]>
</ContactPerson>
<ContactOrganization>
<![CDATA[ ]]>
</ContactOrganization>
</ContactPersonPrimary>
<ContactPosition>
<![CDATA[ ]]>
</ContactPosition>
<ContactAddress>
<AddressType>
<![CDATA[ ]]>
</AddressType>
<Address>
<![CDATA[ ]]>
</Address>
<City>
<![CDATA[ ]]>
</City>
<StateOrProvince>
<![CDATA[ ]]>
</StateOrProvince>
<PostCode>
<![CDATA[ ]]>
</PostCode>
<Country>
<![CDATA[ ]]>
</Country>
</ContactAddress>
<ContactVoiceTelephone>
<![CDATA[ ]]>
</ContactVoiceTelephone>
<ContactFacsimileTelephone>
<![CDATA[ ]]>
</ContactFacsimileTelephone>
<ContactElectronicMailAddress>
<![CDATA[ ]]>
</ContactElectronicMailAddress>
</ContactInformation>
<Fees>
<![CDATA[ ]]>
</Fees>
<AccessConstraints>
<![CDATA[ ]]>
</AccessConstraints>
<MaxWidth>4096</MaxWidth>
<MaxHeight>4096</MaxHeight>
</Service>
<Capability>
<Request>
<GetCapabilities>
<Format>application/vnd.ogc.wms_xml</Format>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?"/>
</Get>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/bmp</Format>
<Format>image/jpeg</Format>
<Format>image/tiff</Format>
<Format>image/png</Format>
<Format>image/png8</Format>
<Format>image/png24</Format>
<Format>image/png32</Format>
<Format>image/gif</Format>
<Format>image/svg+xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?"/>
</Get>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>application/vnd.esri.wms_raw_xml</Format>
<Format>application/vnd.esri.wms_featureinfo_xml</Format>
<Format>application/vnd.ogc.wms_xml</Format>
<Format>application/geojson</Format>
<Format>text/xml</Format>
<Format>text/html</Format>
<Format>text/plain</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?"/>
</Get>
</HTTP>
</DCPType>
</GetFeatureInfo>
<esri_wms:GetStyles>
<Format>application/vnd.ogc.sld+xml</Format>
<DCPType>
<HTTP>
<Get>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?"/>
</Get>
</HTTP>
</DCPType>
</esri_wms:GetStyles>
</Request>
<Exception>
<Format>application/vnd.ogc.se_xml</Format>
<Format>application/vnd.ogc.se_inimage</Format>
<Format>application/vnd.ogc.se_blank</Format>
<Format>text/xml</Format>
<Format>XML</Format>
</Exception>
<Layer>
<Title>
<![CDATA[ Layers ]]>
</Title>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:0</CRS>
<CRS>EPSG:9217</CRS>
<!--  9217 is customized SR = PROJCS["VN2000",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",108.25],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]  -->
<EX_GeographicBoundingBox>
<westBoundLongitude>108.549444</westBoundLongitude>
<eastBoundLongitude>109.233283</eastBoundLongitude>
<southBoundLatitude>11.307092</southBoundLatitude>
<northBoundLatitude>12.170651</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="CRS:84" minx="108.549444" miny="11.307092" maxx="109.233283" maxy="12.170651"/>
<BoundingBox CRS="EPSG:4326" minx="11.307092" miny="108.549444" maxx="12.170651" maxy="109.233283"/>
<BoundingBox CRS="EPSG:0" minx="532687.840000" miny="1250489.697300" maxx="607009.080400" maxy="1345845.903300"/>
<BoundingBox CRS="EPSG:9217" minx="532687.840000" miny="1250489.697300" maxx="607009.080400" maxy="1345845.903300"/>
<Layer queryable="1">
<Title>
<![CDATA[ bdn ]]>
</Title>
<Abstract>
<![CDATA[ ]]>
</Abstract>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:0</CRS>
<CRS>EPSG:9217</CRS>
<!--  9217 is customized SR = PROJCS["VN2000",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",108.25],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]  -->
<EX_GeographicBoundingBox>
<westBoundLongitude>108.549444</westBoundLongitude>
<eastBoundLongitude>109.233283</eastBoundLongitude>
<southBoundLatitude>11.307092</southBoundLatitude>
<northBoundLatitude>12.170651</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="CRS:84" minx="108.549444" miny="11.307092" maxx="109.233283" maxy="12.170651"/>
<BoundingBox CRS="EPSG:4326" minx="11.307092" miny="108.549444" maxx="12.170651" maxy="109.233283"/>
<BoundingBox CRS="EPSG:0" minx="532687.840000" miny="1250489.697300" maxx="607009.080400" maxy="1345845.903300"/>
<BoundingBox CRS="EPSG:9217" minx="532687.840000" miny="1250489.697300" maxx="607009.080400" maxy="1345845.903300"/>
<Layer queryable="1">
<Name>1</Name>
<Title>
<![CDATA[ Hành chính cấp xã ]]>
</Title>
<Abstract>
<![CDATA[ ]]>
</Abstract>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:0</CRS>
<CRS>EPSG:9217</CRS>
<!--  9217 is customized SR = PROJCS["VN2000",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",108.25],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]  -->
<EX_GeographicBoundingBox>
<westBoundLongitude>108.549444</westBoundLongitude>
<eastBoundLongitude>109.233267</eastBoundLongitude>
<southBoundLatitude>11.307092</southBoundLatitude>
<northBoundLatitude>12.166196</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="CRS:84" minx="108.549444" miny="11.307092" maxx="109.233267" maxy="12.166196"/>
<BoundingBox CRS="EPSG:4326" minx="11.307092" miny="108.549444" maxx="12.166196" maxy="109.233267"/>
<BoundingBox CRS="EPSG:0" minx="532687.840000" miny="1250489.700000" maxx="607009.080000" maxy="1345353.090000"/>
<BoundingBox CRS="EPSG:9217" minx="532687.840000" miny="1250489.700000" maxx="607009.080000" maxy="1345353.090000"/>
<Style>
<Name>default</Name>
<Title>1</Title>
<LegendURL width="166" height="144">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?request=GetLegendGraphic%26version=1.3.0%26format=image/png%26layer=1" xlink:type="simple"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>2</Name>
<Title>
<![CDATA[ Địa giới NT ]]>
</Title>
<Abstract>
<![CDATA[ ]]>
</Abstract>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:0</CRS>
<CRS>EPSG:9217</CRS>
<!--  9217 is customized SR = PROJCS["VN2000",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",108.25],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]  -->
<EX_GeographicBoundingBox>
<westBoundLongitude>108.549444</westBoundLongitude>
<eastBoundLongitude>109.233283</eastBoundLongitude>
<southBoundLatitude>11.307092</southBoundLatitude>
<northBoundLatitude>12.170651</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="CRS:84" minx="108.549444" miny="11.307092" maxx="109.233283" maxy="12.170651"/>
<BoundingBox CRS="EPSG:4326" minx="11.307092" miny="108.549444" maxx="12.170651" maxy="109.233283"/>
<BoundingBox CRS="EPSG:0" minx="532687.840900" miny="1250489.697300" maxx="607009.080400" maxy="1345845.903300"/>
<BoundingBox CRS="EPSG:9217" minx="532687.840900" miny="1250489.697300" maxx="607009.080400" maxy="1345845.903300"/>
<Style>
<Name>default</Name>
<Title>2</Title>
<LegendURL width="124" height="96">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?request=GetLegendGraphic%26version=1.3.0%26format=image/png%26layer=2" xlink:type="simple"/>
</LegendURL>
</Style>
</Layer>
<Layer queryable="1">
<Name>3</Name>
<Title>
<![CDATA[ Trụ sở UBND các cấp ]]>
</Title>
<Abstract>
<![CDATA[ ]]>
</Abstract>
<CRS>CRS:84</CRS>
<CRS>EPSG:4326</CRS>
<CRS>EPSG:0</CRS>
<CRS>EPSG:9217</CRS>
<!--  9217 is customized SR = PROJCS["VN2000",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",108.25],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]  -->
<EX_GeographicBoundingBox>
<westBoundLongitude>108.690979</westBoundLongitude>
<eastBoundLongitude>109.170210</eastBoundLongitude>
<southBoundLatitude>11.338382</southBoundLatitude>
<northBoundLatitude>12.006145</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="CRS:84" minx="108.690979" miny="11.338382" maxx="109.170210" maxy="12.006145"/>
<BoundingBox CRS="EPSG:4326" minx="11.338382" miny="108.690979" maxx="12.006145" maxy="109.170210"/>
<BoundingBox CRS="EPSG:0" minx="548133.108100" miny="1253928.935000" maxx="600205.405400" maxy="1327670.126000"/>
<BoundingBox CRS="EPSG:9217" minx="548133.108100" miny="1253928.935000" maxx="600205.405400" maxy="1327670.126000"/>
<Style>
<Name>default</Name>
<Title>3</Title>
<LegendURL width="136" height="80">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://localhost:6080/arcgis/services/Test_BD/BDN/MapServer/WmsServer?request=GetLegendGraphic%26version=1.3.0%26format=image/png%26layer=3" xlink:type="simple"/>
</LegendURL>
</Style>
<MinScaleDenominator>9449.404762</MinScaleDenominator>
<MaxScaleDenominator>236235.119048</MaxScaleDenominator>
</Layer>
</Layer>
</Layer>
</Capability>
</WMS_Capabilities>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.