当前位置: 首页>>代码示例>>C++>>正文


C++ OGRLinearRing::getPoint方法代码示例

本文整理汇总了C++中OGRLinearRing::getPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLinearRing::getPoint方法的具体用法?C++ OGRLinearRing::getPoint怎么用?C++ OGRLinearRing::getPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OGRLinearRing的用法示例。


在下文中一共展示了OGRLinearRing::getPoint方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: polygonToDrawable

    osg::Geometry* polygonToDrawable(OGRPolygon* polygon) const
    {
        osg::Geometry* geom = new osg::Geometry();
        osg::Vec3Array* vertices = new osg::Vec3Array();
        geom->setVertexArray(vertices);
        {
            OGRLinearRing *ring = polygon->getExteriorRing();
            OGRPoint point;
            for(int i = 0; i < ring->getNumPoints(); i++)
            {
                ring->getPoint(i, &point);
                vertices->push_back(osg::Vec3(point.getX(), point.getY(), point.getZ()));
            }
            geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, vertices->size()));
        }

        if (polygon->getNumInteriorRings())
        {
            for (int i = 0; i < polygon->getNumInteriorRings(); i++)
            {
                OGRLinearRing *ring = polygon->getInteriorRing(i);
                OGRPoint point;
                for (int j = 0; j < ring->getNumPoints(); j++)
                {
                    ring->getPoint(j, &point);
                    vertices->push_back(osg::Vec3(point.getX(), point.getY(), point.getZ()));
                }
                geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, vertices->size()-ring->getNumPoints() , ring->getNumPoints()));
            }
        }
        osgUtil::Tessellator tsl;
        tsl.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
        tsl.setBoundaryOnly(false);
        tsl.retessellatePolygons(*geom);

        osg::Vec3Array* array = triangulizeGeometry(geom);
        geom->setVertexArray(array);
        geom->removePrimitiveSet(0,geom->getNumPrimitiveSets());
        geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, array->size()));

        return geom;
    }
开发者ID:Kurdakov,项目名称:emscripten_OSG,代码行数:42,代码来源:ReaderWriterOGR.cpp

示例2: extrusion

void MapExtruder::extrusion()
{
	_sides = new OGRMultiPolygon();

	int n = _map2d->getNumGeometries();
	for(int i=0;i<n;i++)
	{

		OGRLinearRing* ring = ((OGRPolygon*)_map2d->getGeometryRef(i))->getExteriorRing();
		ring->closeRings();
		int nPoints = ring->getNumPoints();


		for(int j=0;j<nPoints-1;j++)
		{
			
			OGRPolygon side;
			OGRLinearRing* ring_side = new OGRLinearRing();

			OGRPoint p1,p4;

			ring->getPoint(j,&p1);
			ring->getPoint(j+1,&p4);

			OGRPoint p2(p1.getX(),p1.getY(),_height);
			OGRPoint p3(p4.getX(),p4.getY(),_height);
			
			
	
			ring_side->addPoint(&p1);			
		    ring_side->addPoint(&p2);
			ring_side->addPoint(&p3);
			ring_side->addPoint(&p4);
			ring_side->addPoint(&p1);

			side.addRing(ring_side);
			_sides->addGeometry(&side);
		}
	}
}
开发者ID:HEShuang,项目名称:3DCityLoD,代码行数:40,代码来源:MapExtruder.cpp

示例3: extrude

