/u_CoordConverterFactorySimple.pas

https://bitbucket.org/djvk/sasplanet · Pascal · 121 lines · 91 code · 10 blank · 20 comment · 5 complexity · a190eca03e8be7dd101e2b952bf79cc6 MD5 · raw file

  1. {******************************************************************************}
  2. {* SAS.Planet (SAS.Планета) *}
  3. {* Copyright (C) 2007-2011, SAS.Planet development team. *}
  4. {* This program is free software: you can redistribute it and/or modify *}
  5. {* it under the terms of the GNU General Public License as published by *}
  6. {* the Free Software Foundation, either version 3 of the License, or *}
  7. {* (at your option) any later version. *}
  8. {* *}
  9. {* This program is distributed in the hope that it will be useful, *}
  10. {* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
  11. {* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
  12. {* GNU General Public License for more details. *}
  13. {* *}
  14. {* You should have received a copy of the GNU General Public License *}
  15. {* along with this program. If not, see <http://www.gnu.org/licenses/>. *}
  16. {* *}
  17. {* http://sasgis.ru *}
  18. {* az@sasgis.ru *}
  19. {******************************************************************************}
  20. unit u_CoordConverterFactorySimple;
  21. interface
  22. uses
  23. i_CoordConverter,
  24. i_ConfigDataProvider,
  25. i_CoordConverterFactory;
  26. type
  27. TCoordConverterFactorySimple = class(TInterfacedObject, ICoordConverterFactory)
  28. protected
  29. function GetCoordConverterByConfig(AConfig: IConfigDataProvider): ICoordConverter;
  30. function GetCoordConverterByCode(AProjectionEPSG: Integer; ATileSplitCode: Integer): ICoordConverter;
  31. end;
  32. implementation
  33. uses
  34. SysUtils,
  35. c_CoordConverter,
  36. u_CoordConverterMercatorOnSphere,
  37. u_CoordConverterMercatorOnEllipsoid,
  38. u_CoordConverterSimpleLonLat,
  39. u_ResStrings;
  40. { TCoordConverterFactorySimple }
  41. function TCoordConverterFactorySimple.GetCoordConverterByCode(AProjectionEPSG,
  42. ATileSplitCode: Integer): ICoordConverter;
  43. var
  44. VRadiusA: Double;
  45. VRadiusB: Double;
  46. begin
  47. if ATileSplitCode = CTileSplitQuadrate256x256 then begin
  48. case AProjectionEPSG of
  49. CGoogleProjectionEPSG: begin
  50. VRadiusA := 6378137;
  51. Result := TCoordConverterMercatorOnSphere.Create(VRadiusA);
  52. end;
  53. 53004: begin
  54. VRadiusA := 6371000;
  55. Result := TCoordConverterMercatorOnSphere.Create(VRadiusA);
  56. end;
  57. CYandexProjectionEPSG: begin
  58. VRadiusA := 6378137;
  59. VRadiusB := 6356752;
  60. Result := TCoordConverterMercatorOnEllipsoid.Create(VRadiusA, VRadiusB);
  61. end;
  62. CGELonLatProjectionEPSG: begin
  63. VRadiusA := 6378137;
  64. VRadiusB := 6356752;
  65. Result := TCoordConverterSimpleLonLat.Create(VRadiusA, VRadiusB);
  66. end;
  67. else
  68. raise Exception.CreateFmt(SAS_ERR_MapProjectionUnexpectedType, [IntToStr(AProjectionEPSG)]);
  69. end;
  70. end else begin
  71. raise Exception.Create('Неизвестный тип разделения карты на тайлы');
  72. end;
  73. end;
  74. function TCoordConverterFactorySimple.GetCoordConverterByConfig(
  75. AConfig: IConfigDataProvider): ICoordConverter;
  76. var
  77. VProjection: byte;
  78. VRadiusA: Double;
  79. VRadiusB: Double;
  80. VEPSG: Integer;
  81. VTileSplitCode: Integer;
  82. begin
  83. VTileSplitCode := CTileSplitQuadrate256x256;
  84. VEPSG := 0;
  85. VProjection := 1;
  86. VRadiusA := 6378137;
  87. VRadiusB := VRadiusA;
  88. if AConfig <> nil then begin
  89. VEPSG := AConfig.ReadInteger('EPSG', VEPSG);
  90. VProjection := AConfig.ReadInteger('projection', VProjection);
  91. VRadiusA := AConfig.ReadFloat('sradiusa', VRadiusA);
  92. VRadiusB := AConfig.ReadFloat('sradiusb', VRadiusA);
  93. end;
  94. if VEPSG <> 0 then begin
  95. try
  96. Result := GetCoordConverterByCode(VEPSG, VTileSplitCode);
  97. except
  98. Result := nil;
  99. end;
  100. end;
  101. if Result = nil then begin
  102. case VProjection of
  103. 1: Result := TCoordConverterMercatorOnSphere.Create(VRadiusA);
  104. 2: Result := TCoordConverterMercatorOnEllipsoid.Create(VRadiusA, VRadiusB);
  105. 3: Result := TCoordConverterSimpleLonLat.Create(VRadiusA, VRadiusB);
  106. else
  107. raise Exception.CreateFmt(SAS_ERR_MapProjectionUnexpectedType, [IntToStr(VProjection)]);
  108. end;
  109. end;
  110. end;
  111. end.