Example #1
0
        //**********************************************************************
        //							GTIFMapSysToProj()
        //
        //		Given a MapSys and zone value generate the best projection_t
        //		code possible.
        //**********************************************************************
        public static projection_t GTIFMapSysToProj(int MapSys, int nZone)
        {
            projection_t ProjCode = (projection_t)KvUserDefined;

            if (MapSys == MapSys_UTM_North)
            {
                ProjCode = projection_t.Proj_UTM_zone_1N + nZone - 1;
            }
            else if (MapSys == MapSys_UTM_South)
            {
                ProjCode = projection_t.Proj_UTM_zone_1S + nZone - 1;
            }
            else if (MapSys == MapSys_State_Plane_27)
            {
                ProjCode = (projection_t)(10000 + nZone);

                // Tennesse override
                if (nZone == 4100)
                {
                    ProjCode = projection_t.Proj_Tennessee_CS27;
                }
            }
            else if (MapSys == MapSys_State_Plane_83)
            {
                ProjCode = (projection_t)(10000 + nZone + 30);

                // Kentucky North override
                if (nZone == 1601)
                {
                    ProjCode = projection_t.Proj_Kentucky_CS83_North;
                }
            }

            return(ProjCode);
        }
Example #2
0
 public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out projection_t val, int index, int count)
 {
     // ignore count
     val = 0;
     ushort[] vals;
     if (GTIFKeyGet(gtif, thekey, out vals, index, 1) == 0)
     {
         return(0);
     }
     val = (projection_t)vals[0];
     return(1);
 }
