Created
October 1, 2012 19:41
-
-
Save rcoup/3813984 to your computer and use it in GitHub Desktop.
ESRI FileGDB/FGDB API - Null/Empty Geometries Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<esri:DataElement xsi:type='esri:DEFeatureDataset' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:esri='http://www.esri.com/schemas/ArcGIS/10.1'> | |
<CatalogPath>\test1</CatalogPath> | |
<Name>test1</Name> | |
<ChildrenExpanded>false</ChildrenExpanded> | |
<DatasetType>esriDTFeatureDataset</DatasetType> | |
<Versioned>false</Versioned> | |
<CanVersion>false</CanVersion> | |
<Extent xsi:nil="true"/> | |
<SpatialReference xsi:type='esri:ProjectedCoordinateSystem'> | |
<WKT>PROJCS["WGS_1984_UTM_Zone_20N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-63.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0],AUTHORITY["EPSG",32620]]</WKT> | |
<XOrigin>-5120900</XOrigin> | |
<YOrigin>-9998100</YOrigin> | |
<XYScale>10000</XYScale> | |
<ZOrigin>-100000</ZOrigin> | |
<ZScale>10000</ZScale> | |
<MOrigin>-100000</MOrigin> | |
<MScale>10000</MScale> | |
<XYTolerance>0.001</XYTolerance> | |
<ZTolerance>0.001</ZTolerance> | |
<MTolerance>0.001</MTolerance> | |
<HighPrecision>true</HighPrecision> | |
<WKID>32620</WKID> | |
</SpatialReference> | |
</esri:DataElement> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<esri:DataElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:esri="http://www.esri.com/schemas/ArcGIS/10.1" xsi:type="esri:DEFeatureClass"> | |
<CatalogPath>\test1\tt</CatalogPath> | |
<Name>tt</Name> | |
<ChildrenExpanded>false</ChildrenExpanded> | |
<DatasetType>esriDTFeatureClass</DatasetType> | |
<Versioned>false</Versioned> | |
<CanVersion>false</CanVersion> | |
<ConfigurationKeyword/> | |
<HasOID>true</HasOID> | |
<OIDFieldName>OBJECTID</OIDFieldName> | |
<Fields xsi:type="esri:Fields"> | |
<FieldArray xsi:type="esri:ArrayOfField"> | |
<Field xsi:type="esri:Field"> | |
<Name>OBJECTID</Name> | |
<Type>esriFieldTypeOID</Type> | |
<IsNullable>false</IsNullable> | |
<Length>4</Length> | |
<Precision>0</Precision> | |
<Scale>0</Scale> | |
<Required>true</Required> | |
<Editable>false</Editable> | |
<AliasName>OBJECTID</AliasName> | |
<ModelName>OBJECTID</ModelName> | |
</Field> | |
<Field xsi:type="esri:Field"> | |
<Name>SHAPE</Name> | |
<Type>esriFieldTypeGeometry</Type> | |
<IsNullable>true</IsNullable> | |
<Length>0</Length> | |
<Precision>0</Precision> | |
<Scale>0</Scale> | |
<Required>true</Required> | |
<GeometryDef xsi:type="esri:GeometryDef"> | |
<AvgNumPoints>0</AvgNumPoints> | |
<GeometryType>esriGeometryPoint</GeometryType> | |
<HasM>false</HasM> | |
<HasZ>false</HasZ> | |
<SpatialReference xsi:type="esri:ProjectedCoordinateSystem"> | |
<WKT>PROJCS["WGS_1984_UTM_Zone_20N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID[" WGS_1984",6378137.0,298.257223563]],PRIMEM[" Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-63.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0],AUTHORITY["EPSG",32620]]</WKT> | |
<XOrigin>-5120900</XOrigin> | |
<YOrigin>-9998100</YOrigin> | |
<XYScale>10000</XYScale> | |
<ZOrigin>-100000</ZOrigin> | |
<ZScale>10000</ZScale> | |
<MOrigin>-100000</MOrigin> | |
<MScale>10000</MScale> | |
<XYTolerance>0.001</XYTolerance> | |
<ZTolerance>0.001</ZTolerance> | |
<MTolerance>0.001</MTolerance> | |
<HighPrecision>true</HighPrecision> | |
<WKID>32620</WKID> | |
</SpatialReference> | |
<GridSize0>0</GridSize0> | |
</GeometryDef> | |
<AliasName>SHAPE</AliasName> | |
<ModelName>SHAPE</ModelName> | |
</Field> | |
<Field xsi:type="esri:Field"> | |
<Name>StopID</Name> | |
<Type>esriFieldTypeInteger</Type> | |
<IsNullable>true</IsNullable> | |
<Length>4</Length> | |
<Precision>0</Precision> | |
<Scale>0</Scale> | |
<AliasName>StopID</AliasName> | |
<ModelName>StopID</ModelName> | |
</Field> | |
<Field xsi:type="esri:Field"> | |
<Name>StopType</Name> | |
<Type>esriFieldTypeSmallInteger</Type> | |
<IsNullable>true</IsNullable> | |
<Length>2</Length> | |
<Precision>0</Precision> | |
<Scale>0</Scale> | |
<AliasName>StopType</AliasName> | |
<ModelName>StopType</ModelName> | |
</Field> | |
</FieldArray> | |
</Fields> | |
<Indexes xsi:type="esri:Indexes"> | |
<IndexArray xsi:type="esri:ArrayOfIndex"> | |
<Index xsi:type="esri:Index"> | |
<Name>FDO_OBJECTID</Name> | |
<IsUnique>true</IsUnique> | |
<IsAscending>true</IsAscending> | |
<Fields xsi:type="esri:Fields"> | |
<FieldArray xsi:type="esri:ArrayOfField"> | |
<Field xsi:type="esri:Field"> | |
<Name>OBJECTID</Name> | |
<Type>esriFieldTypeOID</Type> | |
<IsNullable>false</IsNullable> | |
<Length>4</Length> | |
<Precision>0</Precision> | |
<Scale>0</Scale> | |
<Required>true</Required> | |
<Editable>false</Editable> | |
<AliasName>OBJECTID</AliasName> | |
<ModelName>OBJECTID</ModelName> | |
</Field> | |
</FieldArray> | |
</Fields> | |
</Index> | |
<Index xsi:type="esri:Index"> | |
<Name>FDO_SHAPE</Name> | |
<IsUnique>false</IsUnique> | |
<IsAscending>true</IsAscending> | |
<Fields xsi:type="esri:Fields"> | |
<FieldArray xsi:type="esri:ArrayOfField"> | |
<Field xsi:type="esri:Field"> | |
<Name>SHAPE</Name> | |
<Type>esriFieldTypeGeometry</Type> | |
<IsNullable>true</IsNullable> | |
<Length>0</Length> | |
<Precision>0</Precision> | |
<Scale>0</Scale> | |
<Required>true</Required> | |
<GeometryDef xsi:type="esri:GeometryDef"> | |
<AvgNumPoints>0</AvgNumPoints> | |
<GeometryType>esriGeometryPoint</GeometryType> | |
<HasM>false</HasM> | |
<HasZ>false</HasZ> | |
<SpatialReference xsi:type="esri:ProjectedCoordinateSystem"> | |
<WKT>PROJCS["WGS_1984_UTM_Zone_20N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID[" WGS_1984",6378137.0,298.257223563]],PRIMEM[" Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-63.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0],AUTHORITY["EPSG",32620]]</WKT> | |
<XOrigin>-5120900</XOrigin> | |
<YOrigin>-9998100</YOrigin> | |
<XYScale>10000</XYScale> | |
<ZOrigin>-100000</ZOrigin> | |
<ZScale>10000</ZScale> | |
<MOrigin>-100000</MOrigin> | |
<MScale>10000</MScale> | |
<XYTolerance>0.001</XYTolerance> | |
<ZTolerance>0.001</ZTolerance> | |
<MTolerance>0.001</MTolerance> | |
<HighPrecision>true</HighPrecision> | |
<WKID>32620</WKID> | |
</SpatialReference> | |
<GridSize0>0</GridSize0> | |
</GeometryDef> | |
<AliasName>SHAPE</AliasName> | |
<ModelName>SHAPE</ModelName> | |
</Field> | |
</FieldArray> | |
</Fields> | |
</Index> | |
</IndexArray> | |
</Indexes> | |
<CLSID>{52353152-891A-11D0-BEC6-00805F7C4268}</CLSID> | |
<EXTCLSID/> | |
<RelationshipClassNames xsi:type="esri:Names"/> | |
<AliasName>BusStops</AliasName> | |
<ModelName/> | |
<HasGlobalID>false</HasGlobalID> | |
<GlobalIDFieldName/> | |
<RasterFieldName/> | |
<ExtensionProperties xsi:type="esri:PropertySet"> | |
<PropertyArray xsi:type="esri:ArrayOfPropertySetProperty"/> | |
</ExtensionProperties> | |
<ControllerMemberships xsi:type="esri:ArrayOfControllerMembership"/> | |
<FeatureType>esriFTSimple</FeatureType> | |
<ShapeType>esriGeometryPoint</ShapeType> | |
<ShapeFieldName>SHAPE</ShapeFieldName> | |
<HasM>false</HasM> | |
<HasZ>false</HasZ> | |
<HasSpatialIndex>true</HasSpatialIndex> | |
<AreaFieldName/> | |
<LengthFieldName/> | |
<Extent xsi:nil="true"/> | |
<SpatialReference xsi:type="esri:ProjectedCoordinateSystem"> | |
<WKT>PROJCS["WGS_1984_UTM_Zone_20N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID[" WGS_1984",6378137.0,298.257223563]],PRIMEM[" Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-63.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0],AUTHORITY["EPSG",32620]]</WKT> | |
<XOrigin>-5120900</XOrigin> | |
<YOrigin>-9998100</YOrigin> | |
<XYScale>10000</XYScale> | |
<ZOrigin>-100000</ZOrigin> | |
<ZScale>10000</ZScale> | |
<MOrigin>-100000</MOrigin> | |
<MScale>10000</MScale> | |
<XYTolerance>0.001</XYTolerance> | |
<ZTolerance>0.001</ZTolerance> | |
<MTolerance>0.001</MTolerance> | |
<HighPrecision>true</HighPrecision> | |
<WKID>32620</WKID> | |
</SpatialReference> | |
</esri:DataElement> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Debug FileGDB API behaviour | |
// Robert Coup | |
// | |
// Compile via: | |
// gcc -o test1 test1.cpp -l FileGDBAPI -l fgdbunixrtl -L/path/to/FileGDB_API/lib -I/path/to/FileGDB_API/include -ggdb -O0 | |
// | |
// ------------- | |
// Based off FileGDB Sample: FeatureDatasets | |
// Copyright 2011 ESRI | |
// | |
// All rights reserved under the copyright laws of the United States | |
// and applicable international laws, treaties, and conventions. | |
// | |
// You may freely redistribute and use this sample code, with or | |
// without modification, provided you include the original copyright | |
// notice and use restrictions. | |
// | |
// See the use restrictions at <your File Geodatabase API install location>/license/userestrictions.txt. | |
// | |
#include <string> | |
#include <iostream> | |
#include <fstream> | |
#include <iomanip> | |
#include <limits> | |
#include <stdlib.h> | |
#include <FileGDBAPI.h> | |
using namespace std; | |
using namespace FileGDBAPI; | |
const wstring fieldName(L"StopID"); | |
double calcEnv[] = {numeric_limits<double>::max(), numeric_limits<double>::max(), -numeric_limits<double>::max(), -numeric_limits<double>::max()}; | |
void handleError(fgdbError hr, const char* message) { | |
if (hr != S_OK) { | |
wstring errorText; | |
wcout << "An error occurred: " << message << endl; | |
ErrorInfo::GetErrorDescription(hr, errorText); | |
wcout << errorText << "(" << hr << ")." << endl; | |
exit(1); | |
} | |
} | |
const char * getGeometryTypeStr(GeometryType t) { | |
// ESRI, a function like this would be Super Handy. | |
switch (t) { | |
case 0: | |
return "geometryNull"; | |
case 1: | |
return "geometryPoint"; | |
case 2: | |
return "geometryMultipoint"; | |
case 3: | |
return "geometryPolyline"; | |
case 4: | |
return "geometryPolygon"; | |
case 9: | |
return "geometryMultiPatch"; | |
default: | |
return "geometryWtf?"; | |
} | |
} | |
wstring getShapeTypeStr(ShapeType t) { | |
// ESRI, a function like this would be Super Handy. And what's with decimal masks? | |
wstring s; | |
if (t == 0) { | |
return L"shapeNull"; | |
} | |
if ((t & shapePoint) == shapePoint) s += L"shapePoint "; | |
if ((t & shapePointM) == shapePointM) s += L"shapePointM "; | |
if ((t & shapePointZM) == shapePointZM) s += L"shapePointZM "; | |
if ((t & shapePointZ) == shapePointZ) s += L"shapePointZ "; | |
if ((t & shapeMultipoint) == shapeMultipoint) s += L"shapeMultipoint "; | |
if ((t & shapeMultipointM) == shapeMultipointM) s += L"shapeMultipointM "; | |
if ((t & shapeMultipointZM) == shapeMultipointZM) s += L"shapeMultipointZM "; | |
if ((t & shapeMultipointZ) == shapeMultipointZ) s += L"shapeMultipointZ "; | |
if ((t & shapePolyline) == shapePolyline) s += L"shapePolyline "; | |
if ((t & shapePolylineM) == shapePolylineM) s += L"shapePolylineM "; | |
if ((t & shapePolylineZM) == shapePolylineZM) s += L"shapePolylineZM "; | |
if ((t & shapePolylineZ) == shapePolylineZ) s += L"shapePolylineZ "; | |
if ((t & shapePolygon) == shapePolygon) s += L"shapePolygon "; | |
if ((t & shapePolygonM) == shapePolygonM) s += L"shapePolygonM "; | |
if ((t & shapePolygonZM) == shapePolygonZM) s += L"shapePolygonZM "; | |
if ((t & shapePolygonZ) == shapePolygonZ) s += L"shapePolygonZ "; | |
if ((t & shapeMultiPatchM) == shapeMultiPatchM) s += L"shapeMultiPatchM "; | |
if ((t & shapeMultiPatch) == shapeMultiPatch) s += L"shapeMultiPatch "; | |
if ((t & shapeGeneralPolyline) == shapeGeneralPolyline) s += L"shapeGeneralPolyline "; | |
if ((t & shapeGeneralPolygon) == shapeGeneralPolygon) s += L"shapeGeneralPolygon "; | |
if ((t & shapeGeneralPoint) == shapeGeneralPoint) s += L"shapeGeneralPoint "; | |
if ((t & shapeGeneralMultipoint) == shapeGeneralMultipoint) s += L"shapeGeneralMultipoint "; | |
if ((t & shapeGeneralMultiPatch) == shapeGeneralMultiPatch) s += L"shapeGeneralMultiPatch "; | |
if ((t & shapeHasZs) == shapeHasZs) s += L"shapeHasZs "; | |
if ((t & shapeHasMs) == shapeHasMs) s += L"shapeHasMs "; | |
if ((t & shapeHasCurves) == shapeHasCurves) s += L"shapeHasCurves "; | |
if ((t & shapeHasIDs) == shapeHasIDs) s += L"shapeHasIDs "; | |
if ((t & shapeHasNormals) == shapeHasNormals) s += L"shapeHasNormals "; | |
if ((t & shapeHasTextures) == shapeHasTextures) s += L"shapeHasTextures "; | |
if ((t & shapeHasPartIDs) == shapeHasPartIDs) s += L"shapeHasPartIDs "; | |
if ((t & shapeHasMaterials) == shapeHasMaterials) s += L"shapeHasMaterials "; | |
if ((t & shapeIsCompressed) == shapeIsCompressed) s += L"shapeIsCompressed "; | |
if ((t & shapeModifierMask) == shapeModifierMask) s += L"shapeModifierMask "; | |
if ((t & shapeMultiPatchModifierMask) == shapeMultiPatchModifierMask) s += L"shapeMultiPatchModifierMask "; | |
if ((t & shapeBasicTypeMask) == shapeBasicTypeMask) s += L"shapeBasicTypeMask "; | |
if ((t & shapeBasicModifierMask) == shapeBasicModifierMask) s += L"shapeBasicModifierMask "; | |
if ((t & shapeNonBasicModifierMask) == shapeNonBasicModifierMask) s += L"shapeNonBasicModifierMask "; | |
if ((t & shapeExtendedModifierMask) == shapeExtendedModifierMask) s += L"shapeExtendedModifierMask "; | |
return s; | |
} | |
void loadPoints(Table &table, int count) | |
{ | |
// insert 3x unique points, but do each count x to encourage a spatial index | |
// to be rebuilt - it doesn't happen with very small layers. | |
static const double DATA[] = { | |
172.875856388595565, -34.317553326293556, | |
173.938052798310451, -34.969506863780353, | |
174.927365327511239, -35.880394733995757, | |
}; | |
// xMin, yMin, xMax, yMax | |
for (int i=0; i<3; i++) { | |
double x = DATA[i*2]; | |
double y = DATA[i*2 + 1]; | |
// | |
for (int j=0; j<count; j++) { | |
Row row; | |
table.CreateRowObject(row); | |
PointShapeBuffer geom; | |
geom.Setup(FileGDBAPI::shapePoint); | |
Point* point2; | |
geom.GetPoint(point2); | |
point2->x = x; | |
point2->y = y; | |
handleError(row.SetGeometry(geom), "loadPoints, set geom"); | |
row.SetInteger(fieldName, (i+1) * (j+1)); | |
handleError(table.Insert(row), "loadPoints, inserting row"); | |
} | |
wcout << "Inserted point " << i << " (x" << count << "): " << x << ", " << y << endl; | |
calcEnv[0] = min(calcEnv[0], x); | |
calcEnv[1] = min(calcEnv[1], y); | |
calcEnv[2] = max(calcEnv[2], x); | |
calcEnv[3] = max(calcEnv[3], y); | |
} | |
} | |
// EMPTY Geometries | |
void loadEmpty(Table &table, int count) { | |
for (int i=0; i<count; i++) { | |
Row row; | |
table.CreateRowObject(row); | |
PointShapeBuffer geom; | |
handleError(geom.Setup(FileGDBAPI::shapePoint), "loadEmpty, setup"); | |
geom.SetEmpty(); | |
handleError(row.SetGeometry(geom), "loadEmpty, set geom"); | |
int32 oid = 200000 + i; | |
row.SetInteger(fieldName, oid); | |
handleError(table.Insert(row), "loadEmpty, inserting row"); | |
wcout << "Inserted EMPTY geometry: OID=" << oid << "\n"; | |
} | |
} | |
// NULL GEOMETRIES | |
void loadNull(Table &table, int count) { | |
for (int i=0; i<count; i++) { | |
Row row; | |
table.CreateRowObject(row); | |
PointShapeBuffer geom; | |
//handleError(geom.Setup(FileGDBAPI::shapeNull), "loadNull, setup"); | |
//handleError(row.SetGeometry(geom), "loadNull, set geom"); | |
//handleError(row.SetGeometry(NULL), "loadNull, SetGeometry"); | |
handleError(row.SetNull(L"SHAPE"), "loadNull, SetNull"); | |
int32 oid = 100000 + i; | |
row.SetInteger(fieldName, oid); | |
handleError(table.Insert(row), "loadNull, inserting row"); | |
wcout << "Inserted NULL geometry: OID=" << oid << "\n"; | |
} | |
} | |
void dumpEnvelope(Table &table) { | |
// Get the envelope | |
Envelope envelope; | |
handleError(table.GetExtent(envelope), "dumpEnvelope, GetExtent"); | |
wcout << endl << "Table envelope: xMin=" << envelope.xMin | |
<< " yMin=" << envelope.yMin | |
<< " xMax=" << envelope.xMax | |
<< " yMax=" << envelope.yMax << endl; | |
// will be rubbish if we haven't called loadPoints() at all :) | |
wcout << "Calculated envelope: xMin=" << calcEnv[0] | |
<< " yMin=" << calcEnv[1] | |
<< " xMax=" << calcEnv[2] | |
<< " yMax=" << calcEnv[3] << endl; | |
} | |
void dumpFeatures(Table &table) { | |
EnumRows results; | |
handleError(table.Search(L"*", L"", false, results), "dumpFeatures, table.Search"); | |
// Iterate through the results, populating the results vector. | |
Row row; | |
PointShapeBuffer geometry; | |
Point* point; | |
while (results.Next(row) == S_OK) | |
{ | |
int32 field = -1; | |
int32 objectID = -1; | |
ShapeType shapeType = (ShapeType)-1; | |
GeometryType geomType = (GeometryType)-1; | |
handleError(row.GetOID(objectID), "dumpFeatures, getOID"); | |
handleError(row.GetInteger(fieldName, field), "dumpFeatures, GetInteger"); | |
wcout << "OID=" << objectID << "; StopID=" << field << endl << "\tgeometry:"; | |
bool isNull = false; | |
handleError(row.IsNull(L"SHAPE", isNull), "dumpFeatures, isNull"); | |
if (isNull) { | |
wcout << "NULL"; | |
} else { | |
// Extract the geometry | |
handleError(row.GetGeometry(geometry), "dumpFeatures, getGeometry"); | |
handleError(geometry.GetShapeType(shapeType), "dumpFeatures, GetShapeType"); | |
handleError(geometry.GetGeometryType(geomType), "dumpFeatures, GetGeometryType"); | |
wcout << " shapeType=" << shapeType << " [" << getShapeTypeStr(shapeType) << "]"; | |
wcout << " geomType=" << getGeometryTypeStr(geomType); | |
if (geometry.IsEmpty()) { | |
wcout << " EMPTY"; | |
} else if ((shapeType == shapeNull) || (geomType == geometryNull)) { | |
// pass | |
} else { | |
geometry.GetPoint(point); | |
wcout << " X=" << point->x << ", Y=" << point->y; | |
} | |
} | |
wcout << endl; | |
} | |
} | |
int main() | |
{ | |
// Delete the geodatabase in the current directory if it's already there. | |
Geodatabase geodatabase; | |
fgdbError hr = DeleteGeodatabase(L"./test1.gdb"); | |
if (hr == S_OK) | |
{ | |
wcout << "test1.gdb has been deleted" << endl; | |
} | |
else if (hr != -2147024893) | |
{ | |
// might not exist | |
handleError(hr, "Deleting GDB"); | |
} | |
// Create a new geodatabase in the current directory. | |
handleError(CreateGeodatabase(L"./test1.gdb", geodatabase), "Creating GDB"); | |
wcout << "test1.gdb has been created." << endl; | |
// Load a feature dataset XML definition into a string. An example of a data | |
// element is provided in the sample as "TransitFD.xml". | |
string featureDatasetDef; | |
string fdDefLine; | |
ifstream fdDefFile("./test1-fd.xml"); | |
while (getline(fdDefFile, fdDefLine)) | |
featureDatasetDef.append(fdDefLine + "\n"); | |
fdDefFile.close(); | |
// Create the feature dataset. | |
handleError(geodatabase.CreateFeatureDataset(featureDatasetDef), "Creating FeatureDataset"); | |
wcout << "The feature dataset (\\test1) has been created." << endl; | |
// Load a table XML definition into a string. There are several differences | |
// between this example and adding a table at the root level of the geodatabase: | |
// - The table must have a shape field | |
// - The spatial reference must match that of the feature dataset | |
// - The definition's CatalogPath must include the feature dataset | |
string tableDef; | |
string tableDefLine; | |
ifstream tableDefFile("./test1-t.xml"); | |
while (getline(tableDefFile, tableDefLine)) | |
tableDef.append(tableDefLine + "\n"); | |
tableDefFile.close(); | |
// Create the table. | |
Table table; | |
handleError(geodatabase.CreateTable(tableDef, L"\\test1", table), "Creating table"); | |
wcout << "The table (\\test1\\tt) has been created." << endl; | |
// add some points | |
wcout << '\n' << "Testing Point Shapes, Write" << '\n' << endl; | |
wcout << setiosflags(ios::fixed) << setprecision(6); | |
// Begin load only mode. This shuts off the update of all indexes. | |
table.LoadOnlyMode(true); | |
// CREATE SOME GEOMETRIES HERE | |
// changing the order does interesting things... | |
loadEmpty(table, 2); | |
loadNull(table, 2); | |
loadPoints(table, 1); | |
loadEmpty(table, 2); | |
loadNull(table, 2); | |
// End load only mode. This rebuilds all indexes including the spatial index. | |
// If all grid size values in the spatial index are zero, the values will be | |
// calculated based on the existing data. | |
table.LoadOnlyMode(false); | |
dumpEnvelope(table); | |
wcout << endl; | |
dumpFeatures(table); | |
// Close the table. | |
handleError(geodatabase.CloseTable(table), "Closing Table"); | |
// Close the geodatabase | |
handleError(CloseGeodatabase(geodatabase), "Closing GDB"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run under linux/64bit with v1.2 of the API.