osg::ref_ptr<osg::Group> MapExtruder::osg_assemble()
{
  	osg::ref_ptr<osg::Group> osg = new osg::Group;
	osg::ref_ptr<osg::Node> surface = osgDB::readNodeFile(_map2dFile);

	ExtrudeVisitor extrude(_height);
	surface->accept(extrude);
	osg->addChild(surface);

	int n = _sides ->getNumGeometries();
	osg::ref_ptr<osg::Geode> geode = new osg::Geode;			


	for(int i=0;i<n;i++)
	{
		osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
		osg::ref_ptr<osg::Vec3Array> verts = new osg::Vec3Array;

		std::vector<OGRPoint> points;
		OGRLinearRing *ring = ((OGRPolygon*)_sides->getGeometryRef(i))->getExteriorRing();
		int m = ring->getNumPoints();
		for(int j=0;j<m;j++)
		{
			OGRPoint pt;
			ring->getPoint(j,&pt);
			verts->push_back(osg::Vec3(pt.getX(),pt.getY(),pt.getZ()));
		}

		geom->setVertexArray(verts);
	
		osg::Vec4Array* colors = new osg::Vec4Array;
		colors->push_back(YELLOW);
		geom->setColorArray(colors);
		geom->setColorBinding(osg::Geometry::BIND_OVERALL);
    

		geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,m));
		geode->addDrawable(geom);
	}
	
	osg->addChild(geode);

	return osg;
}
开发者ID:HEShuang,项目名称:3DCityLoD,代码行数:44,代码来源:MapExtruder.cpp

示例4: triangulizeGeometry

PolygonView::PolygonView(MapPolygon* mapPolygon,bool polygonFill,osg::Vec4 color)
{

	this->mapPolygon=mapPolygon;
	this->geometryEdgePolygon=new osg::Geometry;
	/*this->geometryPolygon=new osg::Geometry;*/
	this->vertices=new osg::Vec3Array;

	/*this->geometryPolygon->setVertexArray(this->vertices);*/

	this->geometryEdgePolygon->setVertexArray(this->vertices);
	OGRLinearRing *poExteriorRing=mapPolygon->getExteriorRing();

	normals=new osg::Vec3Array;
	normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));

	this->polygonFillColor=new osg::Vec4Array;
	this->polygonEdgeColor=new osg::Vec4Array;
	this->polygonFillColor->push_back(color);
	this->polygonEdgeColor->push_back(edgeColor);

	{	
		OGRPoint point;
		for(int i = 0; i < poExteriorRing->getNumPoints(); i++)
		{
			poExteriorRing->getPoint(i, &point);
			vertices->push_back(osg::Vec3(point.getX(), 0, point.getY()));
		}
		this->geometryEdgePolygon->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, vertices->size()));
		/*this->geometryPolygon->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, vertices->size()));*/
	}
	if (mapPolygon->getNumInteriorRings())
	{
		for (int i = 0; i < mapPolygon->getNumInteriorRings(); i++)
		{
			OGRLinearRing *ring = mapPolygon->getInteriorRing(i);
			OGRPoint point;

			for (int j = 0; j < ring->getNumPoints(); j++) 
			{
				ring->getPoint(j, &point);
				vertices->push_back(osg::Vec3(point.getX(), 0, point.getY()));
			}
			this->geometryEdgePolygon->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, vertices->size()-ring->getNumPoints() , ring->getNumPoints()));
			/*this->geometryPolygon->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, vertices->size()-ring->getNumPoints() , ring->getNumPoints()));*/
		}
	}

	this->geometryEdgePolygon->setNormalArray(normals);
	this->geometryEdgePolygon->setNormalBinding(osg::Geometry::BIND_OVERALL);

	this->geometryEdgePolygon->setColorArray(this->polygonEdgeColor);
	this->geometryEdgePolygon->setColorBinding(osg::Geometry::BIND_OVERALL);

	if (polygonFill==true)
	{
		this->geometryPolygon=new osg::Geometry;
		this->geometryPolygon->setVertexArray(this->vertices);
		for(int i=0;i<this->geometryEdgePolygon->getNumPrimitiveSets();i++)
		{
			this->geometryPolygon->addPrimitiveSet(this->geometryEdgePolygon->getPrimitiveSet(i));
		}

		osgUtil::Tessellator tsl;
		tsl.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
		tsl.setBoundaryOnly(false);
		tsl.retessellatePolygons(*this->geometryPolygon);

		osg::Vec3Array* array = triangulizeGeometry(this->geometryPolygon);
		this->geometryPolygon->setVertexArray(array);
		this->geometryPolygon->removePrimitiveSet(0,this->geometryPolygon->getNumPrimitiveSets());
		this->geometryPolygon->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, array->size()));

		this->geometryPolygon->setNormalArray(normals);
		this->geometryPolygon->setNormalBinding(osg::Geometry::BIND_OVERALL);

		this->geometryPolygon->setColorArray(this->polygonFillColor);
		this->geometryPolygon->setColorBinding(osg::Geometry::BIND_OVERALL);
	}
}
开发者ID:SijuWu,项目名称:TouchGIS,代码行数:80,代码来源:PolygonView.cpp

