开发者

Precision error when transforming coordinates using proj4js

开发者 https://www.devze.com 2023-01-21 06:44 出处:网络
I am using the library Proj4js to transform coordinates. I\'m transforming coordinates from EPSG: 23029 to EPSG: 4326. The problem is that by transforming the coordinates there is some deviation from

I am using the library Proj4js to transform coordinates. I'm transforming coordinates from EPSG: 23029 to EPSG: 4326. The problem is that by transforming the coordinates there is some deviation from the precision used in the processing load. I noticed this by transforming a coordinate system from origin to destination and vice versa. The code I use to make the transformation is:

<script type="text/javascript" src="/proj4js/lib/proj4js-compressed.js"> </ script>
<script type="text/javascript" src="/proj4js/lib/projCode/merc.js"> </ script>
&l开发者_JAVA技巧t;script type="text/javascript" src="/projCode/tmerc.js"> </ script>
<script type="text/javascript" src="/proj4js/defs/EPSG23029.js"> </ script>
<script type="text/javascript" src="/proj4js/defs/EPSG4326.js"> </ script>

source = new Proj4js.Proj ('EPSG: 23029');
dest = new Proj4js.Proj (map.projection.toString ());

x = feature_selected.geometry.x;
y = feature_selected.geometry.y;

p = new Proj4js.Point (x, y);

p = Proj4js.transform (source, dest, feature_selected.geometry);

when I do the transformation in both directions, the point of origin is not the same.

 x1= -6.34378379330039
 y1=  39.48007480688388

 x2= -6.343783791584894
 y2= 39.4800748068322604

Anyone know how to solve this problem?

thanks.


You will always lose some precision when converting between projection systems. There are a number of sources of error, including limitations on floating point arithmetic in the JavaScript engine and around the reversibility of a transformation between projections.

On the other hand, where is your source data coming from? Considering that you're only losing precision at about the ninth decimal place, it is likely that your source data isn't actually that accurate to begin with (certainly not your usual GPS, or even differentially corrected), so there is not much point worrying about errors introduced in the re-projection algorithm.

EDIT: So, after some calculations - your error after two re-projections is about 1/10th of a millimetre. I highly doubt it is worth trying to improve on that for any real world application.

0

精彩评论

暂无评论...
验证码 换一张
取 消