Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#4604 closed defect (fixed)

Add ability to transform vectors based on GCPs in ogr2ogr

Reported by: Daniel Morissette Owned by: warmerdam
Priority: normal Milestone: 1.10.0
Component: Utilities Version: unspecified
Severity: normal Keywords: ogr2ogr gcp


Every once in a while, we have the need to take non-georeferenced data (e.g. DXF or other CAD files) and draw it on top of a map.

One way to handle this would be to add the ability to specify GCPs in ogr2ogr that would be used to define a transformation that would then be applied to all vector coordinates during the translation. (The gdaltransform program kind of does this for small sets of coordinates, not for whole files)

Attachments (2)

gdal4604.patch (8.4 KB ) - added by Daniel Morissette 12 years ago.
Quick/incomplete hack to add GCP support in ogr2ogr (vs trunk r24170)
testgcp.gml (893 bytes ) - added by Daniel Morissette 12 years ago.
Short GML file for testing…

Download all attachments as: .zip

Change History (7)

by Daniel Morissette, 12 years ago

Attachment: gdal4604.patch added

Quick/incomplete hack to add GCP support in ogr2ogr (vs trunk r24170)

comment:1 by Daniel Morissette, 12 years ago

I attached a quick/incomplete patch that adds preliminary GCP support to ogr2ogr.cpp (based on trunk r24170). I needed this for a single file transformation and unfortunately I do not have more time to polish it, so I am sharing it here in case it is of use to someone else...

A few notes:

  • I don't understand why we have to pass bReversed=TRUE to GDALCreateGCPTransformer() for this patch to work since gdaltransform with the same sets of coordinates works with reversed=FALSE. maybe due to some magic in OGRGeometryFactory::transformWithOptions()?
  • Support for the -order (max transform order) and -i (inverse) args should be added
  • The patch currently overrides the SRS transform with the GCP transform if there is one. A proper implementation should make both GCP and SRS transforms play together nicely, or at the very minimum produce an error if both are specified.

by Daniel Morissette, 12 years ago

Attachment: testgcp.gml added

Short GML file for testing...

comment:2 by Daniel Morissette, 12 years ago

The attached file "testgcp.gml" can be used for testing with the following command

ogr2ogr -gcp 5 -135 0 0 \
        -gcp 283 -135 1000 0 \
        -gcp 5 278 0 1000 \
        -gcp 283 278 1000 1000 \
        -f "GML" out.gml testgcp.gml

The source file testgcp.gml has extent:

 Extent: (5.000000, -135.000000) - (283.000000, 278.000000)

and the output file ends up (as expected) with

 Extent: (0.000000, -0.000000) - (1000.000000, 1000.000000)

comment:3 by rangoy, 12 years ago

This change would be great. Is there any plan for completing this change, and incorporating this into trunk and release?

comment:4 by Even Rouault, 11 years ago

Keywords: ogr2ogr gcp added
Milestone: 1.10.0
Resolution: fixed
Status: newclosed

trunk r25263 : "ogr2ogr: add -gcp, -order n and -tps options to georeference ungeoreference vectors (derived from patch by dmorissette, #4604)"

For Daniel:

  • the mystery about bReversed has been solved. It was due to an uninitialized variable in the original patch (a member variable used before being set to the value passed in the constructor).
  • the -gcp option is now compatible with -s_srs and -t_srs

comment:5 by Daniel Morissette, 11 years ago

Thank you very much Even for your work on this... and for pointing my mistake with bReversed (I see it now, Doh!).

Note: See TracTickets for help on using tickets.