ขอให้สังเกตว่าไลบรารี "Core" ที่มี API API และรหัสทั่วไปถูกปล่อยออกมาพร้อมกับใบอนุญาต MIT
อย่างไรก็ตามไลบรารีการใช้งานอะแดปเตอร์ได้รับอนุญาตในลักษณะเดียวกับไลบรารีที่ดัดแปลงซึ่งระบุไว้ในไฟล์ "license_notice" แยกต่างหาก (ในไดเรกทอรีฐานอะแดปเตอร์) สำหรับการใช้งานแต่ละครั้ง
โครงการ N#/C#/. นี้มีไว้สำหรับการแปลงพิกัดระหว่างระบบอ้างอิงพิกัดที่แตกต่างกัน (CRS)
อะแดปเตอร์กำลังใช้ไลบรารี. NET ส่วนที่สามเป็น Adaptee's
รหัสได้ถูกนำไปใช้กับ F# แต่การทดสอบ (และค่าคงที่ที่สร้างขึ้นในโครงการย่อย "programerAre.crStransformations.constants") ถูกนำมาใช้กับ C#
เวอร์ชันเหล่านี้ด้านล่างนี้ใช้กับ v3.0.0 ของ NuGet release เช่น programmerare.crstransformations.core:
รุ่นเป้าหมาย. NET คือ. NET Standard 2.0 (เช่น. NET Framework 4.6.1 หรือใหม่กว่า) แต่เวอร์ชัน 10.36 ของไลบรารีที่มีค่าคงที่ (ProgramerAre.CrStransformations.Constants) สามารถใช้กับ. NET Framework 2.0 หรือใหม่กว่า
เวอร์ชัน F# คือ 6.0.1 (เช่นสำหรับการอ้างอิงแพ็คเกจเป็น "fsharp.core")
ห้าไลบรารีต่อไปนี้จากโครงการรหัสนี้ได้รับการเผยแพร่/แจกจ่ายให้กับ NuGet:
สามไลบรารีด้านบนซึ่งรวมถึง " อะแดปเตอร์ " ในชื่อคือการใช้อะแดปเตอร์ของไลบรารี " Core " ข้างต้น
อะแดปเตอร์ทั้งสามนั้นใช้ไลบรารี Adaptee ทั้งสามสำหรับการแปลงพิกัด
ห้องสมุด ' Mightylittlegeodesy ' ข้างต้นมีประโยชน์สำหรับการเปลี่ยนแปลงระหว่าง WGS84 (ซึ่งเป็น CRS ทั่วโลกที่พบบ่อยมาก) และระบบอ้างอิงพิกัดพิกัดสวีเดน (CRS) Sweref99 (13 เวอร์ชันเช่น "Sweref99 TM") และ RT90 (6 เวอร์ชันเช่น "RT90 2.5 GON V")
ไลบรารีข้างต้น "programmerare.CRSTRANSFORMATIONS. ค่าคงที่ " จริง ๆ แล้วเป็นอิสระจากคนอื่น ๆ
มันไม่ได้ขึ้นอยู่กับสิ่งใดและไม่มีอะไรขึ้นอยู่กับมัน
มันเป็นไลบรารี C# (เช่นไม่ได้ขึ้นอยู่กับ F# เหมือนคนอื่น ๆ ) ด้วยคลาสเดียวที่มีค่าคงที่ C# จำนวนมาก
(ห้องสมุดแกน/อะแดปเตอร์อีกสี่ตัวถูกนำไปใช้กับ F#)
คลาส C# คงที่ถูกสร้างขึ้นจากชุดข้อมูล EPSG เวอร์ชัน 10.036 ซึ่งเป็นเหตุผลสำหรับหมายเลขเวอร์ชัน
ไม่จำเป็นต้องรวมไลบรารี "Core" เนื่องจากมีการพึ่งพาโดยนัย/สกรรมกริยาจากไลบรารี "อะแดปเตอร์" ทั้งหมดไปยัง "แกน"
ไม่จำเป็นต้องใช้ไลบรารี "ค่าคงที่" แต่อาจน่าสนใจหากคุณต้องการใช้ค่าคงที่สำหรับหมายเลข EPSG แทนที่จะใช้การเข้ารหัสด้วยตัวอักษรจำนวนเต็มหรือกำหนดค่าคงที่จำนวนเต็มของคุณเอง
<!-- Use one, two or three of the below three Adapters -->
< PackageReference Include = " Programmerare.CrsTransformations.Adapter.DotSpatial " Version = " 3.0.0 " />
< PackageReference Include = " Programmerare.CrsTransformations.Adapter.ProjNet " Version = " 3.0.0 " />
< PackageReference Include = " Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy " Version = " 3.0.0 " />
<!-- The Core should not be necessary to include explicitly as below (since it should be implicitly included when using one of the others above ) -->
< PackageReference Include = " Programmerare.CrsTransformations.Core " Version = " 3.0.0 " />
<!-- Optional (and totally independent) library with only one class with lots of integer constants -->
< PackageReference Include = " Programmerare.CrsTransformations.Constants " Version = " 10.36.0 " />ห้องสมุดข้างต้นสามารถดูได้ที่หน้า NuGet ของฉัน
รหัส (IE Core และ Adapter Libraries) ได้ถูกนำไปใช้กับ F# แต่รหัสทดสอบเขียนด้วย C# ใน "ProgramerAre.crStransformations.test"
นอกจากนี้ยังมีตัวอย่างโครงการรหัสสำหรับสามภาษา. NET C#, F# และ VB.NET
โครงการทั้งสามนี้ใช้รหัสชนิดเดียวกัน (เช่นทำสิ่งเดียวกัน) แต่มีไวยากรณ์ที่แตกต่างกันสำหรับภาษาที่แตกต่างกัน
นอกเหนือจากรหัส C# ที่กล่าวถึงข้างต้น (เช่นโครงการทดสอบ C# และโครงการตัวอย่าง C# NUGET) หน้า GitHub นี้ด้านล่างนี้ยังแสดงวิธีการใช้ไลบรารีด้วยรหัส C#
วิธีการแปลงพิกัดถูกกำหนดในอินเตอร์เฟส icrstransformationAdapter
ขณะนี้มีเจ็ดคลาสที่ใช้อินเทอร์เฟซ สาม 'Leafs' และสี่ 'คอมโพสิต'
อะแดปเตอร์ Leaf แต่ละตัวใช้ไลบรารี Adaptee สำหรับการใช้งาน
'คอมโพสิต' ทั้งสี่กำลังใช้ Leafs เช่นนี้:
อีกสองประเภทหลักคือ CRSIdentifier และ CRSCoordinate ทั้งสองอย่างนี้แสดงไว้ในส่วนด้านล่าง
using System . Collections . Generic ; // IList
using Programmerare . CrsTransformations ; // ICrsTransformationAdapter
using Programmerare . CrsTransformations . CompositeTransformations ; // CrsTransformationAdapterCompositeFactory
using Programmerare . CrsTransformations . Adapter . DotSpatial ;
using Programmerare . CrsTransformations . Adapter . ProjNet ;
using Programmerare . CrsTransformations . Adapter . MightyLittleGeodesy ;
// ...
// The interface with seven implementations as illustrated below
ICrsTransformationAdapter crsTransformationAdapter ;
// The interface is defined in the library "Programmerare.CrsTransformations.Core" with this full name:
// Programmerare.CrsTransformations.ICrsTransformationAdapter
// The three 'Leaf' implementations:
// Library "Programmerare.CrsTransformations.Adapter.DotSpatial", class:
// Programmerare.CrsTransformations.Adapter.DotSpatial.CrsTransformationAdapterDotSpatial
crsTransformationAdapter = new CrsTransformationAdapterDotSpatial ( ) ;
// Library "Programmerare.CrsTransformations.Adapter.ProjNet", class:
// Programmerare.CrsTransformations.Adapter.ProjNet.CrsTransformationAdapterProjNet
crsTransformationAdapter = new CrsTransformationAdapterProjNet ( ) ;
// Library "Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy", class:
// Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy.CrsTransformationAdapterMightyLittleGeodesy
crsTransformationAdapter = new CrsTransformationAdapterMightyLittleGeodesy ( ) ;
// - - - - - - - - - - - -
// The four 'Composite' implementations below are all located in the library
// "Programmerare.CrsTransformations.Core" and the factory class is:
// Programmerare.CrsTransformations.CompositeTransformations.CrsTransformationAdapterCompositeFactory
var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory . Create ( ) ;
crsTransformationAdapter = crsTransformationAdapterCompositeFactory . CreateCrsTransformationMedian ( ) ;
crsTransformationAdapter = crsTransformationAdapterCompositeFactory . CreateCrsTransformationAverage ( ) ;
crsTransformationAdapter = crsTransformationAdapterCompositeFactory . CreateCrsTransformationFirstSuccess ( ) ;
// All of the above three factory methods without any parameter will try to use as many of
// the three (currently) 'leaf' implementations as are available in runtime
// (e.g. are included as NuGet dependencies).
// If you want to specify explicitly which ones to be used, you can provide
// a parameter 'IList<ICrsTransformationAdapter>' to the Create method like this:
crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory . Create (
new List < ICrsTransformationAdapter > {
new CrsTransformationAdapterDotSpatial ( ) ,
new CrsTransformationAdapterProjNet ( ) ,
new CrsTransformationAdapterMightyLittleGeodesy ( ) ,
}
) ;
// The fourth 'Composite' below does not use any implicit implementations
// but if you want to use a result created as a weighted average then the weights need
// to be specified explicitly per leaf implementation as in the example below.
var weightFactory = CrsTransformationAdapterWeightFactory . Create ( ) ;
crsTransformationAdapter = crsTransformationAdapterCompositeFactory . CreateCrsTransformationWeightedAverage (
new List < CrsTransformationAdapterWeight > {
weightFactory . CreateFromInstance ( new CrsTransformationAdapterDotSpatial ( ) , 1.0 ) ,
weightFactory . CreateFromInstance ( new CrsTransformationAdapterProjNet ( ) , 1.0 ) ,
weightFactory . CreateFromInstance ( new CrsTransformationAdapterMightyLittleGeodesy ( ) , 2.0 ) ,
}
) ;
// The weight values above illustrates a situation where you (for some reason) want to consider
// the transformation results from 'MightyLittleGeodesy' as being 'two times better' than the others.วิธีการแปลงทั้งหมด (กำหนดไว้ในอินเตอร์เฟสด้านบน ICRStransformationAdapter ) ต้องการพารามิเตอร์สองตัวพิกัดอินพุตหนึ่งตัวและหนึ่งพารามิเตอร์ที่ระบุระบบเป้าหมายเช่นระบบอ้างอิงพิกัดที่ประสานงานอินพุตจะถูกแปลงเป็น
ระบบเป้าหมายสามารถระบุได้ด้วยสามประเภทข้อมูล (เช่นด้วยวิธีการโอเวอร์โหลด) ไม่ว่าจะเป็นจำนวนเต็มหรือสตริงหรือ 'CRSIdentifier'
หากใช้จำนวนเต็มหรือสตริงจะมีการสร้าง 'crsidentifier' ภายในเพื่อส่งเป็นพารามิเตอร์ไปยังการใช้งานอะแดปเตอร์
ดังนั้นหากคุณตั้งใจจะทำการเปลี่ยนแปลงมากมายจากหรือไปยังระบบอ้างอิงพิกัดคุณอาจเลือกที่จะสร้าง crsidentifier ด้วยตัวคุณเอง แต่เพื่อความสะดวกมากขึ้นคุณอาจต้องการใช้วิธีการโอเวอร์โหลดกับจำนวนเต็มเป็นพารามิเตอร์
พิกัด (ประเภท CRSCOORMANT) รวมถึงข้อมูลเกี่ยวกับระบบอ้างอิงพิกัดเช่น 'CRSIdentIfier' แต่ยังมีวิธีการจากโรงงาน (การสร้างอินสแตนซ์พิกัด) ซึ่งเกินพิกัดด้วยพารามิเตอร์จำนวนเต็มหรือสตริง
มีวิธีการจากโรงงานมากมายที่มีชื่อที่แตกต่างกันและลำดับที่แตกต่างกันสำหรับค่าตำแหน่งสอง (x/y) ตามที่ไม่เหมาะสมในตัวอย่างด้านล่าง
ขึ้นอยู่กับความหมายที่ต้องการในบริบทของคุณ คุณ อาจต้องการใช้วิธีการที่แตกต่าง
using Programmerare . CrsTransformations . Identifier ; // CrsIdentifier
using Programmerare . CrsTransformations . Coordinate ; // CrsCoordinate
using static Programmerare . CrsTransformations . Coordinate . CrsCoordinateFactory ;
// The above row with "using static" enables many factory methods:
// LatLon , LonLat , YX , XY , ... and so on (see the example code below)
// ...
int epsgNumber = 4326 ;
string crsCode = "EPSG:" + epsgNumber ;
CrsIdentifier crsIdentifier ; // namespace Programmerare.CrsTransformations.Identifier
crsIdentifier = CrsIdentifierFactory . CreateFromEpsgNumber ( epsgNumber ) ;
// Alternative:
crsIdentifier = CrsIdentifierFactory . CreateFromCrsCode ( crsCode ) ;
double latitude = 59.330231 ;
double longitude = 18.059196 ;
CrsCoordinate crsCoordinate ; // namespace Programmerare.CrsTransformations.Coordinate
// All the below methods are alternatives for creating the same coordinate
// with the above latitude/longitude and coordinate reference system.
// No class or object is used for the methods below because of the following static import:
// using static Programmerare.CrsTransformations.Coordinate.CrsCoordinateFactory;
crsCoordinate = LatLon ( latitude , longitude , epsgNumber ) ;
crsCoordinate = LatLon ( latitude , longitude , crsCode ) ;
crsCoordinate = LatLon ( latitude , longitude , crsIdentifier ) ;
crsCoordinate = LonLat ( longitude , latitude , epsgNumber ) ;
crsCoordinate = LonLat ( longitude , latitude , crsCode ) ;
crsCoordinate = LonLat ( longitude , latitude , crsIdentifier ) ;
crsCoordinate = YX ( latitude , longitude , epsgNumber ) ;
crsCoordinate = YX ( latitude , longitude , crsCode ) ;
crsCoordinate = YX ( latitude , longitude , crsIdentifier ) ;
crsCoordinate = XY ( longitude , latitude , epsgNumber ) ;
crsCoordinate = XY ( longitude , latitude , crsCode ) ;
crsCoordinate = XY ( longitude , latitude , crsIdentifier ) ;
crsCoordinate = NorthingEasting ( latitude , longitude , epsgNumber ) ;
crsCoordinate = NorthingEasting ( latitude , longitude , crsCode ) ;
crsCoordinate = NorthingEasting ( latitude , longitude , crsIdentifier ) ;
crsCoordinate = EastingNorthing ( longitude , latitude , epsgNumber ) ;
crsCoordinate = EastingNorthing ( longitude , latitude , crsCode ) ;
crsCoordinate = EastingNorthing ( longitude , latitude , crsIdentifier ) ;
crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude ( latitude , longitude , epsgNumber ) ;
crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude ( latitude , longitude , crsCode ) ;
crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude ( latitude , longitude , crsIdentifier ) ;
crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude ( longitude , latitude , epsgNumber ) ;
crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude ( longitude , latitude , crsCode ) ;
crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude ( longitude , latitude , crsIdentifier ) ;
CrsIdentifier targetCrs = CrsIdentifierFactory . CreateFromEpsgNumber ( 3006 ) ;
ICrsTransformationAdapter crsTransformationAdapter = CrsTransformationAdapterCompositeFactory . Create ( ) . CreateCrsTransformationAverage ( ) ;
CrsTransformationResult crsTransformationResult = crsTransformationAdapter . Transform ( crsCoordinate , targetCrs ) ;
// see more example code further down in this webpage ด้านล่างเป็นรหัสตัวอย่าง C# ขนาดเล็กที่ทำงานกับเวอร์ชันปัจจุบัน 1.0.0
รหัสตัวอย่างแปลงพิกัดจาก CRS Global WGS84 (รหัส EPSG 4326) ละติจูด/ลองจิจูดไปยัง CRS SWEREF99TM ของสวีเดน (รหัส EPSG 3006)
using Programmerare . CrsTransformations ;
using Programmerare . CrsTransformations . Coordinate ;
using Programmerare . CrsTransformations . CompositeTransformations ;
using System ; // Console
class SmallCSharpeExample {
static void Main ( string [ ] args ) {
int epsgWgs84 = 4326 ;
int epsgSweRef = 3006 ;
// alternative to the above two hardcodings: use the library "Programmerare.CrsTransformations.Constants"
// and constants EpsgNumber.WORLD__WGS_84__4326 and EpsgNumber.SWEDEN__SWEREF99_TM__3006
// from the class Programmerare.CrsConstants.ConstantsByAreaNameNumber.v9_5_4.EpsgNumber
CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory . LatLon ( 59.330231 , 18.059196 , epsgWgs84 ) ;
ICrsTransformationAdapter crsTransformationAdapter = CrsTransformationAdapterCompositeFactory . Create ( ) . CreateCrsTransformationMedian ( ) ;
// If the NuGet configuration includes all (currently three) adapter implementations, then the
// above created 'Composite' implementation will below use all three 'leaf' implementations
// and return a coordinate with a median longitude and a median latitude
CrsTransformationResult centralStockholmResultSweRef = crsTransformationAdapter . Transform ( centralStockholmWgs84 , epsgSweRef ) ;
if ( centralStockholmResultSweRef . IsSuccess ) {
Console . WriteLine ( centralStockholmResultSweRef . OutputCoordinate ) ;
// Console output from the above code row:
// CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
}
}
} using Programmerare . CrsConstants . ConstantsByAreaNameNumber . v10_036 ;
using Programmerare . CrsTransformations ;
using Programmerare . CrsTransformations . CompositeTransformations ;
using Programmerare . CrsTransformations . Coordinate ;
using System ;
using System . Collections . Generic ;
.. .
// Some terminology regarding the names used in the below code example:
// "CRS" = Coordinate Reference System
// "WGS84" is the most frequently used coordinate system (e.g. the coordinates usually used in a GPS)
// "SWEREF99TM" is the official coordinate system used by authorities in Sweden
// "EPSG" = "European Petroleum Survey Group" was (but the EPSG name is still often used)
// an organization defining CRS with integer numbers e.g. 4326 for WGS84 or 3006 for SWEREF99TM
int epsgWgs84 = EpsgNumber . WORLD__WGS_84__4326 ;
int epsgSweRef = EpsgNumber . SWEDEN__SWEREF99_TM__3006 ;
// The above "EpsgNumber" class with LOTS OF constants (and more constants classes) have been generated,
// using "FreeMarker" and database downloaded from EPSG ( http://www.epsg.org or http://www.epsg-registry.org )
// from "crs-transformation-code-generation" in the project https://github.com/TomasJohansson/crsTransformations
CrsCoordinate centralStockholmWgs84 = CrsCoordinateFactory . LatLon ( 59.330231 , 18.059196 , epsgWgs84 ) ;
// https://kartor.eniro.se/m/03Yxp
// SWEREF99TM coordinates (for WGS84 59.330231, 18.059196)
// according to Eniro (above URL): 6580822, 674032 (northing, easting)
ICrsTransformationAdapter crsTransformationAdapter ; // interface with concrete "leaf" implementation or "composite" implementations
// This code example is using a "composite" which will use multiple libraries to do the same transformation and then
// return a coordinate with the median values (median of the northing values and median of the easting values)
crsTransformationAdapter = CrsTransformationAdapterCompositeFactory . Create ( ) . CreateCrsTransformationMedian ( ) ;
// The above factory will try to use those known objects which implements the interface i.e. the number
// of "leaf" objects will depend on how many you included as for example NuGet dependencies (three in the above NuGet example)
Console . WriteLine ( "Number of 'leafs' : " + crsTransformationAdapter . TransformationAdapterChildren . Count ) ;
// Console output from the above row:
// Number of 'leafs' : 3
// Transform the WGS84 coordinate to a SWEREF99TM coordinate:
CrsCoordinate centralStockholmSweRef = crsTransformationAdapter . TransformToCoordinate ( centralStockholmWgs84 , epsgSweRef ) ;
Console . WriteLine ( "Median Composite Northing: " + centralStockholmSweRef . Northing ) ;
Console . WriteLine ( "Median Composite Easting: " + centralStockholmSweRef . Easting ) ;
// Console output from the above two rows:
// Median Composite Northing: 6580821.99121561
// Median Composite Easting: 674032.357177155
// (and these can be compared with the 'Eniro' values above i.e. '6580822, 674032 (northing, easting)' )
// The coordinate class provides four properties with different names for the same east-west value and
// four properties for the same name each north-south value, as below:
// Four EQUIVALENT properties: Easting , X , Longitude , XEastingLongitude
// Four EQUIVALENT properties: Northing , Y , Latitude , YNorthingLatitude
// Regarding the above alternative methods, depending on the desired semantic in your context, you may want to use:
// X/Y for a geocentric or cartesian system
// Longitude/Latitude for a geodetic or geographic system
// Easting/Northing for a cartographic or projected system
// xEastingLongitude/yNorthingLatitude for general code handling different types of system
// If you want more details for the result you can use the following 'Transform' method:
// (instead of the method 'TransformToCoordinate' used above)
CrsTransformationResult centralStockholmResultSweRef = crsTransformationAdapter . Transform ( centralStockholmWgs84 , epsgSweRef ) ;
if ( ! centralStockholmResultSweRef . IsSuccess ) {
Console . WriteLine ( "No coordinate result" ) ;
}
else {
if ( centralStockholmResultSweRef . IsReliable (
2 , // minimumNumberOfSuccesfulResults
0.01 // maxDeltaValueForXLongitudeAndYLatitude
) ) {
// at least 2 succesful results and the maximal difference in northing or easting is less than 0.01
// (and if you want to know the exact difference you can find it in this code example further down the page)
Console . WriteLine ( "Reliable result" ) ; // according to your chosen parameters to the method 'isReliable'
}
else {
Console . WriteLine ( "Not reliable result" ) ;
}
Console . WriteLine ( centralStockholmResultSweRef . OutputCoordinate ) ;
// Console output from the above code row:
// CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
// When your code is in a context where you only have the result (but not the adapter object)
// (e.g. in a method receiving the result as a parameter)
// you can get back the object which created the result as below:
ICrsTransformationAdapter crsTransformationAdapterResultSource = centralStockholmResultSweRef . CrsTransformationAdapterResultSource ;
CrsTransformationAdapteeType adapteeType = crsTransformationAdapterResultSource . AdapteeType ;
Console . WriteLine ( "adapteeType: " + adapteeType ) ; // console output: COMPOSITE_MEDIAN
// The above code row returned an enum which is not really a true adaptee just like the 'composite' is not a true adapter.
// However, when iterating (as below) the "leaf" results,
// it might be more interesting to keep track of from where the different values originated
IList < CrsTransformationResult > transformationResultChildren = centralStockholmResultSweRef . TransformationResultChildren ;
foreach ( CrsTransformationResult crsTransformationResultLeaf in transformationResultChildren ) {
if ( ! crsTransformationResultLeaf . IsSuccess ) continue ; // continue with the next 'leaf'
ICrsTransformationAdapter resultAdapter = crsTransformationResultLeaf . CrsTransformationAdapterResultSource ;
Console . WriteLine ( resultAdapter . AdapteeType ) ;
// The above code row will output rows like this:
// "LEAF_PROJ_NET_4_GEO_API_1_4_1" or "LEAF_MIGHTY_LITTLE_GEODESY_1_0_1" and so on
if ( ! crsTransformationResultLeaf . IsReliable (
2 , // minimumNumberOfSuccesfulResults
1000 // maxDeltaValueForXLongitudeAndYLatitude
) ) {
// The above constraint "at least 2 implementations" will always fail because now we are dealing with "leafs"
// The above delta value constraint has very high tolerance but it does not matter since
// the constraint about the number of implementations will fail
Console . WriteLine ( "Only 'composites' can have more than one result and this is a 'leaf' and thus does not have at least two results" ) ;
}
Console . WriteLine ( "Adapter long name: " + resultAdapter . LongNameOfImplementation ) ; // full class name including package
Console . WriteLine ( "Adapter short name: " + resultAdapter . ShortNameOfImplementation ) ; // class name suffix i.e. the unique part
// The above "long" names will be for example:
// Programmerare.CrsTransformations.Adapter.DotSpatial.CrsTransformationAdapterDotSpatial
// Programmerare.CrsTransformations.Adapter.MightyLittleGeodesy.CrsTransformationAdapterMightyLittleGeodesy
// The above "short" names will be for example:
// DotSpatial
// MightyLittleGeodesy
Console . WriteLine ( "adaptee: " + resultAdapter . AdapteeType ) ;
// The above row will output for example:
// LEAF_DOT_SPATIAL_2_0_0_RC1
// LEAF_MIGHTY_LITTLE_GEODESY_1_0_1
// (note that the version number is included for the adaptees)
Console . WriteLine ( "isComposite: " + resultAdapter . IsComposite ) ; // "False" since we are iterating "leaf" results
Console . WriteLine ( "Coordinate result for " + resultAdapter . AdapteeType + " : " + crsTransformationResultLeaf . OutputCoordinate ) ;
// The above row will output these rows when doing the iteration:
// Coordinate result for LEAF_DOT_SPATIAL_2_0_0_RC1 : CrsCoordinate(xEastingLongitude=674032.357322213, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
// Coordinate result for LEAF_PROJ_NET_4_GEO_API_1_4_1 : CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99437121, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
// Coordinate result for LEAF_MIGHTY_LITTLE_GEODESY_1_0_1 : CrsCoordinate(xEastingLongitude=674032.357, yNorthingLatitude=6580821.991, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
// Note that the median value for "x" is 674032.357177155 for the above
// three values 674032.357 , 674032.357177155 , 674032.357322213 .
// That is the same value as was displayed before the iteration of the children/leafs for the median composite.
// The same applies for the above "y" i.e. the median is 6580821.99121561
// for the three y values 6580821.991 , 6580821.99121561 , 6580821.99437121
}
// The result object also provides convenience methods for the results (which you of course otherwise might calculate by iterating the above results)
CrsTransformationResultStatistic crsTransformationResultStatistic = centralStockholmResultSweRef . CrsTransformationResultStatistic ;
// Note that the initially created composite was a "median composite" returning the median as the main value,
// but you can also create an average composite and regardless you can access both the median and the average with the aggregated statistics object:
Console . WriteLine ( "average coordinate: " + crsTransformationResultStatistic . CoordinateAverage ) ;
Console . WriteLine ( "median coordinate: " + crsTransformationResultStatistic . CoordinateMedian ) ;
// Console output from the above two rows:
// average coordinate: CrsCoordinate(xEastingLongitude=674032.357166456, yNorthingLatitude=6580821.99219561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
// median coordinate: CrsCoordinate(xEastingLongitude=674032.357177155, yNorthingLatitude=6580821.99121561, crsIdentifier=CrsIdentifier(crsCode='EPSG:3006', isEpsgCode=True, epsgNumber=3006))
Console . WriteLine ( "MaxDifferenceForXEastingLongitude: " + crsTransformationResultStatistic . MaxDifferenceForXEastingLongitude ) ;
Console . WriteLine ( "MaxDifferenceForYNorthingLatitude: " + crsTransformationResultStatistic . MaxDifferenceForYNorthingLatitude ) ;
// Output from the above two rows:
// MaxDifferenceForXEastingLongitude: 0.000322213280014694
// MaxDifferenceForYNorthingLatitude: 0.00337121076881886
// As you can see in the above iteration, the min and max x values are 674032.357 and 674032.357322213 (and the difference is 0.000322213).
// Similarly the min and max y values are 6580821.991 and 6580821.99437121 (and the difference is 0.00337121).
// The above two "MaxDifference" methods are used within the implementation of the convenience method 'isReliable'
// (also illustrated in this example further above)
}เวอร์ชัน 3.0.0 เพิ่มการสนับสนุนสำหรับ WKT-CRS แต่โปรดทราบว่าสตริง WKT-CRS ถูกส่งต่อไปยังการใช้งานโดยไม่พยายามคิดว่าสตริงที่ให้คือ "WKT OGC" หรือ "WKT ESRI"
ตัวอย่างโค้ดโดยใช้อะแดปเตอร์คอมโพสิต (พร้อมการใช้งาน Leaf Dotspatial และ Projnet):
crstransformationadaptercompositewkttest.cs
ค่าคงที่จำนวนเต็มถูกสร้างขึ้นโดยใช้ฐานข้อมูล EPSG
และ Java Library Freemarker ใน "crs-transformation-code-generation" ในโครงการ https://github.com/tomasjohansson/crstransformations
ค่าคงที่แต่ละค่าใช้สำหรับการกำหนดระบบอ้างอิงพิกัด (CRS)
ชื่อของค่าคงที่คือการเชื่อมต่อของสามส่วนต่อไปนี้:
โปรดทราบว่าภาพหน้าจอและข้อความด้านล่างในส่วนนี้มีไว้สำหรับรุ่นเก่า 9.5.4 แต่ ตอนนี้มีเวอร์ชันในภายหลัง คุณสามารถค้นหาเวอร์ชันล่าสุดของ 'programerare.crstransformations.constants' ในที่เก็บ Nuget
ตัวอย่างผลลัพธ์ SQL เมื่อเลือกสามคอลัมน์ด้านบน:
สามส่วนข้างต้นถูกต่อกัน (ตามลำดับข้างต้นเช่น Areaname+crsname+epsgnumber) โดยมีสองขีด จำกัด เป็นตัวคั่นระหว่างชิ้นส่วน
ช่องว่างและอักขระพิเศษอื่น ๆ จะถูกแทนที่ด้วยขีดเส้นใต้
ชื่อคงที่จะถูกเพิ่มขึ้นตามที่แสดงไว้ด้านล่าง
ภาพหน้าจอจาก Visual Studio 2017 เมื่อใช้ Intellisense/Autocompletion กับ Class EPSGNUMBER: 

ตัวอย่างเพิ่มเติมของชื่อคงที่ใน c# programmerare.crsconstants.constantsbyareanamenumber.v9_5_4.epsgnumber:
(และคุณสามารถเปรียบเทียบชื่อคงที่เหล่านี้ด้านล่างกับคอลัมน์ผลลัพธ์สามคอลัมน์จากภาพหน้าจอ SQL ด้านบน)
WORLD__WGS_84__4326
WORLD__85_S_TO_85_N__WGS_84__PSEUDO_MERCATOR__3857
NORTH_AMERICA__NAD83__NAD83__4269
USA__US_NATIONAL_ATLAS_EQUAL_AREA__2163
CANADA__NAD83__CANADA_ATLAS_LAMBERT__3978
UK__GREAT_BRITAIN_MAINLAND_ONSHORE__OSGB_1936__BRITISH_NATIONAL_GRID__ODN_HEIGHT__7405
IRELAND__ONSHORE__TM65__IRISH_GRID__29902
AUSTRALIA__GDA__GDA94__4283
NEW_ZEALAND__ONSHORE__NZGD49__NEW_ZEALAND_MAP_GRID__27200
SWEDEN__SWEREF99_TM__3006
FINLAND__19_5_E_TO_20_5_E_ONSHORE_NOMINAL__ETRS89__GK20FIN__3874
DENMARK__ONSHORE_BORNHOLM__ETRS89__KP2000_BORNHOLM__2198
NORWAY__ONSHORE__NGO_1948__OSLO__4817
ICELAND__ONSHORE__REYKJAVIK_1900__4657
NETHERLANDS__ONSHORE__AMERSFOORT__RD_NEW__28992
BELGIUM__ONSHORE__BELGE_1972__BELGIAN_LAMBERT_72__31370
GERMANY__WEST_GERMANY__10_5_E_TO_13_5_E__DHDN__3_DEGREE_GAUSS_KRUGER_ZONE_4__31468
AUSTRIA__ETRS89__AUSTRIA_LAMBERT__3416
EUROPE__LIECHTENSTEIN_AND_SWITZERLAND__CH1903__LV03__21781 ตัวอย่างข้างต้นที่มีค่าคงที่แสดงน้อยมาก
มีค่าคงที่หลายพันค่าในชั้นเรียนที่สร้างขึ้น
จำนวนค่าคงที่จริง (สำหรับรุ่นของคลาสค่าคงที่ที่คุณใช้) สามารถเรียกคืนได้อย่างง่ายดายด้วย c# code 'typeof (epsgnumber) .getfields (). ความยาว'
หมายเลขเดียวกันสามารถตรวจสอบได้ด้วยค่าที่ส่งคืนโดยคำสั่ง SQL 'เลือกจำนวน (coord_ref_sys_code) ที่แตกต่างจาก epsg_coordinatereferencesystem' (หรือเพียงแค่ 'เลือกจำนวน (*) จาก epsg_coordinatereferencesy ระบบ' ตั้งแต่ 'coord_ref_sys_code' เป็นกุญแจหลัก)