[Gdal-dev] Problem in Coordinate Transformation
bargi
bhagwat.maimt at gmail.com
Thu Feb 21 01:57:34 EST 2008
Hi to all,
I am working on a project in which I have to project shapefiles on our
Application.
I am facing problem in transforming coordinate from one system to another
................
I googled a lot and found some code and try to run it.........but Its not
working properly..............
The code is as follow:
[code]
if ( !__GOOGRFeatureSourceDriversRegistered ) {
OGRRegisterAll();
__GOOGRFeatureSourceDriversRegistered = true;
}
OGRDataSource *ogrDataSource = OGRSFDriverRegistrar::Open( qPrintable(
file ));
if ( !ogrDataSource ) {
return false;
}
const int nLayers = ogrDataSource->GetLayerCount();
OGRLayer *layer = ogrDataSource->GetLayer( 0 );
m_displayName = layer->GetLayerDefn()->GetName();
m_path = file;
m_driverName = ogrDataSource->GetDriver()->GetName();
for ( int i = 0; i < nLayers; ++i ) {
layer = ogrDataSource->GetLayer( i );
OGRSpatialReference* pSourceSRS = layer->GetSpatialRef();
OGRSpatialReference* pTargetSRS = pSourceSRS->Clone();
pTargetSRS->SetProjCS("TM");
pTargetSRS->SetTM(0,0,1,0,0);
OGRGeometry* poGeometry;
double x,y;
OGRCoordinateTransformation* poCT =
OGRCreateCoordinateTransformation(pSourceSRS,pTargetSRS);
layer->ResetReading();
OGRFeature *ogrFeature = 0;
while ( (ogrFeature = layer->GetNextFeature()) ) {
poGeometry = ogrFeature->GetGeometryRef();
if (poGeometry !=NULL) {
if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString)
{
OGRPoint *poPoint = (OGRPoint *) poGeometry;
x = poPoint->getX();
y = poPoint->getY();
if (poCT!= NULL || !poCT->Transform(1,&x,&y)) {
poPoint->setX(x); //Set coordinate
poPoint->setY(y);
qDebug()<< poCT;
printf( "(\n%f,%f) ->
(%f,%f)\n",poPoint->getX(),poPoint->getY(),x, y );
GOFeature *feature = new GOFeature( ogrFeature );
features.push_back( feature );
}
}
}
}
}
[/code]
But it is not changing the coordinate............
The output is as follow when printf statement run......
(0.000000,0.000000) -> (0.000000,0.000000)
I am not able to understand where is the problem ?????
I this forum I found a post in which there was given suggestion for
Transformation which is as follow:
[code]
o Create a new layer for the output.
o Make sure you pass the altered OGRSpatialReference to the
CreateLayer() call.
o You might as well just call transform() on the geometry
instead of extracting the point and transforming that.
[/code]
When I try to use CreateLayer("MyFile",pTargetSRS,wkbunknow,null) function
,It gives error that ABC.shp file open in readonly ,MyFile cannot be
created........
The following line
features.push_back( feature );
Is for adding features to a list from which we can extract features to
draw................
Also please tell me how can I stored changed coordinate of features and
retrieve them later..........
Any queries are welcome.........
Please help me to resolve the problem and please give steps of
implementation.....
Thanks
--
View this message in context: http://www.nabble.com/Problem-in-Coordinate-Transformation-tp15605836p15605836.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
More information about the gdal-dev
mailing list