Select to view content in your preferred language

Converting State Plane to Lat/Lng project problem

878
2
05-30-2013 06:33 AM
KevinYanuk
Deactivated User
Hello,

I am trying to take a map extent coordinates (in State Plane), and convert them to pairs of Lat/Long coordinates.  I am getting a 'wkid is null or undefined' error during the geometry service project function.

My code:

function getCoords {
    var topLeft = toLatLng(map.extent.xmin, map.extent.ymax);
    var topRight = toLatLng(map.extent.xmax, map.extent.ymax);
    var bottomRight = toLatLng(map.extent.xmax, map.extent.ymin);
    var bottomLeft = toLatLng(map.extent.xmin, map.extent.ymin);

    [...]
}

function toLatLng(x,y) {
    var pt = new esri.geometry.Point(x, y, map.SpatialReference);
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    var graphic = new esri.Graphic(pt, symbol);
    var outSR = new esri.SpatialReference({ wkid: 4326 });

    try{
        geometrySvc.project([graphic], outSR,  // this is where it fails
        function (features) {
            pt = features[0].geometry;
        });
    } catch (e) { alert(e.message); }

    var retv = pt.x + "," + pt.y + ",0";
    return (retv);
}



Any advice is much appreciated
0 Kudos
2 Replies
RobertBorchert
Honored Contributor
Do you have to do it in Javascript?

Is this only a one time deal or an ongoing process?

Hello,

I am trying to take a map extent coordinates (in State Plane), and convert them to pairs of Lat/Long coordinates.  I am getting a 'wkid is null or undefined' error during the geometry service project function.

My code:

function getCoords {
    var topLeft = toLatLng(map.extent.xmin, map.extent.ymax);
    var topRight = toLatLng(map.extent.xmax, map.extent.ymax);
    var bottomRight = toLatLng(map.extent.xmax, map.extent.ymin);
    var bottomLeft = toLatLng(map.extent.xmin, map.extent.ymin);

    [...]
}

function toLatLng(x,y) {
    var pt = new esri.geometry.Point(x, y, map.SpatialReference);
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    var graphic = new esri.Graphic(pt, symbol);
    var outSR = new esri.SpatialReference({ wkid: 4326 });

    try{
        geometrySvc.project([graphic], outSR,  // this is where it fails
        function (features) {
            pt = features[0].geometry;
        });
    } catch (e) { alert(e.message); }

    var retv = pt.x + "," + pt.y + ",0";
    return (retv);
}



Any advice is much appreciated
0 Kudos
KevinYanuk
Deactivated User
Do you have to do it in Javascript?

Is this only a one time deal or an ongoing process?


This will occur when a user will click a button in the web map.  The current state plane map extent coordinates will be converted for use in a Google Earth KML file as such:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
  <name>TestTemplate.kml</name>
  <Style id="polyStyle">
    <PolyStyle>
      <color>00000000</color>
    </PolyStyle>
  </Style>
  <Placemark>
    <name>Test Template</name>
    <styleUrl>#polyStyle</styleUrl>
    <Polygon>
      <outerBoundaryIs>
        <LinearRing>
          <coordinates>
           -72.135128,50.516577,0    <!-- TEST COORDS -->
           -72.646124,50.516424,0
           -72.648152,50.514756,0
           -72.648377,50.514901,0
          </coordinates>
        </LinearRing>
      </outerBoundaryIs>
    </Polygon>
  </Placemark>
</Document>
</kml>
0 Kudos