Updated projection factories

This commit is contained in:
ClemensFischer 2026-01-20 23:05:33 +01:00
parent c245a8f722
commit d5ee7bbfc0
2 changed files with 33 additions and 70 deletions

View file

@ -6,71 +6,29 @@ namespace MapControl
{
public virtual MapProjection GetProjection(string crsId)
{
MapProjection projection = null;
switch (crsId)
MapProjection projection = crsId switch
{
case WebMercatorProjection.DefaultCrsId:
projection = new WebMercatorProjection();
break;
case WorldMercatorProjection.DefaultCrsId:
projection = new WorldMercatorProjection();
break;
case EquirectangularProjection.DefaultCrsId:
case "CRS:84":
case "EPSG:4087":
projection = new EquirectangularProjection(crsId);
break;
case Wgs84UpsNorthProjection.DefaultCrsId:
projection = new Wgs84UpsNorthProjection();
break;
case Wgs84UpsSouthProjection.DefaultCrsId:
projection = new Wgs84UpsSouthProjection();
break;
case Wgs84AutoUtmProjection.DefaultCrsId:
projection = new Wgs84AutoUtmProjection();
break;
case Wgs84AutoTmProjection.DefaultCrsId:
projection = new Wgs84AutoTmProjection();
break;
case OrthographicProjection.DefaultCrsId:
projection = new OrthographicProjection();
break;
case AutoEquirectangularProjection.DefaultCrsId:
projection = new AutoEquirectangularProjection();
break;
case GnomonicProjection.DefaultCrsId:
projection = new GnomonicProjection();
break;
case StereographicProjection.DefaultCrsId:
projection = new StereographicProjection();
break;
case AzimuthalEquidistantProjection.DefaultCrsId:
projection = new AzimuthalEquidistantProjection();
break;
default:
if (crsId.StartsWith("EPSG:") && int.TryParse(crsId.Substring(5), out int epsgCode))
{
projection = GetProjection(epsgCode);
}
break;
}
WebMercatorProjection.DefaultCrsId => new WebMercatorProjection(),
WorldMercatorProjection.DefaultCrsId => new WorldMercatorProjection(),
EquirectangularProjection.DefaultCrsId or "CRS:84" or "EPSG:4087" => new EquirectangularProjection(crsId),
Wgs84UpsNorthProjection.DefaultCrsId => new Wgs84UpsNorthProjection(),
Wgs84UpsSouthProjection.DefaultCrsId => new Wgs84UpsSouthProjection(),
Wgs84AutoUtmProjection.DefaultCrsId => new Wgs84AutoUtmProjection(),
Wgs84AutoTmProjection.DefaultCrsId => new Wgs84AutoTmProjection(),
OrthographicProjection.DefaultCrsId => new OrthographicProjection(),
AutoEquirectangularProjection.DefaultCrsId => new AutoEquirectangularProjection(),
GnomonicProjection.DefaultCrsId => new GnomonicProjection(),
StereographicProjection.DefaultCrsId => new StereographicProjection(),
AzimuthalEquidistantProjection.DefaultCrsId => new AzimuthalEquidistantProjection(),
_ => GetProjectionFromEpsgCode(crsId),
};
return projection ?? throw new NotSupportedException($"MapProjection \"{crsId}\" is not supported.");
}
public MapProjection GetProjectionFromEpsgCode(string crsId) =>
crsId.StartsWith("EPSG:") && int.TryParse(crsId.Substring(5), out int epsgCode) ? GetProjection(epsgCode) : null;
public virtual MapProjection GetProjection(int epsgCode) => epsgCode switch
{
var code when code >= Etrs89UtmProjection.FirstZoneEpsgCode && code <= Etrs89UtmProjection.LastZoneEpsgCode => new Etrs89UtmProjection(epsgCode % 100),

View file

@ -25,17 +25,22 @@ namespace MapControl.Projections
{ 29193, WktConstants.ProjCsSad69Utm23S },
};
public override MapProjection GetProjection(string crsId) => crsId switch
public override MapProjection GetProjection(string crsId)
{
MapControl.WebMercatorProjection.DefaultCrsId => new WebMercatorProjection(),
MapControl.WorldMercatorProjection.DefaultCrsId => new WorldMercatorProjection(),
MapControl.Wgs84UpsNorthProjection.DefaultCrsId => new Wgs84UpsNorthProjection(),
MapControl.Wgs84UpsSouthProjection.DefaultCrsId => new Wgs84UpsSouthProjection(),
MapControl.Wgs84AutoUtmProjection.DefaultCrsId => new Wgs84AutoUtmProjection(),
MapControl.OrthographicProjection.DefaultCrsId => new Wgs84OrthographicProjection(),
MapControl.StereographicProjection.DefaultCrsId => new Wgs84StereographicProjection(),
_ => base.GetProjection(crsId)
};
MapProjection projection = crsId switch
{
MapControl.WebMercatorProjection.DefaultCrsId => new WebMercatorProjection(),
MapControl.WorldMercatorProjection.DefaultCrsId => new WorldMercatorProjection(),
MapControl.Wgs84UpsNorthProjection.DefaultCrsId => new Wgs84UpsNorthProjection(),
MapControl.Wgs84UpsSouthProjection.DefaultCrsId => new Wgs84UpsSouthProjection(),
MapControl.Wgs84AutoUtmProjection.DefaultCrsId => new Wgs84AutoUtmProjection(),
MapControl.OrthographicProjection.DefaultCrsId => new Wgs84OrthographicProjection(),
MapControl.StereographicProjection.DefaultCrsId => new Wgs84StereographicProjection(),
_ => GetProjectionFromEpsgCode(crsId)
};
return projection ?? base.GetProjection(crsId);
}
public override MapProjection GetProjection(int epsgCode) => epsgCode switch
{