POST
|
I figured out all the problems I had with this. The first is with this line cabazonGeom.Setup(FileGDBAPI::shapePolyline, 0, 3); I should have been using 1 instead of 0. 0 would mean that there is no line or points, just an empty geometry. Since the parts was then set to 1 I then needed to add the following statements: int* parts;
cabazonGeom.GetParts(parts); This is needed so the parts can be set up correctly. Finally before the calculation of the extent I need to set where part[0] needed to be. parts[0] = 0; This statement says that coordinate at zero is the start of the first part of the polyline. Then applying that to the table and saving the database let the geometry be created and proper. The final successful code is as follows: Row cabazonRow;
table.CreateRowObject(cabazonRow);
MultiPartShapeBuffer cabazonGeom;
cabazonGeom.Setup(FileGDBAPI::shapePolyline, 1, 3);
Point* points;
cabazonGeom.GetPoints(points);
points[0].x = -116.78443;
points[0].y = 33.919902;
points[1].x = -117.78443;
points[1].y = 34.919902;
points[2].x = -117.78443;
points[2].y = 33.919902;
int* parts;
cabazonGeom.GetParts(parts);
parts[0] = 0;
cabazonGeom.CalculateExtent();
cabazonRow.SetGeometry(cabazonGeom); The second part of the question (multi-part polyline's was simple after this), its code is as follows: MultiPartShapeBuffer cabazonGeom;
cabazonGeom.Setup(FileGDBAPI::shapePolyline, 2, 6);
int numPts;
cabazonGeom.GetNumPoints(numPts);
int numParts;
cabazonGeom.GetNumParts(numParts);
int* parts;
cabazonGeom.GetParts(parts);
Point* points;
cabazonGeom.GetPoints(points);
points[0].x = -116.78443;
points[0].y = 33.919902;
points[1].x = -117.78443;
points[1].y = 34.919902;
points[2].x = -117.78443;
points[2].y = 33.919902;
points[3].x = -115.78443;
points[3].y = 33.919902;
points[4].x = -114.78443;
points[4].y = 34.919902;
points[5].x = -114.78443;
points[5].y = 33.919902;
parts[0] = 0;
parts[1] = 3;
cabazonGeom.CalculateExtent();
hr = cabazonRow.SetGeometry(cabazonGeom); The above code should create a multi-part polyline that looks like this |\ /| (approximately).
... View more
06-18-2019
11:09 AM
|
0
|
0
|
1172
|
POST
|
So currently I am trying to work on having the same table within several different datasets as a structure similar to the following. GdbManagement.gdb --CA_CANADA (dataset) ----Polygon (table) ----Polyline (table) ----Multipoint (table) --GB_UNITED_KINGDOM (dataset) ----Polygon (table) ----Polyline (table) ----Multipoint (table) ... and so on. The three tables are true duplicates at creation, but eventually will contain different data, but I am having a problem with creating the same table in a different dataset. I have tried to close and open on each iteration, define the table once, and shorting the name, which all have failed. So I am looking for some help to get past this issue. Any help is appreciated. Current code I am using for testing (the single table is just a test that it doesn't currently create the table a second time). using namespace std;
using namespace FileGDBAPI;
int main() {
fgdbError hr;
wstring errorText;
Geodatabase geodatabase;
if ((hr = CreateGeodatabase(L"../GeodatabaseManagement/GdbManagement.gdb", geodatabase)) != S_OK) {
wcout << "An error occurred while creating the geodatabase." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
CloseGeodatabase(geodatabase);
SpatialReference spatialReference;
spatialReference.SetSpatialReferenceID(4326);
spatialReference.SetSpatialReferenceText(L"GEOGCS[\"WGS84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]");
string inCountries[5] = { "CA_CANADA", "GB_UNITED_KINGDOM", "US_UNITED_STATES", "JA_JAPAN", "CN_CHINA" };
// Create the geometryDef
GeometryDef geometryDef;
geometryDef.SetGeometryType(geometryPolyline);
geometryDef.SetSpatialReference(spatialReference);
geometryDef.SetHasZ(false); //Set to true if the feature class is to be Z enabled. Defaults to FALSE.
geometryDef.SetHasM(false); //Set to true if the feature class is to be M enabled. Defaults to FALSE.
// Create the field def for the table.
std::vector<FieldDef> fieldDefs;
FieldDef fieldDef1;
fieldDef1.SetName(L"OBJECTID");
fieldDef1.SetType(fieldTypeOID);
fieldDef1.SetIsNullable(false);
fieldDefs.push_back(fieldDef1);
FieldDef fieldDef2;
fieldDef2.SetName(L"Shape");
fieldDef2.SetType(fieldTypeGeometry);
fieldDef2.SetIsNullable(true);
fieldDef2.SetGeometryDef(geometryDef);
fieldDefs.push_back(fieldDef2);
FieldDef fieldDef3;
fieldDef3.SetName(L"StopID");
fieldDef3.SetType(fieldTypeInteger);
fieldDef3.SetIsNullable(true);
fieldDef3.SetAlias(L"Stop Identifier");
fieldDefs.push_back(fieldDef3);
FieldDef fieldDef4;
fieldDef4.SetName(L"StopType");
fieldDef4.SetType(fieldTypeSmallInteger);
fieldDef4.SetIsNullable(true);
fieldDefs.push_back(fieldDef4);
FieldDef fieldDef5;
fieldDef5.SetName(L"Test_Value");
fieldDef5.SetType(fieldTypeString);
fieldDef5.SetIsNullable(true);
fieldDef5.SetAlias(L"This is a test");
fieldDef5.SetLength(4000);
fieldDefs.push_back(fieldDef5);
for (int i = 0; i < 5; i++) {
if ((hr = OpenGeodatabase(L"../GeodatabaseManagement/GdbManagement.gdb", geodatabase)) != S_OK) {
wcout << "An error occurred while opening the geodatabase." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
string country = "\\" + inCountries[i];
wstring wide_string = wstring(country.begin(), country.end());
const wchar_t* result = wide_string.c_str();
if ((hr = geodatabase.CreateFeatureDataset(result, spatialReference)) != S_OK) {
wcout << "An error occurred while creating the geodatabase!" << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
// Create the table.
Table table;
country = "\\" + inCountries[i] + "\\Test";
wide_string = wstring(country.begin(), country.end());
result = wide_string.c_str();
if ((hr = geodatabase.CreateTable(result, fieldDefs, L"DEFAULTS", table)) != S_OK) {
wcout << "An error occurred while creating the table." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
//return -1;
}
wcout << "The table has been created." << endl;
//Compact the geodatabase.Recomended after bulk updates.
if ((hr = geodatabase.CompactDatabase()) != S_OK) {
wcout << "An error occurred while compacting the geodatabase." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
// Close the geodatabase before the delete.
if ((hr = CloseGeodatabase(geodatabase)) != S_OK) {
wcout << "An error occurred while closing the geodatabase." << endl;
ErrorInfo::GetErrorDescription(hr, errorText);
wcout << errorText << "(" << hr << ")." << endl;
return -1;
}
}
return 0;
}
... View more
06-04-2019
07:03 AM
|
0
|
0
|
753
|
POST
|
Row cabazonRow;
table.CreateRowObject(cabazonRow);
MultiPartShapeBuffer cabazonGeom;
cabazonGeom.Setup(FileGDBAPI::shapePolyline, 0, 3);
Point* points;
cabazonGeom.GetPoints(points);
points[0].x = -116.78443;
points[0].y = 33.919902;
points[1].x = -117.78443;
points[1].y = 34.919902;
points[2].x = -117.78443;
points[2].y = 33.919902;
cabazonGeom.CalculateExtent();
cabazonRow.SetGeometry(cabazonGeom); This is currently what I have for creating a linesegment (doesn't work currently). I was wondering how I could create a proper linesegment and proper multipart linesegment. The API samples seem a little lacking in how to do it (they work fine with points, but go a little crazy with multiple points). Any help is appreciated! Running this from windows 7, Microsoft Visual Studio 2017 c++. If more details are need I will provide what I can.
... View more
06-03-2019
10:07 AM
|
0
|
1
|
1415
|
Online Status |
Offline
|
Date Last Visited |
02-18-2022
08:42 AM
|