How to get Projection Details(GCS / PCS) using file Geodtabase API.

5371
8
03-31-2015 07:28 AM
GaneshmoorthiM
New Contributor III

Hi,

I would like to get the spatial reference of the feature class using file Geodtabase API.I am using FGDB API 1.4 and C# VS 2010. I have tried to use FieldDef to get Spatial Reference but receiving null error. Please guide me. Also attaching the error message.

Untitled.jpg

string fcName = gdbFCList[2].Remove(0, 1);

                Table fcTable = _geodatabase.OpenTable(fcName);

                FieldInfo fieldInfo = fcTable.FieldInformation as FieldInfo;

FieldDef[] fieldDefs=fcTable.FieldDefs;

also tried following code

string spr = fcTable.FieldDefs[2].geometryDef.spatialReference.ToString();

8 Replies
VinceAngelo
Esri Esteemed Contributor

It's difficult to tell from your question what error was generated from what code. 

While a ToString exists on all objects, the documentation offers a SpatialReferenceText property to return "The Text Representation of the Spatial Reference System."

If you can post a more complete example, either using the sample data included with the API, or with your data included in the question, and for testing purposes, with each object in the retrieval process as it's own object, with error trapping at each stage, and with the complete output of the test, we'll probably be better able to help you.

- V

0 Kudos
VinceAngelo
Esri Esteemed Contributor

You didn't include your output, and your code still assumes that the geometry field will be in the third column (array radix 2).  If you don't test the column type of the columns, and attempt to extract a coordinate reference from a string field, a null GeometryDef is the correct response.

- V

0 Kudos
GaneshmoorthiM
New Contributor III

I am facing problem with FieldDef  and it throw null while assigning to FieldDefs (FieldDef[] fieldDefs = fcTable.FieldDefs; ).

I have declared it after validating geometry. But still receiving the same null error in the FieldDef.

My out put is get the spatial reference/Projection Name of Feature class or Feature Dataset as a string.

Please find the attached updated code.

0 Kudos
VinceAngelo
Esri Esteemed Contributor

Best practice is to construct a simple test without extraneous function calls, so that the operation order is clearly evident.  Adapting existing code is fine, if the file is renamed and the fat trimmed away.

As this question has morphed from proper method invocation to a casting issue, I'm going to have to leave it to someone who uses C# to review what may be wrong.

- V

0 Kudos
GaneshmoorthiM
New Contributor III

The code throws null error when i try to cast FieldDef ( FieldDef[] fieldDefs =fcTable.FieldDefs;)

While debugging, the definition( FieldDefs, IndexDef)properties in the Esri:FileGDB:Table getting null values (Also tried with other C# samples provide with File Geodatabase API). Can any one tell me why it is throwing null value and can i  get Spatial Reference Details using File GeoDatabase API without using FieldDefs.

0 Kudos
MichaelBarsky
New Contributor II

And I'm having the same issue. Whenever I try to access FieldDefs, its null

0 Kudos
DonnyVelazquez
Occasional Contributor

gm.moorthi

I'm having the same issue. Whenever I try to access FieldDefs, its null.

 

Did you solve this?

0 Kudos
UkrgeoconsultingLtd_
New Contributor

.........

Table table = geodatabase.OpenTable(\\featuredatasetname);

// get table definition anp put in xml              
var ds = table.Definition;
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(ds);

//parse xml nodes

/*

...

<SpatialReference xsi:type="esri:GeographicCoordinateSystem">
<WKT>GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",.......
........
<WKID>4326</WKID>
</SpatialReference>

*/

0 Kudos