示例5: ExportDataToCSV


//.........这里部分代码省略.........
				}

				CSVFile << "geometry" << endl;

			}

			for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
			{

				OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
				CString str;

				if( poFieldDefn->GetType() == OFTInteger )
					CSVFile <<  poFeature->GetFieldAsInteger( iField ) << ",";
				else if( poFieldDefn->GetType() == OFTReal )
					CSVFile <<  poFeature->GetFieldAsDouble(iField) << ",";
				else if( poFieldDefn->GetType() == OFTString )
				{
					str = poFeature->GetFieldAsString(iField);
					if(str.Find(',') >=0) 
						CSVFile << "\"" << poFeature->GetFieldAsString(iField)  << "\",";
					else
						CSVFile <<   poFeature->GetFieldAsString(iField)  << ",";
				}
				else
				{
					str = poFeature->GetFieldAsString(iField);
					if(str.Find(',') >=0) 
						CSVFile << "\"" << poFeature->GetFieldAsString(iField)  << "\",";
					else
						CSVFile <<   poFeature->GetFieldAsString(iField)  << ",";
				}

			}

			OGRGeometry *poGeometry;

			poGeometry = poFeature->GetGeometryRef();
			if( poGeometry != NULL )
			{
				if(wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
				{
					OGRPoint *poPoint = (OGRPoint *) poGeometry;

					CSVFile << "\"<Point><coordinates>" <<  poPoint->getX() << ","  << poPoint->getY() << ",0.0" << "</coordinates></Point>\"" ;
				}
				else if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString)
				{
					OGRLineString *poLine = (OGRLineString *) poGeometry;

					CSVFile << "\"<LineString><coordinates>";

					for(unsigned int si = 0; si< poLine->getNumPoints(); si++)
					{
						CSVFile	 <<  poLine->getX(si) << ","  << poLine->getY(si) << ",0.0";

						if(si!=poLine->getNumPoints()-1)
							CSVFile << " ";
					}

					CSVFile << "</coordinates></LineString>\",";

				} if (wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon )
				{

					OGRPolygon* polygon = (OGRPolygon*)(poGeometry);

					OGRLinearRing *ring = polygon->getExteriorRing();
					OGRPoint point;

					CSVFile << "\"<Polygon><outerBoundaryIs><LinearRing><coordinates>";

					for(int i = 0; i < ring->getNumPoints(); i++)
					{
						ring->getPoint(i, &point);
						CSVFile	 <<  point.getX() << ","  << point.getY() << ",0.0";

						if(i!=ring->getNumPoints()-1)
							CSVFile << " ";
					}

					CSVFile << "</coordinates></LinearRing></outerBoundaryIs></Polygon>\"";
				}
				CSVFile << endl;

			}
			feature_count ++;
		}
		OGRFeature::DestroyFeature( poFeature );
		message_str.Format("Layer %d has %d features.", i+1, feature_count);
		m_MessageList.AddString(message_str);


	}

	OGRDataSource::DestroyDataSource( poDS );

	CSVFile.close();
#endif
}
开发者ID:epapatzikou,项目名称:nexta,代码行数:101,代码来源:Dlg_GISDataExchange.cpp

示例6: readQuadIndex

