Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WANDER
utils
Commits
79efe7ea
Commit
79efe7ea
authored
2 months ago
by
Knuiman, Bart
Browse files
Options
Downloads
Patches
Plain Diff
Added projection methods to go from WebMercator to RD and GPS.
parent
b18bf241
Branches
master
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Scripts/Projections.cs
+51
-13
51 additions, 13 deletions
Scripts/Projections.cs
with
51 additions
and
13 deletions
Scripts/Projections.cs
+
51
−
13
View file @
79efe7ea
...
...
@@ -7,7 +7,7 @@ namespace Wander
{
public
static
class
Projections
{
public
enum
Projecti
on
public
enum
Comm
on
{
NotSet
,
WGS84
,
...
...
@@ -15,16 +15,16 @@ namespace Wander
WebMercator
}
static
CoordinateSystem
FromEnumProjection
(
CoordinateSystemFactory
f
,
Projecti
on
pr
)
static
CoordinateSystem
FromEnumProjection
(
CoordinateSystemFactory
f
,
Comm
on
pr
)
{
Debug
.
Assert
(
pr
!=
Projecti
on
.
NotSet
,
"Invalid enum to for a projection."
);
Debug
.
Assert
(
pr
!=
Comm
on
.
NotSet
,
"Invalid enum to for a projection."
);
switch
(
pr
)
{
case
Projecti
on
.
WGS84
:
case
Comm
on
.
WGS84
:
return
GeographicCoordinateSystem
.
WGS84
;
case
Projecti
on
.
RD
:
case
Comm
on
.
RD
:
return
f
.
CreateFromWkt
(
"PROJCS[\"Amersfoort / RD New\",GEOGCS[\"Amersfoort\",DATUM[\"Amersfoort\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],TOWGS84[565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725],AUTHORITY[\"EPSG\",\"6289\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4289\"]],PROJECTION[\"Oblique_Stereographic\"],PARAMETER[\"latitude_of_origin\",52.15616055555555],PARAMETER[\"central_meridian\",5.38763888888889],PARAMETER[\"scale_factor\",0.9999079],PARAMETER[\"false_easting\",155000],PARAMETER[\"false_northing\",463000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH],AUTHORITY[\"EPSG\",\"28992\"]]"
);
case
Projecti
on
.
WebMercator
:
case
Comm
on
.
WebMercator
:
return
ProjectedCoordinateSystem
.
WebMercator
;
}
return
ProjectedCoordinateSystem
.
WebMercator
;
...
...
@@ -36,7 +36,7 @@ namespace Wander
}
// Usage: ICoordinateTransformation.MathTransform.Transform( ref x, ref y )
public
static
ICoordinateTransformation
CreateProjection
(
string
fromWkt
,
Projecti
on
to
)
public
static
ICoordinateTransformation
CreateProjection
(
string
fromWkt
,
Comm
on
to
)
{
var
f
=
new
CoordinateSystemFactory
();
var
fromCoordinates
=
FromCustomWKT
(
f
,
fromWkt
);
...
...
@@ -45,7 +45,7 @@ namespace Wander
return
factory
.
CreateFromCoordinateSystems
(
fromCoordinates
,
toCoordinates
);
}
public
static
ICoordinateTransformation
CreateProjection
(
Projecti
on
from
,
string
toWkt
)
public
static
ICoordinateTransformation
CreateProjection
(
Comm
on
from
,
string
toWkt
)
{
var
f
=
new
CoordinateSystemFactory
();
var
fromCoordinates
=
FromEnumProjection
(
f
,
from
);
...
...
@@ -55,9 +55,9 @@ namespace Wander
}
// Usage: ICoordinateTransformation.MathTransform.Transform( ref x, ref y )
public
static
ICoordinateTransformation
CreateProjection
(
Projecti
on
from
,
Projecti
on
to
)
public
static
ICoordinateTransformation
CreateProjection
(
Comm
on
from
,
Comm
on
to
)
{
if
(
from
==
Projecti
on
.
NotSet
||
to
==
Projecti
on
.
NotSet
)
if
(
from
==
Comm
on
.
NotSet
||
to
==
Comm
on
.
NotSet
)
return
null
;
var
f
=
new
CoordinateSystemFactory
();
var
fromCoordinates
=
FromEnumProjection
(
f
,
from
);
...
...
@@ -66,6 +66,36 @@ namespace Wander
return
factory
.
CreateFromCoordinateSystems
(
fromCoordinates
,
toCoordinates
);
}
public
static
ICoordinateTransformation
GPS2Web
()
{
return
CreateProjection
(
Common
.
WGS84
,
Common
.
WebMercator
);
}
public
static
ICoordinateTransformation
Web2GPS
()
{
return
CreateProjection
(
Common
.
WebMercator
,
Common
.
WGS84
);
}
public
static
ICoordinateTransformation
GPS2RD
()
{
return
CreateProjection
(
Common
.
WGS84
,
Common
.
RD
);
}
public
static
ICoordinateTransformation
RD2GPS
()
{
return
CreateProjection
(
Common
.
RD
,
Common
.
WGS84
);
}
public
static
ICoordinateTransformation
RD2Web
()
{
return
CreateProjection
(
Common
.
RD
,
Common
.
WebMercator
);
}
public
static
ICoordinateTransformation
Web2RD
()
{
return
CreateProjection
(
Common
.
WebMercator
,
Common
.
RD
);
}
// Usage: ICoordinateTransformation.MathTransform.Transform( ref x, ref y )
// Use this site to lookup WKT's https://epsg.io/4326
public
static
ICoordinateTransformation
CreateProjection
(
string
fromWKT
,
string
toWKT
)
...
...
@@ -78,17 +108,25 @@ namespace Wander
}
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
public
static
void
Transform
(
I
CoordinateTransformation
transform
,
ref
Vector3
v
)
public
static
void
Transform
(
this
CoordinateTransformation
transform
,
ref
Vector3
v
)
{
var
res
=
transform
.
MathTransform
.
Transform
(
v
.
x
,
v
.
z
);
v
.
x
=
(
float
)
res
.
x
;
v
.
z
=
(
float
)
res
.
y
;
}
// NOTE: For GPS, use Input: Lon(x)/lat(y). Output: also Lon(x)/lat(y).
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
public
static
(
float
x
,
float
y
)
Transform
(
ICoordinateTransformation
transform
,
float
x
,
float
y
)
public
static
(
double
x
,
double
y
)
Transform
(
this
ICoordinateTransformation
transform
,
double
x
,
double
y
)
{
return
((
float
,
float
))
transform
.
MathTransform
.
Transform
(
x
,
y
);
return
transform
.
MathTransform
.
Transform
(
x
,
y
);
}
// NOTE: For GPS, use Input: Lon(x)/lat(y). Output: also Lon(x)/lat(y).
[
MethodImpl
(
MethodImplOptions
.
AggressiveInlining
)]
public
static
(
float
x
,
float
y
)
TransformF
(
this
ICoordinateTransformation
transform
,
double
x
,
double
y
)
{
return
((
float
,
float
))
transform
.
MathTransform
.
Transform
(
x
,
y
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment