### Proj4dart Installation Source: https://github.com/marci002/proj4dart/blob/master/README.md Instructions on how to add Proj4dart to your project's dependencies. ```APIDOC ## Installing Proj4dart Add proj4dart to `pubspec.yml` (dependencies section), then run `pub get` to download the new dependencies. ```yaml dependencies: proj4dart: any # or the latest version on Pub ``` ``` -------------------------------- ### Supported Projections Source: https://context7.com/marci002/proj4dart/llms.txt Examples of how to define and use various common map projections supported by Proj4dart. ```APIDOC ## Supported Projections ### Description Proj4dart supports over 25 map projection types, which can be specified using their Proj4 codes in definition strings. This section provides examples for several common projections. ### Method `Projection.parse(String proj4String)` ### Parameters #### Path Parameters - **proj4String** (string) - Required - The Proj4 definition string for the projection. ### Request Example ```dart import 'package:proj4dart/proj4dart.dart'; var wgs84 = Projection.WGS84; var point = Point(x: 12.5, y: 41.9); // Rome, Italy // Transverse Mercator (tmerc) var tmerc = Projection.parse( '+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=500000 +y_0=0 +datum=WGS84 +units=m', ); print('Transverse Mercator: ${wgs84.transform(tmerc, point).toArray()}'); // Universal Transverse Mercator (utm) var utm33n = Projection.parse('+proj=utm +zone=33 +datum=WGS84 +units=m'); print('UTM Zone 33N: ${wgs84.transform(utm33n, point).toArray()}'); // Lambert Conformal Conic (lcc) var lcc = Projection.parse( '+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m', ); print('Lambert CC: ${wgs84.transform(lcc, point).toArray()}'); // Mercator (merc) var merc = Projection.parse('+proj=merc +a=6378137 +b=6378137 +units=m'); print('Mercator: ${wgs84.transform(merc, point).toArray()}'); // Albers Equal Area (aea) var aea = Projection.parse( '+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m', ); print('Albers: ${wgs84.transform(aea, point).toArray()}'); // Azimuthal Equidistant (aeqd) var aeqd = Projection.parse( '+proj=aeqd +lat_0=41.9 +lon_0=12.5 +x_0=0 +y_0=0 +datum=WGS84 +units=m', ); print('Azimuthal Equidistant: ${wgs84.transform(aeqd, point).toArray()}'); // Stereographic (stere) var stere = Projection.parse( '+proj=stere +lat_0=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m', ); print('Stereographic: ${wgs84.transform(stere, point).toArray()}'); ``` ### Supported Projection Codes `aea, aeqd, cass, cea, eqc, eqdc, etmerc, gauss, geocent, gnom, gstmerc, krovak, laea, lcc, longlat, merc, mill, moll, nzmg, omerc, ortho, poly, qsc, robin, sinu, somerc, stere, sterea, tmerc, utm, vandg` ``` -------------------------------- ### Install Proj4dart Dependency Source: https://github.com/marci002/proj4dart/blob/master/README.md Add the library to your Dart project's pubspec.yaml file to enable coordinate transformation capabilities. ```yaml dependencies: proj4dart: any ``` -------------------------------- ### Transform between Projections using ProjectionTuple Source: https://github.com/marci002/proj4dart/blob/master/README.md This example demonstrates how to transform a point from one projection (EPSG:4326) to another custom projection (EPSG:23700) and vice versa using the ProjectionTuple class in Proj4Dart. ```APIDOC ## Transform between Projections using ProjectionTuple ### Description This example demonstrates how to transform a point from one projection (EPSG:4326) to another custom projection (EPSG:23700) and vice versa using the ProjectionTuple class in Proj4Dart. ### Method N/A (This is a code example demonstrating library usage) ### Endpoint N/A ### Parameters N/A ### Request Example ```dart 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()}'); // Inverse transform (projected crs -> lonlat) var pointInverse = tuple.inverse(pointForward); print( 'INVERSE: Transform point ${pointForward.toArray()} from EPSG:23700 to EPSG:4326: ${pointInverse.toArray()}'); } ``` ### Response #### Success Response (200) N/A (This is a code example) #### Response Example ``` FORWARD: Transform point [17.888058560281515, 46.89226406700879] from EPSG:4326 to EPSG:23700: [561651.8408065987, 172658.61998377228] INVERSE: Transform point [561651.8408065987, 172658.61998377228] from EPSG:23700 to EPSG:4326: [17.888058565574845, 46.89226406698969] ``` ``` -------------------------------- ### Utilize Various Map Projections in Dart with Proj4dart Source: https://context7.com/marci002/proj4dart/llms.txt This example showcases how to parse and utilize over 25 different map projection types supported by Proj4dart. It demonstrates transformations between WGS84 and common projections like Transverse Mercator (tmerc), UTM, Lambert Conformal Conic (lcc), Mercator (merc), Albers Equal Area (aea), Azimuthal Equidistant (aeqd), and Stereographic (stere). ```dart import 'package:proj4dart/proj4dart.dart'; void main() { var wgs84 = Projection.WGS84; var point = Point(x: 12.5, y: 41.9); // Rome, Italy // Transverse Mercator (tmerc) - Used for UTM zones var tmerc = Projection.parse( '+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=500000 +y_0=0 +datum=WGS84 +units=m', ); print('Transverse Mercator: ${wgs84.transform(tmerc, point).toArray()}'); // Universal Transverse Mercator (utm) var utm33n = Projection.parse('+proj=utm +zone=33 +datum=WGS84 +units=m'); print('UTM Zone 33N: ${wgs84.transform(utm33n, point).toArray()}'); // Lambert Conformal Conic (lcc) var lcc = Projection.parse( '+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m', ); print('Lambert CC: ${wgs84.transform(lcc, point).toArray()}'); // Mercator (merc) - Web Mercator variant var merc = Projection.parse('+proj=merc +a=6378137 +b=6378137 +units=m'); print('Mercator: ${wgs84.transform(merc, point).toArray()}'); // Albers Equal Area (aea) var aea = Projection.parse( '+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m', ); print('Albers: ${wgs84.transform(aea, point).toArray()}'); // Azimuthal Equidistant (aeqd) var aeqd = Projection.parse( '+proj=aeqd +lat_0=41.9 +lon_0=12.5 +x_0=0 +y_0=0 +datum=WGS84 +units=m', ); print('Azimuthal Equidistant: ${wgs84.transform(aeqd, point).toArray()}'); // Stereographic (stere) var stere = Projection.parse( '+proj=stere +lat_0=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m', ); print('Stereographic: ${wgs84.transform(stere, point).toArray()}'); // Supported projection codes: // aea, aeqd, cass, cea, eqc, eqdc, etmerc, gauss, geocent, gnom, gstmerc, // krovak, laea, lcc, longlat, merc, mill, moll, nzmg, omerc, ortho, poly, // qsc, robin, sinu, somerc, stere, sterea, tmerc, utm, vandg } ``` -------------------------------- ### Grid-Based Datum Adjustments with NTv2 Source: https://context7.com/marci002/proj4dart/llms.txt Demonstrates how to load an NTv2 grid file (.gsb) for accurate datum transformations and how to use it in projection definitions. ```APIDOC ## Projection.nadgrid - Grid-Based Datum Adjustments ### Description Loads an NTv2 grid file (.gsb) for high-precision datum transformations. Grid-based adjustments offer superior accuracy over standard 3 or 7 parameter transformations for specific regions. ### Method `Projection.nadgrid(String key, List bytes)` ### Parameters #### Path Parameters - **key** (string) - Required - A unique name to register the grid file under. - **bytes** (List) - Required - The byte content of the NTv2 grid file (.gsb). ### Request Example ```dart import 'dart:io'; import 'package:proj4dart/proj4dart.dart'; // Dart (command-line) example: final bytes = await File('path/to/ntv2_grid.gsb').readAsBytes(); Projection.nadgrid('ntv2', bytes); // Flutter example: // final bytes = (await rootBundle.load('assets/nzgd2kgrid0005.gsb')).buffer.asUint8List(); // Projection.nadgrid('nzgd2kgrid0005.gsb', bytes); ``` ### Usage in Projection Definition ```dart var projWithGrid = Projection.add( 'ntv2_from', '+proj=longlat +ellps=clrk66 +nadgrids=@ignorable,ntv2,null', ); var pointSrc = Point(x: -44.382211538462, y: 40.3768); var projDst = Projection.WGS84; var pointForward = projWithGrid.transform(projDst, pointSrc); print('Forward: ${pointSrc.toArray()} -> ${pointForward.toArray()}'); var pointInverse = projDst.transform(projWithGrid, pointForward); print('Inverse: ${pointForward.toArray()} -> ${pointInverse.toArray()}'); ``` ### Response This method does not return a value but registers the grid for use in transformations. ``` -------------------------------- ### Configure Grid Based Datum Adjustments Source: https://github.com/marci002/proj4dart/blob/master/README.md Shows how to load NTv2 .gsb grid files into the library for datum shifting. Includes specific implementations for standard Dart file I/O and Flutter asset loading. ```dart final bytes = await File('assets/my_grid.gsb').readAsBytes(); Projection.nadgrid('key', bytes); ``` ```dart import 'package:flutter/services.dart' show rootBundle; final bytes = (await rootBundle.load(fileName)).buffer.asUint8List(); Projection.nadgrid('key', bytes); ``` -------------------------------- ### Using Predefined Projections Source: https://github.com/marci002/proj4dart/blob/master/README.md How to use the predefined coordinate systems available in Proj4dart. ```APIDOC ## Using Predefined Projection There are 3 predefined Projections and 5 aliases by default: - [EPSG:4326](https://epsg.io/4326), which has the following alias: - WGS84 - [EPSG:4269](https://epsg.io/4269) - [EPSG:3857](https://epsg.io/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: ```dart var projection = Projection.get('EPSG:4326')!; ``` ``` -------------------------------- ### Dart: Create and Manipulate Point Objects with Proj4dart Source: https://context7.com/marci002/proj4dart/llms.txt Demonstrates the creation and manipulation of Point objects in Dart using the Proj4dart library. It covers creating points from various formats like coordinates, arrays, strings, and MGRS, as well as converting them to different representations and creating modified copies. ```dart import 'package:proj4dart/proj4dart.dart'; void main() { // Create a point with x (longitude) and y (latitude) var point1 = Point(x: 17.888058560281515, y: 46.89226406700879); // Create a point with elevation (z) var point2 = Point.withZ(x: -122.4194, y: 37.7749, z: 10.5); // Create a point with measure value (m) var point3 = Point.withM(x: -73.9857, y: 40.7484, z: 100.0, m: 0.5); // Create from array [x, y] or [x, y, z] or [x, y, z, m] var point4 = Point.fromArray([19.04857, 47.14439, 200.0]); // Create from comma-separated string var point5 = Point.fromString('17.888,46.892,100'); // Create from MGRS string var point6 = Point.fromMGRS('33TWN1720316826'); // Convert point to array List coords = point2.toArray(); print('Coordinates: $coords'); // [x, y, z] // Convert to MGRS with accuracy (1-5) String mgrs = point1.toMGRS(5); print('MGRS: $mgrs'); // e.g., '33TWN1720516826' // Copy a point var pointCopy = Point.copy(point1); // Create modified copy var modified = point1.copyWith(z: 500.0); print(point1.toString()); // { x: 17.888058560281515, y: 46.89226406700879, z: null, m: null } } ``` -------------------------------- ### Dart: Retrieve Predefined Projections using Proj4dart Source: https://context7.com/marci002/proj4dart/llms.txt Shows how to retrieve predefined coordinate system projections using the `Projection.get()` method in Proj4dart. It covers accessing common projections like WGS84 and Google Mercator by their EPSG codes or aliases, and demonstrates safe static accessors. ```dart import 'package:proj4dart/proj4dart.dart'; void main() { // Get WGS84 projection (EPSG:4326) var wgs84 = Projection.get('EPSG:4326'); print('WGS84 found: ${wgs84 != null}'); // true // Alternative alias for WGS84 var wgs84Alt = Projection.get('WGS84'); // Get NAD83 projection (EPSG:4269) var nad83 = Projection.get('EPSG:4269'); // Get Google Mercator (EPSG:3857) - has multiple aliases var mercator1 = Projection.get('EPSG:3857'); var mercator2 = Projection.get('GOOGLE'); var mercator3 = Projection.get('EPSG:900913'); var mercator4 = Projection.get('EPSG:3785'); var mercator5 = Projection.get('EPSG:102113'); // All Google Mercator aliases return the same projection print('Same projection: ${identical(mercator1, mercator2)}'); // true // Safe static accessors for WGS84 and Google Mercator (cannot be overwritten) var safeWgs84 = Projection.WGS84; var safeGoogle = Projection.GOOGLE; // Check if a projection exists before using var customProj = Projection.get('EPSG:23700'); if (customProj == null) { print('EPSG:23700 not found, needs to be defined'); } } ``` -------------------------------- ### Load and Use NTv2 Grid for Datum Transformations in Dart Source: https://context7.com/marci002/proj4dart/llms.txt This snippet demonstrates how to load an NTv2 grid file (.gsb) into Proj4dart for high-precision datum transformations. It covers registering the grid, defining a projection that utilizes the grid, and performing forward and inverse transformations. This method is crucial for accurate geographic adjustments in specific regions. ```dart import 'dart:io'; import 'package:proj4dart/proj4dart.dart'; // For Flutter: // import 'package:flutter/services.dart' show rootBundle; void main() async { // === Dart (command-line) example === // Read NTv2 grid file from filesystem final bytes = await File('path/to/ntv2_grid.gsb').readAsBytes(); // Register the grid with a key name Projection.nadgrid('ntv2', bytes); // === Flutter example === // final bytes = (await rootBundle.load('assets/nzgd2kgrid0005.gsb')).buffer.asUint8List(); // Projection.nadgrid('nzgd2kgrid0005.gsb', bytes); // Define projection using the nadgrid // Use @key for optional grids, 'null' as fallback var projWithGrid = Projection.add( 'ntv2_from', '+proj=longlat +ellps=clrk66 +nadgrids=@ignorable,ntv2,null', ); // Source point var pointSrc = Point(x: -44.382211538462, y: 40.3768); // Transform using grid-based adjustment var projDst = Projection.WGS84; var pointForward = projWithGrid.transform(projDst, pointSrc); print('Forward: ${pointSrc.toArray()} -> ${pointForward.toArray()}'); // Output: [-44.382211538462, 40.3768] -> [-44.38074905319326, 40.37745745991217] // Inverse transformation var pointInverse = projDst.transform(projWithGrid, pointForward); print('Inverse: ${pointForward.toArray()} -> ${pointInverse.toArray()}'); // New Zealand example with NZGD49 -> NZGD2000 transformation // final nzBytes = await File('nzgd2kgrid0005.gsb').readAsBytes(); // Projection.nadgrid('nzgd2kgrid0005.gsb', nzBytes); // var nzgd49 = Projection.add( // 'EPSG:4272', // '+proj=longlat +datum=nzgd49 +towgs84=59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993 ' // '+nadgrids=nzgd2kgrid0005.gsb +no_defs', // ); } ``` -------------------------------- ### Using User-defined Projections with OGC WKT Source: https://github.com/marci002/proj4dart/blob/master/README.md How to define custom projections using OGC WKT definition strings. ```APIDOC #### 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](https://epsg.io/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: ```dart 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](example/proj4dart_ogc_wkt_example.dart) ``` -------------------------------- ### Perform Coordinate Transformations Source: https://github.com/marci002/proj4dart/blob/master/README.md Illustrates the process of transforming a coordinate point between two different projection systems using forward and inverse transformation methods. ```dart import 'package:proj4dart/proj4dart.dart'; void main() { var pointSrc = Point(x: 17.888058560281515, y: 46.89226406700879); var projSrc = Projection.get('EPSG:4326')!; 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'); var pointForward = projSrc.transform(projDst, pointSrc); var pointInverse = projDst.transform(projSrc, pointForward); } ``` -------------------------------- ### Proj4dart Core Functionality Source: https://context7.com/marci002/proj4dart/llms.txt This section covers the fundamental usage of Proj4dart, including projection registration and coordinate transformation. ```APIDOC ## Proj4dart Usage Guide ### Description Proj4dart is a library for Dart and Flutter applications that facilitates coordinate transformations between different Coordinate Reference Systems (CRS). It is essential for GIS applications, mapping libraries, GPS data processing, and any scenario requiring accurate spatial data conversions. ### Key Operations 1. **Projection Registration**: Before performing transformations, you need to register the Coordinate Reference Systems (projections) you intend to use. This is typically done once at application startup. * **Method**: `Projection.add(String proj4String)` or `Projection.add(String name, String proj4String)` * **Description**: Adds a new projection definition to the library's registry. Projection definitions can be obtained in Proj4, OGC WKT, or ESRI WKT format from sources like [epsg.io](https://epsg.io). * **Example**: ```dart import 'package:proj4dart/proj4dart.dart'; // Registering a projection using its Proj4 string Projection.add('+proj=longlat +datum=WGS84 +no_defs'); // Or with a name Projection.add('WGS84', '+proj=longlat +datum=WGS84 +no_defs'); ``` 2. **Coordinate Transformation**: Once projections are registered, you can transform coordinates between them. * **Method**: `Projection.transform(Point point, Projection from, Projection to)` or `ProjectionTuple.transform(Point point, String fromProj, String toProj)` * **Description**: Converts a given point's coordinates from a source projection (`from`) to a destination projection (`to`). `Point` objects typically have `x` and `y` properties representing longitude/easting and latitude/northing respectively. * **Example**: ```dart import 'package:proj4dart/proj4dart.dart'; // Assuming WGS84 and a UTM projection are already registered final wgs84 = Projection.get('WGS84'); // Or the default proj4 string final utm = Projection.get('+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs'); if (wgs84 != null && utm != null) { final pointInWGS84 = Point(x: 13.4, y: 52.5); // Example coordinates (lon, lat) final transformedPoint = Projection.transform(pointInWGS84, wgs84, utm); print('Transformed point: x=${transformedPoint.x}, y=${transformedPoint.y}'); } ``` ### Advanced Features * **NTv2 Grid Files**: For high-precision regional transformations, Proj4dart supports loading NTv2 grid files. * **Method**: `Projection.nadgrid(String path)` * **Description**: Loads NTv2 grid shift files to improve accuracy for specific geographic areas. * **Example**: ```dart // Load an NTv2 grid file await Projection.nadgrid('path/to/your/ntv2_file.gsb'); ``` * **Projection Definitions**: Proj4dart is tested with over 21,000 projection definitions, ensuring broad compatibility and accuracy. ### Accuracy The library achieves sub-millimeter accuracy when compared to reference implementations like proj4js and PostGIS. ``` -------------------------------- ### Using User-defined Projections with Proj4 String Source: https://github.com/marci002/proj4dart/blob/master/README.md How to define custom projections using Proj4 definition strings. ```APIDOC ## User-defined Projection Proj4dart supports `Proj4 definition strings`, `OGC WKT definitions` and `ESRI WKT definitions`. They can be obtained from [epsg.io](https://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](https://epsg.io/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: ```dart 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](example/proj4dart_example.dart) ``` -------------------------------- ### Define Custom Projections with ESRI WKT Source: https://github.com/marci002/proj4dart/blob/master/README.md Demonstrates how to define a custom projection using an ESRI WKT string. It shows both adding a named projection to the registry and parsing a projection definition directly. ```dart 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]]'; var namedProjection = Projection.add('EPSG:23700', def); var projection = Projection.parse(def); ``` -------------------------------- ### ProjectionTuple - Bidirectional Transformations Source: https://context7.com/marci002/proj4dart/llms.txt Simplifies bidirectional transformations between two projections using `forward()` and `inverse()` methods. ```APIDOC ## ProjectionTuple - Bidirectional Transformations ### Description The `ProjectionTuple` class simplifies bidirectional transformations between two projections by providing `forward()` and `inverse()` methods. This is more convenient when you need to transform points back and forth between the same two coordinate systems. ### Method `ProjectionTuple(Projection fromProj, Projection toProj)` ### Endpoint N/A (Class) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```dart import 'package:proj4dart/proj4dart.dart'; void main() { // Create a projection tuple for WGS84 <-> EOV transformations var tuple = ProjectionTuple( fromProj: Projection.get('EPSG:4326')!, 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', ), ); var pointSrc = Point(x: 17.888058560281515, y: 46.89226406700879); // Forward: from WGS84 to EOV var pointForward = tuple.forward(pointSrc); print('Forward: ${pointSrc.toArray()} -> ${pointForward.toArray()}'); // Inverse: from EOV back to WGS84 var pointInverse = tuple.inverse(pointForward); print('Inverse: ${pointForward.toArray()} -> ${pointInverse.toArray()}'); // Create tuple for WGS84 <-> Web Mercator var webMercatorTuple = ProjectionTuple( fromProj: Projection.WGS84, toProj: Projection.GOOGLE, ); // Transform multiple points efficiently var cities = [ Point(x: -122.4194, y: 37.7749), // San Francisco Point(x: -73.9857, y: 40.7484), // New York Point(x: 2.3522, y: 48.8566), // Paris ]; for (var city in cities) { var projected = webMercatorTuple.forward(city); print('${city.toArray()} -> ${projected.toArray()}'); } } ``` ### Response #### Success Response (200) - **Point** (Point) - The transformed point. #### Response Example ```json { "x": 561651.8408065987, "y": 172658.61998377228, "z": null } ``` ``` -------------------------------- ### Coordinate Transformation using ProjectionTuple in Dart Source: https://github.com/marci002/proj4dart/blob/master/README.md This snippet demonstrates how to initialize a ProjectionTuple with source and destination projections, then perform forward and inverse transformations on a geographic point. It requires the proj4dart package and handles both built-in EPSG codes and custom PROJ string definitions. ```dart import 'package:proj4dart/proj4dart.dart'; void main() { var pointSrc = Point(x: 17.888058560281515, y: 46.89226406700879); var tuple = ProjectionTuple( fromProj: Projection.get('EPSG:4326')!, 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', ), ); var pointForward = tuple.forward(pointSrc); print('FORWARD: Transform point ${pointSrc.toArray()} from EPSG:4326 to EPSG:23700: ${pointForward.toArray()}'); var pointInverse = tuple.inverse(pointForward); print('INVERSE: Transform point ${pointForward.toArray()} from EPSG:23700 to EPSG:4326: ${pointInverse.toArray()}'); } ``` -------------------------------- ### Define Custom Projection with Proj4 String Source: https://github.com/marci002/proj4dart/blob/master/README.md Create a custom projection using a Proj4 definition string. Use Projection.add to register it globally or Projection.parse for a local instance. ```dart 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'; var namedProjection = Projection.add('EPSG:23700', def); var projection = Projection.parse(def); ``` -------------------------------- ### Projection.add Source: https://context7.com/marci002/proj4dart/llms.txt Registers a named projection into the global store for later retrieval. ```APIDOC ## Projection.add ### Description Creates and registers a named projection from a definition string. Once registered, the projection can be retrieved anywhere using Projection.get(). Supports Proj4 strings, OGC WKT, and ESRI WKT definitions. ### Method Static Method ### Parameters #### Arguments - **name** (String) - Required - The unique identifier for the projection (e.g., 'EPSG:23700'). - **definition** (String) - Required - The projection definition string (Proj4, OGC WKT, or ESRI WKT). ### Request Example Projection.add('EPSG:23700', '+proj=somerc ...'); ### Response #### Success Response - **Projection** (Object) - Returns the registered Projection instance. ``` -------------------------------- ### Dart: ProjectionTuple - Bidirectional Transformations Source: https://context7.com/marci002/proj4dart/llms.txt Simplifies bidirectional coordinate transformations between two projections using `forward()` and `inverse()` methods. This is useful when frequently converting points back and forth between the same two coordinate systems. It can efficiently transform multiple points. ```dart import 'package:proj4dart/proj4dart.dart'; void main() { // Create a projection tuple for WGS84 <-> EOV transformations var tuple = ProjectionTuple( fromProj: Projection.get('EPSG:4326')!, 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', ), ); // Source point in WGS84 var pointSrc = Point(x: 17.888058560281515, y: 46.89226406700879); // Forward: from WGS84 to EOV var pointForward = tuple.forward(pointSrc); print('Forward: ${pointSrc.toArray()} -> ${pointForward.toArray()}'); // Output: [17.888058560281515, 46.89226406700879] -> [561651.8408065987, 172658.61998377228] // Inverse: from EOV back to WGS84 var pointInverse = tuple.inverse(pointForward); print('Inverse: ${pointForward.toArray()} -> ${pointInverse.toArray()}'); // Output: [561651.8408065987, 172658.61998377228] -> [17.888058565574845, 46.89226406698969] // Create tuple for WGS84 <-> Web Mercator var webMercatorTuple = ProjectionTuple( fromProj: Projection.WGS84, toProj: Projection.GOOGLE, ); // Transform multiple points efficiently var cities = [ Point(x: -122.4194, y: 37.7749), // San Francisco Point(x: -73.9857, y: 40.7484), // New York Point(x: 2.3522, y: 48.8566), // Paris ]; for (var city in cities) { var projected = webMercatorTuple.forward(city); print('${city.toArray()} -> ${projected.toArray()}'); } } ``` -------------------------------- ### Define Custom Projection with OGC WKT Source: https://github.com/marci002/proj4dart/blob/master/README.md Create a custom projection using an OGC WKT definition string. This allows for complex coordinate system definitions. ```dart 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"]]'; var namedProjection = Projection.add('EPSG:23700', def); var projection = Projection.parse(def); ``` -------------------------------- ### Projection.parse Source: https://context7.com/marci002/proj4dart/llms.txt Creates an anonymous projection instance without registering it in the global store. ```APIDOC ## Projection.parse ### Description Creates a projection without registering it in the store. Use this for one-off transformations where you do not need to reuse the projection by name. Supports Proj4, OGC WKT, and ESRI WKT definitions. ### Method Static Method ### Parameters #### Arguments - **definition** (String) - Required - The projection definition string (Proj4, OGC WKT, or ESRI WKT). ### Request Example var mercator = Projection.parse('+proj=merc ...'); ### Response #### Success Response - **Projection** (Object) - Returns an anonymous Projection instance. ``` -------------------------------- ### Registering and Transforming Projections in Dart Source: https://context7.com/marci002/proj4dart/llms.txt This snippet demonstrates how to register a coordinate projection using a definition string and perform a coordinate transformation. It is the standard approach for initializing and converting geographic data in Dart and Flutter applications. ```dart import 'package:proj4dart/proj4dart.dart'; void main() { // Register a projection Projection.add('EPSG:3857', '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'); final source = Projection.get('EPSG:4326')!; final dest = Projection.get('EPSG:3857')!; // Transform coordinates final point = Point(x: 12.5, y: 41.9); final transformed = source.transform(dest, point); print('Transformed: ${transformed.x}, ${transformed.y}'); } ```