Projected to Geographic co-ordinate system
IPoint iPoint = new ESRI.ArcGIS.Geometry.Point();
iPoint.X = x;
iPoint.Y = y;
ISpatialReferenceFactory pSpatRefFact = new SpatialReferenceEnvironmentClass();
ISpatialReference pGeoCoordSystem = pSpatRefFact.CreateGeographicCoordinateSystem(4269);//Nad83
// For more esriSRGeoCSType Constants see
//http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeometry/esriSRGeoCSType.htm
IGeometry2 pGeometry = iPoint as Igeometry2;
pGeometry.SpatialReference = pSpatRefFact.CreateProjectedCoordinateSystem(2278);
//For more esriSRProjCSType Constants see
//http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeometry/esriSRProjCSType.htm
pGeometry.ProjectEx(pGeoCoordSystem, esriTransformDirection.esriTransformReverse, null, false, 0, 0);
IPoint GCSPoint = pGeometry as IPoint;
double lat = GCSPoint.Y;
double lng = GCSPoint.X;
Geographic to Projected co-ordinate system
ESRI.ArcGIS.Geometry.Point point1 = new ESRI.ArcGIS.Geometry.Point();
point1.X = x;
point1.Y = y;
ISpatialReferenceFactory pSpatRefFact = new SpatialReferenceEnvironmentClass();
ISpatialReference pProjCoordSystem = pSpatRefFact.CreateProjectedCoordinateSystem(53004);
// Mercator
//For more esriSRProjCSType Constants see
//http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeometry/esriSRProjCSType.htm
//Create a geometry object and project it.
IGeometry2 pGeometry = (IGeometry2)point1;
pGeometry.SpatialReference = pSpatRefFact.CreateGeographicCoordinateSystem(4326); // WGS_1984
// For more esriSRGeoCSType Constants see
//http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeometry/esriSRGeoCSType.htm
pGeometry.ProjectEx(pProjCoordSystem, esriTransformDirection.esriTransformReverse, null, false, 0, 0);
ESRI.ArcGIS.Geometry.Point PCSPoint = pGeo as ESRI.ArcGIS.Geometry.Point;
Convert Coordinates between Geographic coordinate system and Projected coordinate system
This map service cannot use the microsoft virtual earth / google maps tiling scheme because the coordinate system does not match
How to resolve ?
a. Open your mxd in Arcmap.
b. Set the co-ordinate system of the data frame to WGS 1984 Web Mercator.
Does setting VirtualDirectory and Usemimedata= false increase the performance in ArcGIS Server ?
The answer is NO. Not only it doesn't help you increase your performance , in some of cases it will decrease the performance of the map. You all might be thinking why ? Here is how it works
When you use mime (by default Usemimedata= true), every time you load ,pan and zoom your map your mapserver will create the image in the session storage, later accessed thru webhandler .
http://webserver1/testagsapp/ESRI.ArcGIS.ADF.Web.MimeImage.ashx?ImgID=dcdcb008a0fb4257b25641d56d6d1416&CacheTime=1&kc=1
When you set virtualdirectory = "~/VirtualDir"and Usemimedata = false , every time you load ,pan and zoom your map your mapserver will create the image in virtual directory on web server, later accessed thru URL to that image
http://webserver1/testagsapp/VirtualDir/ddc5ctpz_1h5.png
Virtualdirectory doesn't implement cache mechanism means every time you navigate through map new images get created. So there is no reuse of tiles like it does in ArcGIS cache. Virtualdirectory is complete different from arcgiscache. When you request the map tile thru URL, the response time depends on web server speed and speed at which the files can be accessed in VirtualDirectory. Clearly if you have a huge big chunk of files already in your VirtualDirectory , it is very obvious that it takes considerable time to access a file in that VirtualDirectory thru URL unless you have an efficient recycling task that deletes old files in virtual directory very often. Where as with using mime the data is stored temporarily in session storage, gets deleted from the memory once the browser window is closed and you don't have to worry about any file recycling.
Lastly you can ask me what is the purpose of VirtualDirectory then ? If you are using SQL server to store session state, you don't want to fill it up with image tiles and deal with its maintainence by using mime. In this case you can use virtual directory to have images stored on file system rather than SQL server. But if you have the default in process or “InProc” session state storage for your ASP.NET application then I recommend using mime I.e Usemimedata= true and set m_Map.Virtualdirectory to nothing.
Please dont forget to leave a comment especially if you came across the same thing , a different opinion or similar experiences.
Find nearest feature (point,polyline,polygon) given a Featureclass and a Geometry using feature class index
Sometimes we have to find the nearest polyline,point or polygon in a feature class from a given feature(point,polyline or polygon). Here is how you do it.
public Object FindNearestFeature(IGeometry jGeom, IFeatureClass myInputFeatureClass)
{
int jNearestFID = 0;
double jNearestFDistance = 0.0;
IFeatureIndex2 jFeatureIndex = new FeatureIndexClass();
jFeatureIndex.FeatureClass = myInputFeatureClass;
jFeatureIndex.set_OutputSpatialReference( “Shape”,jGeom.SpatialReference);
jFeatureIndex.Index(null,null);
IIndexQuery2 jIndexQuery = (IIndexQuery)jFeatureIndex;
jIndexQuery.NearestFeature(jGeom, out jNearestFID, out jNearestFDistance);
return featureClass.GetFeature(jNearestFID).get_value(myInputFeatureClass.Fields.FindField("myfield"));
}
Notes:
a. Please remember to run Index method on IfeatureIndex2 before you run the NearestFeature method. Otherwise the NearestFeature throws exception.
b. IFeatureIndex2 Obj.Index method takes two arguments. first one for ITrackCancel which is for choosing an event to trigger the cancel event. Importantly, the second argument takes QueryingGeometryFullExtent - IEnvelope object. If you have the map extent or input feature class extent then pass it otherwise pass null. As long as your point is with in the extent of the input feature class, you should do good even though you pass null for QueryingGeometryFullExtent. If your point is not with in the input FeatureClass extent, you should pass the IEnvelope object for jGeom which is jGeom.Envelope as QueryingGeometryFullExtent otherwise IFeatureIndex2Obj.Index will run but returns -1 for Nearest Feature ID in IIndexQuery2Obj.NearestFeature method .
c. Make sure you use IfeatureIndex2Obj.set_OutputSpatialReference method to set the output spatial reference same as the spatial reference of jGeom (input query feature) .
d. jNearestFDistance gives the distance from the jGeom to the nearest feature with FID jNearestFID in myInputFeatureClass.
Server object instance creation failed on all SOC machines
Application: ESRI ArcGIS server manager 9.2, 9.3
Got Error: ‘unable to start service. Error ( server object instance creation failed on all SOC machines. Server Object instance creation failed on machine MY_MACHINE. Access to output directory is denied’

- Grant write permission for ArcGISSOC account on your ArcGIS server output directory that is used for the current map service. The Default ArcGIS Directory is installed in ‘C:\arcgisserver\arcgisoutput’ and ArcGIS server object container account is ‘ArcGISSOC’.
- After doing (a), when you restart the service sometimes it may throw RPC not available error. Please restart the computer if that is the case and you are ready to rock!
Print map in microsoft virtual earth
Until Microsoft virtual earth 6.1 came out , printing the VEMap with VEShapes on it (especially VEShapeType.Polygon, -Polyline) use to be a hell of a task. But with Virtual earth 6.1, they made it easier. I also tested it with some custom tile layers added on my VEMap and it printed them all.
function PrintMap()
{
var pOptions = new VEPrintOptions(true);
map.SetPrintOptions(pOptions);
window.print();
pOptions = new VEPrintOptions(false);
map.SetPrintOptions(pOptions);
}
Set the VEPrintOptions.EnablePrinting to false again because Virtual Earth API says that there might be a decrease in the performance with map set with VEPrintOptions.EnablePrinting = true . That is why it is set to false by default.
Tip: If you have your application in 6.0, you can implement the print functionality just by updating your map handlers address to new 6.1 (http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1). Since virtual earth 6.1 sdk is backward compatible , all your old code in 6.0 should work just fine while at the same time you can add new features exclusively available in Virtual Earth 6.1 like print etc. For more info on new features of 6.1 see this link http://dev.live.com/blogs/devlive/archive/2008/04/11/263.aspx
ESRI.ArcGIS.AnalysisTools.Intersect on Shapefile and SDE feature class
Did you every to use ESRI.ArcGIS.AnalysisTools.Intersect to perform intersection on a shape file and SDE feature class and return the output as a new shape file. I tried it but it wasn't a piece of cake for sure. if they are same type (shapefile ,shapefile ) or (SDE feature class, SDE feature class) its very easy. All you have to do is you have to pass in the multiple feature classes in a ';' delimited list (shapefile1 rank1,shapefile2 rank2), set the workspace using SetEnvironmentVariable "workspace". The problem is you can set the workspace to only one - either the folder or the sde (databaseconnections\conn) So you should be thinking already. How can you set the workspace if I've two different entities that resides on two different workspaces i.e shapefile on local file system folder and featureclass on ArcSDE. Some of the answers I found on ESRI forum are pass the full path for each feature class like "Database Connections\sdeConnectionFileName.sde\myFeatureDataset\myFeatureClass; C:\temp\MyShapefile.shp" . No luck, it throws up error invalid input . So here comes the answer for how to do it?
Instead of accessing the arcsde feature class thru workspace 'databaseconnetions/sdeconn' (arccatalogue way) I created a sde connection file (sample.sde) in the same folder where I've my shapefile using the IPropertyset dynamically and accessed the sde featureclass thru that. That way I set my workspace to a folder and was able to access my shapefile and also sde feature class thru it.
