Exemplo n.º 1
0
 public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out pcstype_t val, int index, int count)
 {
     // ignore count
     val = 0;
     ushort[] vals;
     if (GTIFKeyGet(gtif, thekey, out vals, index, 1) == 0)
     {
         return(0);
     }
     val = (pcstype_t)vals[0];
     return(1);
 }
Exemplo n.º 2
0
		//**********************************************************************
		//							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;
		}
Exemplo n.º 3
0
 public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, pcstype_t val)
 {
     ushort[] val1 = new ushort[] { (ushort)val };
     return(GTIFKeySet(gtif, keyID, val1));
 }
Exemplo n.º 4
0
 public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out pcstype_t val, int index)
 {
     return(GTIFKeyGet(gtif, thekey, out val, index, 0));
 }
Exemplo n.º 5
0
		//**********************************************************************
		//							GTIFPCSToMapSys()
		//**********************************************************************
		//
		// Translate a PCS_ code into a UTM or State Plane map system, a datum,
		// and a zone if possible.
		//
		// @param PCSCode The projection code (PCS_*) as would be stored in the
		// ProjectedCSTypeGeoKey of a GeoTIFF file.
		//
		// @param pDatum Pointer to an integer into which the datum code (GCS_*)
		// is put if the function succeeds.
		//
		// @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_83, MapSys_State_Plane_27 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.
		//
		// The datum (really this is the GCS) is set to a GCS_ value such as GCS_NAD27.
		//
		// This function is useful to recognise (most) UTM and State Plane coordinate
		// systems, even if CSV files aren't available to translate them automatically.
		// It is used as a fallback mechanism by GTIFGetDefn() for normalization when
		// CSV files aren't found.

		public static int GTIFPCSToMapSys(pcstype_t PCSCode, out geographic_t pDatum, out int pZone)
		{
			geographic_t Datum=(geographic_t)KvUserDefined;
			int Proj=KvUserDefined, nZone=KvUserDefined;

			// --------------------------------------------------------------------
			//		UTM with various datums. Note there are lots of PCS UTM
			//		codes not done yet which use strange datums.
			// --------------------------------------------------------------------
			if(PCSCode>=pcstype_t.PCS_NAD27_UTM_zone_3N&&PCSCode<=pcstype_t.PCS_NAD27_UTM_zone_22N)
			{
				Datum=geographic_t.GCS_NAD27;
				Proj=MapSys_UTM_North;
				nZone=PCSCode-pcstype_t.PCS_NAD27_UTM_zone_3N+3;
			}
			else if(PCSCode>=pcstype_t.PCS_NAD83_UTM_zone_3N&&PCSCode<=pcstype_t.PCS_NAD83_UTM_zone_23N)
			{
				Datum=geographic_t.GCS_NAD83;
				Proj=MapSys_UTM_North;
				nZone=PCSCode-pcstype_t.PCS_NAD83_UTM_zone_3N+3;
			}

			else if(PCSCode>=pcstype_t.PCS_WGS72_UTM_zone_1N&&PCSCode<=pcstype_t.PCS_WGS72_UTM_zone_60N)
			{
				Datum=geographic_t.GCS_WGS_72;
				Proj=MapSys_UTM_North;
				nZone=PCSCode-pcstype_t.PCS_WGS72_UTM_zone_1N+1;
			}
			else if(PCSCode>=pcstype_t.PCS_WGS72_UTM_zone_1S&&PCSCode<=pcstype_t.PCS_WGS72_UTM_zone_60S)
			{
				Datum=geographic_t.GCS_WGS_72;
				Proj=MapSys_UTM_South;
				nZone=PCSCode-pcstype_t.PCS_WGS72_UTM_zone_1S+1;
			}

			else if(PCSCode>=pcstype_t.PCS_WGS72BE_UTM_zone_1N&&PCSCode<=pcstype_t.PCS_WGS72BE_UTM_zone_60N)
			{
				Datum=geographic_t.GCS_WGS_72BE;
				Proj=MapSys_UTM_North;
				nZone=PCSCode-pcstype_t.PCS_WGS72BE_UTM_zone_1N+1;
			}
			else if(PCSCode>=pcstype_t.PCS_WGS72BE_UTM_zone_1S&&PCSCode<=pcstype_t.PCS_WGS72BE_UTM_zone_60S)
			{
				Datum=geographic_t.GCS_WGS_72BE;
				Proj=MapSys_UTM_South;
				nZone=PCSCode-pcstype_t.PCS_WGS72BE_UTM_zone_1S+1;
			}

			else if(PCSCode>=pcstype_t.PCS_WGS84_UTM_zone_1N&&PCSCode<=pcstype_t.PCS_WGS84_UTM_zone_60N)
			{
				Datum=geographic_t.GCS_WGS_84;
				Proj=MapSys_UTM_North;
				nZone=PCSCode-pcstype_t.PCS_WGS84_UTM_zone_1N+1;
			}
			else if(PCSCode>=pcstype_t.PCS_WGS84_UTM_zone_1S&&PCSCode<=pcstype_t.PCS_WGS84_UTM_zone_60S)
			{
				Datum=geographic_t.GCS_WGS_84;
				Proj=MapSys_UTM_South;
				nZone=PCSCode-pcstype_t.PCS_WGS84_UTM_zone_1S+1;
			}
			else if(PCSCode>=pcstype_t.PCS_SAD69_UTM_zone_18N&&PCSCode<=pcstype_t.PCS_SAD69_UTM_zone_22N)
			{
				Datum=(geographic_t)KvUserDefined;
				Proj=MapSys_UTM_North;
				nZone=PCSCode-pcstype_t.PCS_SAD69_UTM_zone_18N+18;
			}
			else if(PCSCode>=pcstype_t.PCS_SAD69_UTM_zone_17S&&PCSCode<=pcstype_t.PCS_SAD69_UTM_zone_25S)
			{
				Datum=(geographic_t)KvUserDefined;
				Proj=MapSys_UTM_South;
				nZone=PCSCode-pcstype_t.PCS_SAD69_UTM_zone_17S+17;
			}

			// --------------------------------------------------------------------
			//		State Plane zones, first we translate any PCS_ codes to
			//		a Proj_ code that we can get a handle on.
			// --------------------------------------------------------------------
			for(int i=0; StatePlaneTable[i]!=KvUserDefined; i+=2)
			{
				if(StatePlaneTable[i]==(int)PCSCode) PCSCode=(pcstype_t)StatePlaneTable[i+1];
			}

			if(PCSCode<=(pcstype_t)15900&&PCSCode>=(pcstype_t)10000)
			{
				if(((int)PCSCode%100)>=30)
				{
					Proj=MapSys_State_Plane_83;
					Datum=geographic_t.GCS_NAD83;
				}
				else
				{
					Proj=MapSys_State_Plane_27;
					Datum=geographic_t.GCS_NAD27;
				}

				nZone=PCSCode-(pcstype_t)10000;
				if(Datum==geographic_t.GCS_NAD83) nZone-=30;
			}

			pDatum=Datum;
			pZone=nZone;

			return Proj;
		}
