Click here to Skip to main content
15,892,269 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm realizeing ArcGIS webservices based on customization. I have built a webservice which is to realize one of the functions in ArcTools named FloatToRaster. My code is as belows:
[WebMethod]
public string ConversionTools_FloatToRaster(string string_inFloat, string string_outRaster)
{
    ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
    ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);

    //IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
    //IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(string_inFloat), 0);
    //IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
    //IFeatureDataset pFeatureClass = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileNameWithoutExtension(string_inFloat));
    //FloatToRaster flt = new FloatToRaster();
    //flt.in_float_file();
    ////IRasterDataset pRasterDataset = pWorkspace(System.IO.Path.GetFileNameWithoutExtension(string_inFloat));
    //public string in_float_file
    //{
    //    get{return string_inFloat;}
    //}

    String outDict = System.IO.Path.GetDirectoryName(string_inFloat);
    String outRaster = outDict + "\\" + string_outRaster;

    ESRI.ArcGIS.ConversionTools.FloatToRaster floatToRaster = new ESRI.ArcGIS.ConversionTools.FloatToRaster(string_inFloat, outRaster);//<big>The Problem Line</big>

    ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new Geoprocessor();
    ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(floatToRaster, null);

    string returnString = outRaster;
    if (results.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
    {
        returnString = "Fail Changing!";
    }
    return returnString;
}


string_inFloat is the file path of a float file.
Here is the definition of 'FloatToRaster':
C#
namespace ESRI.ArcGIS.ConversionTools
{
    //     Converts a file of binary floating-point values representing raster data
    //     to a raster dataset.
    public class FloatToRaster : IGPProcess
    {
        public FloatToRaster();
        //     Constructor that takes all required parameters for geoprocessor execution.
        //
        // parameter:
        //   in_float_file:
        //     The input floating-point binary file. The file must have a .flt extension.
        //     There must be a header file in association with the floating-point binary
        //     file, with a .hdr extension. (In, Required)
        //
        //   out_raster:
        //     The raster dataset to be created. (Out, Required)
        public FloatToRaster(object in_float_file, object out_raster);
    }




When I test the program, the Error shows as below:
VB
System.NullReferenceException: object reference is not set to an instant of an object.
   The problem is at <big>ToRaster.FloatToRaster(String string_inFloat, String string_outRaster)</big>  f:\ConversionTools\App_Code\ToRaster.cs:Line 225



The problem is the parameter string_inFloat.
It seems that the 'string_inFloat' parameter doesn't fit the FloatToRaster(object inputFloat, object outRaster) Method.
So I want to know HOW I COULD OPEN A FLOAT FILE!
Posted
Updated 28-Nov-10 0:35am
v5
Comments
Richard MacCutchan 25-Nov-10 11:44am    
Since you are using a third party component here I would suggest the best place to go for an answer is the site that supports that component.
ARopo 25-Nov-10 12:27pm    
what is your problem?

As xcorporation mentioned, though it could have been done better, change this line;
ESRI.ArcGIS.ConversionTools.FloatToRaster floatToRaster = new FloatToRaster(string_inFloat, outRaster);

to read;
ESRI.ArcGIS.ConversionTools.FloatToRaster floatToRaster = new ESRI.ArcGIS.ConversionTools.FloatToRaster(string_inFloat, outRaster);

You may find the compiler is confusing the ESRI.ArcGIS.ConversionTools.FloatToRaster class with your FloatToRaster function when you're trying to create an instance of the ESRI.ArcGIS.ConversionTools.FloatToRaster class.
 
Share this answer
 
Comments
Scarlettlee 28-Nov-10 6:21am    
It still doesn't work. The problem is the same.
Scarlettlee 28-Nov-10 6:40am    
Thank you for the suggestion. But it still doesn't work.
Hi,

public string FloatToRaster(string string_inFloat, string string_outRaster)
{
// Code Details

ESRI.ArcGIS.ConversionTools.FloatToRaster floatToRaster = new FloatToRaster(string_inFloat, outRaster);//The Problem Line

}

You are causing sh*t because your method goes into a infinite loop.

Also,
if you want "out" use something like

C#
public string FloatToRaster(string string_inFloat, out string string_outRaster)
{


Regards,
Chris
 
Share this answer
 
Comments
Scarlettlee 27-Nov-10 4:56am    
I'm sorry, this doesn't work. As I said, the problem parameter is 'string_inFloat' not 'string_outRaster', and I'm very sure that 'string_outRaster' is right.
Thank you all the same.
a string si a string - irrelevant of the field's name

using a proper naming convention will avoid headache's in the future.

fix your infinite loop.

:omg:
 
Share this answer
 
Comments
Scarlettlee 28-Nov-10 6:38am    
it isn's a loop. Sorry for my bad naming for the class which leads to misunderstanding. But when I changed the name, it still doesn't work.
Add an if else statement and write the code.


int count;// for counting if the loop is iterrates till the end of the string or not.
if(int total string lenght<=count)
{
//Your code here. By using this u can stop infinite lopping
}
else
return string//return the string.


Or .Net hase some built in string funstions like split() and all try them.
split() Method splits the sting accoring to spaces. If string contains only one word it will devide it into letters
example:- Split("ABC")== "A","B","C";;
example:- Split("My NAME IS") == "MY" , "NAME" ,"IS";;

Remeber Split() method always returns an array of strings.
HERE how to declare string[] stringarray=Split("MY NAME");
 
Share this answer
 
v5
Comments
Scarlettlee 28-Nov-10 6:39am    
it isn's a loop. Sorry for my bad naming for the class which leads to misunderstanding. But when I changed the name, it still doesn't work.
I have solved my question!
It is because when I test my service, I input a wrong parameter for 'string_outRaster'. When I correct this, the problem is gone.
Thank you all the same. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900