本文整理汇总了C++中OGRGeometry::transform方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRGeometry::transform方法的具体用法?C++ OGRGeometry::transform怎么用?C++ OGRGeometry::transform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRGeometry
的用法示例。
在下文中一共展示了OGRGeometry::transform方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateFeature
OGRErr GTMWaypointLayer::CreateFeature (OGRFeature *poFeature)
{
FILE* fp = poDS->getOutputFP();
if (fp == NULL)
return CE_Failure;
OGRGeometry *poGeom = poFeature->GetGeometryRef();
if ( poGeom == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Features without geometry not supported by GTM writer in waypoints layer." );
return OGRERR_FAILURE;
}
if (NULL != poCT)
{
poGeom = poGeom->clone();
poGeom->transform( poCT );
}
switch( poGeom->getGeometryType() )
{
case wkbPoint:
case wkbPoint25D:
{
OGRPoint* point = (OGRPoint*)poGeom;
double lat = point->getY();
double lon = point->getX();
CheckAndFixCoordinatesValidity(lat, lon);
poDS->checkBounds((float)lat, (float)lon);
writeDouble(fp, lat);
writeDouble(fp, lon);
float altitude = 0.0;
if (poGeom->getGeometryType() == wkbPoint25D)
altitude = (float) point->getZ();
WriteFeatureAttributes(poFeature, altitude);
break;
}
default:
{
CPLError( CE_Failure, CPLE_NotSupported,
"Geometry type of `%s' not supported for 'waypoint' element.\n",
OGRGeometryTypeToName(poGeom->getGeometryType()) );
return OGRERR_FAILURE;
}
}
if (NULL != poCT)
delete poGeom;
return OGRERR_NONE;
}
示例2:
OGRFeature *OGRWarpedLayer::GetFeature( long nFID )
{
OGRFeature* poFeature = m_poDecoratedLayer->GetFeature(nFID);
if( poFeature != NULL )
{
OGRGeometry* poGeom = poFeature->GetGeometryRef();
if( poGeom != NULL && poGeom->transform(m_poCT) != OGRERR_NONE )
{
delete poFeature->StealGeometry();
}
}
return poFeature;
}
示例3: OGRFeature
OGRFeature *OGRWarpedLayer::SrcFeatureToWarpedFeature(OGRFeature* poSrcFeature)
{
OGRFeature* poFeature = new OGRFeature(GetLayerDefn());
poFeature->SetFrom(poSrcFeature);
poFeature->SetFID(poSrcFeature->GetFID());
OGRGeometry* poGeom = poFeature->GetGeomFieldRef(m_iGeomField);
if( poGeom == NULL )
return poFeature;
if( poGeom->transform(m_poCT) != OGRERR_NONE )
{
delete poFeature->StealGeometry(m_iGeomField);
}
return poFeature;
}
示例4: ICreateFeature
OGRErr GTMTrackLayer::ICreateFeature (OGRFeature *poFeature)
{
VSILFILE* fpTmpTrackpoints = poDS->getTmpTrackpointsFP();
if (fpTmpTrackpoints == nullptr)
return OGRERR_FAILURE;
VSILFILE* fpTmpTracks = poDS->getTmpTracksFP();
if (fpTmpTracks == nullptr)
return OGRERR_FAILURE;
OGRGeometry *poGeom = poFeature->GetGeometryRef();
if ( poGeom == nullptr )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Features without geometry not supported by GTM writer in "
"track layer." );
return OGRERR_FAILURE;
}
if (nullptr != poCT)
{
poGeom = poGeom->clone();
poGeom->transform( poCT );
}
switch( poGeom->getGeometryType() )
{
case wkbLineString:
case wkbLineString25D:
{
WriteFeatureAttributes(poFeature);
OGRLineString* line = poGeom->toLineString();
for(int i = 0; i < line->getNumPoints(); ++i)
{
double lat = line->getY(i);
double lon = line->getX(i);
float altitude = 0;
CheckAndFixCoordinatesValidity(lat, lon);
poDS->checkBounds((float)lat, (float)lon);
if (line->getGeometryType() == wkbLineString25D)
altitude = static_cast<float>(line->getZ(i));
WriteTrackpoint( lat, lon, altitude, i==0 );
}
break;
}
case wkbMultiLineString:
case wkbMultiLineString25D:
{
for( auto&& line: poGeom->toMultiLineString() )
{
WriteFeatureAttributes(poFeature);
int n = line->getNumPoints();
for(int i = 0; i < n; ++i)
{
double lat = line->getY(i);
double lon = line->getX(i);
float altitude = 0;
CheckAndFixCoordinatesValidity(lat, lon);
if (line->getGeometryType() == wkbLineString25D)
altitude = static_cast<float>(line->getZ(i));
WriteTrackpoint( lat, lon, altitude, i==0 );
}
}
break;
}
default:
{
CPLError( CE_Failure, CPLE_NotSupported,
"Geometry type of `%s' not supported for 'track' element.\n",
OGRGeometryTypeToName(poGeom->getGeometryType()) );
if (nullptr != poCT)
delete poGeom;
return OGRERR_FAILURE;
}
}
if (nullptr != poCT)
delete poGeom;
return OGRERR_NONE;
}
示例5: CreateFeature
OGRErr GTMTrackLayer::CreateFeature (OGRFeature *poFeature)
{
FILE* fpTmpTrackpoints = poDS->getTmpTrackpointsFP();
if (fpTmpTrackpoints == NULL)
return CE_Failure;
FILE* fpTmpTracks = poDS->getTmpTracksFP();
if (fpTmpTracks == NULL)
return CE_Failure;
OGRGeometry *poGeom = poFeature->GetGeometryRef();
if ( poGeom == NULL )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Features without geometry not supported by GTM writer in track layer." );
return OGRERR_FAILURE;
}
if (NULL != poCT)
{
poGeom = poGeom->clone();
poGeom->transform( poCT );
}
switch( poGeom->getGeometryType() )
{
case wkbLineString:
case wkbLineString25D:
{
WriteFeatureAttributes(poFeature);
OGRLineString* line = (OGRLineString*)poGeom;
for(int i = 0; i < line->getNumPoints(); ++i)
{
double lat = line->getY(i);
double lon = line->getX(i);
float altitude = 0;
CheckAndFixCoordinatesValidity(lat, lon);
poDS->checkBounds((float)lat, (float)lon);
if (line->getGeometryType() == wkbLineString25D)
altitude = (float)line->getZ(i);
WriteTrackpoint( lat, lon, altitude, i==0 );
}
break;
}
case wkbMultiLineString:
case wkbMultiLineString25D:
{
int nGeometries = ((OGRGeometryCollection*)poGeom)->getNumGeometries ();
for(int j = 0; j < nGeometries; ++j)
{
WriteFeatureAttributes(poFeature);
OGRLineString* line = (OGRLineString*) ( ((OGRGeometryCollection*)poGeom)->getGeometryRef(j) );
int n = (line) ? line->getNumPoints() : 0;
for(int i = 0; i < n; ++i)
{
double lat = line->getY(i);
double lon = line->getX(i);
float altitude = 0;
CheckAndFixCoordinatesValidity(lat, lon);
if (line->getGeometryType() == wkbLineString25D)
altitude = (float) line->getZ(i);
WriteTrackpoint( lat, lon, altitude, i==0 );
}
}
break;
}
default:
{
CPLError( CE_Failure, CPLE_NotSupported,
"Geometry type of `%s' not supported for 'track' element.\n",
OGRGeometryTypeToName(poGeom->getGeometryType()) );
if (NULL != poCT)
delete poGeom;
return OGRERR_FAILURE;
}
}
if (NULL != poCT)
delete poGeom;
return OGRERR_NONE;
}
示例6: ProcessError
void
PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill,
PCTypeMap&) {
#ifdef HAVE_GDAL
GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing();
// get defaults
std::string prefix = oc.getString("prefix");
std::string type = oc.getString("type");
RGBColor color = RGBColor::parseColor(oc.getString("color"));
int layer = oc.getInt("layer");
std::string idField = oc.getString("shapefile.id-column");
bool useRunningID = oc.getBool("shapefile.use-running-id");
// start parsing
std::string shpName = file + ".shp";
OGRRegisterAll();
OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
if (poDS == NULL) {
throw ProcessError("Could not open shape description '" + shpName + "'.");
}
// begin file parsing
OGRLayer* poLayer = poDS->GetLayer(0);
poLayer->ResetReading();
// build coordinate transformation
OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
OGRSpatialReference destTransf;
// use wgs84 as destination
destTransf.SetWellKnownGeogCS("WGS84");
OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
if (poCT == NULL) {
if (oc.isSet("shapefile.guess-projection")) {
OGRSpatialReference origTransf2;
origTransf2.SetWellKnownGeogCS("WGS84");
poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
}
if (poCT == 0) {
WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed.");
}
}
OGRFeature* poFeature;
poLayer->ResetReading();
unsigned int runningID = 0;
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
// read in edge attributes
std::string id = useRunningID ? toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
++runningID;
id = StringUtils::prune(id);
if (id == "") {
throw ProcessError("Missing id under '" + idField + "'");
}
id = prefix + id;
// read in the geometry
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if (poGeometry == 0) {
OGRFeature::DestroyFeature(poFeature);
continue;
}
// try transform to wgs84
poGeometry->transform(poCT);
OGRwkbGeometryType gtype = poGeometry->getGeometryType();
switch (gtype) {
case wkbPoint: {
OGRPoint* cgeom = (OGRPoint*) poGeometry;
Position pos((SUMOReal) cgeom->getX(), (SUMOReal) cgeom->getY());
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_ERROR("Unable to project coordinates for POI '" + id + "'.");
}
PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(id, poi, layer)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
}
}
break;
case wkbLineString: {
OGRLineString* cgeom = (OGRLineString*) poGeometry;
PositionVector shape;
for (int j = 0; j < cgeom->getNumPoints(); j++) {
Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j));
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'.");
}
shape.push_back_noDoublePos(pos);
}
Polygon* poly = new Polygon(id, type, color, shape, false, (SUMOReal)layer);
if (!toFill.insert(id, poly, layer)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
}
}
break;
case wkbPolygon: {
OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
PositionVector shape;
for (int j = 0; j < cgeom->getNumPoints(); j++) {
Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j));
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'.");
//.........这里部分代码省略.........
示例7: setError
OGRDataSource *AoIIntersection::intersectAoIWithLayers ( OGRDataSource *ogrSourceData, OGRPolygon *aoiPoly, IntersectionSummary *summary, const char *outFmt )
{
OGRDataSource *ogrIntersection = NULL;
// Spatial reference setup
// make a spatial reference for the area of interest polygon
OGRSpatialReference aoiRef;
aoiRef.SetWellKnownGeogCS( "WGS84" );
// make a spatial reference for the coord sys we will use to calculate area in acres - Albers USA equal area conic
bool acreageCalcAvailable = true;
char *aecWkt = "PROJCS[\"USA_Contiguous_Lambert_Conformal_Conic\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-96],PARAMETER[\"Standard_Parallel_1\",33],PARAMETER[\"Standard_Parallel_2\",45],PARAMETER[\"Latitude_Of_Origin\",39],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"102004\"]]";
OGRSpatialReference aecRef;
OGRErr ogrErr = aecRef.importFromWkt( &aecWkt );
if ( ogrErr != OGRERR_NONE )
{
setError ( NO_SPATIAL_REFERENCE );
acreageCalcAvailable = false;
}
// begin creating the output data structure
// OGRDataSource is the root
ogrIntersection = buildIntersectionDataSource( outFmt );
if (! ogrIntersection )
{
setError( NO_OUTPUT_DATASOURCE );
return 0;
}
int acreIndex = 0, areaIndex = 0;
OGRFieldDefn *acreFldDefn = NULL, *areaPctFldDefn = NULL;
OGRFeatureDefn *featureDefn = buildFeatureDefinition( acreIndex, areaIndex, acreFldDefn, areaPctFldDefn );
// walk the layers in the input data
//
OGRLayer *inputLayer;
summary->numLayers = ogrSourceData->GetLayerCount();
for (int layerCt = 0; layerCt < summary->numLayers; ++layerCt)
{
inputLayer = ogrSourceData->GetLayer( layerCt );
if ( inputLayer == NULL )
{
setError( NO_INPUT_LAYER );
// clean up
delete ogrIntersection;
return 0;
}
// make a clone of aoi polygon to be manipulated
OGRPolygon *aoiClone = (OGRPolygon *)aoiPoly->clone();
if ( ! aoiClone )
{
setError( NO_AOI_CLONE );
// clean up
delete ogrIntersection;
return 0;
}
// ensure that the area of interest polygon is in the same spatial reference as the data layer
// find the spatial reference for the layer
OGRSpatialReference *dataRef = inputLayer->GetSpatialRef();
if ( dataRef )
{
OGRCoordinateTransformation *aoiTransform = OGRCreateCoordinateTransformation( &aoiRef, dataRef );
if( aoiTransform == NULL )
{
setError( NO_AOI_TRANSFORM );
// clean up
delete ogrIntersection;
delete aoiClone;
return 0;
}
aoiClone->transform( aoiTransform );
delete aoiTransform;
}
// find the transform from data layer's CS to Albers USA
// for acreage calculation
OGRCoordinateTransformation *aecTransform = NULL;
acreageCalcAvailable = false;
if ( dataRef )
{
aecTransform = OGRCreateCoordinateTransformation( dataRef, &aecRef );
if( aecTransform == NULL )
{
setError( NO_ACRE_TRANSFORM );
}
else
acreageCalcAvailable = true;
}
// the area enclosed by the AoI
// used for computing the percentage of the AoI intersected by polygons
summary->aoiArea = aoiClone->getExteriorRing()->get_Area();
// create a layer for outputting the intersecting polygons
OGRLayer *intersectionLayer = ogrIntersection->CreateLayer( inputLayer->GetLayerDefn()->GetName(), dataRef, wkbPolygon, 0 );
if ( ! intersectionLayer )
{
//.........这里部分代码省略.........
示例8: ProcessError
int
NBHeightMapper::loadShapeFile(const std::string& file) {
#ifdef HAVE_GDAL
#if GDAL_VERSION_MAJOR < 2
OGRRegisterAll();
OGRDataSource* ds = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);
#else
GDALAllRegister();
GDALDataset* ds = (GDALDataset*)GDALOpenEx(file.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);
#endif
if (ds == NULL) {
throw ProcessError("Could not open shape file '" + file + "'.");
}
// begin file parsing
OGRLayer* layer = ds->GetLayer(0);
layer->ResetReading();
// triangle coordinates are stored in WGS84 and later matched with network coordinates in WGS84
// build coordinate transformation
OGRSpatialReference* sr_src = layer->GetSpatialRef();
OGRSpatialReference sr_dest;
sr_dest.SetWellKnownGeogCS("WGS84");
OGRCoordinateTransformation* toWGS84 = OGRCreateCoordinateTransformation(sr_src, &sr_dest);
if (toWGS84 == 0) {
WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed.");
}
int numFeatures = 0;
OGRFeature* feature;
layer->ResetReading();
while ((feature = layer->GetNextFeature()) != NULL) {
OGRGeometry* geom = feature->GetGeometryRef();
assert(geom != 0);
// @todo gracefull handling of shapefiles with unexpected contents or any error handling for that matter
assert(std::string(geom->getGeometryName()) == std::string("POLYGON"));
// try transform to wgs84
geom->transform(toWGS84);
OGRLinearRing* cgeom = ((OGRPolygon*) geom)->getExteriorRing();
// assume TIN with with 4 points and point0 == point3
assert(cgeom->getNumPoints() == 4);
PositionVector corners;
for (int j = 0; j < 3; j++) {
Position pos((double) cgeom->getX(j), (double) cgeom->getY(j), (double) cgeom->getZ(j));
corners.push_back(pos);
myBoundary.add(pos);
}
addTriangle(corners);
numFeatures++;
/*
OGRwkbGeometryType gtype = geom->getGeometryType();
switch (gtype) {
case wkbPolygon: {
break;
}
case wkbPoint: {
WRITE_WARNING("got wkbPoint");
break;
}
case wkbLineString: {
WRITE_WARNING("got wkbLineString");
break;
}
case wkbMultiPoint: {
WRITE_WARNING("got wkbMultiPoint");
break;
}
case wkbMultiLineString: {
WRITE_WARNING("got wkbMultiLineString");
break;
}
case wkbMultiPolygon: {
WRITE_WARNING("got wkbMultiPolygon");
break;
}
default:
WRITE_WARNING("Unsupported shape type occurred");
break;
}
*/
OGRFeature::DestroyFeature(feature);
}
#if GDAL_VERSION_MAJOR < 2
OGRDataSource::DestroyDataSource(ds);
#else
GDALClose(ds);
#endif
OCTDestroyCoordinateTransformation(toWGS84);
OGRCleanupAll();
return numFeatures;
#else
UNUSED_PARAMETER(file);
WRITE_ERROR("Cannot load shape file since SUMO was compiled without GDAL support.");
return 0;
#endif
}
示例9: WCTSRecurseAndTransform
void WCTSRecurseAndTransform( CPLXMLNode *psTree,
OGRCoordinateTransformation *poCT )
{
if( psTree == NULL )
return;
/* -------------------------------------------------------------------- */
/* If this isn't a geometry mode just recurse. */
/* -------------------------------------------------------------------- */
if( !WCTSIsGeometryElement( psTree ) )
{
WCTSRecurseAndTransform( psTree->psChild, poCT );
WCTSRecurseAndTransform( psTree->psNext, poCT );
return;
}
/* -------------------------------------------------------------------- */
/* Convert this node, and it's children (but not it's sibling) */
/* into serialized XML form for feeding to the GML geometry */
/* parser. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psNext = psTree->psNext;
OGRGeometry *poGeometry;
psTree->psNext = NULL;
poGeometry = (OGRGeometry *) OGR_G_CreateFromGMLTree( psTree );
psTree->psNext = psNext;
if( poGeometry == NULL )
{
/* should we raise an exception? For now, no.*/
WCTSRecurseAndTransform( psTree->psNext, poCT );
return;
}
/* -------------------------------------------------------------------- */
/* Attempt to transform the geometry (inplace). */
/* -------------------------------------------------------------------- */
if( poGeometry->transform( poCT ) != OGRERR_NONE )
WCTSEmitServiceException( "Unable to transform some geometries." );
/* -------------------------------------------------------------------- */
/* Convert back to XML Tree format. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psAltered, sTempCopy;
if( strstr(psTree->pszValue,"Box") == NULL )
psAltered = OGR_G_ExportToGMLTree( (OGRGeometryH) poGeometry );
else
psAltered = OGR_G_ExportEnvelopeToGMLTree( (OGRGeometryH) poGeometry );
OGRGeometryFactory::destroyGeometry( poGeometry );
/* -------------------------------------------------------------------- */
/* do fancy swap to copy contents of altered tree in over the */
/* node being changed. We do this in such a funky way because */
/* we can't change the nodes that point to psTree to point to */
/* psAltered. */
/* -------------------------------------------------------------------- */
CPLAssert( psAltered->psNext == NULL );
memcpy( &sTempCopy, psTree, sizeof(CPLXMLNode));
memcpy( psTree, psAltered, sizeof(CPLXMLNode));
memcpy( psAltered, &sTempCopy, sizeof(CPLXMLNode));
psTree->psNext = psAltered->psNext;
psAltered->psNext = NULL;
CPLDestroyXMLNode( psAltered );
/* -------------------------------------------------------------------- */
/* Continue on to sibling nodes, but do no further travelling */
/* to this nodes children. */
/* -------------------------------------------------------------------- */
WCTSRecurseAndTransform( psTree->psNext, poCT );
}