void readQuadIndex(int series, QString file, QString layerName, Projection *pj)
{
  OGRDataSource       *ds = OGRSFDriverRegistrar::Open(file.toLatin1().data(), false);
  if (!ds) {
    fprintf(stderr, "Could not open quad index '%s'.\n", file.toLatin1().data());
    exit(-1);
  }

  OGRLayer  *layer;
  layer = ds->GetLayerByName(layerName.toLatin1().data());
  if (!layer) {
    fprintf(stderr, "Could not read layer '%s'.\n", layerName.toLatin1().data());
    exit(-1);
  }

  OGRSpatialReference *srs = layer->GetSpatialRef();
  if (!srs) {
    fprintf(stderr, "Missing spatial reference for layer '%s'.\n", 
            layerName.toLatin1().data());
    exit(-1);
  }
  char *proj = NULL;
  srs->exportToProj4(&proj);
  if (!proj) {
    fprintf(stderr, "Error computing PROJ4 spatial reference for layer '%s'.\n", 
            layerName.toLatin1().data());
    exit(-1);
  }
  Projection pjIndex(proj);
  CPLFree(proj);


  layer->ResetReading();
  OGRFeatureDefn *def = layer->GetLayerDefn();

  int idFieldNr = def->GetFieldIndex("ID");
  int nameFieldNr = def->GetFieldIndex("NAME");
  if (idFieldNr < 0 || nameFieldNr < 0) {
    fprintf(stderr, "Missing index layer fields.\n");
    exit(-1);
  }


  OGRFeature *f;
  while ((f = layer->GetNextFeature()) != NULL) {
    QString id(f->GetFieldAsString(idFieldNr));
    QString name(f->GetFieldAsString(nameFieldNr));

    //    printf("Quad id: %s; name: %s\n", id.toLatin1().data(), name.toLatin1().data());

    OGRGeometry *g;
    g = f->GetGeometryRef();
    if (g != NULL && wkbFlatten(g->getGeometryType()) == wkbPolygon) {
      OGRPolygon *p = (OGRPolygon *)g;
      OGRLinearRing *r = p->getExteriorRing();
      if (!r) {
        fprintf(stderr, "Quad has no exterior polygon ring %s\n", 
                id.toLatin1().data());
        continue;
      }

      int size = r->getNumPoints();
      QPolygonF boundary;
      for (int i = 0; i < size; i++) {
        OGRPoint p;
        r->getPoint(i, &p);
        boundary << QPointF(p.getX(), p.getY());
      }

      QPolygonF projBoundary = pj->transformFrom(&pjIndex, boundary);
      
      quads[id] = Quad(series, id, name, projBoundary);
    } else {
      fprintf(stderr, "Missing or invalid geometry for quad %s\n", 
              id.toLatin1().data());
    }
  }

  OGRDataSource::DestroyDataSource(ds);
}
开发者ID:djdarkbeat,项目名称:ZTopo,代码行数:80,代码来源:import.cpp

示例7: triangulizeGeometry

