Implemented Proj4 definition (#11303)

* Implement Proj4 definition

* Add proj4 tests
This commit is contained in:
Denis
2016-09-19 16:18:09 +09:00
committed by Masahiro Wakame
parent e0e86e3535
commit 6fbe7a4242
2 changed files with 166 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
/// <reference path="proj4.d.ts"/>
import * as proj4 from 'proj4'
///////////////////////////////////////////
// Tests data initialisation
///////////////////////////////////////////
const name = 'WGS84'
const epsg = {
4269: '+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees',
4326: '+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees',
}
const point1 = [-71, 41]
const point2 = {x: 2, y: 5}
const mgrs = "24XWT783908"
///////////////////////////////////////////
// Tests Measurement
///////////////////////////////////////////
proj4(epsg['4269'], epsg['4326'], point1)
proj4(epsg['4269'], point1)
proj4(epsg['4269'], epsg['4326']).forward(point2)
proj4(epsg['4269'], epsg['4326']).inverse(point2)
///////////////////////////////////
// Named Projections
///////////////////////////////////
proj4.defs('WGS84', epsg['4326'])
proj4.defs([
['EPSG:4326', epsg['4326']],
['EPSG:4269', epsg['4269']]
])
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'))
///////////////////////////////////
// Utils
///////////////////////////////////
// WGS84
proj4.WGS84
// Proj
proj4.Proj('WGS84')
// toPoint
proj4.toPoint([1, 2])
proj4.toPoint([1, 2, 3])
proj4.toPoint([1, 2, 3, 4])
// Point
// WARNING: Deprecated in v3
proj4.Point([1, 2, 3, 4])
+116
View File
@@ -0,0 +1,116 @@
// Type definitions for proj4 2.3.15
// Project: https://github.com/proj4js/proj4js
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "proj4" {
const TemplateCoordinates: Array<number> | InterfaceCoordinates;
interface InterfaceCoordinates {
x: number,
y: number,
z?: number,
m?: number
}
interface InterfaceDatum {
datum_type: number
a: number
b: number
es: number
ep2: number
}
interface Proj4Static {
forward(coordinates: typeof TemplateCoordinates): Array<number>
inverse(coordinates: typeof TemplateCoordinates): Array<number>
}
interface InterfaceProjection {
title: string
projName: string
ellps: string
datumCode: string
units: string
a: number
rf: number
ellipseName: string
b: number
a2: number
b2: number
es: number
e: number
ep2: number
k0: number
axis: string
datum: InterfaceDatum
init: typeof proj4.Proj,
forward(coordinates: typeof TemplateCoordinates): Array<number>
inverse(coordinates: typeof TemplateCoordinates): Array<number>
names: Array<string>
to_meter(value: number): any
from_greenwich(value: number): any
}
namespace proj4 {
/**
* @name defaultDatum
*/
export const defaultDatum: string;
/**
* @name Proj
*/
export function Proj(srsCode:any, callback?: any): InterfaceProjection;
/**
* @name WGS84
*/
export const WGS84: any;
/**
* Depecrated v3
* @name Point
*/
export function Point(x: number, y: number, z?: number): InterfaceCoordinates;
export function Point(coordinates: Array<number>): InterfaceCoordinates;
export function Point(coordinates: InterfaceCoordinates): InterfaceCoordinates;
export function Point(coordinates: string): InterfaceCoordinates;
/**
* @name toPoint
*/
export function toPoint(array: Array<number>): InterfaceCoordinates;
/**
* @name defs
*/
export function defs(name: string): any;
export function defs(name: string, projection: string): any;
export function defs(name: Array<Array<string>>): any;
/**
* @name transform
*/
export function transform(source: InterfaceProjection, dest: InterfaceProjection, point: typeof TemplateCoordinates): any;
/**
* @name mgrs
*/
export function mgrs(coordinates: Array<number>, accuracy: number): string;
/**
* @name version
*/
export const version: string;
}
/**
* @name proj4
*/
function proj4(fromProjection: string): Proj4Static;
function proj4(fromProjection: string, toProjection: string): Proj4Static;
function proj4(fromProjection: string, coordinates: typeof TemplateCoordinates): Array<number>;
function proj4(fromProjection: string, toProjection: string, coordinates: typeof TemplateCoordinates): Array<number>;
export = proj4
}