1

i am using proj4js 2.4.3 and programming a script to convert coordinates etrs89 to wgs84 can someone give me an opinion on whether it is correct? do not know if i am using proj4js well? I have imported the files proj4.js and proj4-src.js and estouy using it in visual studio. my script is:

 <script src="~/Scripts/proj4.js"></script>

 <script type="text/javascript">
     alert("ok!");
     convertir('723544', '4347185', '0')


     function convertir (x, y, z){
         var head1 = document.getElementsByTagName("head")[0];
         var s = document.createElement('script');
         s.type = '/text/javascript';
         s.src = '~/Scripts/proj4.js';
         head1.appendChild(s);


         Systeme1 = new proj4.Proj("EPSG:25830");      
         Systeme2 = new proj4.Proj("EPSG:4326");   Coordenadas Geográficas WGS84"
         alert("ok!");
         var Point = new proj4.toPoint('723544', '4347185', '0');
         Point =  proj4(Systeme1, Systeme2 ).forward(Point);
         alert("punto= " & Point);
         return Point;


     }
 </script>
1
  • What are the output coordinates?
    – mkennedy
    Mar 9 '18 at 19:34
1

For what it is worth I keep an array of projections available at the top of my script and add to when needed (i.e. https://epsg.io/3857 [scroll to bottom to see proj4 definition])

The the x & y is literally two numbers listed as an array.

Then fire this off:

var reprojected = proj4(projections['from'],projections['to'],[x,y]);

I cannot (will not?) comment on the merits of how you do yours for fear of annoying the reprojection gods, again! But this is an example of what actually seems to work for me. Hope it helps.

2
  • I do not know how I can use that fragment in my code, my code must pass two coordinates x, and etrs89 to x, y wgs84
    – user950489
    Mar 12 '18 at 13:31
  • <script type="text/javascript">
    – Ryan
    Mar 13 '18 at 13:59
0
<script type="text/javascript">
var projections = {
    wgs84: "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs",
    ETRS89: "+proj=utm +zone=30 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"
};
  var result = convertir('723544', '4347185');
  console.log(result);

  function convertir (x, y){ // you don't seem to use z
    var head1 = document.getElementsByTagName("head")[0];
    var s = document.createElement('script');
    s.type = '/text/javascript';
    s.src = '~/Scripts/proj4.js';
    head1.appendChild(s);

    return proj4(projections['ETRS89'],projections['wgs84'],[x,y]);
  }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.