Exemplo n.º 6
0
		public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, pcstype_t val)
		{
			ushort[] val1=new ushort[] { (ushort)val };
			return GTIFKeySet(gtif, keyID, val1);
		}
Exemplo n.º 7
0
		public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out pcstype_t val, int index)
		{
			return GTIFKeyGet(gtif, thekey, out val, index, 0);
		}
Exemplo n.º 8
0
		public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out pcstype_t val, int index, int count)
		{
			// ignore count
			val=0;
			ushort[] vals;
			if(GTIFKeyGet(gtif, thekey, out vals, index, 1)==0) return 0;
			val=(pcstype_t)vals[0];
			return 1;
		}
Exemplo n.º 9
0
        //**********************************************************************
        //							GTIFPCSToMapSys()
        //**********************************************************************
        //
        // Translate a PCS_ code into a UTM or State Plane map system, a datum,
        // and a zone if possible.
        //
        // @param PCSCode The projection code (PCS_*) as would be stored in the
        // ProjectedCSTypeGeoKey of a GeoTIFF file.
        //
        // @param pDatum Pointer to an integer into which the datum code (GCS_*)
        // is put if the function succeeds.
        //
        // @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_83, MapSys_State_Plane_27 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.
        //
        // The datum (really this is the GCS) is set to a GCS_ value such as GCS_NAD27.
        //
        // This function is useful to recognise (most) UTM and State Plane coordinate
        // systems, even if CSV files aren't available to translate them automatically.
        // It is used as a fallback mechanism by GTIFGetDefn() for normalization when
        // CSV files aren't found.

        public static int GTIFPCSToMapSys(pcstype_t PCSCode, out geographic_t pDatum, out int pZone)
        {
            geographic_t Datum = (geographic_t)KvUserDefined;
            int          Proj = KvUserDefined, nZone = KvUserDefined;

            // --------------------------------------------------------------------
            //		UTM with various datums. Note there are lots of PCS UTM
            //		codes not done yet which use strange datums.
            // --------------------------------------------------------------------
            if (PCSCode >= pcstype_t.PCS_NAD27_UTM_zone_3N && PCSCode <= pcstype_t.PCS_NAD27_UTM_zone_22N)
            {
                Datum = geographic_t.GCS_NAD27;
                Proj  = MapSys_UTM_North;
                nZone = PCSCode - pcstype_t.PCS_NAD27_UTM_zone_3N + 3;
            }
            else if (PCSCode >= pcstype_t.PCS_NAD83_UTM_zone_3N && PCSCode <= pcstype_t.PCS_NAD83_UTM_zone_23N)
            {
                Datum = geographic_t.GCS_NAD83;
                Proj  = MapSys_UTM_North;
                nZone = PCSCode - pcstype_t.PCS_NAD83_UTM_zone_3N + 3;
            }

            else if (PCSCode >= pcstype_t.PCS_WGS72_UTM_zone_1N && PCSCode <= pcstype_t.PCS_WGS72_UTM_zone_60N)
            {
                Datum = geographic_t.GCS_WGS_72;
                Proj  = MapSys_UTM_North;
                nZone = PCSCode - pcstype_t.PCS_WGS72_UTM_zone_1N + 1;
            }
            else if (PCSCode >= pcstype_t.PCS_WGS72_UTM_zone_1S && PCSCode <= pcstype_t.PCS_WGS72_UTM_zone_60S)
            {
                Datum = geographic_t.GCS_WGS_72;
                Proj  = MapSys_UTM_South;
                nZone = PCSCode - pcstype_t.PCS_WGS72_UTM_zone_1S + 1;
            }

            else if (PCSCode >= pcstype_t.PCS_WGS72BE_UTM_zone_1N && PCSCode <= pcstype_t.PCS_WGS72BE_UTM_zone_60N)
            {
                Datum = geographic_t.GCS_WGS_72BE;
                Proj  = MapSys_UTM_North;
                nZone = PCSCode - pcstype_t.PCS_WGS72BE_UTM_zone_1N + 1;
            }
            else if (PCSCode >= pcstype_t.PCS_WGS72BE_UTM_zone_1S && PCSCode <= pcstype_t.PCS_WGS72BE_UTM_zone_60S)
            {
                Datum = geographic_t.GCS_WGS_72BE;
                Proj  = MapSys_UTM_South;
                nZone = PCSCode - pcstype_t.PCS_WGS72BE_UTM_zone_1S + 1;
            }

            else if (PCSCode >= pcstype_t.PCS_WGS84_UTM_zone_1N && PCSCode <= pcstype_t.PCS_WGS84_UTM_zone_60N)
            {
                Datum = geographic_t.GCS_WGS_84;
                Proj  = MapSys_UTM_North;
                nZone = PCSCode - pcstype_t.PCS_WGS84_UTM_zone_1N + 1;
            }
            else if (PCSCode >= pcstype_t.PCS_WGS84_UTM_zone_1S && PCSCode <= pcstype_t.PCS_WGS84_UTM_zone_60S)
            {
                Datum = geographic_t.GCS_WGS_84;
                Proj  = MapSys_UTM_South;
                nZone = PCSCode - pcstype_t.PCS_WGS84_UTM_zone_1S + 1;
            }
            else if (PCSCode >= pcstype_t.PCS_SAD69_UTM_zone_18N && PCSCode <= pcstype_t.PCS_SAD69_UTM_zone_22N)
            {
                Datum = (geographic_t)KvUserDefined;
                Proj  = MapSys_UTM_North;
                nZone = PCSCode - pcstype_t.PCS_SAD69_UTM_zone_18N + 18;
            }
            else if (PCSCode >= pcstype_t.PCS_SAD69_UTM_zone_17S && PCSCode <= pcstype_t.PCS_SAD69_UTM_zone_25S)
            {
                Datum = (geographic_t)KvUserDefined;
                Proj  = MapSys_UTM_South;
                nZone = PCSCode - pcstype_t.PCS_SAD69_UTM_zone_17S + 17;
            }

            // --------------------------------------------------------------------
            //		State Plane zones, first we translate any PCS_ codes to
            //		a Proj_ code that we can get a handle on.
            // --------------------------------------------------------------------
            for (int i = 0; StatePlaneTable[i] != KvUserDefined; i += 2)
            {
                if (StatePlaneTable[i] == (int)PCSCode)
                {
                    PCSCode = (pcstype_t)StatePlaneTable[i + 1];
                }
            }

            if (PCSCode <= (pcstype_t)15900 && PCSCode >= (pcstype_t)10000)
            {
                if (((int)PCSCode % 100) >= 30)
                {
                    Proj  = MapSys_State_Plane_83;
                    Datum = geographic_t.GCS_NAD83;
                }
                else
                {
                    Proj  = MapSys_State_Plane_27;
                    Datum = geographic_t.GCS_NAD27;
                }

                nZone = PCSCode - (pcstype_t)10000;
                if (Datum == geographic_t.GCS_NAD83)
                {
                    nZone -= 30;
                }
            }

            pDatum = Datum;
            pZone  = nZone;

            return(Proj);
        }