How to create a multipart linesegment in the File Geodatabase API

1409
1
Jump to solution
06-03-2019 10:07 AM
ZacharyPeel
New Contributor
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.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ZacharyPeel
New Contributor

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 solution in original post

0 Kudos
1 Reply
ZacharyPeel
New Contributor

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).

0 Kudos