├── .github └── workflows │ ├── CI build.yml │ ├── CI release.yml │ └── CI snapshot.yml ├── .gitignore ├── LICENSE.md ├── codecov.yml ├── docs ├── CHANGELOG.md ├── HEADER.md └── README.md ├── grids ├── RAC09.txt ├── RAF09.txt ├── RAR07.mnt ├── egm08fr.mnt ├── gg10_gtbt.mnt ├── gg10_ld.mnt ├── gg10_ls.mnt ├── gg10_mart.mnt ├── gg10_mg.mnt ├── gg10_sb.mnt ├── gg10_sm.mnt ├── ggg00.txt ├── ggg00_ld.txt ├── ggg00_ls.txt ├── ggg00_mg.txt ├── ggg00_sb.txt ├── ggg00_sm.txt ├── ggguy00.txt ├── ggker08v2.txt ├── ggm00.txt ├── ggm04v1.txt ├── ggpf02-Bora.mnt ├── ggpf02-Huahine.mnt ├── ggpf02-Maiao.mnt ├── ggpf02-Maupiti.mnt ├── ggpf02-Raiatea.mnt ├── ggpf02-Tahaa.mnt ├── ggpf02-Tupai.mnt ├── ggpf05-HivaOa.mnt ├── ggpf05-Nuku.mnt ├── ggpf08-Fakarava.mnt ├── ggpf08-Gambier.mnt ├── ggpf08-Hao.mnt ├── ggpf08-Mataiva.mnt ├── ggpf08-Raivavae.mnt ├── ggpf08-Reao.mnt ├── ggpf08-Rurutu.mnt ├── ggpf08-Tikehau.mnt ├── ggpf08-Tubuai.mnt ├── ggpf10-Moorea.mnt ├── ggpf10-Tahiti.mnt ├── ggspm06v1.txt ├── gr3df97a.txt └── ntf_r93.gsb ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── cts │ │ ├── CRSFactory.java │ │ ├── CRSHelper.java │ │ ├── CoordinateDimensionException.java │ │ ├── Identifiable.java │ │ ├── IdentifiableComponent.java │ │ ├── Identifier.java │ │ ├── IllegalCoordinateException.java │ │ ├── Parameter.java │ │ ├── crs │ │ ├── CRSException.java │ │ ├── CompoundCRS.java │ │ ├── CoordinateReferenceSystem.java │ │ ├── GeocentricCRS.java │ │ ├── GeodeticCRS.java │ │ ├── Geographic2DCRS.java │ │ ├── Geographic3DCRS.java │ │ ├── ProjectedCRS.java │ │ └── VerticalCRS.java │ │ ├── cs │ │ ├── Axis.java │ │ ├── CoordinateSystem.java │ │ ├── Extent.java │ │ ├── GeographicExtent.java │ │ └── OutOfExtentException.java │ │ ├── datum │ │ ├── AbstractDatum.java │ │ ├── Datum.java │ │ ├── Ellipsoid.java │ │ ├── GeodeticDatum.java │ │ ├── PrimeMeridian.java │ │ └── VerticalDatum.java │ │ ├── op │ │ ├── AbstractCoordinateOperation.java │ │ ├── ChangeCoordinateDimension.java │ │ ├── CoordinateOperation.java │ │ ├── CoordinateOperationException.java │ │ ├── CoordinateOperationFactory.java │ │ ├── CoordinateOperationNotFoundException.java │ │ ├── CoordinateOperationSequence.java │ │ ├── CoordinateRounding.java │ │ ├── CoordinateSwitch.java │ │ ├── Geocentric2Geographic.java │ │ ├── Geographic2Geocentric.java │ │ ├── Identity.java │ │ ├── IterativeTransformation.java │ │ ├── LoadMemorizeCoordinate.java │ │ ├── LongitudeRotation.java │ │ ├── MemorizeCoordinate.java │ │ ├── NonInvertibleOperationException.java │ │ ├── OppositeCoordinate.java │ │ ├── TooManyIterationsException.java │ │ ├── UnitConversion.java │ │ ├── projection │ │ │ ├── AlbersEqualArea.java │ │ │ ├── CassiniSoldner.java │ │ │ ├── CylindricalEqualArea.java │ │ │ ├── EquidistantCylindrical.java │ │ │ ├── GaussSchreiberTransverseMercator.java │ │ │ ├── Krovak.java │ │ │ ├── LambertAzimuthalEqualArea.java │ │ │ ├── LambertConicConformal1SP.java │ │ │ ├── LambertConicConformal2SP.java │ │ │ ├── Mercator1SP.java │ │ │ ├── MillerCylindrical.java │ │ │ ├── NewZealandMapGrid.java │ │ │ ├── ObliqueMercator.java │ │ │ ├── ObliqueStereographicAlternative.java │ │ │ ├── Polyconic.java │ │ │ ├── Projection.java │ │ │ ├── Stereographic.java │ │ │ ├── SwissObliqueMercator.java │ │ │ ├── TransverseMercator.java │ │ │ ├── UniversalTransverseMercator.java │ │ │ └── UniversalTransverseMercatorAuto.java │ │ └── transformation │ │ │ ├── Altitude2EllipsoidalHeight.java │ │ │ ├── FrenchGeocentricNTF2RGF.java │ │ │ ├── GeoTransformation.java │ │ │ ├── GeocentricTransformation.java │ │ │ ├── GeocentricTransformationSequence.java │ │ │ ├── GeocentricTranslation.java │ │ │ ├── GridBasedTransformation.java │ │ │ ├── NTv2GridShiftTransformation.java │ │ │ ├── ParamBasedTransformation.java │ │ │ ├── SevenParameterTransformation.java │ │ │ ├── grid │ │ │ ├── GridShift.java │ │ │ ├── GridShiftFile.java │ │ │ ├── SubGrid.java │ │ │ └── Util.java │ │ │ └── grids │ │ │ ├── BleggGeographicGrid.java │ │ │ ├── GeographicGrid.java │ │ │ ├── Grid.java │ │ │ ├── GridUtils.java │ │ │ ├── IGNGeographicGrid.java │ │ │ ├── IGNVerticalGrid.java │ │ │ └── InterpolationMethodException.java │ │ ├── parser │ │ ├── prj │ │ │ ├── AbstractPrjElement.java │ │ │ ├── PrjElement.java │ │ │ ├── PrjKeyParameters.java │ │ │ ├── PrjMatcher.java │ │ │ ├── PrjNodeElement.java │ │ │ ├── PrjNodeMatcher.java │ │ │ ├── PrjNumberElement.java │ │ │ ├── PrjParser.java │ │ │ ├── PrjParserException.java │ │ │ ├── PrjStringElement.java │ │ │ ├── PrjValueParameters.java │ │ │ └── PrjWriter.java │ │ ├── proj │ │ │ ├── ParameterException.java │ │ │ ├── ProjKeyParameters.java │ │ │ ├── ProjParser.java │ │ │ └── ProjValueParameters.java │ │ └── proj4 │ │ │ └── Proj4Parser.java │ │ ├── registry │ │ ├── AbstractProjRegistry.java │ │ ├── EPSGRegistry.java │ │ ├── ESRIRegistry.java │ │ ├── IGNFRegistry.java │ │ ├── Nad27Registry.java │ │ ├── Nad83Registry.java │ │ ├── Registry.java │ │ ├── RegistryException.java │ │ ├── RegistryManager.java │ │ ├── RegistryManagerListener.java │ │ └── WorldRegistry.java │ │ ├── units │ │ ├── Measure.java │ │ ├── Quantity.java │ │ └── Unit.java │ │ └── util │ │ ├── AngleFormat.java │ │ ├── Complex.java │ │ └── UTMUtils.java └── resources │ └── org │ └── cts │ ├── log4j.properties │ └── registry │ ├── epsg │ ├── esri │ ├── ignf │ ├── nad27 │ ├── nad83 │ └── world └── test ├── java └── org │ └── cts │ ├── CRSFactoryTest.java │ ├── CRSHelperTest.java │ ├── CRSIdentifierTest.java │ ├── CTSTestCase.java │ ├── TestUtils.java │ ├── cs │ └── GeographicextentTest.java │ ├── datum │ ├── EllipsoidTest.java │ ├── GeodeticDatumTest.java │ ├── NoRecursionTest.java │ └── TestPrimeMeridian.java │ ├── op │ ├── BaseCoordinateTransformTest.java │ ├── BatchCoordinateTransformTest.java │ ├── CirceAntilleGuyaneComplianceTest.java │ ├── CirceMayotteComplianceTest.java │ ├── CirceMetropoleComplianceTest.java │ ├── CirceNouvelleCaledonieTest.java │ ├── CirceReunionComplianceTest.java │ ├── EPSGTransformTest.java │ ├── FrenchGridsTest.java │ ├── FrenchProjectionsRobustnessTest.java │ ├── PRJCoordinateTransformationTest.java │ ├── SpecialCoordinateTransformTest.java │ ├── UserDefinedTransform.java │ ├── VerticalTransformTest.java │ ├── projection │ │ ├── ProjectionTest.java │ │ └── TransverseMercatorTest.java │ └── transformation │ │ └── SevenParameterTransformationTest.java │ ├── parser │ ├── prj │ │ ├── IOPrjTest.java │ │ ├── PrjParserTest.java │ │ ├── PrjWriterTest.java │ │ └── Ticket98Test.java │ └── proj4 │ │ └── Proj4ParserTest.java │ ├── registry │ └── RegistryParserTest.java │ └── util │ ├── AngleFormatTest.java │ ├── ComplexTest.java │ └── UTMUtilsTest.java └── resources └── org └── cts ├── op ├── crstransform.csv └── frenchgridstest.csv └── parser └── prj ├── NTF_Lambert_II_etendu.prj └── WaukeeStreets.prj /.github/workflows/CI build.yml: -------------------------------------------------------------------------------- 1 | name: CI build 2 | 3 | on: 4 | pull_request: 5 | branches: [ '**' ] 6 | workflow_run: 7 | workflows: ["CI release"] 8 | branches: [ '**' ] 9 | types: 10 | - completed 11 | workflow_dispatch: 12 | 13 | jobs: 14 | build: 15 | # Main build job used to 16 | name: Build 17 | runs-on: ubuntu-latest 18 | steps: 19 | # Checkout the source code of the project 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | # Set up the jdk using version 11 of Adoptium Temurin 24 | - name: Setup java 11 using Adoptium Temurin 25 | uses: actions/setup-java@v2 26 | with: 27 | distribution: 'temurin' 28 | java-version: '11' 29 | 30 | # Build the project using 31 | # - clean : clean up the workspace 32 | # - validate : perform different check like the dependency and plugin version update 33 | # - compile : compile the source code. 34 | # - test : Perform the tests. 35 | - name: Build 36 | run: mvn -ntp clean validate compile test javadoc:test-javadoc javadoc:jar 37 | 38 | # Check changelog update 39 | - name: Check changelog update 40 | uses: dorny/paths-filter@v2 41 | id: changes 42 | with: 43 | filters: | 44 | changelog: 45 | - 'docs/CHANGELOG.md' 46 | sources: 47 | - '**/pom.xml' 48 | - '**/README.md' 49 | - '**/src/**' 50 | if: github.event_name != 'workflow_dispatch' 51 | 52 | - if: steps.changes.outputs.changelog == 'false' && github.event_name != 'workflow_dispatch' && steps.changes.outputs.sources == 'true' 53 | run: | 54 | echo "Please update the Changelog.md file." 55 | exit 1 56 | -------------------------------------------------------------------------------- /.github/workflows/CI release.yml: -------------------------------------------------------------------------------- 1 | name: CI release 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | nextVersion: 7 | required: false 8 | description: "Next version (optional)" 9 | 10 | jobs: 11 | build: 12 | name: Release and next iteration 13 | runs-on: ubuntu-latest 14 | steps: 15 | # Checkout the source code of the project 16 | - name: Checkout 17 | uses: actions/checkout@v2 18 | 19 | # Install the GPG secret key 20 | - name: Step 2 - Import GPG Key 21 | run: | 22 | echo "${{ secrets.GPG_PUBLIC_KEY }}" | gpg --import 23 | echo "${{ secrets.GPG_SECRET_KEY }}" | gpg --import --no-tty --batch --yes 24 | env: 25 | GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} 26 | GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} 27 | 28 | # Set up the jdk using version 11 of Adoptium Temurin 29 | - name: Setup java 11 using Adoptium Temurin 30 | uses: actions/setup-java@v2 31 | with: 32 | distribution: 'temurin' 33 | java-version: '11' 34 | server-id: ossrh 35 | server-username: MAVEN_USERNAME 36 | server-password: MAVEN_PASSWORD 37 | gpg-private-key: ${{ secrets.GPG_SECRET_KEY }} 38 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 39 | 40 | # Configure git user in order to sign release with OrbisGIS user. 41 | - name: Configure Git User 42 | run: | 43 | git config user.email "info@orbisgis.org" 44 | git config user.name OrbisGIS 45 | 46 | 47 | # Test build 48 | - name: Build test 49 | run: mvn -ntp clean validate compile test javadoc:test-javadoc javadoc:jar 50 | 51 | # Create the release : 52 | # - move from Snapshot version to Release 53 | # - commit and tag release 54 | # - move to next Snapshot 55 | # - upload release to maven repo 56 | - name: Release 57 | run: | 58 | VERSION=${{ github.event.inputs.nextVersion }} 59 | mvn \ 60 | -ntp \ 61 | --batch-mode \ 62 | -P deploy \ 63 | -Dmaven.test.skip=true \ 64 | release:prepare release:perform \ 65 | -Dusername=$GITHUB_ACTOR -Dpassword=$GITHUB_TOKEN ${VERSION:+"-DdevelopmentVersion="$VERSION"-SNAPSHOT"} 66 | env: 67 | MAVEN_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} 68 | MAVEN_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} 69 | MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 70 | 71 | # Export the last git tag into env. 72 | - name: Export env values 73 | run: echo "GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_ENV 74 | 75 | # Make the github release from the last created tag. Write in its body the content of the changelog file. 76 | - name: Make github release 77 | uses: actions/create-release@v1 78 | env: 79 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token 80 | with: 81 | tag_name: ${{ env.GIT_TAG }} 82 | release_name: ${{ env.GIT_TAG }} 83 | body_path: docs/CHANGELOG.md 84 | draft: false 85 | prerelease: false 86 | 87 | # Clear the changelog file and add its header 88 | - name: Clear changelog 89 | run: | 90 | echo "## Changelog for v$( mvn help:evaluate -Dexpression=project.version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }' | cut -d- -f1)" > docs/CHANGELOG.md 91 | git commit -a -m "Empty changelog." 92 | git push origin master 93 | 94 | # If the version change is a major or minor, create a branch from the previous tag for future revisions. 95 | - name: Branch fork 96 | run: | 97 | GIT_TAG="${GIT_TAG:1}" 98 | CUR_TAG="$( mvn help:evaluate -Dexpression=project.version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }' | cut -d- -f1)" 99 | SPLIT0=(${GIT_TAG//./ }) 100 | SPLIT1=(${CUR_TAG//./ }) 101 | if [ "${SPLIT0[0]}" = "${SPLIT1[0]}" ] && [ "${SPLIT0[1]}" = "${SPLIT1[1]}" ]; then 102 | echo "Revision change" 103 | else 104 | echo "Minor or Major change" 105 | BRANCH="${SPLIT0[0]}.${SPLIT0[1]}.X" 106 | git checkout -b "$BRANCH" "v${GIT_TAG}" 107 | mvn versions:set -DnewVersion="${SPLIT0[0]}.${SPLIT0[1]}.$((${SPLIT0[2]}+1))-SNAPSHOT" 108 | git commit -a -m "Set next version." 109 | git push -u origin "$BRANCH" 110 | fi 111 | -------------------------------------------------------------------------------- /.github/workflows/CI snapshot.yml: -------------------------------------------------------------------------------- 1 | name: CI snapshot 2 | 3 | on: 4 | push: 5 | branches: [ '**' ] 6 | workflow_run: 7 | workflows: ["CI release"] 8 | branches: [ '**' ] 9 | types: 10 | - completed 11 | workflow_dispatch: 12 | 13 | jobs: 14 | build: 15 | name: Upload Snapshot 16 | runs-on: ubuntu-latest 17 | steps: 18 | # Checkout the source code of the project 19 | - name: Checkout 20 | uses: actions/checkout@v2 21 | 22 | # Install the GPG secret key 23 | - name: Step 2 - Import GPG Key 24 | run: | 25 | echo "${{ secrets.GPG_PUBLIC_KEY }}" | gpg --import 26 | echo "${{ secrets.GPG_SECRET_KEY }}" | gpg --import --no-tty --batch --yes 27 | env: 28 | GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} 29 | GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} 30 | 31 | # Set up the jdk using version 11 of Adoptium Temurin 32 | - name: Setup java 11 using Adoptium Temurin 33 | uses: actions/setup-java@v2 34 | with: 35 | distribution: 'temurin' 36 | java-version: '11' 37 | server-id: ossrh 38 | server-username: MAVEN_USERNAME 39 | server-password: MAVEN_PASSWORD 40 | gpg-private-key: ${{ secrets.GPG_SECRET_KEY }} 41 | gpg-passphrase: MAVEN_GPG_PASSPHRASE 42 | 43 | # Deploy the snapshot 44 | - name: Deploy 45 | run: mvn deploy -ntp --batch-mode 46 | env: 47 | MAVEN_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} 48 | MAVEN_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} 49 | MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | *.iml 3 | .idea -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: off -------------------------------------------------------------------------------- /docs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Changelog for v1.7.2 2 | 3 | - Use junit-jupiter-api in test scope only #160 4 | - Remove unnecessary logger 5 | - Update github actions 6 | -------------------------------------------------------------------------------- /docs/HEADER.md: -------------------------------------------------------------------------------- 1 | Coordinate Transformations Suite (abridged CTS) is a library developped to 2 | perform Coordinate Transformations using well known geodetic algorithms 3 | and parameter sets. 4 | Its main focus are simplicity, flexibility, interoperability, in this order. 5 | 6 | This library has been originally developed by Michaël Michaud under the JGeod 7 | name. It has been renamed CTS in 2009 and shared to the community from 8 | the OrbisGIS code repository. 9 | 10 | CTS is free software: you can redistribute it and/or modify it under the 11 | terms of the GNU Lesser General Public License as published by the Free Software 12 | Foundation, either version 3 of the License. 13 | 14 | CTS is distributed in the hope that it will be useful, but WITHOUT ANY 15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 16 | A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License along with 19 | CTS. If not, see . 20 | 21 | For more information, please consult: 22 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # CTS 2 | [![GitHub](https://img.shields.io/github/license/orbisgis/cts.svg)](https://github.com/orbisgis/cts/blob/master/docs/LICENSE.md) 3 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d9b34e00264d4702b8340f8544cec21f)](https://www.codacy.com/gh/orbisgis/cts?utm_source=github.com&utm_medium=referral&utm_content=orbisgis/cts&utm_campaign=Badge_Grade) 4 | 5 | Coordinate Transformation Suite (abridged CTS) is a library developed to 6 | perform coordinate transformations using well known geodetic algorithms and 7 | parameter sets. It strives to be simple, flexible and interoperable, in this 8 | order. 9 | 10 | #### History 11 | 12 | Originally developed by Michaël Michaud under the name [JTransfoCoord](http://michael.michaud.free.fr/index_geodesie.html) and then JGeod, the library was 13 | renamed to CTS in 2009. Today CTS is maintained by the OrbisGIS team in 14 | collaboration with Michaël Michaud. 15 | 16 | The new CTS has been funded by the French *Agence Nationale de la Recherche* (ANR) under 17 | research contract ANR-08-VILL-0005-01 and the regional council of the *Région Pays 18 | de La Loire* under the *Système d'Orbservation Géographique de la Ville* 19 | (SOGVILLE) project. 20 | 21 | 22 | #### License 23 | 24 | CTS is free software; you can redistribute it and/or modify it under the terms 25 | of the GNU Lesser General Public License as published by the Free Software Foundation, 26 | either version 3 of the License. 27 | 28 | CTS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 29 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 30 | PURPOSE. See the GNU Lesser General Public License for more details. 31 | 32 | You should have received a copy of the GNU Lesser General Public License along with 33 | CTS. If not, see . 34 | 35 | #### Declaring project dependencies 36 | 37 | You can include CTS in your project thanks to Maven repositories. 38 | 39 | From maven central, check https://search.maven.org/artifact/org.orbisgis/cts/1.7.1/bundle 40 | 41 | To use the current snapshot add in the pom 42 | 43 | ```xml 44 | 45 | orbisgis-snapshot 46 | OrbisGIS sonatype snapshot repository 47 | https://oss.sonatype.org/content/repositories/snapshots/ 48 | 49 | ``` 50 | 51 | and the following dependency 52 | 53 | ```xml 54 | 55 | org.orbisgis 56 | cts 57 | 1.7.2-SNAPSHOT 58 | 59 | ``` 60 | 61 | -------------------------------------------------------------------------------- /grids/RAR07.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/RAR07.mnt -------------------------------------------------------------------------------- /grids/gg10_gtbt.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_gtbt.mnt -------------------------------------------------------------------------------- /grids/gg10_ld.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_ld.mnt -------------------------------------------------------------------------------- /grids/gg10_ls.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_ls.mnt -------------------------------------------------------------------------------- /grids/gg10_mart.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_mart.mnt -------------------------------------------------------------------------------- /grids/gg10_mg.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_mg.mnt -------------------------------------------------------------------------------- /grids/gg10_sb.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_sb.mnt -------------------------------------------------------------------------------- /grids/gg10_sm.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/gg10_sm.mnt -------------------------------------------------------------------------------- /grids/ggg00.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggg00.txt -------------------------------------------------------------------------------- /grids/ggg00_ld.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggg00_ld.txt -------------------------------------------------------------------------------- /grids/ggg00_ls.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggg00_ls.txt -------------------------------------------------------------------------------- /grids/ggg00_mg.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggg00_mg.txt -------------------------------------------------------------------------------- /grids/ggg00_sb.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggg00_sb.txt -------------------------------------------------------------------------------- /grids/ggg00_sm.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggg00_sm.txt -------------------------------------------------------------------------------- /grids/ggguy00.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggguy00.txt -------------------------------------------------------------------------------- /grids/ggker08v2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggker08v2.txt -------------------------------------------------------------------------------- /grids/ggm00.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggm00.txt -------------------------------------------------------------------------------- /grids/ggpf02-Bora.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Bora.mnt -------------------------------------------------------------------------------- /grids/ggpf02-Huahine.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Huahine.mnt -------------------------------------------------------------------------------- /grids/ggpf02-Maiao.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Maiao.mnt -------------------------------------------------------------------------------- /grids/ggpf02-Maupiti.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Maupiti.mnt -------------------------------------------------------------------------------- /grids/ggpf02-Raiatea.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Raiatea.mnt -------------------------------------------------------------------------------- /grids/ggpf02-Tahaa.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Tahaa.mnt -------------------------------------------------------------------------------- /grids/ggpf02-Tupai.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf02-Tupai.mnt -------------------------------------------------------------------------------- /grids/ggpf05-HivaOa.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf05-HivaOa.mnt -------------------------------------------------------------------------------- /grids/ggpf05-Nuku.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf05-Nuku.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Fakarava.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Fakarava.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Gambier.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Gambier.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Mataiva.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Mataiva.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Raivavae.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Raivavae.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Reao.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Reao.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Rurutu.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Rurutu.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Tikehau.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Tikehau.mnt -------------------------------------------------------------------------------- /grids/ggpf08-Tubuai.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf08-Tubuai.mnt -------------------------------------------------------------------------------- /grids/ggpf10-Moorea.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf10-Moorea.mnt -------------------------------------------------------------------------------- /grids/ggpf10-Tahiti.mnt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggpf10-Tahiti.mnt -------------------------------------------------------------------------------- /grids/ggspm06v1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ggspm06v1.txt -------------------------------------------------------------------------------- /grids/ntf_r93.gsb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/grids/ntf_r93.gsb -------------------------------------------------------------------------------- /src/main/java/org/cts/CoordinateDimensionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts; 25 | 26 | /** 27 | * Exception thrown when a double array input has not the expected length. 28 | * 29 | * @author Michaël Michaud 30 | */ 31 | public class CoordinateDimensionException extends IllegalCoordinateException { 32 | 33 | /** 34 | * Creates a new CoordinateDimensionException. 35 | * 36 | * @param s the message 37 | */ 38 | public CoordinateDimensionException(String s) { 39 | super(s); 40 | } 41 | 42 | /** 43 | * Creates a new CoordinateDimensionException. 44 | * 45 | * @param coord the coord responsible for this exception 46 | * @param requiredDimension the dimension required by the calling method 47 | */ 48 | public CoordinateDimensionException(double[] coord, int requiredDimension) { 49 | super("The dimension of " + java.util.Arrays.toString(coord) 50 | + " is not valid : a coord of at least " 51 | + requiredDimension + "D is required"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/cts/IllegalCoordinateException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts; 25 | 26 | /** 27 | * Try to use an illegal coordinate. 28 | * 29 | * @author Michaël Michaud 30 | */ 31 | public class IllegalCoordinateException extends Exception { 32 | 33 | /** 34 | * Create a new IllegalCoordinateException. 35 | * 36 | * @param exception precise description of this exception 37 | */ 38 | public IllegalCoordinateException(String exception) { 39 | super(exception); 40 | } 41 | 42 | /** 43 | * Create a new IllegalCoordinateException. 44 | * 45 | * @param exception precise description of this exception 46 | * @param coord the illegal coordinate as a double array 47 | */ 48 | public IllegalCoordinateException(String exception, double[] coord) { 49 | super(exception + " : " + java.util.Arrays.toString(coord)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/cts/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts; 25 | 26 | import org.cts.units.Measure; 27 | 28 | public class Parameter { 29 | 30 | public static final String ELLIPSOID = "ellipsoid"; 31 | /** 32 | * Key to access central meridian, one possible parameter of the projection. 33 | */ 34 | public static final String CENTRAL_MERIDIAN = "central meridian"; 35 | /** 36 | * Key to access latitude of origin, one possible parameter of the 37 | * projection. 38 | */ 39 | public static final String LATITUDE_OF_ORIGIN = "latitude of origin"; 40 | /** 41 | * Key to access the first standard parallel of secant conformal conic 42 | * projections. 43 | */ 44 | public static final String STANDARD_PARALLEL_1 = "standard parallel 1"; 45 | /** 46 | * Key to access the second standard parallel of secant conformal conic 47 | * projections. 48 | */ 49 | public static final String STANDARD_PARALLEL_2 = "standard parallel 2"; 50 | /** 51 | * Key to access latitude of true scale, one possible parameter of the 52 | * projection. 53 | */ 54 | public static final String LATITUDE_OF_TRUE_SCALE = "latitude of true scale"; 55 | /** 56 | * Key to access azimuth of the initial line of oblique projections. 57 | */ 58 | public static final String AZIMUTH = "azimuth"; 59 | /** 60 | * Key to access angle from the rectified grid to the skew (oblique) grid of 61 | * oblique projections. 62 | */ 63 | public static final String RECTIFIED_GRID_ANGLE = "rectified grid angle"; 64 | /** 65 | * Key to access scale factor, one possible parameter of the projection. 66 | */ 67 | public static final String SCALE_FACTOR = "scale factor"; 68 | /** 69 | * Key to access false_easting, one possible parameter of the projection. 70 | */ 71 | public static final String FALSE_EASTING = "false easting"; 72 | /** 73 | * Key to access false_northing, one possible parameter of the projection. 74 | */ 75 | public static final String FALSE_NORTHING = "false northing"; 76 | private String name; 77 | private Measure measure; 78 | 79 | /** 80 | * Creates a new Parameters defined by his name and his measure. 81 | * 82 | * @param name the name of the new parameter (ex : latitude, false northing) 83 | * @param measure the measure in which the parameter is expressed (ex : 84 | * degrees, meters) 85 | */ 86 | public Parameter(String name, Measure measure) { 87 | this.name = name; 88 | this.measure = measure; 89 | } 90 | 91 | /** 92 | * Returns the name of this Parameter. 93 | */ 94 | public String getName() { 95 | return name; 96 | } 97 | 98 | /** 99 | * Returns the measure in which this Parameter is expressed. 100 | */ 101 | public Measure getMeasure() { 102 | return measure; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/org/cts/crs/CRSException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.crs; 25 | 26 | /** 27 | * @author Erwan Bocher 28 | */ 29 | public class CRSException extends Exception { 30 | 31 | /** 32 | * Build a coordinate reference system exception from a message. 33 | * 34 | * @param message precise description of this exception 35 | */ 36 | public CRSException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Build a coordinate reference system exception based on an exception. 42 | * 43 | * @param ex source of this CRSException 44 | */ 45 | public CRSException(Exception ex) { 46 | super(ex); 47 | } 48 | 49 | /** 50 | * Build a coordinate reference system exception based on a message and an 51 | * exception. 52 | * 53 | * @param message 54 | * @param ex 55 | */ 56 | public CRSException(String message, Exception ex) { 57 | super(message, ex); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/cts/crs/CoordinateReferenceSystem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.crs; 25 | 26 | import org.cts.Identifiable; 27 | import org.cts.cs.CoordinateSystem; 28 | import org.cts.datum.Datum; 29 | import org.cts.op.projection.Projection; 30 | 31 | /** 32 | * A coordinate system which is related to the real world by a 33 | * {@link org.cts.datum.Datum} (ISO/DIS 19111). 34 | *