MultiPolygonView::MultiPolygonView(MapMultiPolygon* mapMultiPolygon,bool polygonFill,osg::Vec4 color)
{
	this->geometryMultiPolygons=new osg::Geometry;
	this->geometryEdgeMultiPolygons=new osg::Geometry;

	this->vertices=new osg::Vec3Array;
	osg::ref_ptr<osg::Vec3Array> verticesCopy=new osg::Vec3Array;
	this->geometryEdgeMultiPolygons->setVertexArray(this->vertices);
	this->geometryMultiPolygons->setVertexArray(verticesCopy);
	normals=new osg::Vec3Array;
	normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));

	this->polygonFillColor=new osg::Vec4Array;
	this->polygonEdgeColor=new osg::Vec4Array;
	this->polygonFillColor->push_back(color);
	this->polygonEdgeColor->push_back(edgeColor);

	
	for (int i=0;i<mapMultiPolygon->getNumGeometries();i++)
	{


		OGRGeometry* ogrGeom=mapMultiPolygon->getGeometryRef(i);
		OGRwkbGeometryType ogrGeomType=ogrGeom->getGeometryType();

		if (wkbPolygon != ogrGeomType && wkbPolygon25D != ogrGeomType)
			continue; // skip



		MapPolygon* mapPolygon=static_cast< MapPolygon*>(ogrGeom);


		OGRLinearRing *poExteriorRing=mapPolygon->getExteriorRing();

			
		OGRPoint point;
		for(int i = 0; i < poExteriorRing->getNumPoints(); i++)
		{
			poExteriorRing->getPoint(i, &point);
			vertices->push_back(osg::Vec3(point.getX(), 0, point.getY()));
			verticesCopy->push_back(osg::Vec3(point.getX(), 0, point.getY()));
		}
		this->geometryEdgeMultiPolygons->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, vertices->size()-poExteriorRing->getNumPoints(), poExteriorRing->getNumPoints()));
		this->geometryMultiPolygons->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, verticesCopy->size()-poExteriorRing->getNumPoints(), poExteriorRing->getNumPoints()));


		if (mapPolygon->getNumInteriorRings())
		{
			for (int i = 0; i < mapPolygon->getNumInteriorRings(); i++)
			{
				OGRLinearRing *ring = mapPolygon->getInteriorRing(i);
				OGRPoint point;

				for (int j = 0; j < ring->getNumPoints(); j++) 
				{
					ring->getPoint(j, &point);
					vertices->push_back(osg::Vec3(point.getX(), 0, point.getY()));
					verticesCopy->push_back(osg::Vec3(point.getX(), 0, point.getY()));
				}
				this->geometryEdgeMultiPolygons->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, vertices->size()-ring->getNumPoints() , ring->getNumPoints()));
				this->geometryMultiPolygons->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, verticesCopy->size()-ring->getNumPoints() , ring->getNumPoints()));
			}
		}
	}


	this->geometryEdgeMultiPolygons->setNormalArray(normals);
	this->geometryEdgeMultiPolygons->setNormalBinding(osg::Geometry::BIND_OVERALL);

	this->geometryEdgeMultiPolygons->setColorArray(this->polygonEdgeColor);
	this->geometryEdgeMultiPolygons->setColorBinding(osg::Geometry::BIND_OVERALL);

	/*if(polygonFill==true)
	{*/


		osgUtil::Tessellator tsl;
		tsl.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
		tsl.setBoundaryOnly(false);
		tsl.retessellatePolygons(*this->geometryMultiPolygons);

		osg::Vec3Array* array = triangulizeGeometry(this->geometryMultiPolygons);
		this->geometryMultiPolygons->setVertexArray(array);
		this->geometryMultiPolygons->removePrimitiveSet(0,this->geometryMultiPolygons->getNumPrimitiveSets());
		this->geometryMultiPolygons->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, array->size()));

		this->geometryMultiPolygons->setNormalArray(normals);
		this->geometryMultiPolygons->setNormalBinding(osg::Geometry::BIND_OVERALL);

		this->geometryMultiPolygons->setColorArray(this->polygonFillColor);
		this->geometryMultiPolygons->setColorBinding(osg::Geometry::BIND_OVERALL);
	//}

}
开发者ID:SijuWu,项目名称:TouchGIS,代码行数:95,代码来源:MultiPolygonView.cpp

示例8: SavePolygons


//.........这里部分代码省略.........
      // 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;
          }
        }
      }

      OGRPolygon polygon;
      linestring.closeRings();

      // simplify poligons
      // remove colinear vertices
      OGRLinearRing linesimple;
      float pointPrevX = 0, pointPrevY = 0;
      for (int i = 0; i < linestring.getNumPoints(); i++)
      {
        OGRPoint point;
        linestring.getPoint(i, &point);

        // start
        if ( i == 0)
        {
          linesimple.addPoint( &point );
          pointPrevX = point.getX();
          pointPrevY = point.getY();
          continue;
        }
        // end vertex
        if ( i == linestring.getNumPoints() - 1 )
        {
          linesimple.addPoint( &point );
          continue;
        }

        OGRPoint pointNext;
        linestring.getPoint(i+1, &pointNext);
        //     | x1 y1 1 |
        // det | x2 y2 1 | = 0 => p1,p2,p3 are colinear
        //     | x3 y3 1 |
        // x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) == 0
        // only if not colinear with previous and next
        if ( pointPrevX*(point.getY()-pointNext.getY()) +
             point.getX()*(pointNext.getY()-pointPrevY) +
             pointNext.getX()*(pointPrevY-point.getY()) != 0 )
        {
          linesimple.addPoint( &point );
          pointPrevX = point.getX();
          pointPrevY = point.getY();
        }
      }

      // as polygon geometry
      polygon.addRing( &linesimple );
      liFeature->SetGeometry( &polygon );

      if( liLayer->CreateFeature( liFeature ) != OGRERR_NONE )
      {
         printf( "\nERROR: Failed to create feature in shapefile.\n" );
         exit( 1 );
      }
      OGRFeature::DestroyFeature( liFeature );
      GDALTermProgress( (float)(k+1) / (float)(m_labels), NULL, NULL );
  }
  GDALTermProgress( 1.0f, NULL, NULL );

  GDALClose( liDS );

}
开发者ID:caomw,项目名称:gdal-segment,代码行数:101,代码来源:vector.cpp

