From SpatialReference well-known ID to well-know text

2147
2
07-09-2013 12:13 AM
by Anonymous User
Not applicable
Original User: vdkamp

An input of my model (shared as geoprocessing service) requires a Coordinate System. It is used as an input for Define Projection.

This coordinate system will not be the coordinate system of the map but can be chosen by the user. At that moment the wkid is known. But Define Projection requires a wkt (PROJCS["....). When I create a SpatialReference object based on the wkid, the wkt stays empty.

How can I get the well-known text of a wkid coordinate system? Can it be done in my flex app? The manual gives a list of list of supported well-known IDs and their corresponding definition strings so it seems that this information is somewhere available.
Or should I pass the wkid to my model and create the coordinate system at the service site?


Thanks,
Albert
0 Kudos
2 Replies
IvanBespalov
Regular Contributor
Albert, you can quickly create own utility, like this:
package ee.alphagis.utils
{
public class SPUtils
{
  /**
   * @param wkid Well-known ID
   * @return spatial reference <b>Well-known Text</b> by input Well-known ID, or <b>null</b> if not found
   */
  public static function returnTextById(wkid:Number):String
  {
   var result:String = null;
   switch (wkid)
   {
    case 3819:
    {
     result = "GEOGCS[\"GCS_HD1909\",DATUM[\"D_Hungarian_Datum_1909\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]"
     break;
    }
    case 3821:
    {
     result = "GEOGCS[\"GCS_TWD_1967\",DATUM[\"D_TWD_1967\",SPHEROID[\"GRS_1967_Truncated\",6378160.0,298.25]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";
     break;
    }
     //TODO: add needed cases here
    default:
    {
     break;
    }
   }
  
   return result;
  }
 
  /**
   * @param wkid Well-known ID
   * @return spatial reference <b>name</b> by input Well-known ID, or <b>null</b> if not found
   */
  public static function returnNameById(wkid:Number):String
  {
   var result:String = null;
   switch (wkid)
   {
    case 3819:
    {
     result = "GCS_HD1909"
     break;
    }
    case 3821:
    {
     result = "GCS_TWD_1967";
     break;
    }
     //TODO: add needed cases here
    default:
    {
     break;
    }
   }
  
   return result;
  }
 
  /**
   * @param wkid Well-known ID
   * @return spatial reference <b>Well-known Text</b> by input name, or <b>null</b> if not found
   */
  public static function returnTextByName(name:String):String
  {
   var result:String = null;
   switch (name)
   {
    case "GCS_HD1909":
    {
     result = "GEOGCS[\"GCS_HD1909\",DATUM[\"D_Hungarian_Datum_1909\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]"
     break;
    }
    case "GCS_TWD_1967":
    {
     result = "GEOGCS[\"GCS_TWD_1967\",DATUM[\"D_TWD_1967\",SPHEROID[\"GRS_1967_Truncated\",6378160.0,298.25]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";
     break;
    }
     //TODO: add needed cases here
    default:
    {
     break;
    }
   }
  
   return result;
  }
}
}


it based on coordinate systems id's reference, published by ESRI team
0 Kudos
by Anonymous User
Not applicable
Original User: vdkamp

Hi Ivan,

My alternative would be to create a spatial reference well-known text myself, based on the Coordinate System IDs page. It would limit the possibilities to only a selected list of wkid's. But I hope that this information, how to get from a well-known ID to a well-know text, is somewhere available so I can use it in my software. Perhaps in the API or in a service like the Geometry Service.


Albert.
0 Kudos