Example #3
0
        //**********************************************************************
        //							GTIFProjToMapSys()
        //**********************************************************************

        // Translate a Proj_ code into a UTM or State Plane map system, and a zone
        // if possible.
        //
        // @param ProjCode The projection code (Proj_*) as would be stored in the
        // ProjectionGeoKey of a GeoTIFF file.
        // @param pZone Pointer to an integer into which the zone will be placed
        // if the function is successful.
        //
        // @return Returns either MapSys_UTM_North, MapSys_UTM_South,
        // MapSys_State_Plane_27, MapSys_State_Plane_83 or KvUserDefined.
        // KvUserDefined indicates that the
        // function failed to recognise the projection as UTM or State Plane.
        //
        // The zone value is only set if the return code is other than KvUserDefined.
        // For utm map system the returned zone will be between 1 and 60. For
        // State Plane, the USGS state plane zone number is returned. For instance,
        // Alabama East is zone 101.
        //
        // This function is useful to recognise UTM and State Plane coordinate
        // systems, and to extract zone numbers so the projections can be
        // represented as UTM rather than as the underlying projection method such
        // Transverse Mercator for instance.
        public static int GTIFProjToMapSys(projection_t ProjCode, out int pZone)
        {
            int nZone  = KvUserDefined;
            int MapSys = KvUserDefined;

            // --------------------------------------------------------------------
            //		Handle UTM.
            // --------------------------------------------------------------------
            if (ProjCode >= projection_t.Proj_UTM_zone_1N && ProjCode <= projection_t.Proj_UTM_zone_60N)
            {
                MapSys = MapSys_UTM_North;
                nZone  = ProjCode - projection_t.Proj_UTM_zone_1N + 1;
            }
            else if (ProjCode >= projection_t.Proj_UTM_zone_1S && ProjCode <= projection_t.Proj_UTM_zone_60S)
            {
                MapSys = MapSys_UTM_South;
                nZone  = ProjCode - projection_t.Proj_UTM_zone_1S + 1;
            }

            // --------------------------------------------------------------------
            //		Handle State Plane. I think there are some anomolies in
            //		here, so this is a bit risky.
            // --------------------------------------------------------------------
            else if (ProjCode >= (projection_t)10101 && ProjCode <= (projection_t)15299)
            {
                if ((int)ProjCode % 100 >= 30)
                {
                    MapSys = MapSys_State_Plane_83;
                    nZone  = ProjCode - (projection_t)10000 - 30;
                }
                else
                {
                    MapSys = MapSys_State_Plane_27;
                    nZone  = ProjCode - (projection_t)10000;
                }
            }

            pZone = nZone;

            return(MapSys);
        }
		//**********************************************************************
		//							GTIFGetProjTRFInfo()
		//
		//		Transform a PROJECTION_TRF_CODE into a projection method,
		//		and a set of parameters. The parameters identify will
		//		depend on the returned method, but they will all have been
		//		normalized into degrees and meters.
		//**********************************************************************
		// COORD_OP_CODE from coordinate_operation.csv.
		public static bool GTIFGetProjTRFInfo(projection_t projTRFCode, out string projTRFName, out short projMethod, double[] projParms)
		{
			if(projParms==null) projParms=new double[7];

			if((projTRFCode>=projection_t.Proj_UTM_zone_1N&&projTRFCode<=projection_t.Proj_UTM_zone_60N)||
				(projTRFCode>=projection_t.Proj_UTM_zone_1S&&projTRFCode<=projection_t.Proj_UTM_zone_60S))
			{
				bool north;
				int zone;
				if(projTRFCode<=projection_t.Proj_UTM_zone_60N)
				{
					north=true;
					zone=projTRFCode-projection_t.Proj_UTM_zone_1N+1;
				}
				else
				{
					north=false;
					zone=projTRFCode-projection_t.Proj_UTM_zone_1S+1;
				}

				projTRFName=string.Format("UTM zone {0}{1}", zone, north?'N':'S');

				projMethod=9807;

				projParms[0]=0;
				projParms[1]=-183+6*zone;
				projParms[2]=0;
				projParms[3]=0;
				projParms[4]=0.9996;
				projParms[5]=500000;
				projParms[6]=north?0:10000000;

				return true;
			}

			// --------------------------------------------------------------------
			//		Get the proj method. If this fails to return a meaningful
			//		number, then the whole function fails.
			// --------------------------------------------------------------------
			projTRFName=null;
			
			string pszFilename=CSVFilename("projop_wparm.csv");

			projMethod=atoshort(CSVGetField(pszFilename, "COORD_OP_CODE", ((int)projTRFCode).ToString(),
				CSVCompareCriteria.CC_Integer, "COORD_OP_METHOD_CODE"));

			if(projMethod==0) return false;

			// --------------------------------------------------------------------
			//		Initialize a definition of what EPSG codes need to be loaded
			//		into what fields in adfProjParms.
			// --------------------------------------------------------------------
			coordtrans_t CTProjMethod=EPSGProjMethodToCTProjMethod(projMethod);
			int[] EPSGCodes=new int[7];
			SetGTParmIds(CTProjMethod, null, EPSGCodes);

			// --------------------------------------------------------------------
			//		Get the parameters for this projection. For the time being
			//		I am assuming the first four parameters are angles, the
			//		fifth is unitless (normally scale), and the remainder are
			//		linear measures. This works fine for the existing
			//		projections, but is a pretty fragile approach.
			// --------------------------------------------------------------------
			for(int i=0; i<7; i++)
			{
				int EPSGCode=EPSGCodes[i];

				// Establish default
				if(EPSGCode==EPSGAngleRectifiedToSkewedGrid) projParms[i]=90.0;
				else if(EPSGCode==EPSGNatOriginScaleFactor||EPSGCode==EPSGInitialLineScaleFactor||
					EPSGCode==EPSGPseudoStdParallelScaleFactor) projParms[i]=1.0;
				else projParms[i]=0.0;

				// If there is no parameter, skip
				if(EPSGCode==0) continue;

				// Find the matching parameter
				int iEPSG=0;
				for(; iEPSG<7; iEPSG++)
				{
					string paramCodeID=string.Format("PARAMETER_CODE_{0}", iEPSG+1);
					if(atoi(CSVGetField(pszFilename, "COORD_OP_CODE", ((int)projTRFCode).ToString(),
						CSVCompareCriteria.CC_Integer, paramCodeID))==EPSGCode) break;
				}

				// not found, accept the default
				if(iEPSG==7) continue;
				{
					// for CT_ObliqueMercator try alternate parameter codes first
					// because EPSG proj method 9812 uses EPSGFalseXXXXX, but 9815 uses EPSGProjCenterXXXXX
					if(CTProjMethod==coordtrans_t.CT_ObliqueMercator&&EPSGCode==EPSGProjCenterEasting) EPSGCode=EPSGFalseEasting;
					else if(CTProjMethod==coordtrans_t.CT_ObliqueMercator&&EPSGCode==EPSGProjCenterNorthing) EPSGCode=EPSGFalseNorthing;
					else continue;

					for(iEPSG=0; iEPSG<7; iEPSG++)
					{
						string paramCodeID=string.Format("PARAMETER_CODE_{0}", iEPSG+1);

						if(atoi(CSVGetField(pszFilename, "COORD_OP_CODE", ((int)projTRFCode).ToString(), CSVCompareCriteria.CC_Integer, paramCodeID))==EPSGCode)
							break;
					}

					if(iEPSG==7) continue;
				}

				// Get the value, and UOM
				string paramUOMID=string.Format("PARAMETER_UOM_{0}", iEPSG+1);
				string paramValueID=string.Format("PARAMETER_VALUE_{0}", iEPSG+1);

				geounits_t UOM=(geounits_t)atoi(CSVGetField(pszFilename, "COORD_OP_CODE", ((int)projTRFCode).ToString(),
					CSVCompareCriteria.CC_Integer, paramUOMID));
				string value=CSVGetField(pszFilename, "COORD_OP_CODE", ((int)projTRFCode).ToString(),
					CSVCompareCriteria.CC_Integer, paramValueID);

				// Transform according to the UOM
				if((int)UOM>=9100&&(int)UOM<9200) projParms[i]=GTIFAngleStringToDD(value, UOM);
				else if((int)UOM>9000&&(int)UOM<9100)
				{
					double inMeters;
					string dummy;

					if(!GTIFGetUOMLengthInfo(UOM, out dummy, out inMeters)) inMeters=1.0;
					projParms[i]=GTIFAtof(value)*inMeters;
				}
				else projParms[i]=GTIFAtof(value);
			}

			// --------------------------------------------------------------------
			//		Get the name.
			// --------------------------------------------------------------------
			projTRFName=CSVGetField(pszFilename, "COORD_OP_CODE", ((int)projTRFCode).ToString(),
				CSVCompareCriteria.CC_Integer, "COORD_OP_NAME");

			return true;
		}
		//**********************************************************************
		//							GTIFGetPCSInfo()
		//**********************************************************************
		public static bool GTIFGetPCSInfo(pcstype_t PCSCode, out string EPSGName, out projection_t projOp,
			out geounits_t UOMLengthCode, out geographic_t geogCS)
		{
			geographic_t datum;
			int zone;

			int Proj=GTIFPCSToMapSys(PCSCode, out datum, out zone);
			if((Proj==MapSys_UTM_North||Proj==MapSys_UTM_South)&&datum!=(geographic_t)KvUserDefined)
			{
				string datumName=null;
				switch(datum)
				{
					case geographic_t.GCS_NAD27: datumName="NAD27"; break;
					case geographic_t.GCS_NAD83: datumName="NAD83"; break;
					case geographic_t.GCS_WGS_72: datumName="WGS 72"; break;
					case geographic_t.GCS_WGS_72BE: datumName="WGS 72BE"; break;
					case geographic_t.GCS_WGS_84: datumName="WGS 84"; break;
					default: break;
				}

				if(datumName!=null)
				{
					EPSGName=string.Format("{0} / UTM zone {1}{2}", datumName, zone, (Proj==MapSys_UTM_North)?'N':'S');
					projOp=((Proj==MapSys_UTM_North)?projection_t.Proj_UTM_zone_1N-1:projection_t.Proj_UTM_zone_1S-1)+zone;
					UOMLengthCode=geounits_t.Linear_Meter;
					geogCS=datum;
					return true;
				}
			}

			// --------------------------------------------------------------------
			//		Search the pcs.override table for this PCS.
			// --------------------------------------------------------------------
			string filename=CSVFilename("pcs.override.csv");
			string[] record=CSVScanFileByName(filename, "COORD_REF_SYS_CODE", ((int)PCSCode).ToString(),
				CSVCompareCriteria.CC_Integer);

			EPSGName="";
			UOMLengthCode=(geounits_t)KvUserDefined;
			projOp=(projection_t)KvUserDefined;
			geogCS=(geographic_t)KvUserDefined;

			// --------------------------------------------------------------------
			//		If not found, search the EPSG PCS database.
			// --------------------------------------------------------------------
			if(record==null)
			{
				filename=CSVFilename("pcs.csv");
				record=CSVScanFileByName(filename, "COORD_REF_SYS_CODE", ((int)PCSCode).ToString(),
					CSVCompareCriteria.CC_Integer);
				if(record==null) return false;
			}

			// --------------------------------------------------------------------
			//		Get the name
			// --------------------------------------------------------------------
			EPSGName=CSLGetField(record, CSVGetFileFieldId(filename, "COORD_REF_SYS_NAME"));

			// --------------------------------------------------------------------
			//		Get the UOM Length code
			// --------------------------------------------------------------------
			string value=CSLGetField(record, CSVGetFileFieldId(filename, "UOM_CODE"));
			if(atoi(value)>0) UOMLengthCode=(geounits_t)atoi(value);

			// --------------------------------------------------------------------
			//		Get the Coord Op code
			// --------------------------------------------------------------------
			value=CSLGetField(record, CSVGetFileFieldId(filename, "COORD_OP_CODE"));
			if(atoshort(value)>0) projOp=(projection_t)atoi(value);

			// --------------------------------------------------------------------
			//		Get the GeogCS (Datum with PM) code
			// --------------------------------------------------------------------
			value=CSLGetField(record, CSVGetFileFieldId(filename, "SOURCE_GEOGCRS_CODE"));
			if(atoi(value)>0) geogCS=(geographic_t)atoi(value);

			return true;
		}
