[geotk] "Custom" location local projection
Martin Desruisseaux
martin.desruisseaux at geomatys.fr
Thu Sep 3 10:28:18 EDT 2009
Hello Sam
Sam B a écrit :
> For my application, I need something a bit special : I would need a
> local projection at a location that I could choose.
Lets suppose that you want a Mercator projection (but any other kind of
projection would be in the same principle):
First a quick tip: tries the following from the command line (from a directory
which contains every JAR files, both geotk and dependencies. It can also be one
of the big bundles downloaded from the download.geotoolkit.org page):
java -jar geotk-referencing-SNAPSHOT.jar list projections
(you may need to add a --encoding=UTF-8 if you are on MacOS, or --encoding=Cp467
if you are on Windows, for a better output). You will get the list of supported
projection. Picks one (e.g. Mercator) and execute:
java -jar geotk-referencing-SNAPSHOT.jar parameters Mercator
You should get:
> OGC: Mercator_2SP
> EPSG: Mercator (2SP) (9805)
> ESRI: Mercator
> GeoTIFF: CT_Mercator
> Geotoolkit.org: Projection Mercator cylindrique
> ╔═══════════════════════════════════════════════════╤═════════╤═════════╤═════════╤════════╤════════╗
> ║ Nom │ Type │ Minimum │ Maximum │ Défaut │ Unités ║
> ╠═══════════════════════════════════════════════════╪═════════╪═════════╪═════════╪════════╪════════╣
> ║ OGC: semi_major │ Double │ 0 │ ∞ │ │ m ║
> ║ ESRI: Semi_Major │ │ │ │ │ ║
> ║ EPSG: Semi-major axis │ │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ OGC: semi_minor │ Double │ 0 │ ∞ │ │ m ║
> ║ ESRI: Semi_Minor │ │ │ │ │ ║
> ║ EPSG: Semi-minor axis │ │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ Geotoolkit.org: roll_longitude │ Boolean │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ OGC: standard_parallel_1 │ Double │ -90 │ +90 │ 0 │ ° ║
> ║ ESRI: Standard_Parallel_1 │ │ │ │ │ ║
> ║ EPSG: Latitude of 1st standard parallel │ │ │ │ │ ║
> ║ GeoTIFF: StdParallel1 │ │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ OGC: latitude_of_origin │ Double │ -90 │ +90 │ 0 │ ° ║
> ║ ESRI: Latitude_Of_Origin │ │ │ │ │ ║
> ║ EPSG: Latitude of natural origin │ │ │ │ │ ║
> ║ GeoTIFF: NatOriginLat │ │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ OGC: central_meridian │ Double │ -180 │ +180 │ 0 │ ° ║
> ║ ESRI: Central_Meridian │ │ │ │ │ ║
> ║ EPSG: Longitude of natural origin │ │ │ │ │ ║
> ║ GeoTIFF: NatOriginLong │ │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ OGC: false_easting │ Double │ -∞ │ +∞ │ 0 │ m ║
> ║ ESRI: False_Easting │ │ │ │ │ ║
> ║ EPSG: False easting │ │ │ │ │ ║
> ║ GeoTIFF: FalseEasting │ │ │ │ │ ║
> ╟───────────────────────────────────────────────────┼─────────┼─────────┼─────────┼────────┼────────╢
> ║ OGC: false_northing │ Double │ -∞ │ +∞ │ 0 │ m ║
> ║ ESRI: False_Northing │ │ │ │ │ ║
> ║ EPSG: False northing │ │ │ │ │ ║
> ║ GeoTIFF: FalseNorthing │ │ │ │ │ ║
> ╚═══════════════════════════════════════════════════╧═════════╧═════════╧═════════╧════════╧════════╝
The names in the first column are what you are going to use in the following
code. Then use a code like that (where yourCentralX|YPosition are in degrees of
longitude/latitude, as reported in the above table):
MathTransformFactory mtFactory = FactoryFinder.getMathTransformFactory(null);
ParameterValueGroup parameters = mtFactory.getDefaultParameters("Mercator");
parameters.parameter("standard_parallel_1").setValue(yourCentralYPosition);
parameters.parameter("central_meridian").setValue(yourCentralXPosition);
// Defines also false northing/easting if useful to you.
If you are interrested only in the MathTransform and not in the ProjectedCRS,
then you could invoke mtFactory.createParameterizedTransform(parameters) right
away (but you need to define "semi_major" and "semi_minor" first). Otherwise you
can continue as below (not that you don't need to define "semi_major" and
"semi_minor"; it will be inferred automatically):
CRSFactory factory = FactoryFinder.getCRSFactory(null);
DefiningConversion conversionFromBase = new DefiningConversion("My
projection", parameters);
Map<String,Object> properties = new HashMap<String,Object>();
properties.put(ProjectedCRS.NAME, "My projection");
ProjectedCRS crs = factory.createProjectedCRS(properties,
DefaultGeographicCRS.WGS84, conversionFromBase, DefaultCartesianCS.PROJECTED);
Does it suit your need?
Martin
More information about the Geotoolkit
mailing list