示例#1
0
 public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out geounits_t val, int index, int count)
 {
     // ignore count
     val = 0;
     ushort[] vals;
     if (GTIFKeyGet(gtif, thekey, out vals, index, 1) == 0)
     {
         return(0);
     }
     val = (geounits_t)vals[0];
     return(1);
 }
		//**********************************************************************
		//						GTIFGetUOMAngleInfo()
		//**********************************************************************
		public static bool GTIFGetUOMAngleInfo(geounits_t UOMAngleCode, out string UOMName, out double inDegrees)
		{
			UOMName=null;
			inDegrees=0;

			switch(UOMAngleCode)
			{
				case geounits_t.Angular_Radian:
					UOMName="radian";
					inDegrees=180.0/Math.PI;
					break;
				case geounits_t.Angular_Degree:
				case geounits_t.Angular_DMS:
				case geounits_t.Angular_DMS_Hemisphere:
				case geounits_t.Angular_DMS_Sexagesimal:
				case geounits_t.Angular_Simple_Degree:
					UOMName="degree";
					inDegrees=1.0;
					break;
				case geounits_t.Angular_Arc_Minute:
					UOMName="arc-minute";
					inDegrees=1/60.0;
					break;
				case geounits_t.Angular_Arc_Second:
					UOMName="arc-second";
					inDegrees=1/3600.0;
					break;
				case geounits_t.Angular_Grad:
					UOMName="grad";
					inDegrees=180.0/200.0;
					break;
				case geounits_t.Angular_Gon:
					UOMName="gon";
					inDegrees=180.0/200.0;
					break;
				case geounits_t.Angular_Microradian:
					UOMName="microradian";
					inDegrees=180.0/(Math.PI*1000000.0);
					break;
			}

			if(UOMName!=null) return true;

			string pszFilename=CSVFilename("unit_of_measure.csv");
			string pszUOMName=CSVGetField(pszFilename, "UOM_CODE", ((int)UOMAngleCode).ToString(),
				CSVCompareCriteria.CC_Integer, "UNIT_OF_MEAS_NAME");

			inDegrees=0;
			UOMName=null;

			// --------------------------------------------------------------------
			//		If the file is found, read from there. Note that FactorC is
			//		an empty field for any of the DMS style formats, and in this
			//		case we really want to return the default InDegrees value
			//		(1.0) from above.
			// --------------------------------------------------------------------
			if(pszUOMName!="")
			{
				double inRadians;

				double factorB=GTIFAtof(CSVGetField(pszFilename, "UOM_CODE", ((int)UOMAngleCode).ToString(),
					CSVCompareCriteria.CC_Integer, "FACTOR_B"));

				double factorC=GTIFAtof(CSVGetField(pszFilename, "UOM_CODE", ((int)UOMAngleCode).ToString(),
					CSVCompareCriteria.CC_Integer, "FACTOR_C"));

				if(factorC!=0.0)
				{
					inRadians=(factorB/factorC);
					inDegrees=inRadians*180.0/Math.PI;
				}

				// We do a special override of some of the DMS formats name
				if(UOMAngleCode==geounits_t.Angular_Degree||UOMAngleCode==geounits_t.Angular_DMS||
					UOMAngleCode==geounits_t.Angular_DMS_Hemisphere||UOMAngleCode==geounits_t.Angular_DMS_Sexagesimal||
					UOMAngleCode==geounits_t.Angular_Simple_Degree)
				{
					inDegrees=1.0;
					UOMName="degree";
					return true;
				}

				UOMName=pszUOMName;
			}
			else return false;

			return true;
		}
		//**********************************************************************
		//						GTIFGetUOMLengthInfo()
		//
		//		Note: This function should eventually also know how to
		//		lookup length aliases in the UOM_LE_ALIAS table.
		//**********************************************************************
		public static bool GTIFGetUOMLengthInfo(geounits_t UOMLengthCode, out string UOMName, out double inMeters)
		{
			// --------------------------------------------------------------------
			//		We short cut meter to save work and avoid failure for missing
			//		in the most common cases.
			// --------------------------------------------------------------------
			if(UOMLengthCode==geounits_t.Linear_Meter)
			{
				UOMName="meter";
				inMeters=1.0;
				return true;
			}

			if(UOMLengthCode==geounits_t.Linear_Foot)
			{
				UOMName="foot";
				inMeters=0.3048;
				return true;
			}

			if(UOMLengthCode==geounits_t.Linear_Foot_US_Survey)
			{
				UOMName="US survey foot";
				inMeters=12.0/39.37;
				return true;
			}

			UOMName=null;
			inMeters=0;

			// --------------------------------------------------------------------
			//		Search the units database for this unit. If we don't find
			//		it return failure.
			// --------------------------------------------------------------------
			string filename=CSVFilename("unit_of_measure.csv");

			string[] record=CSVScanFileByName(filename, "UOM_CODE", ((int)UOMLengthCode).ToString(), CSVCompareCriteria.CC_Integer);
			if(record==null) return false;

			// --------------------------------------------------------------------
			//		Get the name.
			// --------------------------------------------------------------------
			int iNameField=CSVGetFileFieldId(filename, "UNIT_OF_MEAS_NAME");
			UOMName=CSLGetField(record, iNameField);

			// --------------------------------------------------------------------
			//		Get the A and B factor fields, and create the multiplicative
			//		factor.
			// --------------------------------------------------------------------
			int iBFactorField=CSVGetFileFieldId(filename, "FACTOR_B");
			int iCFactorField=CSVGetFileFieldId(filename, "FACTOR_C");

			if(GTIFAtof(CSLGetField(record, iCFactorField))>0.0)
				inMeters=GTIFAtof(CSLGetField(record, iBFactorField))/GTIFAtof(CSLGetField(record, iCFactorField));

			return true;
		}
		//**********************************************************************
		//							GTIFGetGCSInfo()
		//
		//		Fetch the datum, and prime meridian related to a particular GCS.
		//**********************************************************************
		public static bool GTIFGetGCSInfo(geographic_t GCSCode, out string name, out geodeticdatum_t datum,
			out primemeridian_t pm, out geounits_t UOMAngle)
		{
			name=null;
			datum=(geodeticdatum_t)KvUserDefined;

			// --------------------------------------------------------------------
			//		Handle some "well known" GCS codes directly.
			// --------------------------------------------------------------------
			pm=primemeridian_t.PM_Greenwich;
			UOMAngle=geounits_t.Angular_DMS_Hemisphere;
			if(GCSCode==geographic_t.GCS_NAD27)
			{
				datum=geodeticdatum_t.Datum_North_American_Datum_1927;
				name="NAD27";
				return true;
			}
			else if(GCSCode==geographic_t.GCS_NAD83)
			{
				datum=geodeticdatum_t.Datum_North_American_Datum_1983;
				name="NAD83";
				return true;
			}
			else if(GCSCode==geographic_t.GCS_WGS_84)
			{
				datum=geodeticdatum_t.Datum_WGS84;
				name="WGS 84";
				return true;
			}
			else if(GCSCode==geographic_t.GCS_WGS_72)
			{
				datum=geodeticdatum_t.Datum_WGS72;
				name="WGS 72";
				return true;
			}
			else if(GCSCode==(geographic_t)KvUserDefined) return false;

			// --------------------------------------------------------------------
			//		Search the database for the corresponding datum code.
			// --------------------------------------------------------------------
			string filename=CSVFilename("gcs.override.csv");
			datum=(geodeticdatum_t)atoi(CSVGetField(filename, "COORD_REF_SYS_CODE", ((int)GCSCode).ToString(),
				CSVCompareCriteria.CC_Integer, "DATUM_CODE"));

			if((int)datum<1)
			{
				filename=CSVFilename("gcs.csv");
				datum=(geodeticdatum_t)atoi(CSVGetField(filename, "COORD_REF_SYS_CODE", ((int)GCSCode).ToString(),
					CSVCompareCriteria.CC_Integer, "DATUM_CODE"));
			}

			if((int)datum<1) return false;

			pm=(primemeridian_t)KvUserDefined;
			UOMAngle=(geounits_t)KvUserDefined;
			name=null;

			// --------------------------------------------------------------------
			//		Get the PM.
			// --------------------------------------------------------------------
			pm=(primemeridian_t)atoi(CSVGetField(filename, "COORD_REF_SYS_CODE", ((int)GCSCode).ToString(),
				CSVCompareCriteria.CC_Integer, "PRIME_MERIDIAN_CODE"));
			if((int)pm<1) return false;

			// --------------------------------------------------------------------
			//		Get the angular units.
			// --------------------------------------------------------------------
			UOMAngle=(geounits_t)atoi(CSVGetField(filename, "COORD_REF_SYS_CODE", ((int)GCSCode).ToString(),
				CSVCompareCriteria.CC_Integer, "UOM_CODE"));
			if((int)UOMAngle<1) return false;

			// --------------------------------------------------------------------
			//		Get the name.
			// --------------------------------------------------------------------
			name=CSVGetField(filename, "COORD_REF_SYS_CODE", ((int)GCSCode).ToString(), CSVCompareCriteria.CC_Integer,
				"COORD_REF_SYS_NAME");

			return true;
		}
		//**********************************************************************
		//						GTIFAngleStringToDD()
		//
		//		Convert an angle in the specified units to decimal degrees.
		//**********************************************************************
		public static double GTIFAngleStringToDD(string angle, geounits_t UOMAngle)
		{
			if(UOMAngle==geounits_t.Angular_DMS_Sexagesimal) // DDD.MMSSsss
			{
				double tmp=GTIFAtof(angle);
				bool sign=tmp<0;
				tmp=Math.Abs(tmp);

				double dfAngle=Math.Floor(tmp);
				tmp-=dfAngle;
				tmp*=100;

				double dfMinutes=Math.Floor(tmp);
				tmp-=dfMinutes;

				dfAngle+=dfMinutes/60;
				dfAngle+=tmp/36;

				if(sign) dfAngle*=-1;

				return dfAngle;
			}

			if(UOMAngle==geounits_t.Angular_Grad||UOMAngle==geounits_t.Angular_Gon) return 180*(GTIFAtof(angle)/200);
			if(UOMAngle==geounits_t.Angular_Radian) return 180*(GTIFAtof(angle)/Math.PI);
			if(UOMAngle==geounits_t.Angular_Arc_Minute) return GTIFAtof(angle)/60;
			if(UOMAngle==geounits_t.Angular_Arc_Second) return GTIFAtof(angle)/3600;

			// decimal degrees ... some cases missing but seeminly never used
#if DEBUG
			if(!(UOMAngle==geounits_t.Angular_Degree||UOMAngle==(geounits_t)KvUserDefined||UOMAngle==0))
				throw new ArgumentOutOfRangeException("UOMAngle");
#endif
			return GTIFAtof(angle);
		}
		//**********************************************************************
		//							GTIFAngleToDD()
		//
		//		Convert a numeric angle to decimal degress.
		//**********************************************************************
		public static double GTIFAngleToDD(double angle, geounits_t UOMAngle)
		{
			if(UOMAngle==geounits_t.Angular_DMS_Sexagesimal) // DDD.MMSSsss
			{
				string szAngleString=string.Format("{0,12:F7}", angle);
				angle=GTIFAngleStringToDD(szAngleString, UOMAngle);
			}
			else
			{
				double dfInDegrees=1.0;
				string dummy;
				GTIFGetUOMAngleInfo(UOMAngle, out dummy, out dfInDegrees);
				angle=angle*dfInDegrees;
			}

			return angle;
		}
		//**********************************************************************
		//							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;
		}
示例#8
0
 public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, geounits_t val)
 {
     ushort[] val1 = new ushort[] { (ushort)val };
     return(GTIFKeySet(gtif, keyID, val1));
 }
示例#9
0
 public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out geounits_t val, int index)
 {
     return(GTIFKeyGet(gtif, thekey, out val, index, 0));
 }
示例#10
0
		public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, geounits_t val)
		{
			ushort[] val1=new ushort[] { (ushort)val };
			return GTIFKeySet(gtif, keyID, val1);
		}
示例#11
0
		public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out geounits_t val, int index)
		{
			return GTIFKeyGet(gtif, thekey, out val, index, 0);
		}
示例#12
0
		public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out geounits_t val, int index, int count)
		{
			// ignore count
			val=0;
			ushort[] vals;
			if(GTIFKeyGet(gtif, thekey, out vals, index, 1)==0) return 0;
			val=(geounits_t)vals[0];
			return 1;
		}