本文整理汇总了C++中OGRLinearRing::setCoordinateDimension方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLinearRing::setCoordinateDimension方法的具体用法?C++ OGRLinearRing::setCoordinateDimension怎么用?C++ OGRLinearRing::setCoordinateDimension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLinearRing
的用法示例。
在下文中一共展示了OGRLinearRing::setCoordinateDimension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
OGRFeature * OGRBNALayer::BuildFeatureFromBNARecord (BNARecord* record, long fid)
{
OGRFeature *poFeature;
int i;
poFeature = new OGRFeature( poFeatureDefn );
for(i=0;i<nIDs;i++)
{
poFeature->SetField( i, record->ids[i] ? record->ids[i] : "");
}
poFeature->SetFID( fid );
if (bnaFeatureType == BNA_POINT)
{
poFeature->SetGeometryDirectly( new OGRPoint( record->tabCoords[0][0], record->tabCoords[0][1] ) );
}
else if (bnaFeatureType == BNA_POLYLINE)
{
OGRLineString* lineString = new OGRLineString ();
lineString->setCoordinateDimension(2);
lineString->setNumPoints(record->nCoords);
for(i=0;i<record->nCoords;i++)
{
lineString->setPoint(i, record->tabCoords[i][0], record->tabCoords[i][1] );
}
poFeature->SetGeometryDirectly(lineString);
}
else if (bnaFeatureType == BNA_POLYGON)
{
double firstX = record->tabCoords[0][0];
double firstY = record->tabCoords[0][1];
int isFirstPolygon = 1;
double secondaryFirstX = 0, secondaryFirstY = 0;
OGRLinearRing* ring = new OGRLinearRing ();
ring->setCoordinateDimension(2);
ring->addPoint(record->tabCoords[0][0], record->tabCoords[0][1] );
/* record->nCoords is really a safe upper bound */
int nbPolygons = 0;
OGRPolygon** tabPolygons =
(OGRPolygon**)CPLMalloc(record->nCoords * sizeof(OGRPolygon*));
for(i=1;i<record->nCoords;i++)
{
ring->addPoint(record->tabCoords[i][0], record->tabCoords[i][1] );
if (isFirstPolygon == 1 &&
record->tabCoords[i][0] == firstX &&
record->tabCoords[i][1] == firstY)
{
OGRPolygon* polygon = new OGRPolygon ();
polygon->addRingDirectly(ring);
tabPolygons[nbPolygons] = polygon;
nbPolygons++;
if (i == record->nCoords - 1)
{
break;
}
isFirstPolygon = 0;
i ++;
secondaryFirstX = record->tabCoords[i][0];
secondaryFirstY = record->tabCoords[i][1];
ring = new OGRLinearRing ();
ring->setCoordinateDimension(2);
ring->addPoint(record->tabCoords[i][0], record->tabCoords[i][1] );
}
else if (isFirstPolygon == 0 &&
record->tabCoords[i][0] == secondaryFirstX &&
record->tabCoords[i][1] == secondaryFirstY)
{
OGRPolygon* polygon = new OGRPolygon ();
polygon->addRingDirectly(ring);
tabPolygons[nbPolygons] = polygon;
nbPolygons++;
if (i < record->nCoords - 1)
{
/* After the closing of a subpolygon, the first coordinates of the first polygon */
/* should be recalled... in theory */
if (record->tabCoords[i+1][0] == firstX && record->tabCoords[i+1][1] == firstY)
{
if (i + 1 == record->nCoords - 1)
break;
i ++;
}
else
{
#if 0
CPLError(CE_Warning, CPLE_AppDefined,
"Geometry of polygon of fid %d starting at line %d is not strictly conformant. "
"Trying to go on...\n",
fid,
offsetAndLineFeaturesTable[fid].line + 1);
#endif
}
i ++;
//.........这里部分代码省略.........
示例2: SavePolygons
//.........这里部分代码省略.........
int multiring = 0;
printf ("Write File: %s (polygon)\n", OutFilename);
for (size_t k = 0; k < m_labels; k++)
{
if (multiring == 1) {
k = k - 1;
multiring = 0;
}
if (linelists[k].size() == 0)
continue;
// insert field data
OGRFeature *liFeature;
liFeature = OGRFeature::CreateFeature( liLayer->GetLayerDefn() );
liFeature->SetField( "CLASS", (int) k );
liFeature->SetField( "AREA", (int) labelpixels.at(k) );
for ( size_t b = 0; b < m_bands; b++ )
{
stringstream value; value << b+1;
std::string FieldName = value.str() + "_AVERAGE";
liFeature->SetField( FieldName.c_str(), (double) avgCH[b].at(k) );
}
for ( size_t b = 0; b < m_bands; b++ )
{
stringstream value; value << b+1;
std::string FieldName = value.str() + "_STDDEV";
liFeature->SetField( FieldName.c_str(), stdCH[b].at(k) );
}
// initiate polygon start
OGRLinearRing linestring;
linestring.setCoordinateDimension(2);
linestring.addPoint( oX + (double) linelists[k][0].sX * mX, oY + mY * (double) linelists[k][0].sY );
linestring.addPoint( oX + (double) linelists[k][0].eX * mX, oY + mY * (double) linelists[k][0].eY );
linelists[k].erase( linelists[k].begin() );
// construct polygon from lines
while ( linelists[k].size() > 0 )
{
if (multiring == 1) break;
vector<LINE>::iterator it = linelists[k].begin();
for (; it != linelists[k].end(); ++it)
{
double ltX = linestring.getX(linestring.getNumPoints()-1);
double ltY = linestring.getY(linestring.getNumPoints()-1);
double csX = oX + (double) it->sX * mX;
double csY = oY + mY * (double) it->sY;
double ceX = oX + (double) it->eX * mX;
double ceY = oY + mY * (double) it->eY;
if ( ( csX == ltX ) && ( csY == ltY ) ) {
linestring.addPoint(ceX, ceY);
linelists[k].erase(it);
break;
}
if ( ( ceX == ltX ) && ( ceY == ltY ) ) {
linestring.addPoint(csX, csY);
linelists[k].erase(it);
break;
}
if (it == linelists[k].end()-1) {
multiring = 1;
break;