0

I am trying to set a default output name for a shp. file. For this I am to pass the gdbFullValue variable from inside the public class salida to the String fcName so that the output includes the activation code in the final name.

I believe it has to do with getters and setters. But I have been trying around for some time and I am not able to understand what I am missing.

   class Salida
{
    ShapefileManage _shpManageOutput;
    IFeatureClass _outpuFc;
    public String _gdbName;
    public String gdbFullName;
    public Salida(ShapefileManage shpManageOutput, ISpatialReference spatialReference, String gdbName)
    {
        this._shpManageOutput = shpManageOutput;
        this.crearCapaSalida(spatialReference, esriGeometryType.esriGeometryPoint);
        this._gdbName = gdbName;
        string gdbFullName = gdbName.Substring(gdbName.LastIndexOf("/") + 1);
    }

    private string fcName = string.Format("PositionalAccuracySamplePoints" + "_" + "{0}", gdbFullName.Substring(0, 14));
    public string returnOutputName()
    { return fcName; }

What I am getting is a NullReferenceValue or simply a gdbFullName string that is empty and therefore the final output name only includes de static part of the fcName string.

Thanks in advance

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108

2 Answers2

0

You are trying to extract the activation code from gdbFullName before it is set. Note that fcName is a private field which is initiated before your constructor is run.

Why don't you put the creation of the filename into your returnOutputName method?

fvetsch
  • 181
  • 1
  • 11
0

Thanks for your advice. The truth is that I don't think I have shown what I had to show in the post:

The public class salida is being instanciated in another class. Therefore all I had to do was to set the fcName to be calculated when instanciating the class, and not outside. I leave here the code that Works.

class Salida
{
    string _gdbName;
    ShapefileManage _shpManageOutput;
    IFeatureClass _outpuFc;
    //ISpatialReference spatialReference;


    public Salida(ShapefileManage shpManageOutput, ISpatialReference spatialReference, string gdbName)
    {
        this._gdbName = gdbName;
        this._shpManageOutput = shpManageOutput;
        crearCapaSalida(spatialReference, esriGeometryType.esriGeometryPoint);
    }

And in the other class, where the main process can be found is where I instanciate the salida class, with the actual fcName;

// Instanciamos los objetos gdbManage and shpManage
            gdbManageInput = new GeodatabaseManage(_inputGdbPath);
            shpManageOutput = new ShapefileManage(_outputPath);

            // Instanciamos la clase salida, pasandole el spatialReference del dataset.
            IFeatureDataset fd = gdbManageInput.getFeatureDataset(_featureDataset);
            ISpatialReference spatialReference = (fd as IGeoDataset).SpatialReference;
            string gdbName = _inputGdbPath.Substring(_inputGdbPath.LastIndexOf('\\') + 1);
            string last14gdbName = gdbName.Substring(0, 14);
            string nombreSalida = "PositionalAccuracyPoints_" + last14gdbName;
            salida = new Salida(shpManageOutput, spatialReference, nombreSalida);

Anyhow, thanks a lot for the help, if it where not for the comments I wouldn't have been able to orientate myself.