<P>Hello, I have built a GIS sytem in which I use radians as my unit of measurement. To serve that purpose I created a OGRSpatialReference to represent a radian based projection. Here is the code that I use...
<P>////begin code snippet////<BR> <BR>char* strWkt="GEOGCS[\"MY RADIAN WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",7030]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",6326]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]],UNIT[\"radian\",1.0],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",4326]]";<BR> <BR>OGRSpatialReference myProjection;<BR>myProjection.importFromWkt(&strWkt);
<P>////end code snippet////
<P>Notice that my Unit node looks like this ...
<P>UNIT[\"radian\",1.0]
<P>My question: is this a correct use of the wkt string?
<P>If the answer is no than please ignore the rest of this posting. If the answer is yes than there seems to be a bug in the OGRProj4CT class. OGRProj4CT is the class which handles conversions between projections. In cases where one of the projections involved in the conversion has a radians based unit the transform method returns faulty results. Here are the relevant bits of code...
<P><BR>////begin code snippet////<BR>int OGRProj4CT::Initialize( OGRSpatialReference * poSourceIn,OGRSpatialReference * poTargetIn )<BR>{<BR> poSRSSource = poSourceIn->Clone();<BR> poSRSTarget = poTargetIn->Clone();<BR> bSourceLatLong = poSRSSource->IsGeographic();<BR> bTargetLatLong = poSRSTarget->IsGeographic();
<P>////end code snippet////
<P>////begin code snippet////
<P>int OGRProj4CT::Transform( int nCount, double *x, double *y, double *z )
<P>{<BR> int err, i;
<P><BR> if( bSourceLatLong )<BR> {<BR> for( i = 0; i < nCount; i++ )<BR> {<BR> x[i] *= DEG_TO_RAD;<BR> y[i] *= DEG_TO_RAD;<BR> }<BR> }<BR>//transform code snipped out//////
<P>if( bTargetLatLong )<BR> {<BR> for( i = 0; i < nCount; i++ )<BR> {<BR> x[i] *= RAD_TO_DEG;<BR> y[i] *= RAD_TO_DEG;<BR> }<BR> }
<P><BR>////end code snippet////
<P>As you can see the flags bSourceLatLong , bTargetLatLong turn on conversion between radians and degrees. The problem is that no check is made to ascertain that the unit really is degrees. In my local codebase I have made and used the following change successfully.
<P><BR>////begin code snippet////<BR>int OGRProj4CT::Initialize( OGRSpatialReference * poSourceIn,OGRSpatialReference * poTargetIn )<BR>{<BR> poSRSSource = poSourceIn->Clone();<BR> poSRSTarget = poTargetIn->Clone();<BR> bSourceLatLong=FALSE;<BR> bTargetLatLong=FALSE;<BR> if(poSRSSource->IsGeographic())<BR> {<BR> const char * unitType=poSRSSource->GetAttrValue("GEOGCS|UNIT",0);<BR> bSourceLatLong=(strstr(unitType,"degree")!=NULL);<BR> }<BR> if(poSRSTarget->IsGeographic())<BR> {<BR> const char *unitType=poSRSTarget->GetAttrValue("GEOGCS|UNIT",0);<BR> bTargetLatLong=(strstr(unitType,"degree")!=NULL);<BR> }
<P><BR>////end code snippet////
<P><BR>My apologies if this topic has been discussed before. The Yahoo mailing list archives are currently inaccessible.
<P>
<P>Thanks,
<P>David E. Knight
<P>david1<*at*>davideknight<*dot*>com</P>