使用DotSpatial进行SRID投影转换遇NaN问题求助
Hey there! Let's break down why you're getting NaN values and how to fix this:
1. The Core Issue: Your Coordinate Is Outside SRID 2336's Valid Range
First, let's clarify what SRID 2336 represents: it's the CGCS2000 / 3-degree Gauss-Kruger CM 117E projection, designed exclusively for a region in eastern China (roughly longitude 115.5°E to 118.5°E, latitude 18°N to 33°N).
Your input coordinate is (-81.2578, 29.466) — that's in Florida, USA (west longitude, north latitude), which is completely outside the valid bounds of SRID 2336. Projection libraries like DotSpatial return NaN when trying to project coordinates outside the target projection's supported area, since the mathematical calculations don't apply to those locations.
2. Verify Your Target SRID
If you meant to project to a local projection for Florida (or the US), you'll need to use the correct SRID instead of 2336. For example:
- For Florida state plane, common options are SRID 2236 (NAD83 / Florida East) or SRID 3080 (NAD83(2011) / Florida East)
- For UTM, your coordinate falls in UTM Zone 17N, which uses SRID 32617 (WGS84) or SRID 26917 (NAD83)
3. Double-Check Coordinate Order in DotSpatial
While this isn't the root cause here, it's a good habit to confirm:
- For SRID 4326 (WGS84 lat/lon), DotSpatial expects the order to be Longitude (X), Latitude (Y). You mentioned swapping them already, which was a smart check, but since your coordinate is outside 2336's range, this wouldn't fix the
NaNissue.
4. Z-Value Isn't the Problem
The new[] {0d} you're passing for Z-values is totally fine. DotSpatial will either preserve the Z-value (if the projection doesn't include vertical datum conversion) or ignore it if elevation handling isn't needed. This isn't causing your NaN result.
Test with a Valid Coordinate for SRID 2336
To confirm your code works, try a coordinate within 2336's range (e.g., Guangzhou, China):
double[] xy = new[] { 117.0, 23.0 }; double[] z = new[] { 0d }; DotSpatial.Projections.Reproject.ReprojectPoints( xy, z, DotSpatial.Projections.ProjectionInfo.FromEpsgCode(4326), DotSpatial.Projections.ProjectionInfo.FromEpsgCode(2336), 0, 1 ); // You'll get valid projected coordinates here instead of NaN
内容的提问来源于stack exchange,提问作者Doug