Example #6
0
 public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, projection_t val)
 {
     ushort[] val1 = new ushort[] { (ushort)val };
     return(GTIFKeySet(gtif, keyID, val1));
 }
Example #7
0
 public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out projection_t val, int index)
 {
     return(GTIFKeyGet(gtif, thekey, out val, index, 0));
 }
Example #8
0
		//**********************************************************************
		//							GTIFProjToMapSys()
		//**********************************************************************

		// Translate a Proj_ code into a UTM or State Plane map system, and a zone
		// if possible.
		//
		// @param ProjCode The projection code (Proj_*) as would be stored in the
		// ProjectionGeoKey of a GeoTIFF file.
		// @param pZone Pointer to an integer into which the zone will be placed
		// if the function is successful.
		//
		// @return Returns either MapSys_UTM_North, MapSys_UTM_South,
		// MapSys_State_Plane_27, MapSys_State_Plane_83 or KvUserDefined.
		// KvUserDefined indicates that the
		// function failed to recognise the projection as UTM or State Plane.
		//
		// The zone value is only set if the return code is other than KvUserDefined.
		// For utm map system the returned zone will be between 1 and 60. For
		// State Plane, the USGS state plane zone number is returned. For instance,
		// Alabama East is zone 101.
		//
		// This function is useful to recognise UTM and State Plane coordinate
		// systems, and to extract zone numbers so the projections can be
		// represented as UTM rather than as the underlying projection method such
		// Transverse Mercator for instance.
		public static int GTIFProjToMapSys(projection_t ProjCode, out int pZone)
		{
			int nZone=KvUserDefined;
			int MapSys=KvUserDefined;

			// --------------------------------------------------------------------
			//		Handle UTM.
			// --------------------------------------------------------------------
			if(ProjCode>=projection_t.Proj_UTM_zone_1N&&ProjCode<=projection_t.Proj_UTM_zone_60N)
			{
				MapSys=MapSys_UTM_North;
				nZone=ProjCode-projection_t.Proj_UTM_zone_1N+1;
			}
			else if(ProjCode>=projection_t.Proj_UTM_zone_1S&&ProjCode<=projection_t.Proj_UTM_zone_60S)
			{
				MapSys=MapSys_UTM_South;
				nZone=ProjCode-projection_t.Proj_UTM_zone_1S+1;
			}

			// --------------------------------------------------------------------
			//		Handle State Plane. I think there are some anomolies in
			//		here, so this is a bit risky.
			// --------------------------------------------------------------------
			else if(ProjCode>=(projection_t)10101&&ProjCode<=(projection_t)15299)
			{
				if((int)ProjCode%100>=30)
				{
					MapSys=MapSys_State_Plane_83;
					nZone=ProjCode-(projection_t)10000-30;
				}
				else
				{
					MapSys=MapSys_State_Plane_27;
					nZone=ProjCode-(projection_t)10000;
				}
			}

			pZone=nZone;

			return MapSys;
		}
Example #9
0
		public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, projection_t val)
		{
			ushort[] val1=new ushort[] { (ushort)val };
			return GTIFKeySet(gtif, keyID, val1);
		}
Example #10
0
		public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out projection_t val, int index)
		{
			return GTIFKeyGet(gtif, thekey, out val, index, 0);
		}
Example #11
0
		public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out projection_t val, int index, int count)
		{
			// ignore count
			val=0;
			ushort[] vals;
			if(GTIFKeyGet(gtif, thekey, out vals, index, 1)==0) return 0;
			val=(projection_t)vals[0];
			return 1;
		}