[gdal-dev] copying OGRSpatialReference

Frank Warmerdam warmerdam at p...
Sun Jul 15 23:15:26 EDT 2001


Ben Discoe wrote:
> 
> I'm unclear on how to copy a OGRSpatialReference value. If i just use the
> default assignment operator, like this:
> 
> OGRSpatialReference test1;
> test1.SetProjCS("UTM Zone 12, Northern Hemisphere");
> OGRSpatialReference test2 = test1;
>
> then it crashes when both are deleted, presumably because it's a shallow
> rather than deep copy.

Ben,

Fixed. 

> The "Clone" method looks like it's provided to be used instead, but when i
> try:
> 
> OGRSpatialReference test1;
> OGRSpatialReference *test2 = test1.Clone();
> 
> it crashes as well. Actually, Clone() seems to work as long as the source
> has some nodes, so perhaps is it just a little bug with empty projections.

Fixed. 

In general I have always used the Clone() method to make copies, but I have
now implemented copy constructors and assignment operators. You are exposing
the fact that I myself use these classes in fairly specific ways and so I 
don't fall into these traps I have laid for others. 

Nevertheless, I am happy to fix them as they come up. 

Best regards,

---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at p...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list