示例9: transformVectorLayerToKmlGeometry

    bool transformVectorLayerToKmlGeometry(KmlLayerInfo<T>& LayerInfo)
    {

      // TODO manage when data are coming from datastore

      GDALDataset_COMPAT* DataSource;
      OGRLayer *Layer;
      OGRFeature *Feature;


      DataSource = GDALOpenRO_COMPAT(LayerInfo.SourceFilename.c_str());
      if( DataSource == nullptr )
      {
        OPENFLUID_LogWarning("Cannot open shapefile "+LayerInfo.SourceFilename+". This Kml output is ignored.");
        return false;
      }

      std::string LayerName = openfluid::tools::Filesystem::basename(LayerInfo.SourceFilename);

      Layer = DataSource->GetLayerByName(LayerName.c_str());

      if (Layer == nullptr)
      {
        OPENFLUID_LogWarning("Cannot open shapefile layer from " + LayerInfo.SourceFilename +
                               ". This Kml output is ignored.");
        return false;
      }


      int OfldIDFieldIndex = Layer->GetLayerDefn()->GetFieldIndex("OFLD_ID");

      if (OfldIDFieldIndex < 0)
      {
        OPENFLUID_LogWarning("Cannot find OFLD_ID attribute in " + LayerInfo.SourceFilename +
                               ". This Kml output is ignored.");
        return false;
      }


      Layer->ResetReading();
      while((Feature = Layer->GetNextFeature()) != nullptr)
      {
        openfluid::core::UnitID_t UnitID = Feature->GetFieldAsInteger(OfldIDFieldIndex);

        if (OPENFLUID_IsUnitExist(LayerInfo.UnitsClass,UnitID))
        {

          OGRGeometry *Geometry;

          Geometry = Feature->GetGeometryRef();

          std::stringstream CoordSS;

          CoordSS << std::fixed << std::setprecision(12);

          T KUI;

          KUI.UnitID = UnitID;

          if (Geometry != nullptr)
          {

            if (Geometry->getGeometryType() != wkbPolygon && Geometry->getGeometryType() != wkbLineString)
            {
              OPENFLUID_LogWarning("Unsupported geometry type in " + LayerInfo.SourceFilename +
                                     ". This Kml output is ignored.");
              return false;
            }

            KUI.GeometryType = Geometry->getGeometryType();

            // polygons
            if (Geometry->getGeometryType() == wkbPolygon)
            {
              OGRLinearRing* Ring;

              Ring = ((OGRPolygon*)(Geometry))->getExteriorRing();

              int NumPoints = Ring->getNumPoints()-1;

              for (int i=0;i<NumPoints;i++)
              {
                OGRPoint *Point = new OGRPoint();
                Ring->getPoint(i,Point);
                CoordSS << " " << Point->getX() << "," << Point->getY();
                delete Point;
              }

              // close the polygon
              if (NumPoints > 0)
              {
                OGRPoint *Point = new OGRPoint();
                Ring->getPoint(0,Point);
                CoordSS << " " << Point->getX() << "," << Point->getY();
                delete Point;
              }

            }


//.........这里部分代码省略.........
开发者ID:OpenFLUID,项目名称:openfluid,代码行数:101,代码来源:KmlObserverBase.hpp


注:本文中的OGRLinearRing::getPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。