A point in the real world may have different coordinates, depending on 35 | * the CoordinateReferenceSystem used. The different types of 36 | * CoordinateReferenceSystem defined by EPSG 37 | * are :

38 | *
    39 | *
  • Geocentric coordinate reference system
  • 40 | *
  • Geographic 3D coordinate reference system
  • 41 | *
  • Geographic 2D coordinate reference system
  • 42 | *
  • Projected coordinate reference system
  • 43 | *
  • Vertical coordinate reference system
  • 44 | *
  • Compound coordinate reference system
  • 45 | *
  • Engineering coordinate reference system
  • 46 | *
47 | * 48 | * @author Michaël Michaud 49 | */ 50 | public interface CoordinateReferenceSystem extends Identifiable { 51 | 52 | /** 53 | * Coordinate Reference System Type. 54 | */ 55 | public enum Type { 56 | 57 | GEOCENTRIC, GEOGRAPHIC3D, GEOGRAPHIC2D, PROJECTED, VERTICAL, COMPOUND, ENGINEERING 58 | } 59 | 60 | /** 61 | * Returns this CoordinateReferenceSystem Type. 62 | * 63 | * @return 64 | */ 65 | public Type getType(); 66 | 67 | /** 68 | * Returns the {@link CoordinateSystem} used by this 69 | * CoordinateReferenceSystem. 70 | * 71 | * @return 72 | */ 73 | public CoordinateSystem getCoordinateSystem(); 74 | 75 | /** 76 | * Returns the {@link Datum} to which this 77 | * CoordinateReferenceSystem is refering. For compound 78 | * CoordinateReferenceSystem, getDatum returns the the main 79 | * datum, ie the {@link org.cts.datum.GeodeticDatum} (or horizontal Datum). 80 | * 81 | * @return 82 | */ 83 | public Datum getDatum(); 84 | 85 | /** 86 | * Returns the {@link Projection} to which this 87 | * CoordinateReferenceSystem is refering. It returns null if no 88 | * projection is defined for this CRS. 89 | * 90 | * @return 91 | */ 92 | public Projection getProjection(); 93 | 94 | /** 95 | * Returns a WKT representation of the CoordinateReferenceSystem. 96 | * 97 | * @return 98 | */ 99 | public String toWKT(); 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/org/cts/cs/Extent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.cs; 25 | 26 | /** 27 | * An 28 | * Extent defines a part of an infinite n-dimension space thanks to 29 | * a method returning true for any set of coordinates lying inside this part and 30 | * false for coordinates lying outside (input coordinates must be an array of n 31 | * doubles). 32 | * 33 | * @author Michaël Michaud 34 | */ 35 | public interface Extent { 36 | 37 | /** 38 | * Return the name of this extent. 39 | */ 40 | public String getName(); 41 | 42 | /** 43 | * Return wether coord is inside this Extent or not. It's up to the user to 44 | * check consistency between coord and extent type. 45 | */ 46 | public boolean isInside(double[] coord); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/cts/cs/OutOfExtentException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.cs; 25 | 26 | import java.util.Arrays; 27 | 28 | /** 29 | * An exception arising while trying to work out of a valid area defined by an 30 | * Extent object. 31 | * 32 | * @author Michaël Michaud 33 | */ 34 | public class OutOfExtentException extends Exception { 35 | 36 | /** 37 | * Create a new OutOfExtentException. 38 | * 39 | * @param exception description of this exception 40 | */ 41 | public OutOfExtentException(String exception) { 42 | super(exception); 43 | } 44 | 45 | /** 46 | * Create a new OutOfExtentException. 47 | * 48 | * @param coord the coord responsible for this exception 49 | */ 50 | public OutOfExtentException(double[] coord) { 51 | super("The coordinate " + Arrays.toString(coord) + " is out of the valid Extent"); 52 | } 53 | 54 | /** 55 | * Create a new OutOfExtentException. 56 | * 57 | * @param coord the coord responsible for this exception 58 | * @param extent the valid extent 59 | */ 60 | public OutOfExtentException(double[] coord, Extent extent) { 61 | super("The coordinate " + Arrays.toString(coord) + " is out of " 62 | + extent.toString()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/cts/datum/AbstractDatum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.datum; 25 | 26 | import org.cts.IdentifiableComponent; 27 | import org.cts.Identifier; 28 | import org.cts.cs.Extent; 29 | 30 | /** 31 | * A simple implementation of {@link Datum} interface with a default 32 | * constructor. 33 | * 34 | * @author Michaël Michaud 35 | */ 36 | public abstract class AbstractDatum extends IdentifiableComponent 37 | implements Datum { 38 | 39 | /** 40 | * The valid {@link Extent} of this Datum. 41 | */ 42 | private Extent extent; 43 | 44 | /** 45 | * The description of this Datum origin. 46 | */ 47 | private String origin; 48 | 49 | /** 50 | * The realization epoch of this Datum as a String. 51 | */ 52 | private String epoch; 53 | 54 | /** 55 | * Creates a new Datum. 56 | * 57 | * @param identifier the identifier of this Datum 58 | * @param extent valid domain extent (extent definition depends on the kind 59 | * of Datum) 60 | * @param origin description of the origin or anchor point of this Datum. 61 | * @param epoch epoch of this Datum realization 62 | */ 63 | protected AbstractDatum(Identifier identifier, Extent extent, String origin, String epoch) { 64 | super(identifier); 65 | this.extent = extent; 66 | this.origin = origin; 67 | this.epoch = epoch; 68 | } 69 | 70 | /** 71 | * Returns the valid extent of this Datum. 72 | */ 73 | @Override 74 | public Extent getExtent() { 75 | return extent; 76 | } 77 | 78 | /** 79 | * Returns the description of this Datum origin. 80 | */ 81 | @Override 82 | public String getOrigin() { 83 | return origin; 84 | } 85 | 86 | /** 87 | * Returns the realization epoch of this Datum as a String. 88 | */ 89 | @Override 90 | public String getEpoch() { 91 | return epoch; 92 | } 93 | 94 | /** 95 | * Returns a String representation of this Datum. 96 | */ 97 | @Override 98 | public String toString() { 99 | return getIdentifier().toString(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/org/cts/datum/Datum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.datum; 25 | 26 | import org.cts.Identifiable; 27 | import org.cts.cs.Extent; 28 | import org.cts.op.CoordinateOperation; 29 | 30 | /** 31 | * A datum (plural datums) is a reference from which measurements are made.

32 | * In surveying and geodesy, a datum is a reference point on the earth's surface 33 | * against which position measurements are made, and an associated model of the 34 | * shape of the earth for computing positions. Horizontal datums are used for 35 | * describing a point on the earth's surface, in latitude and longitude or 36 | * another coordinate system. Vertical datums are used to measure elevations or 37 | * underwater depths. In engineering and drafting, a datum is a reference point, 38 | * surface, or axis on an object against which measurements are made. 39 | * (Taken from wikipedia on 40 | * 2006-10-06) 41 | * 42 | * @author Michaël Michaud 43 | */ 44 | public interface Datum extends Identifiable { 45 | 46 | /** 47 | * Returns origin description of this Datum. 48 | */ 49 | public String getOrigin(); 50 | 51 | /** 52 | * Returns the valid extent of this Datum. 53 | */ 54 | public Extent getExtent(); 55 | 56 | /** 57 | * Returns the realization epoch as a String. 58 | */ 59 | public String getEpoch(); 60 | 61 | /** 62 | * Returns the ellipsoid of this datum. 63 | */ 64 | public Ellipsoid getEllipsoid(); 65 | 66 | /** 67 | * Returns the ellipsoid of this datum. 68 | */ 69 | public CoordinateOperation getToWGS84(); 70 | 71 | /** 72 | * Returns the primemeridian of this datum. 73 | */ 74 | public PrimeMeridian getPrimeMeridian(); 75 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/op/AbstractCoordinateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.IdentifiableComponent; 27 | import org.cts.Identifier; 28 | import org.cts.IllegalCoordinateException; 29 | 30 | /** 31 | * AbstractCoordinateOperation is a partial implementation of the 32 | * {@link CoordinateOperation} interface. 33 | * 34 | * @author Michaël Michaud 35 | */ 36 | public abstract class AbstractCoordinateOperation 37 | extends IdentifiableComponent 38 | implements CoordinateOperation { 39 | 40 | protected double precision = 0.0; 41 | 42 | /** 43 | * Create a new {@link CoordinateOperation} instance. 44 | * 45 | * @param identifier this CoordinateOperation identifier 46 | */ 47 | protected AbstractCoordinateOperation(Identifier identifier) { 48 | super(identifier); 49 | } 50 | 51 | /** 52 | * Return a double[] representing the same location as coord but in another 53 | * CoordinateReferenceSystem. 54 | * 55 | * @param coord the input coordinate 56 | * @return a double array containing the output coordinate 57 | * @throws IllegalCoordinateException if coord is not 58 | * compatible with this CoordinateOperation. 59 | * @throws org.cts.op.CoordinateOperationException if this operation 60 | * failed during the transformation process. 61 | */ 62 | public abstract double[] transform(double[] coord) 63 | throws IllegalCoordinateException, CoordinateOperationException; 64 | 65 | /** 66 | * Creates the inverse CoordinateOperation. This method can be used to chain 67 | * {@link org.cts.op.CoordinateOperation}s and/or inverse CoordinateOperation in 68 | * a unique CoordinateOperationSequence. This method is not declared 69 | * abstract, so that implementation classes have not to implement it if they 70 | * represent non invertible operation. 71 | */ 72 | public CoordinateOperation inverse() 73 | throws NonInvertibleOperationException { 74 | throw new NonInvertibleOperationException(this.toString() 75 | + " is non invertible"); 76 | } 77 | 78 | /** 79 | * Returns the precision of the transformation.

Precision is a double 80 | * representing the mean error, in meters made on the position resulting 81 | * from this {@link org.cts.op.CoordinateOperation}.

ex. : 0.001 means that 82 | * the precision of the resulting position is about one millimeter

83 | * Default precision (or maximum precision) is considered to be equals to 84 | * 1E-9 which is the value of an ulp (units in the last place) for a double 85 | * value equals to 6378137.0 (Earth semi-major axis). 86 | */ 87 | public double getPrecision() { 88 | return precision; 89 | } 90 | 91 | 92 | /** 93 | * @return true if this operation does not change coordinates. 94 | */ 95 | public boolean isIdentity() { 96 | return false; 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/op/ChangeCoordinateDimension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.IllegalCoordinateException; 28 | 29 | /** 30 | * Change de coordinate dimension. For example, this operation can add or remove 31 | * a vertical dimension to a 2D coordinate. 32 | * 33 | * @author Michaël Michaud 34 | */ 35 | public class ChangeCoordinateDimension extends AbstractCoordinateOperation { 36 | 37 | private static final Identifier G3DG2D = 38 | new Identifier("EPSG", "9659", "Geographic 3D to 2D conversion", "Geo3D->2D"); 39 | private static final Identifier G2DG3D = 40 | new Identifier("EPSG", "9659i", "Geographic 2D to 3D conversion", "Geo2D->3D"); 41 | 42 | public final static ChangeCoordinateDimension TO3D = new ChangeCoordinateDimension(G2DG3D, 2, 3) { 43 | @Override 44 | public CoordinateOperation inverse() { 45 | return TO2D; 46 | } 47 | }; 48 | 49 | public final static ChangeCoordinateDimension TO2D = new ChangeCoordinateDimension(G3DG2D, 3, 2) { 50 | @Override 51 | public CoordinateOperation inverse() { 52 | return TO3D; 53 | } 54 | }; 55 | 56 | private int inputDim, outputDim; 57 | 58 | /** 59 | * Creates a new CoordinateOperation increasing (resp decreasing) the coord 60 | * size by length. 61 | * 62 | * @param inputDim dimension of the input coordinate 63 | * @param outputDim dimension of the output coordinate 64 | */ 65 | private ChangeCoordinateDimension(Identifier identifier, int inputDim, int outputDim) { 66 | super(identifier); 67 | this.inputDim = inputDim; 68 | this.outputDim = outputDim; 69 | } 70 | 71 | /** 72 | * Add a vertical coordinate. 73 | * 74 | * @param coord is an array containing one, two or three ordinates 75 | * @return 76 | */ 77 | @Override 78 | public double[] transform(double[] coord) { 79 | if (inputDim == outputDim) { 80 | return coord; 81 | } 82 | double[] cc = new double[outputDim]; 83 | System.arraycopy(coord, 0, cc, 0, Math.min(inputDim, outputDim)); 84 | return cc; 85 | } 86 | 87 | /** 88 | * Creates the inverse CoordinateOperation. 89 | */ 90 | @Override 91 | public CoordinateOperation inverse() { 92 | return new ChangeCoordinateDimension(new Identifier(CoordinateOperation.class), outputDim, inputDim); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/CoordinateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.Identifiable; 27 | import org.cts.IllegalCoordinateException; 28 | 29 | /** 30 | * A CoordinateOperation is an object able to modify values of a coordinate.

31 | * This is the main interface used to implement geodetic algorithms and perform 32 | * coordinate conversions or coordinate transformations from one 33 | * {@link org.cts.crs.CoordinateReferenceSystem} to another. 34 | * 35 | * @author Michaël Michaud 36 | */ 37 | public interface CoordinateOperation extends Identifiable { 38 | 39 | /** 40 | * Transform values of a double array.

WARNING : In the general 41 | * case, double values of the coord parameter are changed without the 42 | * creation of a new array. In some cases (when the returned array must have 43 | * a different length, a new double array is created and returned. 44 | * 45 | * @param coord coordinate to be transformed 46 | * @return the same object with new values or a new double array 47 | * @throws IllegalCoordinateException if coord is not 48 | * compatible with this CoordinateOperation. 49 | * @throws org.cts.op.CoordinateOperationException if this operation 50 | * failed during the transformation process. 51 | */ 52 | public double[] transform(double[] coord) throws IllegalCoordinateException, CoordinateOperationException; 53 | 54 | /** 55 | * Return the inverse CoordinateOperation, or throw a 56 | * NonInvertibleOperationException. If op.inverse() is not null, 57 | *

58 |      * op.inverse().transform(op.transform(point));
59 |      * 
should let point unchanged. 60 | */ 61 | public CoordinateOperation inverse() throws NonInvertibleOperationException; 62 | 63 | /** 64 | * Return the precision of the transformation.

Precision is a double 65 | * representing the mean error, in meters made on the position resulting 66 | * from this 67 | * CoordinateOperation.

ex. : 0.001 means that the precision 68 | * of the resulting position is about one millimeter

Default precision 69 | * (or maximum precision) is considered to be equals to 1E-9 which is the 70 | * value of an ulp (units in the last place) for a double value equals to 71 | * 6378137.0 (Earth semi-major axis). 72 | */ 73 | public double getPrecision(); 74 | 75 | /** 76 | * @return true if this operation does not change coordinates. 77 | */ 78 | public boolean isIdentity(); 79 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/op/CoordinateOperationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | /** 27 | * An exception thrown because a CoordinateOperation could not be 28 | * found or created. 29 | * 30 | * @author Michaël Michaud 31 | */ 32 | public class CoordinateOperationException extends Exception { 33 | 34 | /** 35 | * Creates a new CoordinateOperationException. 36 | * 37 | * @param exception description of this exception 38 | */ 39 | public CoordinateOperationException(String exception) { 40 | super(exception); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/CoordinateOperationNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.crs.CoordinateReferenceSystem; 27 | import org.cts.datum.Datum; 28 | 29 | /** 30 | * Exception thrown when a coordinate operation has not been found 31 | * or could not be calculated. 32 | * 33 | * @author Michaël Michaud 34 | */ 35 | public class CoordinateOperationNotFoundException extends CoordinateOperationException { 36 | 37 | /** 38 | * Creates a new CoordinateOperationNotFoundException. 39 | * 40 | * @param exception description of this exception 41 | */ 42 | public CoordinateOperationNotFoundException(String exception) { 43 | super(exception); 44 | } 45 | 46 | /** 47 | * Creates a new CoordinateOperationNotFoundException because no 48 | * CoordinateOperation has been found from source Datum to target Datum. 49 | */ 50 | public CoordinateOperationNotFoundException(Datum source, Datum target) { 51 | super("No CoordinateOperation has been found to convert coordinates from\n" + source + " to\n" + target); 52 | } 53 | 54 | /** 55 | * Creates a new CoordinateOperationNotFoundException because no 56 | * CoordinateOperation has been found from source CoordinateReferenceSystem 57 | * to target CoordinateReferenceSystem. 58 | */ 59 | public CoordinateOperationNotFoundException(CoordinateReferenceSystem source, CoordinateReferenceSystem target) { 60 | super("No CoordinateOperation has been found to convert coordinates from\n" + source + " to\n" + target); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/CoordinateRounding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.CoordinateDimensionException; 27 | import org.cts.Identifier; 28 | import org.cts.IllegalCoordinateException; 29 | 30 | import java.util.Arrays; 31 | 32 | /** 33 | * A class to change the coordinate precision 34 | * 35 | * @author Michaël Michaud 36 | */ 37 | public class CoordinateRounding extends AbstractCoordinateOperation { 38 | 39 | /** 40 | * Round the coordinates to millimeter value. 41 | */ 42 | public final static CoordinateRounding MILLIMETER = createCoordinateRoundingOperation(0.001); 43 | 44 | /** 45 | * Round the coordinates to centimeter value. 46 | */ 47 | public final static CoordinateRounding CENTIMETER = createCoordinateRoundingOperation(0.01); 48 | 49 | /** 50 | * Round the coordinates to decimeter value. 51 | */ 52 | public final static CoordinateRounding DECIMETER = createCoordinateRoundingOperation(0.1); 53 | 54 | /** 55 | * Round the coordinates to meter value. 56 | */ 57 | public final static CoordinateRounding METER = createCoordinateRoundingOperation(0.0); 58 | 59 | /** 60 | * Round the coordinates to kilometer value. 61 | */ 62 | public final static CoordinateRounding KILOMETER = createCoordinateRoundingOperation(1000.0); 63 | 64 | /** 65 | * Store the inverse resolution of the rounding. 66 | */ 67 | private double inv_resolution = 1.0; 68 | 69 | /** 70 | * Creates a new coordinate rounding operation from the smallest 71 | * representable value. Note that CoordinateRounding is not invertible. 72 | * 73 | * @param resolution the target resolution. 74 | */ 75 | private CoordinateRounding(double resolution) { 76 | super(new Identifier(CoordinateRounding.class, 77 | "ordinates are multiple of " + resolution)); 78 | this.inv_resolution = 1.0 / resolution; 79 | } 80 | 81 | /** 82 | * Returns a coordinate representing the same point as coord but with 83 | * coordinates rounded as specified. 84 | * 85 | * @param coord is an array containing one, two or three ordinates 86 | * @throws IllegalCoordinateException if coord is not 87 | * compatible with this CoordinateOperation. 88 | */ 89 | @Override 90 | public double[] transform(double[] coord) throws IllegalCoordinateException { 91 | if (coord == null || coord.length == 0) { 92 | throw new CoordinateDimensionException(Arrays.toString(coord) 93 | + " is an invalid coordinate"); 94 | } 95 | for (int i = 0; i < coord.length; i++) { 96 | if (Double.isNaN(coord[i])) { 97 | continue; 98 | } 99 | coord[i] = Math.rint(coord[i] * inv_resolution) / inv_resolution; 100 | } 101 | return coord; 102 | } 103 | 104 | /** 105 | * Creates a coordinate rounding operation from a decimal place number. 106 | * 107 | * @param decimalPlaces number of decimal places 108 | */ 109 | public static CoordinateRounding createCoordinateRoundingOperationFromDecimalPlaces(int decimalPlaces) { 110 | double u = 1.0; 111 | for (int i = 0; i < decimalPlaces; i++) { 112 | u *= 10.0; 113 | } 114 | return new CoordinateRounding(1.0 / u); 115 | } 116 | 117 | /** 118 | * Creates a coordinate rounding operation from the smallest representable 119 | * value. 120 | * 121 | * @param resolution smallest representable value 122 | */ 123 | public static CoordinateRounding createCoordinateRoundingOperation(double resolution) { 124 | return new CoordinateRounding(resolution); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/CoordinateSwitch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.CoordinateDimensionException; 27 | import org.cts.Identifier; 28 | import org.cts.IllegalCoordinateException; 29 | 30 | /** 31 | * A class to switch to values in a double array. 32 | * 33 | * @author Michaël Michaud 34 | */ 35 | public class CoordinateSwitch extends AbstractCoordinateOperation { 36 | 37 | /** 38 | * Switch the two first value of a coordinate. For instance longitude and 39 | * latitude in the case of geographic coordinates. 40 | */ 41 | public final static CoordinateSwitch SWITCH_LAT_LON = new CoordinateSwitch(0, 1); 42 | /** 43 | * Position of the ordinate to switch. 44 | */ 45 | int pos1, pos2; 46 | 47 | /** 48 | * Change ordinate at pos1 with ordinate at pos2. 49 | * 50 | * @param coord is an array containing one, two or three ordinates 51 | * @throws IllegalCoordinateException if coord is not 52 | * compatible with this CoordinateOperation. 53 | */ 54 | @Override 55 | public double[] transform(double[] coord) 56 | throws IllegalCoordinateException { 57 | if (coord.length < Math.min(pos1, pos2)) { 58 | throw new CoordinateDimensionException(coord, Math.max(pos1, pos2)); 59 | } 60 | double d1 = coord[pos1]; 61 | coord[pos1] = coord[pos2]; 62 | coord[pos2] = d1; 63 | return coord; 64 | } 65 | 66 | /** 67 | * Creates the inverse CoordinateOperation. 68 | */ 69 | @Override 70 | public CoordinateOperation inverse() { 71 | return this; 72 | } 73 | 74 | /** 75 | * Creates a new operation to switch coord pos1 and coord pos2. 76 | * 77 | * @param pos1 position of the ordinate to switch to pos2 78 | * @param pos2 position of the ordinate to switch to pos1 79 | */ 80 | public CoordinateSwitch(int pos1, int pos2) { 81 | super(new Identifier(CoordinateOperation.class, "Coordinates switch")); 82 | this.pos1 = pos1; 83 | this.pos2 = pos2; 84 | } 85 | 86 | /** 87 | * Returns true if o is equals to this operation. 88 | * 89 | * @param o The object to compare to 90 | */ 91 | @Override 92 | public boolean equals(Object o) { 93 | if (this == o) return true; 94 | return o instanceof CoordinateSwitch && 95 | pos1 == ((CoordinateSwitch) o).pos1 && 96 | pos2 == ((CoordinateSwitch) o).pos2; 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/op/Identity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.IllegalCoordinateException; 28 | import org.cts.op.transformation.GeocentricTransformation; 29 | import org.cts.op.transformation.ParamBasedTransformation; 30 | 31 | /** 32 | * The identity transformation.

This transformation doesn't do anything. 33 | * 34 | * @author Michaël Michaud 35 | */ 36 | public class Identity extends AbstractCoordinateOperation implements ParamBasedTransformation, GeocentricTransformation { 37 | 38 | /** 39 | * The identity transformation. When used to transform coordinates, it 40 | * returns the input coordinates. 41 | */ 42 | public static final Identity IDENTITY = new Identity(); 43 | 44 | /** 45 | * Identity is defined as a Singleton in order to avoid unuseful object 46 | * creation. 47 | */ 48 | private Identity() { 49 | super(new Identifier(CoordinateOperation.class, "Identity")); 50 | this.precision = 0.0; 51 | } 52 | 53 | /** 54 | * Apply the identity transformation to input coordinates. 55 | * 56 | * @param coord is an array containing one, two or three ordinates 57 | */ 58 | @Override 59 | public double[] transform(double[] coord) { 60 | return coord; 61 | } 62 | 63 | /** 64 | * Creates the inverse CoordinateOperation. 65 | */ 66 | @Override 67 | public GeocentricTransformation inverse() { 68 | return this; 69 | } 70 | 71 | /** 72 | * Returns true if o is also an Identity CoordinateOperation. 73 | * 74 | * @param o The object to compare this ProjectedCRS against 75 | */ 76 | @Override 77 | public boolean equals(Object o) { 78 | if (this == o) { 79 | return true; 80 | } 81 | if (o instanceof CoordinateOperation) { 82 | return ((CoordinateOperation) o).isIdentity(); 83 | } 84 | return false; 85 | } 86 | 87 | /** 88 | * Returns 0 for all identity operations. 89 | */ 90 | @Override 91 | public int hashCode() { 92 | return 0; 93 | } 94 | 95 | /** 96 | * @return true if this operation does not change coordinates. 97 | */ 98 | public boolean isIdentity() { 99 | return true; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/IterativeTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.IllegalCoordinateException; 28 | 29 | /** 30 | * The IterativeTransformation is used to repeat a 31 | * {@link org.cts.op.CoordinateOperation} until one or more coordinate(s) 32 | * converge to predifined values (saved in additional dimensions using 33 | * {@link org.cts.op.MemorizeCoordinate}). This transformation should be used 34 | * when an iterative process is recommended (for instance when using a grid 35 | * using longitude and latitude calculated by a first approximate 36 | * transformation. 37 | * 38 | * @author Jules Party 39 | */ 40 | public class IterativeTransformation extends AbstractCoordinateOperation implements CoordinateOperation { 41 | 42 | CoordinateOperation op; 43 | int[] realValueIndex; 44 | int[] calculatedValueIndex; 45 | double[] tolerance; 46 | int maxIterations = 12; 47 | 48 | /** 49 | * Build a new IterativeTransformation. 50 | * 51 | * @param op the transformation to iterate 52 | * @param realValueIndex a list of indexes referring to the reference values 53 | * the iteration should reach 54 | * @param calculatedValueIndex the list of indexes referring to the calculated 55 | * values that must reach the reference values defined above 56 | * @param tol the maximal difference accepted between the real value and the 57 | * target value 58 | * @throws Exception when the arrays in parameter does not have the same 59 | * length 60 | */ 61 | public IterativeTransformation(CoordinateOperation op, int[] realValueIndex, int[] calculatedValueIndex, 62 | double[] tol, int maxIterations) throws Exception { 63 | super(new Identifier(IterativeTransformation.class)); 64 | this.op = op; 65 | if (calculatedValueIndex.length != realValueIndex.length) { 66 | throw new Exception("The two arrays in argument must have the same length."); 67 | } 68 | this.calculatedValueIndex = calculatedValueIndex; 69 | this.realValueIndex = realValueIndex; 70 | this.tolerance = tol; 71 | this.maxIterations = maxIterations; 72 | } 73 | 74 | @Override 75 | public double[] transform(double[] coord) throws IllegalCoordinateException, CoordinateOperationException { 76 | boolean iter = false; 77 | int count = 0; 78 | for (int i = 0; i < realValueIndex.length; i++) { 79 | iter = iter || Math.abs(coord[realValueIndex[i]] - coord[calculatedValueIndex[i]]) > tolerance[i]; 80 | } 81 | while (iter) { 82 | coord = op.transform(coord); 83 | iter = false; 84 | for (int i = 0; i < realValueIndex.length; i++) { 85 | iter = iter || Math.abs(coord[realValueIndex[i]] - coord[calculatedValueIndex[i]]) > tolerance[i]; 86 | } 87 | if (++count > maxIterations) throw new TooManyIterationsException(this, count); 88 | } 89 | return coord; 90 | } 91 | 92 | @Override 93 | public double getPrecision() { 94 | // Precision of this iterative operation is difficult to guess 95 | // because we don't know it uses radians, degrees or meters 96 | // We just suppose it is less than the base transformation 97 | return op.getPrecision() / 2.0; 98 | } 99 | 100 | public String toString() { 101 | return "Iterative transformation based on [\n" + op.toString().replaceAll("\n", "\n\t") + "\n]"; 102 | } 103 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/op/LoadMemorizeCoordinate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.IllegalCoordinateException; 28 | 29 | /** 30 | * Add a fourth dimension to save one of the other coordinates. It is used in 31 | * CoumpoundCRS transformation to save the altitude value. 32 | * 33 | * @author Michaël Michaud 34 | */ 35 | public class LoadMemorizeCoordinate extends AbstractCoordinateOperation { 36 | 37 | private final int indexSaved; 38 | public static CoordinateOperation loadX = new LoadMemorizeCoordinate(0); 39 | public static CoordinateOperation loadY = new LoadMemorizeCoordinate(1); 40 | public static CoordinateOperation loadZ = new LoadMemorizeCoordinate(2); 41 | 42 | /** 43 | * Creates a new CoordinateOperation removing the last double value from 44 | * a coordinate array and loading it at the specified index in the array. 45 | * 46 | * @param index final dimension of the new coordinate 47 | */ 48 | public LoadMemorizeCoordinate(int index) { 49 | super(new Identifier(CoordinateOperation.class, "Load last saved coordinate in position " + index)); 50 | this.indexSaved = index; 51 | } 52 | 53 | public int getIndexSaved() { 54 | return indexSaved; 55 | } 56 | 57 | /** 58 | * Load the last memorized coordinates : remove the last ordinate 59 | * of the array, and load it at index indexSaved. 60 | * 61 | * @param coord is an array containing four ordinates or more 62 | * @return 63 | * @throws IllegalCoordinateException if coord is not 64 | * compatible with this CoordinateOperation. 65 | */ 66 | @Override 67 | public double[] transform(double[] coord) throws IllegalCoordinateException { 68 | if (coord.length < 4) { 69 | throw new IllegalCoordinateException("There is no saved value in these coordinates."); 70 | } 71 | double[] cc = new double[coord.length - 1]; 72 | System.arraycopy(coord, 0, cc, 0, coord.length - 1); 73 | cc[indexSaved] = coord[coord.length - 1]; 74 | return cc; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/MemorizeCoordinate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.IllegalCoordinateException; 28 | 29 | import java.util.Arrays; 30 | 31 | /** 32 | * Add a fourth dimension to save one of the other coordinates. It is used in 33 | * CoumpoundCRS transformation to save the altitude value. 34 | * 35 | * @author Michaël Michaud 36 | */ 37 | public class MemorizeCoordinate extends AbstractCoordinateOperation { 38 | 39 | private final int[] indexesSaved; 40 | public static CoordinateOperation memoX = new MemorizeCoordinate(0); 41 | public static CoordinateOperation memoY = new MemorizeCoordinate(1); 42 | public static CoordinateOperation memoZ = new MemorizeCoordinate(2); 43 | public static CoordinateOperation memoXY = new MemorizeCoordinate(0, 1); 44 | public static CoordinateOperation memoXYZ = new MemorizeCoordinate(0, 1, 2); 45 | 46 | /** 47 | * Creates a new CoordinateOperation increasing (resp decreasing) the coord 48 | * size by length. 49 | * 50 | * @param indexes indexes of ordinates to memorize 51 | */ 52 | public MemorizeCoordinate(int... indexes) { 53 | super(new Identifier(CoordinateOperation.class, "Save coordinates at indexes " + Arrays.toString(indexes))); 54 | this.indexesSaved = indexes; 55 | } 56 | 57 | /** 58 | * Add a fourth coordinate, to save a value. 59 | * 60 | * @param coord is an array containing one, two or three ordinates 61 | */ 62 | @Override 63 | public double[] transform(double[] coord) { 64 | double[] cc = new double[Math.max(coord.length + indexesSaved.length, 4)]; 65 | System.arraycopy(coord, 0, cc, 0, Math.min(coord.length, cc.length)); 66 | for (int i = 0; i < indexesSaved.length; i++) { 67 | cc[Math.max(coord.length + i, 3 + i)] = coord[indexesSaved[i]]; 68 | } 69 | return cc; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/NonInvertibleOperationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | /** 27 | *

Try to use an interpolation method which is not defined or not yet 28 | * implemented.

29 | * 30 | * @author Michaël Michaud 31 | */ 32 | public class NonInvertibleOperationException extends CoordinateOperationException { 33 | 34 | /** 35 | * Create a new NonInvertibleOperationException. 36 | * 37 | * @param exception description of this exception 38 | */ 39 | public NonInvertibleOperationException(String exception) { 40 | super(exception); 41 | } 42 | 43 | /** 44 | * Create a new InterpolationMethodException. 45 | * 46 | * @param op the interpolation method 47 | */ 48 | public NonInvertibleOperationException(CoordinateOperation op) { 49 | super("" + op.getName() + " is not invertible"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/OppositeCoordinate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | import org.cts.CoordinateDimensionException; 27 | import org.cts.Identifier; 28 | import org.cts.IllegalCoordinateException; 29 | 30 | /** 31 | * This transformation turn the choosing coordinate into its opposite. 32 | * 33 | * @author Jules Party 34 | */ 35 | public class OppositeCoordinate extends AbstractCoordinateOperation { 36 | 37 | /** 38 | * The index of the coordinate to transform. 39 | */ 40 | private int index; 41 | 42 | /** 43 | * Construct the transformation turning the value at the given index into 44 | * its opposite. 45 | * 46 | * @param index the index of the value to turn into its opposite 47 | */ 48 | public OppositeCoordinate(int index) { 49 | super(new Identifier(CoordinateOperation.class, "Transform the coordinate " + index + " into its opposite.")); 50 | this.index = index; 51 | this.precision = 0.0; 52 | } 53 | 54 | /** 55 | * Apply the OppositeCoordinate transformation to input coordinates. 56 | * 57 | * @param coord is an array containing one, two or three ordinates 58 | * @throws IllegalCoordinateException 59 | */ 60 | @Override 61 | public double[] transform(double[] coord) throws IllegalCoordinateException { 62 | if (index >= coord.length) { 63 | throw new CoordinateDimensionException(coord, index); 64 | } 65 | coord[index] = -coord[index]; 66 | return coord; 67 | } 68 | 69 | /** 70 | * Creates the inverse CoordinateOperation. 71 | */ 72 | @Override 73 | public CoordinateOperation inverse() { 74 | return this; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/TooManyIterationsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op; 25 | 26 | /** 27 | * Manage an exception when the number of iterations exceeded a max count. 28 | * 29 | * @author Michaël Michaud 30 | */ 31 | public class TooManyIterationsException extends CoordinateOperationException { 32 | 33 | /** 34 | * Create a new NonInvertibleOperationException. 35 | * 36 | * @param exception description of this exception 37 | */ 38 | public TooManyIterationsException(String exception) { 39 | super(exception); 40 | } 41 | 42 | /** 43 | * Create a new InterpolationMethodException. 44 | * 45 | * @param op the interpolation method 46 | * @param count max number of iterations 47 | */ 48 | public TooManyIterationsException(IterativeTransformation op, int count) { 49 | super("Iterative process " + op.getName() + " exceeded the maximum number of iterations (" + count + ")"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/GeoTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation; 25 | 26 | /** 27 | * A GeoTransformation is a coordinate operation that bind two Geocentric 28 | * Coordinate Reference System. There is several sorts of GeoTransformation such 29 | * as the GeocentricTranslation and the SevenParameterTransformation. 30 | * 31 | * @author Erwan Bocher 32 | */ 33 | public interface GeoTransformation { 34 | 35 | /** 36 | * Returns a WKT representation of the transformation. 37 | * 38 | * @return 39 | */ 40 | String toWKT(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/GeocentricTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation; 25 | 26 | import org.cts.op.CoordinateOperation; 27 | import org.cts.op.NonInvertibleOperationException; 28 | 29 | /** 30 | * An interface to mark Geocentric transformations. 31 | * For transformation from or to a {@link org.cts.crs.CompoundCRS}, 32 | * it is important to use a GeocentricTransformation 33 | * rather than a 2D transformation like NTv2GridShiftTransformation. 34 | * 35 | * @author Michaël Michaud 36 | */ 37 | public interface GeocentricTransformation extends CoordinateOperation { 38 | 39 | public GeocentricTransformation inverse() throws NonInvertibleOperationException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/GeocentricTransformationSequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.op.CoordinateOperation; 28 | import org.cts.op.CoordinateOperationSequence; 29 | import org.cts.op.NonInvertibleOperationException; 30 | 31 | import java.util.Arrays; 32 | import java.util.List; 33 | 34 | /** 35 | * A GeocentricTransformationSequence is a CoordinateOperationSequence which 36 | * result is a {@link GeocentricTransformation}. 37 | * 38 | * @author Michaël Michaud 39 | */ 40 | public class GeocentricTransformationSequence 41 | extends CoordinateOperationSequence 42 | implements GeocentricTransformation { 43 | 44 | /** 45 | * @param identifier * @see org.cts.op.CoordinateOperationSequence 46 | * @param sequence 47 | */ 48 | public GeocentricTransformationSequence(Identifier identifier, 49 | CoordinateOperation... sequence) { 50 | super(identifier, sequence); 51 | } 52 | 53 | /** 54 | * @param identifier * @see org.cts.op.CoordinateOperationSequence 55 | * @param sequence 56 | */ 57 | public GeocentricTransformationSequence(Identifier identifier, 58 | List sequence) { 59 | super(identifier, sequence); 60 | } 61 | 62 | /** 63 | * @param identifier * @see org.cts.op.CoordinateOperationSequence 64 | * @param sequence 65 | * @param precision 66 | */ 67 | public GeocentricTransformationSequence(Identifier identifier, 68 | CoordinateOperation[] sequence, double precision) { 69 | super(identifier, sequence, precision); 70 | } 71 | 72 | @Override 73 | public GeocentricTransformation inverse() throws NonInvertibleOperationException { 74 | CoordinateOperation[] inverse_sequence 75 | = new CoordinateOperation[sequence.length]; 76 | for (int i = 0; i < sequence.length; i++) { 77 | // If one of the CoordinateOperation is not invertible, it 78 | // will throw a NonInvertibleOperationException. 79 | inverse_sequence[sequence.length - i - 1] = sequence[i].inverse(); 80 | //if (inverse_sequence[sequence.length-i-1] == null) return null; 81 | } 82 | return new GeocentricTransformationSequence(getIdentifier(), 83 | inverse_sequence, precision); 84 | } 85 | 86 | /** 87 | * Returns true if o is equals to this. GeocentricTranslations 88 | * are equals if they both are identity, or if all their parameters are 89 | * equal. 90 | * 91 | * @param o The object to compare this ProjectedCRS against 92 | * @return 93 | */ 94 | @Override 95 | public boolean equals(Object o) { 96 | if (this == o) { 97 | return true; 98 | } 99 | if (o instanceof GeocentricTransformationSequence) { 100 | if (sequence.length == ((GeocentricTransformationSequence) o).sequence.length) { 101 | for (int i = 0; i < sequence.length; i++) { 102 | if (!sequence[i].equals(((GeocentricTransformationSequence) o).sequence[i])) { 103 | return false; 104 | } 105 | } 106 | } 107 | } 108 | return false; 109 | } 110 | 111 | /** 112 | * Returns the hash code for this GeocentricTranslation. 113 | * 114 | * @return 115 | */ 116 | @Override 117 | public int hashCode() { 118 | if (isIdentity()) { 119 | return 0; 120 | } 121 | int hash = 5; 122 | hash = 19 * hash + Arrays.deepHashCode(this.sequence); 123 | return hash; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/GridBasedTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation; 25 | 26 | /** 27 | * Marker for transformation based on grids like NTv2 or 28 | * vertical transformations 29 | * 30 | * @author Michaël Michaud 31 | */ 32 | public interface GridBasedTransformation { 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/ParamBasedTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation; 25 | 26 | /** 27 | * Marker for transformations including 7 parameters transformation (Bursa-Wolf), 28 | * Translation and Identity. 29 | * 30 | * @author Michaël Michaud 31 | */ 32 | public interface ParamBasedTransformation extends GeocentricTransformation { 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/grid/Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation.grid; 25 | 26 | public class Util { 27 | 28 | public static int getIntLE(byte[] b, int i) { 29 | return b[(i++)] & 0xFF | b[(i++)] << 8 & 0xFF00 | b[(i++)] << 16 & 0xFF0000 | b[i] << 24; 30 | } 31 | 32 | public static int getIntBE(byte[] b, int i) { 33 | return b[(i++)] << 24 | b[(i++)] << 16 & 0xFF0000 | b[(i++)] << 8 & 0xFF00 | b[i] & 0xFF; 34 | } 35 | 36 | public static int getInt(byte[] b, boolean bigEndian) { 37 | if (bigEndian) { 38 | return getIntBE(b, 0); 39 | } 40 | return getIntLE(b, 0); 41 | } 42 | 43 | public static float getFloat(byte[] b, boolean bigEndian) { 44 | int i; 45 | if (bigEndian) { 46 | i = getIntBE(b, 0); 47 | } else { 48 | i = getIntLE(b, 0); 49 | } 50 | return Float.intBitsToFloat(i); 51 | } 52 | 53 | public static double getDouble(byte[] b, boolean bigEndian) { 54 | int i; 55 | int j; 56 | if (bigEndian) { 57 | i = getIntBE(b, 0); 58 | j = getIntBE(b, 4); 59 | } else { 60 | i = getIntLE(b, 4); 61 | j = getIntLE(b, 0); 62 | } 63 | long l = ((long) i) << 32 | j & 0xFFFFFFFF; 64 | 65 | return Double.longBitsToDouble(l); 66 | } 67 | 68 | public static boolean isNioAvailable() { 69 | boolean nioAvailable = false; 70 | try { 71 | Class.forName("java.nio.channels.FileChannel"); 72 | nioAvailable = true; 73 | } catch (ClassNotFoundException cnfe) { 74 | } 75 | return nioAvailable; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/grids/Grid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation.grids; 25 | 26 | import org.cts.cs.OutOfExtentException; 27 | 28 | /** 29 | * A grid is a data structure containing numeric data organized in rows and 30 | * columns. Cell 0,0 represents a real location x0, y0, and every cell has a 31 | * width (dx) and a height (dy) so that a cell at row i and column j represents 32 | * a location of coordinates 33 | *
    34 | *
  • x = j*dx+x0
  • 35 | *
  • y = i*dy+y0
  • 36 | *
37 | * The main grid parameters are : 38 | *
    39 | *
  • The number of columns (c) and rows (r) (with a total number of values in 40 | * the grid equals to c * r)
  • 41 | *
  • x0, y0, the real coordinates of the grid cell at column 0, row 0
  • 42 | *
  • gridWidth and gridHeight, which represent the real grid width and the 43 | * real grid height
  • 44 | *
45 | * Other derivative parameters are 46 | *
    47 | *
  • dx = gridWidth/(column number -1)
  • 48 | *
  • dx = gridHeight/(row number -1)
  • 49 | *
50 | * For interpolation methods, see 51 | * 52 | * What's the point? Interpolation and extrapolation with a regular grid DEM 53 | * 54 | * 55 | * @author Michaël Michaud 56 | */ 57 | public interface Grid { 58 | 59 | public enum InterpolationMethod { 60 | 61 | NEAREST, BILINEAR, BICUBIC 62 | } 63 | 64 | /** 65 | * Nearest interpolation method. 66 | */ 67 | public int NEAREST = 1; 68 | /** 69 | * Bilinear interpolation method. 70 | */ 71 | public int BILINEAR = 2; 72 | /** 73 | * Bicubic interpolation method. 74 | */ 75 | public int BICUBIC = 3; 76 | 77 | /** 78 | * Get the number of columns of this grid. 79 | * 80 | * @return 81 | */ 82 | public int getColumnNumber(); 83 | 84 | /** 85 | * Get the number of rows of this grid. 86 | * 87 | * @return 88 | */ 89 | public int getRowNumber(); 90 | 91 | /** 92 | * Get the real world abscisse (x) of the first column. 93 | * 94 | * @return 95 | */ 96 | public double getX0(); 97 | 98 | /** 99 | * Get the real world ordinate (y) of the first row. 100 | * 101 | * @return 102 | */ 103 | public double getY0(); 104 | 105 | /** 106 | * Get the first ordinate of the last grid column. 107 | */ 108 | public double getXL(); 109 | 110 | /** 111 | * Get the second ordinate of the last grid row. 112 | */ 113 | public double getYL(); 114 | 115 | /** 116 | * Real world interval between two consecutive columns. The method returns a 117 | * negative value if x values decreases when column indices increases. 118 | * 119 | * @return 120 | */ 121 | public double getDX(); 122 | 123 | /** 124 | * Real world interval between two consecutive row. The method returns a 125 | * negative value if y values decreases when column indices increases. 126 | * 127 | * @return 128 | */ 129 | public double getDY(); 130 | 131 | /** 132 | * Get the value corrsponding to the x,y position. WARNING : x, y represent 133 | * the real world coordinates and not the matrix coordinate. 134 | * 135 | * @param x 136 | * @param y 137 | * @param method 138 | * @return 139 | * @throws org.cts.cs.OutOfExtentException 140 | * @throws org.cts.op.transformation.grids.InterpolationMethodException 141 | */ 142 | public double[] getValue(double x, double y, InterpolationMethod method) 143 | throws OutOfExtentException, InterpolationMethodException; 144 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/grids/GridUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation.grids; 25 | 26 | import java.io.*; 27 | import java.net.MalformedURLException; 28 | import java.net.URL; 29 | 30 | /** 31 | * A utility class to manage grids 32 | * 33 | * @author Erwan Bocher 34 | */ 35 | public class GridUtils { 36 | 37 | static String URL_PATH = "https://github.com/orbisgis/cts/raw/master/grids/"; 38 | 39 | /** 40 | * Find the grid used by the transformation 41 | *

42 | * If the grid is not packaged into the resources folder then we look into a 43 | * ./cts folder. 44 | * If the grid does not exist in this folder, we try to download it from 45 | * the CTS repository. 46 | * 47 | * @param nameGrid name of the grid with its extension 48 | * @return 49 | * @throws FileNotFoundException 50 | * @throws IOException 51 | */ 52 | public static File findGrid(String nameGrid) throws FileNotFoundException, IOException { 53 | //If the grid doesn't exist in resources folder then 54 | //We look into a .cts folder 55 | String ctsFolderPath = new File(System.getProperty("user.home")).getAbsolutePath() + File.separator + ".cts"; 56 | File ctsFileFolder = new File(ctsFolderPath); 57 | File gridFile = new File(ctsFolderPath + File.separator + nameGrid); 58 | if (ctsFileFolder.exists()) { 59 | if (gridFile.exists()) { 60 | return gridFile; 61 | } else if (ctsFileFolder.canWrite()) { 62 | //Try to download the grid on the CTS repository 63 | downloadFile(gridFile, new URL(URL_PATH + nameGrid)); 64 | return gridFile; 65 | } else { 66 | throw new IOException("Cannot download the grid : " + nameGrid + " into .cts folder"); 67 | } 68 | } else { 69 | boolean ctsDir = ctsFileFolder.mkdir(); 70 | if (ctsDir && ctsFileFolder.canWrite()) { 71 | //Try to download the grid on the CTS repository 72 | downloadFile(gridFile, new URL(URL_PATH + nameGrid)); 73 | return gridFile; 74 | } else { 75 | throw new IOException("Unable to create the .cts folder"); 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * Download a file from an URL to a specified target 82 | * 83 | * @param outputFile 84 | * @param urlGrid 85 | * @throws MalformedURLException 86 | * @throws IOException 87 | */ 88 | public static void downloadFile(final File outputFile, final URL urlGrid) 89 | throws MalformedURLException, IOException { 90 | BufferedInputStream in = null; 91 | FileOutputStream fout = null; 92 | try { 93 | in = new BufferedInputStream(urlGrid.openStream()); 94 | fout = new FileOutputStream(outputFile); 95 | 96 | final byte data[] = new byte[1024]; 97 | int count; 98 | while ((count = in.read(data, 0, 1024)) != -1) { 99 | fout.write(data, 0, count); 100 | } 101 | } finally { 102 | try { 103 | if (in != null) { 104 | in.close(); 105 | } 106 | } catch (IOException ie) { 107 | //Do nothing 108 | } 109 | try { 110 | if (fout != null) { 111 | fout.close(); 112 | } 113 | } catch (IOException ie) { 114 | //Do nothing 115 | } 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/cts/op/transformation/grids/InterpolationMethodException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.transformation.grids; 25 | 26 | /** 27 | *

Try to use an interpolation method which is not defined or not yet 28 | * implemented.

29 | * 30 | * @author Michaël Michaud 31 | */ 32 | public class InterpolationMethodException extends Exception { 33 | 34 | /** 35 | * Create a new InterpolationMethodException. 36 | * 37 | * @param exception description of this exception 38 | */ 39 | public InterpolationMethodException(String exception) { 40 | super(exception); 41 | } 42 | 43 | /** 44 | * Create a new InterpolationMethodException. 45 | * 46 | * @param method the interpolation method 47 | */ 48 | public InterpolationMethodException(Grid.InterpolationMethod method) { 49 | super("" + method + " is not a valid interpolation method"); 50 | } 51 | 52 | /** 53 | * Create a new InterpolationMethodException. 54 | * 55 | * @param method the interpolation method 56 | * @param gridClass the class trying to use the interpolation method 57 | */ 58 | public InterpolationMethodException(Grid.InterpolationMethod method, Class gridClass) { 59 | super("" + method + " is not a valid interpolation method for " + gridClass.getName()); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/AbstractPrjElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | import java.util.Collections; 27 | import java.util.List; 28 | 29 | /** 30 | * @author Antoine Gourlay, Erwan Bocher 31 | */ 32 | public abstract class AbstractPrjElement implements PrjElement { 33 | 34 | /** 35 | * The list of the children of this PrjElement. 36 | */ 37 | private List children; 38 | 39 | /** 40 | * Create a PrjElement that uses the list of PrjElement in parameter as 41 | * children. 42 | * 43 | * @param children the children of the PrjElement to create 44 | */ 45 | AbstractPrjElement(List children) { 46 | this.children = children; 47 | } 48 | 49 | /** 50 | * Create a PrjElement without children. 51 | */ 52 | AbstractPrjElement() { 53 | this(Collections.EMPTY_LIST); 54 | } 55 | 56 | @Override 57 | public List getChildren() { 58 | return children; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * @author Antoine Gourlay, Erwan Bocher 30 | */ 31 | public interface PrjElement { 32 | 33 | /** 34 | * Return the list of the children of this PrjElement. 35 | * 36 | * @return 37 | */ 38 | List getChildren(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjKeyParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | /** 27 | * List all parameters used to define a PRJ file 28 | * 29 | * @author Erwan Bocher, Jules Party 30 | */ 31 | public class PrjKeyParameters { 32 | 33 | public static final String GEOGCS = "geogcs"; 34 | public static final String GEOCCS = "geoccs"; 35 | public static final String UNIT = "unit"; 36 | public static final String VERTUNIT = "vertunit"; 37 | public static final String PROJECTION = "projection"; 38 | public static final String PARAMETER = "parameter"; 39 | public static final String AUTHORITY = "authority"; 40 | public static final String PROJCS = "projcs"; 41 | public static final String PRIMEM = "primem"; 42 | public static final String SPHEROID = "spheroid"; 43 | public static final String AXIS = "axis"; 44 | public static final String COMPDCS = "compd_cs"; 45 | public static final String VERTCS = "vert_cs"; 46 | //Internal key parameters used by the parser 47 | public static final String VERTUNITVAL = "vertunitval"; 48 | public static final String GEOGUNITREFNAME = "geogunitrefname"; 49 | public static final String GEOGUNIT = "geogunit"; 50 | public static final String GEOGUNITVAL = "geogunitval"; 51 | public static final String NAME = "name"; 52 | public static final String REFNAME = "refname"; 53 | public static final String GEOGREFNAME = "geogrefname"; 54 | public static final String PROJREFNAME = "projrefname"; 55 | public static final String VERTREFNAME = "vertrefname"; 56 | public static final String SPHEROIDREFNAME = "spheroidrefname"; 57 | public static final String DATUMREFNAME = "datumrefname"; 58 | public static final String VERTDATUM = "vert_datum"; 59 | public static final String VERTDATUMREFNAME = "vertdatumrefname"; 60 | public static final String VERTDATUMTYPE = "vertdatumtype"; 61 | public static final String PRIMEMREFNAME = "primemrefname"; 62 | public static final String UNITREFNAME = "unitrefname"; 63 | public static final String VERTUNITREFNAME = "vertunitrefname"; 64 | public static final String AXIS1 = "axis1"; 65 | public static final String AXIS1TYPE = "axis1type"; 66 | public static final String AXIS2 = "axis2"; 67 | public static final String AXIS2TYPE = "axis2type"; 68 | public static final String AXIS3 = "axis3"; 69 | public static final String AXIS3TYPE = "axis3type"; 70 | public static final String VERTAXIS = "vertaxis"; 71 | public static final String VERTAXISTYPE = "vertaxistype"; 72 | public static final String PMVALUE = "pmvalue"; 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjNodeElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * @author Antoine Gourlay 30 | */ 31 | public class PrjNodeElement extends AbstractPrjElement { 32 | 33 | /** 34 | * The name of this node. 35 | */ 36 | private String name; 37 | 38 | /** 39 | * Creates a node from its name and the list of its children. 40 | * 41 | * @param name the name of the node 42 | * @param children the list of the children elements of the node 43 | */ 44 | PrjNodeElement(String name, List children) { 45 | super(children); 46 | this.name = name; 47 | } 48 | 49 | /** 50 | * Return the name of this node. 51 | */ 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | /** 57 | * Return a String representation of the PrjNodeElement. 58 | */ 59 | @Override 60 | public String toString() { 61 | return "PrjNodeElement[" + name + ", ...]"; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjNodeMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * @author Antoine Gourlay 30 | */ 31 | public interface PrjNodeMatcher { 32 | 33 | /** 34 | * Return the name of the node match by this PrjNodeMatcher. 35 | */ 36 | String getName(); 37 | 38 | /** 39 | * Match the node in parameter. 40 | * 41 | * @param list the node to match with this PrjNodeMatcher 42 | */ 43 | void run(List list); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjNumberElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | /** 27 | * @author Antoine Gourlay 28 | */ 29 | public class PrjNumberElement extends AbstractPrjElement { 30 | 31 | /** 32 | * The value of the PrjNumberElement. 33 | */ 34 | private double value; 35 | 36 | /** 37 | * Create a new PrjNumberElement. 38 | * 39 | * @param value the value of the new element 40 | */ 41 | PrjNumberElement(double value) { 42 | this.value = value; 43 | } 44 | 45 | /** 46 | * Return the value of the element. 47 | */ 48 | public double getValue() { 49 | return value; 50 | } 51 | 52 | /** 53 | * Return a String representation of the PrjStringElement. 54 | */ 55 | @Override 56 | public String toString() { 57 | return "PrjNumberElement[" + value + "]"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjParserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | /** 27 | * Return an exception when the prj cannot be parsed. 28 | * 29 | * @author Antoine Gourlay 30 | */ 31 | public class PrjParserException extends RuntimeException { 32 | 33 | /** 34 | * Build a PrjParserException from a cause. 35 | * 36 | * @param cause the cause of the error 37 | */ 38 | public PrjParserException(Throwable cause) { 39 | super(cause); 40 | } 41 | 42 | /** 43 | * Build a PrjParserException from a message and a cause. 44 | * 45 | * @param message the message to throw 46 | * @param cause the cause of the error 47 | */ 48 | public PrjParserException(String message, Throwable cause) { 49 | super(message, cause); 50 | } 51 | 52 | /** 53 | * Build a PrjParserException from a message. 54 | * 55 | * @param message the message to throw 56 | */ 57 | public PrjParserException(String message) { 58 | super(message); 59 | } 60 | 61 | /** 62 | * Build a new PrjParserException. 63 | */ 64 | public PrjParserException() { 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/prj/PrjStringElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.prj; 25 | 26 | /** 27 | * @author Antoine Gourlay 28 | */ 29 | public class PrjStringElement extends AbstractPrjElement { 30 | 31 | /** 32 | * The value of the PrjStringElement. 33 | */ 34 | private String value; 35 | 36 | /** 37 | * Create a new PrjStringElement. 38 | * 39 | * @param value the value of the new element 40 | */ 41 | PrjStringElement(String value) { 42 | super(); 43 | this.value = value; 44 | 45 | } 46 | 47 | /** 48 | * Return the value of the PrjStringElement. 49 | */ 50 | public String getValue() { 51 | return value; 52 | } 53 | 54 | /** 55 | * Return a String representation of the PrjStringElement. 56 | */ 57 | @Override 58 | public String toString() { 59 | return "PrjStringElement[" + value + "]"; 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/proj/ParameterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.proj; 25 | 26 | /** 27 | * @author Erwan Bocher 28 | */ 29 | public class ParameterException extends RuntimeException { 30 | 31 | /** 32 | * Build a new ParameterException from a message. 33 | * 34 | * @param message the message to throw 35 | */ 36 | public ParameterException(String message) { 37 | super(message); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/proj/ProjValueParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.proj; 25 | 26 | /** 27 | * @author Erwan Bocher 28 | */ 29 | public class ProjValueParameters { 30 | 31 | //+proj value parameters 32 | public static String LONGLAT = "longlat"; 33 | public static String GEOCENT = "geocent"; 34 | public static String TMERC = "tmerc"; 35 | public static String MILL = "mill"; 36 | public static String STERE = "stere"; 37 | public static String STEREA = "sterea"; 38 | public static String LCC = "lcc"; 39 | public static String GSTMERC = "gstmerc"; 40 | public static String LAEA = "laea"; 41 | public static String EQC = "eqc"; 42 | public static String KROVAK = "krovak"; 43 | public static String CEA = "cea"; 44 | public static String CASS = "cass"; 45 | public static String AEA = "aea"; 46 | public static String SOMERC = "somerc"; 47 | public static String OMERC = "omerc"; 48 | public static String POLY = "poly"; 49 | public static String MERC = "merc"; 50 | public static String NZMG = "nzmg"; 51 | public static String UTM = "utm"; 52 | public static String LEAC = "leac"; 53 | //Unit values 54 | public static String M = "m"; 55 | public static String RAD = "rad"; 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/cts/parser/proj4/Proj4Parser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.proj4; 25 | 26 | import org.cts.parser.proj.ProjKeyParameters; 27 | 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | import java.util.regex.Pattern; 31 | 32 | /** 33 | * A simple Proj4 parser to return a list of parameters used to build a 34 | * CoordinateSystem 35 | * 36 | * @author Erwan Bocher, CNRS 37 | */ 38 | public class Proj4Parser { 39 | 40 | /** 41 | * The regex that must be used to parse. 42 | */ 43 | static final Pattern regex = Pattern.compile("[ ]\\+|\\s<>"); 44 | 45 | public static Map readParameters(String projText) { 46 | if (projText == null || projText.isEmpty()) { 47 | throw new IllegalArgumentException("Please set a correct proj4 representation"); 48 | } 49 | Map params = new HashMap(); 50 | 51 | String[] tokens = regex.split(projText); 52 | 53 | if (tokens[0].startsWith("+proj")) { 54 | for (String token : tokens) { 55 | String[] keyValue = token.split("="); 56 | if (keyValue.length == 2) { 57 | String key = formatKey(keyValue[0]); 58 | ProjKeyParameters.checkUnsupported(key); 59 | params.put(key, keyValue[1]); 60 | } else { 61 | String key = formatKey(token); 62 | ProjKeyParameters.checkUnsupported(key); 63 | params.put(key, null); 64 | } 65 | } 66 | return params; 67 | } else { 68 | throw new IllegalArgumentException("The proj4 representation must startwith +proj"); 69 | } 70 | } 71 | 72 | /** 73 | * Remove + char if exists 74 | * 75 | * @param key 76 | */ 77 | private static String formatKey(String key) { 78 | String formatKey = key; 79 | if (key.startsWith("+")) { 80 | formatKey = key.substring(1); 81 | } 82 | return formatKey; 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/AbstractProjRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | 27 | import org.cts.CRSHelper; 28 | import org.cts.Identifier; 29 | import org.cts.crs.CRSException; 30 | import org.cts.crs.CoordinateReferenceSystem; 31 | import org.cts.parser.proj.ProjKeyParameters; 32 | import org.cts.parser.proj.ProjParser; 33 | 34 | import java.util.Map; 35 | 36 | /** 37 | * @author Erwan Bocher 38 | */ 39 | public abstract class AbstractProjRegistry implements Registry { 40 | 41 | /** 42 | * The parser associated to the PROJ registry. 43 | */ 44 | protected final ProjParser projParser; 45 | 46 | @Override 47 | public CoordinateReferenceSystem getCoordinateReferenceSystem(Identifier identifier) throws RegistryException, CRSException { 48 | Map params = getParameters(identifier.getAuthorityKey()); 49 | if (!identifier.getAuthorityName().equalsIgnoreCase(getRegistryName())) { 50 | throw new RegistryException("CRS code '" + identifier.getCode() + 51 | "' does not match this registry name : " + getRegistryName()); 52 | } 53 | if (params == null) { 54 | throw new CRSException("Registry '" + getRegistryName() + "' contains no parameter for " + identifier); 55 | } 56 | // try to set a name from params to the identifier if identifier name is empty 57 | if (identifier.getName() == null || identifier.getName().isEmpty()) { 58 | String title = params.get(ProjKeyParameters.title); 59 | if (title != null && !title.isEmpty()) { 60 | identifier = new Identifier(identifier.getAuthorityName(), identifier.getAuthorityKey(), title); 61 | } 62 | } 63 | return CRSHelper.createCoordinateReferenceSystem(identifier, params); 64 | } 65 | 66 | /** 67 | * Return all parameters need to build a CoordinateReferenceSystem. 68 | * 69 | * @param code 70 | * @return 71 | * @throws RegistryException 72 | */ 73 | abstract public Map getParameters(String code) throws RegistryException; 74 | 75 | /** 76 | * Create a new AbstractProjRegistry. 77 | */ 78 | public AbstractProjRegistry() { 79 | projParser = new ProjParser(this); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/EPSGRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * This class parses the epsg file available in the resources package. 33 | * For a given code, it returns a map of parameters required by 34 | * {@link org.cts.CRSHelper} to build a {@link org.cts.crs.CoordinateReferenceSystem}. 35 | * 36 | * @author Erwan Bocher 37 | */ 38 | public class EPSGRegistry extends AbstractProjRegistry implements Registry { 39 | 40 | /** 41 | * The regex that must be used to parse EPSG registry. 42 | */ 43 | static final Pattern EPSG_REGEX = Pattern.compile("\\s+|<>"); 44 | 45 | @Override 46 | public String getRegistryName() { 47 | return "epsg"; 48 | } 49 | 50 | @Override 51 | public Map getParameters(String code) throws RegistryException { 52 | try { 53 | return projParser.readParameters(code, EPSG_REGEX); 54 | } catch (IOException ex) { 55 | throw new RegistryException("Cannot load the EPSG registry", ex); 56 | } 57 | } 58 | 59 | @Override 60 | public Set getSupportedCodes() throws RegistryException { 61 | try { 62 | return projParser.getSupportedCodes(EPSG_REGEX); 63 | } catch (IOException ex) { 64 | throw new RegistryException("Cannot load the EPSG registry", ex); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/ESRIRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * This class parses the esri file available in the resources package. 33 | * For a given code, it returns a map of parameters required by 34 | * {@link org.cts.CRSHelper} to build a {@link org.cts.crs.CoordinateReferenceSystem}. 35 | * 36 | * @author Erwan Bocher 37 | */ 38 | public class ESRIRegistry extends AbstractProjRegistry implements Registry { 39 | 40 | /** 41 | * The regex that must be used to parse ESRI registry. 42 | */ 43 | static final Pattern ESRI_REGEX = Pattern.compile("\\s+|no_defs <>"); 44 | 45 | @Override 46 | public String getRegistryName() { 47 | return "esri"; 48 | } 49 | 50 | @Override 51 | public Map getParameters(String code) throws RegistryException { 52 | try { 53 | return projParser.readParameters(code, ESRI_REGEX); 54 | } catch (IOException ex) { 55 | throw new RegistryException("Cannot load the ESRI registry", ex); 56 | } 57 | } 58 | 59 | @Override 60 | public Set getSupportedCodes() throws RegistryException { 61 | try { 62 | return projParser.getSupportedCodes(ESRI_REGEX); 63 | } catch (IOException ex) { 64 | throw new RegistryException("Cannot load the ESRI registry", ex); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/IGNFRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * This class parses the ignf file available in the resources package. 33 | * For a given code, it returns a map of parameters required by 34 | * {@link org.cts.CRSHelper} to build a {@link org.cts.crs.CoordinateReferenceSystem}. 35 | * 36 | * @author Erwan Bocher 37 | */ 38 | public class IGNFRegistry extends AbstractProjRegistry { 39 | 40 | /** 41 | * The regex that must be used to parse IGNF registry. 42 | */ 43 | static final Pattern IGNF_REGEX = Pattern.compile("[ ]\\+|\\s<>"); 44 | 45 | @Override 46 | public String getRegistryName() { 47 | return "ignf"; 48 | } 49 | 50 | @Override 51 | public Map getParameters(String code) throws RegistryException { 52 | try { 53 | return projParser.readParameters(code, IGNF_REGEX); 54 | } catch (IOException ex) { 55 | throw new RegistryException("Cannot load the IGNF registry", ex); 56 | } 57 | } 58 | 59 | @Override 60 | public Set getSupportedCodes() throws RegistryException { 61 | try { 62 | return projParser.getSupportedCodes(IGNF_REGEX); 63 | } catch (IOException ex) { 64 | throw new RegistryException("Cannot load the IGNF registry", ex); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/Nad27Registry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * This class parses the nad27 file available in the resources package. 33 | * For a given code, it returns a map of parameters required by 34 | * {@link org.cts.CRSHelper} to build a {@link org.cts.crs.CoordinateReferenceSystem}. 35 | * 36 | * @author Erwan Bocher 37 | */ 38 | public class Nad27Registry extends AbstractProjRegistry { 39 | 40 | /** 41 | * The regex that must be used to parse NAD27 registry. 42 | */ 43 | static final Pattern NAD27_REGEX = Pattern.compile("\\s+"); 44 | 45 | @Override 46 | public String getRegistryName() { 47 | return "nad27"; 48 | } 49 | 50 | @Override 51 | public Map getParameters(String code) throws RegistryException { 52 | try { 53 | return projParser.readParameters(code, NAD27_REGEX); 54 | } catch (IOException ex) { 55 | throw new RegistryException("Cannot load the NAD27 registry", ex); 56 | } 57 | } 58 | 59 | @Override 60 | public Set getSupportedCodes() throws RegistryException { 61 | try { 62 | return projParser.getSupportedCodes(NAD27_REGEX); 63 | } catch (IOException ex) { 64 | throw new RegistryException("Cannot load the NAD27 registry", ex); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/Nad83Registry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * This class parses the nad83 file available in the resources package. 33 | * For a given code, it returns a map of parameters required by 34 | * {@link org.cts.CRSHelper} to build a {@link org.cts.crs.CoordinateReferenceSystem}. 35 | * 36 | * @author Erwan Bocher 37 | */ 38 | public class Nad83Registry extends AbstractProjRegistry { 39 | 40 | /** 41 | * The regex that must be used to parse NAD83 registry. 42 | */ 43 | static final Pattern NAD83_REGEX = Pattern.compile("\\s+"); 44 | 45 | @Override 46 | public String getRegistryName() { 47 | return "nad83"; 48 | } 49 | 50 | @Override 51 | public Map getParameters(String code) throws RegistryException { 52 | try { 53 | return projParser.readParameters(code, NAD83_REGEX); 54 | } catch (IOException ex) { 55 | throw new RegistryException("Cannot load the NAD83 registry", ex); 56 | } 57 | } 58 | 59 | @Override 60 | public Set getSupportedCodes() throws RegistryException { 61 | try { 62 | return projParser.getSupportedCodes(NAD83_REGEX); 63 | } catch (IOException ex) { 64 | throw new RegistryException("Cannot load the NAD83 registry", ex); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/Registry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import org.cts.Identifier; 27 | import org.cts.crs.CRSException; 28 | import org.cts.crs.CoordinateReferenceSystem; 29 | 30 | import java.util.Set; 31 | 32 | /** 33 | * @author Erwan Bocher 34 | */ 35 | public interface Registry { 36 | 37 | /** 38 | * Return the name of the registry. 39 | * 40 | * @return 41 | */ 42 | public String getRegistryName(); 43 | 44 | /** 45 | * Return all parameters need to build a CoordinateReferenceSystem. 46 | * 47 | * @param identifier 48 | * @return 49 | * @throws RegistryException 50 | * @throws org.cts.crs.CRSException 51 | */ 52 | //public Map getParameters(String code) throws RegistryException; 53 | public CoordinateReferenceSystem getCoordinateReferenceSystem(Identifier identifier) throws RegistryException, CRSException; 54 | 55 | /** 56 | * Return all supported codes for this registry. 57 | * 58 | * @return 59 | * @throws RegistryException 60 | */ 61 | public Set getSupportedCodes() throws RegistryException; 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/RegistryException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | /** 27 | * A class to return an exception when a registry fail 28 | * 29 | * @author ebocher 30 | */ 31 | public class RegistryException extends Exception { 32 | 33 | /** 34 | * Build a new RegistryException from a message. 35 | * 36 | * @param message the message to throw 37 | */ 38 | public RegistryException(String message) { 39 | super(message); 40 | } 41 | 42 | /** 43 | * Build a new RegistryException from a message and an exception. 44 | * 45 | * @param message the message to throw 46 | * @param ex 47 | */ 48 | public RegistryException(String message, Exception ex) { 49 | super(message, ex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/RegistryManagerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | /** 27 | * @author Erwan Bocher 28 | */ 29 | public interface RegistryManagerListener { 30 | 31 | /** 32 | * Called when a registry is registered in the {@link RegistryManager} 33 | * 34 | * @param registryName 35 | */ 36 | void registryAdded(String registryName); 37 | 38 | /** 39 | * Called when a registry is removed from the {@link RegistryManager} 40 | * 41 | * @param registryName 42 | */ 43 | void registryRemoved(String registryName); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/cts/registry/WorldRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.registry; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * This class parses the world file available in the resources package. 33 | * For a given code, it returns a map of parameters required by 34 | * {@link org.cts.CRSHelper} to build a {@link org.cts.crs.CoordinateReferenceSystem}. 35 | * 36 | * @author Jules Party 37 | */ 38 | public class WorldRegistry extends AbstractProjRegistry { 39 | 40 | /** 41 | * The regex used to parse world registry. 42 | */ 43 | static final Pattern WORLD_REGEX = Pattern.compile("\\s+"); 44 | 45 | @Override 46 | public String getRegistryName() { 47 | return "world"; 48 | } 49 | 50 | @Override 51 | public Map getParameters(String code) throws RegistryException { 52 | try { 53 | return projParser.readParameters(code, WORLD_REGEX); 54 | } catch (IOException ex) { 55 | throw new RegistryException("Cannot load the world registry", ex); 56 | } 57 | } 58 | 59 | @Override 60 | public Set getSupportedCodes() throws RegistryException { 61 | try { 62 | return projParser.getSupportedCodes(WORLD_REGEX); 63 | } catch (IOException ex) { 64 | throw new RegistryException("Cannot load the world registry", ex); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/org/cts/units/Quantity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.units; 25 | 26 | /** 27 | * According to wikipedia, quantity is a kind of property which exists as 28 | * magnitude or multitude. Mass, time, distance, heat, and angular separation 29 | * are among the familiar examples of quantitative properties. This interface 30 | * has no particular method, and let programmers free to implement Quantities as 31 | * they want. A internal Factory class has been added to help creating 32 | * Quantities from a simple String. To use it, just write : 33 | *
Quantity SPEED = Quantity.Factory.create("Speed");
Otherwise, you 34 | * can create your own implementation of Quantity : 35 | *
36 |  * public class Speed implements Quantity {
37 |  *     // your implementation
38 |  * }
39 |  * 
Note that two quantities are considered as comparable if their 40 | * toString method return equalsIgnoreCase values. 41 | *

42 | * For a complete package about units, quantities and measurements, see JSR-275. 43 | * 44 | * @author Michaël Michaud 45 | */ 46 | public interface Quantity { 47 | 48 | public Quantity LENGTH = Factory.create("Length"); 49 | public Quantity ANGLE = Factory.create("Angle"); 50 | public Quantity NODIM = Factory.create("Dimensionless"); 51 | public Quantity TIME = Factory.create("Time"); 52 | 53 | /** 54 | * A factory to easily create 55 | * Quantities from simple Strings. 56 | */ 57 | public class Factory { 58 | 59 | /** 60 | * Creates a new Quantity from a String. 61 | * 62 | * @param name the name of the Quantity to be created 63 | * @return a new Quantity object 64 | */ 65 | public static Quantity create(final String name) { 66 | return new Quantity() { 67 | @Override 68 | public String toString() { 69 | return name; 70 | } 71 | 72 | @Override 73 | public boolean equals(Object o) { 74 | if (!(o instanceof Quantity)) { 75 | return false; 76 | } 77 | return toString().equalsIgnoreCase(o.toString()); 78 | } 79 | 80 | @Override 81 | public int hashCode() { 82 | return 5; 83 | } 84 | }; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/resources/org/cts/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, stdout 3 | 4 | # Direct log messages to stdout 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.Target=System.out 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 9 | 10 | -------------------------------------------------------------------------------- /src/test/java/org/cts/CRSHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | 25 | package org.cts; 26 | 27 | import org.cts.crs.CoordinateReferenceSystem; 28 | import org.cts.datum.Ellipsoid; 29 | import org.cts.datum.GeodeticDatum; 30 | import org.cts.op.CoordinateOperation; 31 | import org.cts.op.CoordinateOperationFactory; 32 | import org.cts.op.projection.Projection; 33 | import org.cts.op.projection.TransverseMercator; 34 | import org.cts.op.transformation.GeocentricTransformation; 35 | import org.cts.op.transformation.GeocentricTranslation; 36 | import org.cts.op.transformation.NTv2GridShiftTransformation; 37 | import org.cts.registry.EPSGRegistry; 38 | import org.cts.registry.IGNFRegistry; 39 | import org.junit.jupiter.api.Disabled; 40 | import org.junit.jupiter.api.Test; 41 | 42 | import java.util.Set; 43 | 44 | import static org.junit.jupiter.api.Assertions.*; 45 | 46 | /** 47 | * Tests for CRSHelper class 48 | */ 49 | class CRSHelperTest { 50 | 51 | @Test 52 | void testEpsgParser() throws Exception { 53 | CRSFactory factory = new CRSFactory(); 54 | factory.getRegistryManager().addRegistry(new EPSGRegistry()); 55 | CoordinateReferenceSystem crs = factory.getCRS("EPSG:27572"); 56 | assertEquals("EPSG", crs.getAuthorityName()); 57 | assertEquals("27572", crs.getAuthorityKey()); 58 | GeodeticDatum datum = (GeodeticDatum)crs.getDatum(); 59 | assertEquals(datum, GeodeticDatum.NTF_PARIS); 60 | Set ops = datum.getGeocentricTransformations(GeodeticDatum.WGS84); 61 | assertNotNull(CoordinateOperationFactory.getMostPrecise( 62 | CoordinateOperationFactory.includeFilter(ops, GeocentricTranslation.class))); 63 | } 64 | 65 | @Test 66 | void testEpsgParser2() throws Exception { 67 | CRSFactory factory = new CRSFactory(); 68 | factory.getRegistryManager().addRegistry(new EPSGRegistry()); 69 | CoordinateReferenceSystem crs = factory.getCRS("EPSG:3874"); 70 | assertEquals("EPSG", crs.getAuthorityName()); 71 | assertEquals("3874", crs.getAuthorityKey()); 72 | GeodeticDatum datum = (GeodeticDatum)crs.getDatum(); 73 | assertEquals(datum.getEllipsoid(), Ellipsoid.GRS80); 74 | Projection projection = crs.getProjection(); 75 | assertTrue(projection instanceof TransverseMercator); 76 | } 77 | 78 | @Test 79 | void testIgnfParser() throws Exception { 80 | CRSFactory factory = new CRSFactory(); 81 | factory.getRegistryManager().addRegistry(new IGNFRegistry()); 82 | CoordinateReferenceSystem crs = factory.getCRS("IGNF:LAMB2"); 83 | assertEquals("IGNF", crs.getAuthorityName()); 84 | assertEquals("LAMB2", crs.getAuthorityKey()); 85 | GeodeticDatum datum = (GeodeticDatum)crs.getDatum(); 86 | assertEquals(datum, GeodeticDatum.NTF_PARIS); 87 | Set ops = datum.getGeographicTransformations(GeodeticDatum.RGF93); 88 | assertNotNull(CoordinateOperationFactory.getMostPrecise( 89 | CoordinateOperationFactory.includeFilter(ops, NTv2GridShiftTransformation.class))); 90 | datum.removeAllTransformations(); 91 | GeodeticDatum.RGF93.removeAllTransformations(); 92 | } 93 | 94 | @Test 95 | @Disabled 96 | void testCreateCRS() throws Exception { 97 | CRSFactory factory = new CRSFactory(); 98 | factory.getRegistryManager().addRegistry(new EPSGRegistry()); 99 | CoordinateReferenceSystem crs = factory.getCRS("EPSG:2100"); 100 | assertNotNull(crs); 101 | assertNotNull(crs.getDatum()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/test/java/org/cts/CRSIdentifierTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | 25 | package org.cts; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | import static org.junit.jupiter.api.Assertions.assertEquals; 30 | 31 | /** 32 | * 33 | * @author ebocher 34 | */ 35 | class CRSIdentifierTest extends CTSTestCase { 36 | 37 | @Test 38 | void testEPSG4326AuthorityName() throws Exception { 39 | assertEquals("EPSG", cRSFactory.getCRS("EPSG:4326").getAuthorityName()); 40 | } 41 | 42 | @Test 43 | void testEPSG4326AuthorityKey() throws Exception { 44 | assertEquals("4326", cRSFactory.getCRS("EPSG:4326").getAuthorityKey()); 45 | } 46 | 47 | @Test 48 | void testEPSG4326Code() throws Exception { 49 | assertEquals("EPSG:4326", cRSFactory.getCRS("EPSG:4326").getCode()); 50 | } 51 | 52 | @Test 53 | void testEPSG4326Name() throws Exception { 54 | assertEquals("WGS 84", cRSFactory.getCRS("EPSG:4326").getName()); 55 | } 56 | 57 | @Test 58 | void testEPSG27572AuthorityName() throws Exception { 59 | assertEquals("EPSG", cRSFactory.getCRS("EPSG:27572").getAuthorityName()); 60 | } 61 | 62 | @Test 63 | void testEPSG27572AuthorityKey() throws Exception { 64 | assertEquals("27572", cRSFactory.getCRS("EPSG:27572").getAuthorityKey()); 65 | } 66 | 67 | @Test 68 | void testEPSG27572Code() throws Exception { 69 | assertEquals("EPSG:27572", cRSFactory.getCRS("EPSG:27572").getCode()); 70 | } 71 | 72 | @Test 73 | void testEPSG27572Name() throws Exception { 74 | assertEquals("NTF (Paris) / Lambert zone II", cRSFactory.getCRS("EPSG:27572").getName()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/org/cts/TestUtils.java: -------------------------------------------------------------------------------- 1 | package org.cts; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | /** 6 | * Class providing methods for test purpose. 7 | * 8 | * @author Sylvain PALOMINOS (UBS LabSTICC 2020) 9 | */ 10 | public class TestUtils { 11 | 12 | /** 13 | * Default precision for the test according the the java double precision which is around 1.0e-16. 14 | */ 15 | public static final double PRECISION = 1.0e-15; 16 | 17 | /** 18 | * Do a {@link org.junit.jupiter.api.Assertions#assertEquals(double, double, double)} with the given expected and 19 | * actual values with the given precision. 20 | * The precision is converted into a delta as request in junit. 21 | * 22 | * @param expected Expected double value. 23 | * @param actual Actual value. 24 | * @param precision Precision of the assertion. 25 | */ 26 | public static void assertEqualsWithPrecision(double expected, double actual, double precision){ 27 | double exp = Math.floor(expected == 0 ? 1 : Math.log10(Math.abs(expected))); 28 | //Use PRECISION as minimum delta 29 | double delta = Math.max(Math.pow(10, exp) * precision, PRECISION); 30 | assertEquals(expected, actual, delta); 31 | } 32 | 33 | /** 34 | * Do a {@link org.junit.jupiter.api.Assertions#assertEquals(double, double, double)} with the given expected and 35 | * actual values. 36 | * The precision used is the default one : {@link TestUtils#PRECISION}. 37 | * 38 | * @param expected Expected double value. 39 | * @param actual Actual value. 40 | */ 41 | public static void assertEqualsWithPrecision(double expected, double actual){ 42 | assertEqualsWithPrecision(expected, actual, PRECISION); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/cts/cs/GeographicextentTest.java: -------------------------------------------------------------------------------- 1 | package org.cts.cs; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | import static org.junit.jupiter.api.Assertions.assertTrue; 7 | import static org.junit.jupiter.api.Assertions.assertFalse; 8 | 9 | public class GeographicextentTest { 10 | 11 | @Test 12 | void testGeographicExtentConstructor() { 13 | GeographicExtent extent = new GeographicExtent("test", 10.0, 20.0, 30.0, 40.0); 14 | assertEquals(10.0, extent.getSouthernBound()); 15 | assertEquals(20.0, extent.getNorthernBound()); 16 | assertEquals(30.0, extent.getWesternBound()); 17 | assertEquals(40.0, extent.getEasternBound()); 18 | assertEquals(360.0, extent.getModulo()); 19 | assertTrue(extent.isInside(15.0, 35.0)); 20 | assertTrue(extent.isInside(10.0, 35.0)); 21 | assertTrue(extent.isInside(20.0, 35.0)); 22 | assertTrue(extent.isInside(15.0, 30.0)); 23 | assertTrue(extent.isInside(15.0, 40.0)); 24 | assertFalse(extent.isInside(5.0, 35.0)); 25 | assertFalse(extent.isInside(25.0, 35.0)); 26 | assertFalse(extent.isInside(15.0, 25.0)); 27 | assertFalse(extent.isInside(15.0, 45.0)); 28 | } 29 | 30 | @Test 31 | void testInversedLatitudeBounds() { 32 | // InversedLatitude : southern latitude must be < northern latitude 33 | GeographicExtent extent = new GeographicExtent("test", 34 | 20.0, 35 | 10.0, 36 | 30.0, 37 | 40.0 38 | ); 39 | assertFalse(extent.isInside(0.0, 35)); 40 | assertFalse(extent.isInside(10.0, 35)); 41 | assertFalse(extent.isInside(15.0, 35)); 42 | assertFalse(extent.isInside(20.0, 35)); 43 | assertFalse(extent.isInside(25.0, 35)); 44 | } 45 | 46 | @Test 47 | void testInversedLongitudeBounds() { 48 | // InversedLongitude : means that the extent includes the 180 meridian 49 | GeographicExtent extent = new GeographicExtent("test", 50 | 10.0, 51 | 20.0, 52 | 170.0, 53 | -170.0 54 | ); 55 | assertTrue(extent.isInside(15.0, 170)); 56 | assertTrue(extent.isInside(15.0, 175)); 57 | assertTrue(extent.isInside(15.0, 180)); 58 | assertTrue(extent.isInside(15.0, -180)); 59 | assertTrue(extent.isInside(15.0, -175)); 60 | assertTrue(extent.isInside(15.0, -170)); 61 | 62 | assertFalse(extent.isInside(15.0, 160)); 63 | assertFalse(extent.isInside(15.0, -160)); 64 | } 65 | 66 | @Test 67 | void testLongitudeSup180() { 68 | // Eastern longitude > 180 to express an extent including the 180 meridian 69 | GeographicExtent extent = new GeographicExtent("test", 70 | 10.0, 71 | 20.0, 72 | 170.0, 73 | 190.0 74 | ); 75 | assertTrue(extent.isInside(15.0, 170)); 76 | assertTrue(extent.isInside(15.0, 175)); 77 | assertTrue(extent.isInside(15.0, 180)); 78 | assertTrue(extent.isInside(15.0, -180)); 79 | assertTrue(extent.isInside(15.0, -175)); 80 | assertTrue(extent.isInside(15.0, -170)); 81 | 82 | assertFalse(extent.isInside(15.0, 160)); 83 | assertFalse(extent.isInside(15.0, -160)); 84 | } 85 | 86 | @Test 87 | void testInversedLongitudeInGrades() { 88 | // InversedLongitude : means that the extent includes the 180 meridian 89 | // note the modulo parameter 90 | GeographicExtent extent = new GeographicExtent("test", 91 | 10.0, 92 | 20.0, 93 | 190.0, 94 | -190.0, 95 | 400.0 96 | ); 97 | assertTrue(extent.isInside(15.0, 190)); 98 | assertTrue(extent.isInside(15.0, 195)); 99 | assertTrue(extent.isInside(15.0, 200)); 100 | assertTrue(extent.isInside(15.0, -200)); 101 | assertTrue(extent.isInside(15.0, -195)); 102 | assertTrue(extent.isInside(15.0, -190)); 103 | 104 | assertFalse(extent.isInside(15.0, 180)); 105 | assertFalse(extent.isInside(15.0, -180)); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/org/cts/datum/GeodeticDatumTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | 25 | package org.cts.datum; 26 | 27 | import org.cts.CTSTestCase; 28 | import org.cts.Identifier; 29 | import org.cts.cs.GeographicExtent; 30 | import org.cts.op.Identity; 31 | import org.cts.op.transformation.GeocentricTranslation; 32 | 33 | import org.junit.jupiter.api.Test; 34 | 35 | import static org.cts.datum.GeodeticDatum.*; 36 | import static org.junit.jupiter.api.Assertions.assertEquals; 37 | import static org.junit.jupiter.api.Assertions.assertTrue; 38 | 39 | /** 40 | * 41 | * @author Jules Party 42 | */ 43 | class GeodeticDatumTest extends CTSTestCase { 44 | 45 | @Test 46 | void testWGS84() { 47 | assertEquals(WGS84.getToWGS84(), Identity.IDENTITY, "WGS84_geTtoWGS84"); 48 | assertEquals(WGS84.getPrimeMeridian(), PrimeMeridian.GREENWICH, "WGS84_getPrimeMeridian"); 49 | assertEquals(WGS84.getEllipsoid(), Ellipsoid.WGS84, "WGS84_getEllipsoid"); 50 | assertEquals(WGS84.getExtent(), GeographicExtent.WORLD, "WGS84_getExtend"); 51 | } 52 | 53 | @Test 54 | void testNTF_PARIS() { 55 | assertEquals(NTF_PARIS.getToWGS84(), new GeocentricTranslation(-168.0, -60.0, 320.0, 1.0), "WGS84_getExtend"); 56 | assertEquals(NTF_PARIS.getPrimeMeridian(), PrimeMeridian.PARIS, "NTF_PARIS_getPrimeMeridian"); 57 | assertEquals(NTF_PARIS.getEllipsoid(), Ellipsoid.CLARKE1880IGN, "NTF_PARIS_getEllipsoid"); 58 | assertEquals(NTF_PARIS.getExtent(), GeographicExtent.WORLD, "NTF_PARIS_getExtend"); 59 | } 60 | 61 | @Test 62 | void testNTF() { 63 | assertEquals(NTF.getToWGS84(), new GeocentricTranslation(-168.0, -60.0, 320.0, 1.0), "NTF_geTtoWGS84"); 64 | assertEquals(NTF.getPrimeMeridian(), PrimeMeridian.GREENWICH, "NTF_getPrimeMeridian"); 65 | assertEquals(NTF.getEllipsoid(), Ellipsoid.CLARKE1880IGN, "NTF_getEllipsoid"); 66 | assertEquals(NTF.getExtent(), GeographicExtent.WORLD, "NTF_getExtend"); 67 | } 68 | 69 | @Test 70 | void testRGF93() { 71 | assertEquals(RGF93.getToWGS84(), Identity.IDENTITY, "RGF93_geTtoWGS84"); 72 | assertEquals(RGF93.getPrimeMeridian(), PrimeMeridian.GREENWICH, "RGF93_getPrimeMeridian"); 73 | assertEquals(RGF93.getEllipsoid(), Ellipsoid.GRS80, "RGF93_getEllipsoid"); 74 | assertEquals(RGF93.getExtent(), GeographicExtent.WORLD, "RGF93_getExtend"); 75 | } 76 | 77 | @Test 78 | void testED50() { 79 | assertEquals(ED50.getToWGS84(), new GeocentricTranslation(-84.0, -97.0, -117.0, 1.0), "ED50_geTtoWGS84"); 80 | assertEquals(ED50.getPrimeMeridian(), PrimeMeridian.GREENWICH, "ED50_getPrimeMeridian"); 81 | assertEquals(ED50.getEllipsoid(), Ellipsoid.INTERNATIONAL1924, "ED50_getEllipsoid"); 82 | assertEquals(ED50.getExtent(), GeographicExtent.WORLD, "ED50_getExtend"); 83 | } 84 | 85 | 86 | 87 | @Test 88 | void testCreateGeodeticDatum() { 89 | GeodeticDatum datum = GeodeticDatum.createGeodeticDatum(new Identifier(GeodeticDatum.class,"MyDatum"), 90 | PrimeMeridian.PARIS, Ellipsoid.GRS80, 91 | new GeocentricTranslation(10,10,10), new GeographicExtent("",0, 0, 0, 0), "",""); 92 | //datum.addGeocentricTransformation(WGS84, new GeocentricTranslation(10,10,10)); 93 | assertEquals(datum.getPrimeMeridian(), PrimeMeridian.PARIS); 94 | assertEquals(datum.getEllipsoid(), Ellipsoid.GRS80); 95 | assertEquals(datum.getToWGS84(), new GeocentricTranslation(10, 10, 10)); 96 | assertTrue(datum.getGeocentricTransformations(WGS84).size()>0); 97 | assertEquals(datum.getGeocentricTransformations(WGS84).iterator().next(), new GeocentricTranslation(10, 10, 10)); 98 | assertTrue(WGS84.getGeocentricTransformations(datum).size()>0); 99 | assertEquals(WGS84.getGeocentricTransformations(datum).iterator().next(), new GeocentricTranslation(-10, -10, -10)); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/test/java/org/cts/datum/NoRecursionTest.java: -------------------------------------------------------------------------------- 1 | package org.cts.datum; 2 | 3 | import org.cts.Identifier; 4 | import org.cts.crs.Geographic2DCRS; 5 | import org.cts.op.*; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.function.Executable; 8 | 9 | import static org.cts.datum.GeodeticDatum.WGS84; 10 | import static org.junit.jupiter.api.Assertions.assertThrows; 11 | 12 | class NoRecursionTest extends BaseCoordinateTransformTest { 13 | 14 | /** 15 | * Test that a Datum with no toWGS84 method defined does does not produce infinite recursion 16 | * (bug report #98) 17 | */ 18 | @Test 19 | void testNoRecursion() { 20 | // datum without toWGS84 definition 21 | GeodeticDatum gd = GeodeticDatum.createGeodeticDatum(PrimeMeridian.GREENWICH, Ellipsoid.GRS80, null); 22 | final Geographic2DCRS crs = new Geographic2DCRS(new Identifier(Geographic2DCRS.class), gd); 23 | final Geographic2DCRS wgs = new Geographic2DCRS(new Identifier(Geographic2DCRS.class), WGS84); 24 | 25 | assertThrows( 26 | IllegalArgumentException.class, 27 | new Executable() { 28 | @Override 29 | public void execute() throws Throwable { 30 | CoordinateOperationFactory.createCoordinateOperations(crs, wgs); 31 | } 32 | }, 33 | "Expected CoordinateOperationException but did not throw" 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/cts/datum/TestPrimeMeridian.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | 25 | package org.cts.datum; 26 | 27 | import org.cts.CTSTestCase; 28 | 29 | import org.junit.jupiter.api.Test; 30 | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; 32 | import static org.junit.jupiter.api.Assertions.assertTrue; 33 | 34 | /** 35 | * 36 | * @author Erwan Bocher 37 | */ 38 | class TestPrimeMeridian extends CTSTestCase { 39 | 40 | @Test 41 | void testGREENWICH_PM() { 42 | assertTrue(checkEquals("GREENWICH ", PrimeMeridian.GREENWICH.getLongitudeFromGreenwichInDegrees(), 0, 10E-9)); 43 | assertEquals("8901", PrimeMeridian.GREENWICH.getAuthorityKey()); 44 | } 45 | 46 | @Test 47 | void testLISBON_PM() { 48 | assertTrue(checkEquals("LISBON ", PrimeMeridian.LISBON.getLongitudeFromGreenwichInDegrees(), -9.131906111111112, 10E-16)); 49 | assertEquals("8902", PrimeMeridian.LISBON.getAuthorityKey()); 50 | } 51 | 52 | @Test 53 | void testPARIS_PM() { 54 | assertTrue(checkEquals("PARIS ", PrimeMeridian.PARIS.getLongitudeFromGreenwichInDegrees(), 2.337229167, 10E-10)); 55 | assertEquals("8903", PrimeMeridian.PARIS.getAuthorityKey()); 56 | } 57 | 58 | @Test 59 | void testBOGOTA_PM() { 60 | assertTrue(checkEquals("BOGOTA ", PrimeMeridian.BOGOTA.getLongitudeFromGreenwichInDegrees(), -74.08091666666667, 10E-15)); 61 | assertEquals("8904", PrimeMeridian.BOGOTA.getAuthorityKey()); 62 | } 63 | 64 | @Test 65 | void testMADRID_PM() { 66 | assertTrue(checkEquals("MADRID ", PrimeMeridian.MADRID.getLongitudeFromGreenwichInDegrees(), -3.687938888888889, 10E-16)); 67 | assertEquals("8905", PrimeMeridian.MADRID.getAuthorityKey()); 68 | } 69 | 70 | @Test 71 | void testROME_PM() { 72 | assertTrue(checkEquals("ROME ", PrimeMeridian.ROME.getLongitudeFromGreenwichInDegrees(), 12.45233333333333, 10E-15)); 73 | assertEquals("8906", PrimeMeridian.ROME.getAuthorityKey()); 74 | } 75 | 76 | @Test 77 | void testBERN_PM() { 78 | assertTrue(checkEquals("BERN ", PrimeMeridian.BERN.getLongitudeFromGreenwichInDegrees(), 7.439583333333333, 10E-16)); 79 | assertEquals("8907", PrimeMeridian.BERN.getAuthorityKey()); 80 | } 81 | 82 | @Test 83 | void testJAKARTA_PM() { 84 | assertTrue(checkEquals("JAKARTA ", PrimeMeridian.JAKARTA.getLongitudeFromGreenwichInDegrees(), 106.8077194444444, 10E-14)); 85 | assertEquals("8908", PrimeMeridian.JAKARTA.getAuthorityKey()); 86 | } 87 | 88 | @Test 89 | void testFERRO_PM() { 90 | assertTrue(checkEquals("FERRO ", PrimeMeridian.FERRO.getLongitudeFromGreenwichInDegrees(), -17.66666666666667, 10E-15)); 91 | assertEquals("8909", PrimeMeridian.FERRO.getAuthorityKey()); 92 | } 93 | 94 | @Test 95 | void testBRUSSELS_PM() { 96 | assertTrue(checkEquals("BRUSSELS ", PrimeMeridian.BRUSSELS.getLongitudeFromGreenwichInDegrees(), 4.367975, 10E-9)); 97 | assertEquals("8910", PrimeMeridian.BRUSSELS.getAuthorityKey()); 98 | } 99 | 100 | @Test 101 | void testSTOCKHOLM_PM() { 102 | assertTrue(checkEquals("STOCKHOLM ", PrimeMeridian.STOCKHOLM.getLongitudeFromGreenwichInDegrees(), 18.05827777777778, 10E-15)); 103 | assertEquals("8911", PrimeMeridian.STOCKHOLM.getAuthorityKey()); 104 | } 105 | 106 | @Test 107 | void testATHENS_PM() { 108 | assertTrue(checkEquals("ATHENS ", PrimeMeridian.ATHENS.getLongitudeFromGreenwichInDegrees(), 23.7163375, 10E-9)); 109 | assertEquals("8912", PrimeMeridian.ATHENS.getAuthorityKey()); 110 | } 111 | 112 | @Test 113 | void testOSLO_PM() { 114 | assertTrue(checkEquals("OSLO ", PrimeMeridian.OSLO.getLongitudeFromGreenwichInDegrees(), 10.72291666666667, 10E-15)); 115 | assertEquals("8913", PrimeMeridian.OSLO.getAuthorityKey()); 116 | } 117 | 118 | @Test 119 | void testPARIS_RGS_PM() { 120 | assertTrue(checkEquals("PARIS_RGS ", PrimeMeridian.PARIS_RGS.getLongitudeFromGreenwichInDegrees(), 2.201395, 10E-9)); 121 | assertEquals("8914", PrimeMeridian.PARIS_RGS.getAuthorityKey()); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/test/java/org/cts/op/projection/ProjectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.projection; 25 | 26 | import org.cts.Parameter; 27 | import org.cts.datum.Ellipsoid; 28 | import org.cts.units.Measure; 29 | import org.cts.units.Unit; 30 | import org.junit.jupiter.api.Test; 31 | 32 | import java.util.HashMap; 33 | 34 | import static org.junit.jupiter.api.Assertions.assertTrue; 35 | 36 | /** 37 | * @author Michaël Michaud 38 | */ 39 | class ProjectionTest { 40 | 41 | @Test 42 | // Just check that tmerc-1(tmerc(x,y)) let the coordinate unchanged +/- 1 mm 43 | void testInverseProjection() throws Exception { 44 | UniversalTransverseMercator utm = new UniversalTransverseMercator(Ellipsoid.GRS80, 45 | new HashMap() {{ 46 | put(Parameter.CENTRAL_MERIDIAN, new Measure(0, Unit.DEGREE)); 47 | put(Parameter.FALSE_NORTHING, new Measure(0, Unit.METER)); 48 | }}); 49 | assertTrue(utm.isDirect()); 50 | assertTrue(!utm.inverse().isDirect()); 51 | assertTrue(!utm.inverse().toString().equals(utm.toString())); 52 | assertTrue(utm.inverse().inverse() == utm); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/cts/op/projection/TransverseMercatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.op.projection; 25 | 26 | import org.cts.CTSTestCase; 27 | import org.cts.Parameter; 28 | import org.cts.datum.Ellipsoid; 29 | import org.cts.units.Measure; 30 | import org.cts.units.Unit; 31 | import org.junit.jupiter.api.Test; 32 | 33 | import java.util.HashMap; 34 | 35 | import static org.junit.jupiter.api.Assertions.assertTrue; 36 | 37 | /** 38 | * @author Michaël Michaud. 39 | */ 40 | class TransverseMercatorTest extends CTSTestCase { 41 | 42 | @Test 43 | // Just check that tmerc-1(tmerc(x,y)) let the coordinate unchanged +/- 1 mm 44 | void testTransverseMercator() throws Exception { 45 | TransverseMercator tmerc1 = new TransverseMercator(Ellipsoid.GRS80, new HashMap(){{ 46 | put(Parameter.SCALE_FACTOR, new Measure(1.0, Unit.UNIT)); 47 | put(Parameter.CENTRAL_MERIDIAN, new Measure(20, Unit.DEGREE)); 48 | put(Parameter.FALSE_EASTING, new Measure(500000.0, Unit.METER)); 49 | put(Parameter.FALSE_NORTHING, new Measure(0, Unit.METER)); 50 | put(Parameter.LATITUDE_OF_ORIGIN, new Measure(20, Unit.DEGREE)); 51 | }}); 52 | assertTrue(checkEquals2D("0,0 -> tmerc -> tmerc-1 -> 0,0", 53 | new double[]{0.0,0.0}, 54 | tmerc1.inverse().transform(tmerc1.transform(new double[]{0.0,0.0})), 0.001)); 55 | 56 | TransverseMercator tmerc2 = new TransverseMercator(Ellipsoid.GRS80, new HashMap(){{ 57 | put(Parameter.SCALE_FACTOR, new Measure(1.0, Unit.UNIT)); 58 | put(Parameter.CENTRAL_MERIDIAN, new Measure(20, Unit.DEGREE)); 59 | put(Parameter.FALSE_EASTING, new Measure(20500000.0, Unit.METER)); 60 | put(Parameter.FALSE_NORTHING, new Measure(0, Unit.METER)); 61 | put(Parameter.LATITUDE_OF_ORIGIN, new Measure(20, Unit.DEGREE)); 62 | }}); 63 | 64 | } 65 | 66 | @Test 67 | // Check that changing false easting parameter changes the result 68 | void testTransverseMercatorFalseEasting() { 69 | TransverseMercator tmerc1 = new TransverseMercator(Ellipsoid.GRS80, new HashMap(){{ 70 | put(Parameter.SCALE_FACTOR, new Measure(1.0, Unit.UNIT)); 71 | put(Parameter.CENTRAL_MERIDIAN, new Measure(20, Unit.DEGREE)); 72 | put(Parameter.FALSE_EASTING, new Measure(500000.0, Unit.METER)); 73 | put(Parameter.FALSE_NORTHING, new Measure(0, Unit.METER)); 74 | put(Parameter.LATITUDE_OF_ORIGIN, new Measure(20, Unit.DEGREE)); 75 | }}); 76 | TransverseMercator tmerc2 = new TransverseMercator(Ellipsoid.GRS80, new HashMap(){{ 77 | put(Parameter.SCALE_FACTOR, new Measure(1.0, Unit.UNIT)); 78 | put(Parameter.CENTRAL_MERIDIAN, new Measure(20, Unit.DEGREE)); 79 | put(Parameter.FALSE_EASTING, new Measure(20500000.0, Unit.METER)); 80 | put(Parameter.FALSE_NORTHING, new Measure(0, Unit.METER)); 81 | put(Parameter.LATITUDE_OF_ORIGIN, new Measure(20, Unit.DEGREE)); 82 | }}); 83 | assertTrue(!checkEquals2D("", tmerc1.transform(new double[]{0.0,0.0}), tmerc2.transform(new double[]{0.0,0.0}), 1000)); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/cts/parser/prj/IOPrjTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | 25 | package org.cts.parser.prj; 26 | 27 | import java.io.File; 28 | 29 | import org.cts.CTSTestCase; 30 | import org.cts.crs.CoordinateReferenceSystem; 31 | 32 | import org.junit.jupiter.api.Test; 33 | 34 | import static org.junit.jupiter.api.Assertions.assertNotNull; 35 | 36 | /** 37 | * This class is used to test the prj reader and writer. 38 | * 39 | * @author ebocher 40 | */ 41 | public class IOPrjTest extends CTSTestCase { 42 | 43 | @Test 44 | public void readPrjNTF_Lambert_II_etendu() throws Exception { 45 | String filePath = IOPrjTest.class.getResource("NTF_Lambert_II_etendu.prj").toURI().getPath(); 46 | CoordinateReferenceSystem crs = cRSFactory.createFromPrj(new File(filePath)); 47 | assertNotNull(crs); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/cts/parser/prj/PrjWriterTest.java: -------------------------------------------------------------------------------- 1 | package org.cts.parser.prj; 2 | 3 | import org.junit.jupiter.api.Disabled; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static org.junit.jupiter.api.Assertions.assertEquals; 7 | 8 | /** 9 | * Created by UMichael on 26/05/2017. 10 | */ 11 | class PrjWriterTest { 12 | 13 | @Test 14 | void testPrettyRoundingIntegerValues() { 15 | // Round values around 0 16 | assertEquals("0", PrjWriter.prettyRound(0.0, 1E-11)); 17 | assertEquals("0", PrjWriter.prettyRound(0.000000000001, 1E-11)); 18 | assertEquals("0", PrjWriter.prettyRound(-0.000000000001, 1E-11)); 19 | // but not if difference > 1E-11 20 | assertEquals("0.000001", PrjWriter.prettyRound(0.000001, 1E-11)); 21 | // Round values if difference < 1E-11 for small values 22 | assertEquals("99", PrjWriter.prettyRound(99.0, 1E-11)); 23 | assertEquals("99", PrjWriter.prettyRound(99.000000000001, 1E-11)); 24 | assertEquals("-99", PrjWriter.prettyRound(-99.000000000001, 1E-11)); 25 | assertEquals("100", PrjWriter.prettyRound(99.999999999999, 1E-11)); 26 | assertEquals("-100", PrjWriter.prettyRound(-99.999999999999, 1E-11)); 27 | // Do not round for larger differences 28 | assertEquals("99.000001", PrjWriter.prettyRound(99.000001, 1E-11)); 29 | assertEquals("-99.000001", PrjWriter.prettyRound(-99.000001, 1E-11)); 30 | // Round values if difference < 1E-4 for values > 400 31 | assertEquals("100000", PrjWriter.prettyRound(100000.00005, 1E-4)); 32 | assertEquals("100000", PrjWriter.prettyRound(99999.99995, 1E-4)); 33 | } 34 | 35 | @Test 36 | void testPrettyRoundingFractionalValues() { 37 | assertEquals("0.3333333333333333", PrjWriter.prettyRound(1.0/3.0, 1E-11)); 38 | assertEquals("-0.3333333333333333", PrjWriter.prettyRound(-1.0/3.0, 1E-11)); 39 | assertEquals("0.3333333333333333", PrjWriter.prettyRound(0.3333333333333333, 1E-11)); 40 | assertEquals("0.6666666666666666", PrjWriter.prettyRound(0.6666666666666667, 1E-11)); 41 | // improve precision if number has been truncated to 12 decimals or more 42 | assertEquals("0.3333333333333333", PrjWriter.prettyRound(0.333333333333, 1E-11)); 43 | assertEquals("0.3333333333333333", PrjWriter.prettyRound(0.3333333333331987, 1E-11)); 44 | assertEquals("0.6666666666666666", PrjWriter.prettyRound(0.6666666666671111, 1E-11)); 45 | // ...but not if the number has been too much rounded 46 | assertEquals("0.33333333333", PrjWriter.prettyRound(0.33333333333, 1E-11)); 47 | assertEquals("0.66666666667", PrjWriter.prettyRound(0.66666666667, 1E-11)); 48 | // For large values, round if difference is less than 1E-4 49 | assertEquals("200000.5", PrjWriter.prettyRound(200000.5000065, 1E-4)); 50 | assertEquals("-200000.5", PrjWriter.prettyRound(-200000.4999999, 1E-4)); 51 | } 52 | 53 | @Test 54 | void testPrettyRoundingSpecialValues() { 55 | assertEquals("3.141592653589793", PrjWriter.prettyRound(Math.PI, 1E-11)); 56 | assertEquals("0.3183098861837907", PrjWriter.prettyRound(1.0/Math.PI, 1E-11)); 57 | assertEquals("0.7853981633974483", PrjWriter.prettyRound(45.0*Math.PI/180.0, 1E-11)); 58 | assertEquals("0.7853981633974483", PrjWriter.prettyRound(0.7853981633974000, 1E-11)); 59 | assertEquals("0.41887902047863906", PrjWriter.prettyRound(24.0*Math.PI/180.0, 1E-11)); 60 | assertEquals("0.41887902047863906", PrjWriter.prettyRound(0.4188790204786, 1E-11)); 61 | assertEquals("-0.39269908169872414", PrjWriter.prettyRound(-22.5*Math.PI/180.0, 1E-11)); 62 | assertEquals("-0.39269908169872414", PrjWriter.prettyRound(-0.39269908169872, 1E-11)); 63 | } 64 | 65 | @Test 66 | @Disabled 67 | void testFormatPRJ() { 68 | String prj = "GEOCCS[\"WGS 84 (geocentric)\",\n" 69 | + " DATUM[\"World Geodetic System 1984\",\n" 70 | + " SPHEROID[\"WGS 84\",6378137.0,298.257223563,\n" 71 | + " AUTHORITY[\"EPSG\",\"7030\"]],\n" 72 | + " AUTHORITY[\"EPSG\",\"6326\"]],\n" 73 | + " PRIMEM[\"Greenwich\",0.0,\n" 74 | + " AUTHORITY[\"EPSG\",\"8901\"]],\n" 75 | + " UNIT[\"m\",1.0],\n" 76 | + " AXIS[\"Geocentric X\",OTHER],\n" 77 | + " AXIS[\"Geocentric Y\",EAST],\n" 78 | + " AXIS[\"Geocentric Z\",NORTH],\n" 79 | + " AUTHORITY[\"EPSG\",\"4328\"]]"; 80 | assertEquals(prj, PrjWriter.formatWKT(prj)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/org/cts/parser/prj/Ticket98Test.java: -------------------------------------------------------------------------------- 1 | package org.cts.parser.prj; 2 | 3 | import org.cts.CTSTestCase; 4 | import org.cts.crs.CoordinateReferenceSystem; 5 | import org.cts.op.Identity; 6 | import org.cts.op.transformation.SevenParameterTransformation; 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertFalse; 10 | import static org.junit.jupiter.api.Assertions.assertTrue; 11 | 12 | public class Ticket98Test extends CTSTestCase { 13 | 14 | @Test 15 | void albertEqualsAreaParsingFromESRITest() throws Exception { 16 | CoordinateReferenceSystem crs = cRSFactory.getCRS("ESRI:102039"); 17 | assertTrue(crs.getDatum().getToWGS84() instanceof SevenParameterTransformation); 18 | assertFalse(crs.getDatum().getToWGS84().equals(Identity.IDENTITY)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/cts/parser/proj4/Proj4ParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Coordinate Transformations Suite (abridged CTS) is a library developped to 3 | * perform Coordinate Transformations using well known geodetic algorithms 4 | * and parameter sets. 5 | * Its main focus are simplicity, flexibility, interoperability, in this order. 6 | * 7 | * This library has been originally developed by Michaël Michaud under the JGeod 8 | * name. It has been renamed CTS in 2009 and shared to the community from 9 | * the OrbisGIS code repository. 10 | * 11 | * CTS is free software: you can redistribute it and/or modify it under the 12 | * terms of the GNU Lesser General Public License as published by the Free Software 13 | * Foundation, either version 3 of the License. 14 | * 15 | * CTS is distributed in the hope that it will be useful, but WITHOUT ANY 16 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 17 | * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License along with 20 | * CTS. If not, see . 21 | * 22 | * For more information, please consult: 23 | */ 24 | package org.cts.parser.proj4; 25 | 26 | import java.util.Map; 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | import static org.junit.jupiter.api.Assertions.assertNull; 29 | import org.junit.jupiter.api.Test; 30 | 31 | /** 32 | * Test for proj4 parser 33 | * @author Erwan Bocher CNRS 34 | */ 35 | public class Proj4ParserTest { 36 | 37 | @Test 38 | void testParseUTMNorth() { 39 | Map params = Proj4Parser.readParameters("+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs"); 40 | assertEquals(params.get("proj"), "utm"); 41 | assertEquals(params.get("zone"), "32"); 42 | assertEquals(params.get("datum"), "WGS84"); 43 | assertEquals(params.get("units"), "m"); 44 | assertNull(params.get("no_defs")); 45 | } 46 | 47 | @Test 48 | void testParseUTMSouth() { 49 | Map params = Proj4Parser.readParameters("+proj=utm +zone=32 +south +datum=WGS84 +units=m +no_defs"); 50 | assertEquals(params.get("proj"), "utm"); 51 | assertEquals(params.get("zone"), "32"); 52 | assertEquals(params.get("datum"), "WGS84"); 53 | assertEquals(params.get("units"), "m"); 54 | assertNull(params.get("south")); 55 | assertNull(params.get("no_defs")); 56 | } 57 | 58 | @Test 59 | void testParse() { 60 | Map params = Proj4Parser.readParameters("+proj=tmerc +lat_0=0 +lon_0=106 +k=1 +x_0=500000 +y_0=0 +ellps=krass +towgs84=-17.51,-108.32,-62.39,0,0,0,0 +units=m +no_defs"); 61 | assertEquals(params.get("proj"), "tmerc"); 62 | assertEquals(params.get("lat_0"), "0"); 63 | assertEquals(params.get("lon_0"), "106"); 64 | assertEquals(params.get("k"), "1"); 65 | assertEquals(params.get("x_0"), "500000"); 66 | assertEquals(params.get("y_0"), "0"); 67 | assertEquals(params.get("towgs84"), "-17.51,-108.32,-62.39,0,0,0,0"); 68 | assertEquals(params.get("ellps"), "krass"); 69 | assertEquals(params.get("units"), "m"); 70 | assertNull(params.get("no_defs")); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/resources/org/cts/parser/prj/NTF_Lambert_II_etendu.prj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/orbisgis/cts/78fbda39bd4602594862dff99902b03d1eef79d0/src/test/resources/org/cts/parser/prj/NTF_Lambert_II_etendu.prj -------------------------------------------------------------------------------- /src/test/resources/org/cts/parser/prj/WaukeeStreets.prj: -------------------------------------------------------------------------------- 1 | PROJCS["NAD_1983_StatePlane_Iowa_South_FIPS_1402_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",1640416.666666667],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-93.5],PARAMETER["Standard_Parallel_1",40.61666666666667],PARAMETER["Standard_Parallel_2",41.78333333333333],PARAMETER["Latitude_Of_Origin",40.0],UNIT["Foot_US",0.3048006096012192]] --------------------------------------------------------------------------------