<div dir="ltr"><div><div class="gmail_signature"><div dir="ltr"><div style="margin-bottom:0px;margin-left:0px;padding-bottom:5px"><div style="overflow:hidden"><div style="word-wrap:break-word"><div><p style="margin:0cm 0cm 0.0001pt">Hi,<br></p></div></div></div></div></div></div></div><div dir="ltr"><div dir="ltr"><div>I'm extracting contours in geo-referenced images and saving the results to shape files. At a later point I would like to read the shapefile and transform the contours into the original integer coordinate system of the original image. To be able to do this, I would have to save the "geo transform" (or the inverse) in the shape file. Is there any way I can do this?<br></div><div><br></div><div>Here is my current save routine(minus error checking etc)</div><div><br></div><div><div><font face="monospace, monospace">/*</font></div><div><font face="monospace, monospace">projection = PROJCS["WGS_1984_UTM_Zone_...</font></div><div><font face="monospace, monospace">geoTransform = [0.1   0  x]</font></div><div><font face="monospace, monospace">               [  0  -0.1 y]</font></div><div><font face="monospace, monospace">               */</font></div><div><font face="monospace, monospace">bool OGRShapeFile::write(const PolygonIWithHolesList& imageContours, const QString& filename, const QString& projection, const QTransform& geoTransform)</font></div><div><font face="monospace, monospace">{</font></div><div><font face="monospace, monospace">    // imageContours are integer pixel coordinates</font></div><div><font face="monospace, monospace">    // first we transform them according to the geo transform.</font></div><div><font face="monospace, monospace">    PolygonFWithHolesList contours;</font></div><div><font face="monospace, monospace">    foreach(PolygonIWithHoles contour, imageContours)</font></div><div><font face="monospace, monospace">        contours << poly->toPolygonF(geoTransform);</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    OGRSpatialReference spatialReference;</font></div><div><font face="monospace, monospace">    if (!projection.isNull())</font></div><div><font face="monospace, monospace">    {</font></div><div><font face="monospace, monospace">        std::string tmp1 = projection.toStdString();</font></div><div><font face="monospace, monospace">        char* tmp2 = (char*)tmp1.c_str();</font></div><div><font face="monospace, monospace">        spatialReference.importFromWkt(&tmp2);</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    OGRSFDriver* poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");</font></div><div><font face="monospace, monospace">    OGRDataSource *poDS = poDriver->CreateDataSource(filename.toLocal8Bit(), NULL);</font></div><div><font face="monospace, monospace">    OGRLayer *poLayer = poDS->CreateLayer("point", &spatialReference, wkbPolygon, NULL);</font></div><div><font face="monospace, monospace">    </font></div><div><font face="monospace, monospace">    foreach(const PolygonFWithHoles& polygon, contours)</font></div><div><font face="monospace, monospace">    {</font></div><div><font face="monospace, monospace">        OGRPolygon p;</font></div><div><font face="monospace, monospace">        p.assignSpatialReference(&spatialReference);</font></div><div><font face="monospace, monospace">        for (int i=0; i<polygon.holeCount()+1; i++)</font></div><div><font face="monospace, monospace">        {</font></div><div><font face="monospace, monospace">            ...</font></div><div><font face="monospace, monospace">            p.addRing(&ring);</font></div><div><font face="monospace, monospace">        }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">        OGRFeature *poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());</font></div><div><font face="monospace, monospace">        poFeature->SetGeometry(&p);</font></div><div><font face="monospace, monospace">        poLayer->CreateFeature(poFeature);</font></div><div><font face="monospace, monospace">        OGRFeature::DestroyFeature(poFeature);</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace">    OGRDataSource::DestroyDataSource(poDS);</font></div><div><font face="monospace, monospace">    return true;</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div></div></div></div>