public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out string val, int index, int count) { val = null; if (count < 0) { return(0); } if (!gtif.gt_keys.ContainsKey(thekey)) { return(0); } GeoKey key = gtif.gt_keys[thekey]; if (key.gk_type != tagtype_t.TYPE_ASCII) { return(0); } string val_ = (string)key.gk_data; if (count == 0 || (count + index) > val_.Length) { val = val_.Substring(index); } else { val = val_.Substring(index, count); } return(val.Length); }
public static void GTIFPrint(GTIF gtif, GTIFPrintMethod print, object aux) { if (print == null) { print = DefaultPrint; } if (aux == null) { aux = Console.Out; } string message = FMT_GEOTIFF + "\n"; print(message, aux); message = string.Format("\t" + FMT_VERSION + "\n", gtif.gt_version); print(message, aux); message = string.Format("\t" + FMT_REV + "\n", gtif.gt_rev_major, gtif.gt_rev_minor); print(message, aux); message = string.Format("\t{0}\n", FMT_TAGS); print(message, aux); PrintGeoTags(gtif, print, aux); message = string.Format("\t\t{0}\n", FMT_TAGEND); print(message, aux); message = string.Format("\t{0}\n", FMT_KEYS); print(message, aux); foreach (GeoKey key in gtif.gt_keys.Values) { PrintKey(key, print, aux); } message = string.Format("\t\t{0}\n", FMT_KEYEND); print(message, aux); message = string.Format("\t{0}\n", FMT_GEOEND); print(message, aux); }
static void PrintGeoTags(GTIF gt, GTIFPrintMethod print, object aux) { TIFF tif = gt.gt_tif; if (tif == null) { return; } object data; int count; if (gt.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out count, out data)) { PrintTag((int)GTIFF_TIEPOINTS, count / 3, (double[])data, 3, print, aux); } if (gt.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out data)) { PrintTag((int)GTIFF_PIXELSCALE, count / 3, (double[])data, 3, print, aux); } if (gt.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out count, out data)) { PrintTag((int)GTIFF_TRANSMATRIX, count / 4, (double[])data, 4, print, aux); } }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out double[] val, int index, int count) { val = null; if (!gtif.gt_keys.ContainsKey(thekey)) { return(0); } GeoKey key = gtif.gt_keys[thekey]; if (key.gk_type != tagtype_t.TYPE_DOUBLE) { return(0); } double[] val_ = (double[])key.gk_data; if (count == 0 || (count + index) > val_.Length) { count = val_.Length - index; } if (count <= 0) { return(0); } val = new double[count]; Array.Copy(val_, index, val, 0, count); return(count); }
public static int GTIFKeyInfo(GTIF gtif, geokey_t key, out tagtype_t type) { type=tagtype_t.TYPE_UNKNOWN; if(!gtif.gt_keys.ContainsKey(key)) return 0; GeoKey keyptr=gtif.gt_keys[key]; type=keyptr.gk_type; return keyptr.gk_count; }
//********************************************************************* // // Public Routines // //********************************************************************* // This function deallocates an existing GeoTIFF access handle previously // created with GTIFNew(). If the handle was // used to write GeoTIFF keys to the TIFF file, the // GTIFWriteKeys() function should be used // to flush results to the file before calling GTIFFree(). GTIFFree() // should be called before XTIFFClose() is // called on the corresponding TIFF file handle. public static void GTIFFree(GTIF gtif) { if (gtif == null) { return; } gtif.gt_keys.Clear(); }
// return the Header info of this geotiff file public static void GTIFDirectoryInfo(GTIF gtif, int[] version, out int keycount) { if (version != null && version.Length >= 3) { version[0] = gtif.gt_version; version[1] = gtif.gt_rev_major; version[2] = gtif.gt_rev_minor; } keycount = gtif.gt_keys.Count; }
// return the Header info of this geotiff file public static void GTIFDirectoryInfo(GTIF gtif, int[] version, out int keycount) { if(version!=null&&version.Length>=3) { version[0]=gtif.gt_version; version[1]=gtif.gt_rev_major; version[2]=gtif.gt_rev_minor; } keycount=gtif.gt_keys.Count; }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out vdatum_t val, int index, int count) { // ignore count val = 0; ushort[] vals; if (GTIFKeyGet(gtif, thekey, out vals, index, 1) == 0) { return(0); } val = (vdatum_t)vals[0]; return(1); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out double val, int index, int count) { // ignore count val = 0; double[] vals; if (GTIFKeyGet(gtif, thekey, out vals, index, 1) == 0) { return(0); } val = vals[0]; return(1); }
public static int GTIFKeyInfo(GTIF gtif, geokey_t key, out tagtype_t type) { type = tagtype_t.TYPE_UNKNOWN; if (!gtif.gt_keys.ContainsKey(key)) { return(0); } GeoKey keyptr = gtif.gt_keys[key]; type = keyptr.gk_type; return(keyptr.gk_count); }
static void PrintGeoTags(GTIF gt, GTIFPrintMethod print, object aux) { TIFF tif=gt.gt_tif; if(tif==null) return; object data; int count; if(gt.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out count, out data)) PrintTag((int)GTIFF_TIEPOINTS, count/3, (double[])data, 3, print, aux); if(gt.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out data)) PrintTag((int)GTIFF_PIXELSCALE, count/3, (double[])data, 3, print, aux); if(gt.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out count, out data)) PrintTag((int)GTIFF_TRANSMATRIX, count/4, (double[])data, 4, print, aux); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out string val) { val = null; if (!gtif.gt_keys.ContainsKey(thekey)) { return(0); } GeoKey key = gtif.gt_keys[thekey]; if (key.gk_type != tagtype_t.TYPE_ASCII) { return(0); } val = (string)key.gk_data; return(val.Length); }
public static void GTIFPrint(GTIF gtif, GTIFPrintMethod print, object aux) { if(print==null) print=DefaultPrint; if(aux==null) aux=Console.Out; string message=FMT_GEOTIFF+"\n"; print(message, aux); message=string.Format("\t"+FMT_VERSION+"\n", gtif.gt_version); print(message, aux); message=string.Format("\t"+FMT_REV+"\n", gtif.gt_rev_major, gtif.gt_rev_minor); print(message, aux); message=string.Format("\t{0}\n", FMT_TAGS); print(message, aux); PrintGeoTags(gtif, print, aux); message=string.Format("\t\t{0}\n", FMT_TAGEND); print(message, aux); message=string.Format("\t{0}\n", FMT_KEYS); print(message, aux); foreach(GeoKey key in gtif.gt_keys.Values) PrintKey(key, print, aux); message=string.Format("\t\t{0}\n", FMT_KEYEND); print(message, aux); message=string.Format("\t{0}\n", FMT_GEOEND); print(message, aux); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, double[] val) { if (val == null) // delete the indicated tag { if (!gtif.gt_keys.ContainsKey(keyID)) { return(false); } gtif.gt_keys.Remove(keyID); gtif.gt_flags |= gtiff_flags.FLAG_FILE_MODIFIED; return(true); } if (gtif.gt_keys.ContainsKey(keyID)) { gtif.gt_keys.Remove(keyID); gtif.gt_flags |= gtiff_flags.FLAG_FILE_MODIFIED; } // We need to create the key try { GeoKey key = new GeoKey(); key.gk_key = keyID; key.gk_type = tagtype_t.TYPE_DOUBLE; key.gk_count = val.Length; double[] tmp = new double[val.Length]; val.CopyTo(tmp, 0); key.gk_data = tmp; gtif.gt_keys.Add(keyID, key); gtif.gt_flags |= gtiff_flags.FLAG_FILE_MODIFIED; return(true); } catch { return(false); } }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, string val) { if (val == null) // delete the indicated tag { if (!gtif.gt_keys.ContainsKey(keyID)) { return(false); } gtif.gt_keys.Remove(keyID); gtif.gt_flags |= gtiff_flags.FLAG_FILE_MODIFIED; return(true); } if (gtif.gt_keys.ContainsKey(keyID)) { gtif.gt_keys.Remove(keyID); gtif.gt_flags |= gtiff_flags.FLAG_FILE_MODIFIED; } val = val.Trim('\0'); // We need to create the key try { GeoKey key = new GeoKey(); key.gk_key = keyID; key.gk_type = tagtype_t.TYPE_ASCII; key.gk_count = val.Length; key.gk_data = val.Substring(0, val.Length); gtif.gt_keys.Add(keyID, key); gtif.gt_flags |= gtiff_flags.FLAG_FILE_MODIFIED; return(true); } catch { return(false); } }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, double val) { double[] val1 = new double[] { val }; return(GTIFKeySet(gtif, keyID, val1)); }
//***********************************************************************/ //* GTIFPCSToImage() */ //***********************************************************************/ // Translate a projection coordinate to pixel/line coordinates. // // At this time this function does not support PCS to image translations for // tiepoints-only based definitions, only matrix and pixelscale/tiepoints // formulations are supposed. // // @param gtif The handle from GTIFNew() indicating the target file. // @param x A reference to the double containing the pixel offset on input, // and into which the easting/longitude will be put on completion. // @param y A reference to the double containing the line offset on input, // and into which the northing/latitude will be put on completion. // // @return true if the transformation succeeds, or false if it fails. It may // fail if the file doesn't have properly setup transformation information, // or it is in a form unsupported by this function. public static bool GTIFPCSToImage(GTIF gtif, ref double x, ref double y) { bool result = false; int tiepoint_count, count, transform_count; TIFF tif = gtif.gt_tif; double[] tiepoints = null; double[] pixel_scale = null; double[] transform = null; // -------------------------------------------------------------------- // Fetch tiepoints and pixel scale. // -------------------------------------------------------------------- object ap; if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out tiepoint_count, out ap)) { tiepoint_count = 0; } else if (ap is double[]) { tiepoints = (double[])ap; } if (!gtif.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out ap)) { count = 0; } else if (ap is double[]) { pixel_scale = (double[])ap; } if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out transform_count, out ap)) { transform_count = 0; } else if (ap is double[]) { transform = (double[])ap; } // -------------------------------------------------------------------- // Handle matrix - convert to "geotransform" format, invert and // apply. // -------------------------------------------------------------------- if (transform_count == 16) { double x_in = x, y_in = y; double[] gt_in = new double[6]; double[] gt_out = new double[6]; gt_in[0] = transform[0]; gt_in[1] = transform[1]; gt_in[2] = transform[3]; gt_in[3] = transform[4]; gt_in[4] = transform[5]; gt_in[5] = transform[7]; if (!inv_geotransform(gt_in, gt_out)) { result = false; } else { x = x_in * gt_out[0] + y_in * gt_out[1] + gt_out[2]; y = x_in * gt_out[3] + y_in * gt_out[4] + gt_out[5]; result = true; } } // -------------------------------------------------------------------- // If the pixelscale count is zero, but we have tiepoints use // the tiepoint based approach. // -------------------------------------------------------------------- else if (tiepoint_count > 6 && count == 0) { result = GTIFTiepointTranslate(tiepoint_count / 6, tiepoints, 3, tiepoints, 0, ref x, ref y); } // -------------------------------------------------------------------- // For now we require one tie point, and a valid pixel scale. // -------------------------------------------------------------------- else if (count >= 3 && tiepoint_count >= 6) { x = (x - tiepoints[3]) / pixel_scale[0] + tiepoints[0]; y = (y - tiepoints[4]) / (-1 * pixel_scale[1]) + tiepoints[1]; result = true; } return(result); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out vdatum_t val, int index, int count) { // ignore count val=0; ushort[] vals; if(GTIFKeyGet(gtif, thekey, out vals, index, 1)==0) return 0; val=(vdatum_t)vals[0]; return 1; }
// Print off the directory info, using whatever method is specified // (defaults to fprintf if null). The "aux" parameter is provided for user // defined method for passing parameters or whatever. // // The output format is a "GeoTIFF meta-data" file, which may be // used to import information with the GTIFFImport() routine. public static void GTIFPrint(GTIF gtif) { GTIFPrint(gtif, null, null); }
static int ReadTag(GTIF gt, GTIFReadMethod scan, object aux) { string message = scan(aux); if (message == null) { return(-1); } if (message.Length >= 12) { if (message.ToLower().Substring(0, 12) == FMT_TAGEND.ToLower().Substring(0, 12)) { return(0); } } try { int firstp = message.IndexOfAny(new char[] { '(', ' ', '\t' }); if (firstp < 0) { return(StringError(message)); } string tagname = message.Substring(0, firstp).Trim(); message = message.Substring(firstp); int colon = message.IndexOf(':'); if (colon < 0) { return(StringError(message)); } message = message.Substring(0, colon); message = message.Trim(' ', '\t', '(', ')'); string[] spl = message.Split(','); if (spl.Length != 2) { return(StringError(message)); } int nrows = int.Parse(spl[0]); int ncols = int.Parse(spl[1]); int tag = GTIFTagCode(tagname); if (tag < 0) { return(StringError(tagname)); } int count = nrows * ncols; double[] dptr = new double[count]; for (int i = 0; i < nrows; i++) { message = scan(aux); if (message == null) { return(-1); } spl = message.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (spl.Length != ncols) { StringError(message); } for (int j = 0; j < ncols; j++) { message = spl[j]; dptr[i * ncols + j] = GTIFAtof(message); } } gt.gt_methods.set(gt.gt_tif, (ushort)tag, count, dptr); } catch { return(StringError(message)); } return(1); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, double[] val) { if(val==null) // delete the indicated tag { if(!gtif.gt_keys.ContainsKey(keyID)) return false; gtif.gt_keys.Remove(keyID); gtif.gt_flags|=gtiff_flags.FLAG_FILE_MODIFIED; return true; } if(gtif.gt_keys.ContainsKey(keyID)) { gtif.gt_keys.Remove(keyID); gtif.gt_flags|=gtiff_flags.FLAG_FILE_MODIFIED; } // We need to create the key try { GeoKey key=new GeoKey(); key.gk_key=keyID; key.gk_type=tagtype_t.TYPE_DOUBLE; key.gk_count=val.Length; double[] tmp=new double[val.Length]; val.CopyTo(tmp, 0); key.gk_data=tmp; gtif.gt_keys.Add(keyID, key); gtif.gt_flags|=gtiff_flags.FLAG_FILE_MODIFIED; return true; } catch { return false; } }
public static bool GTIFImport(GTIF gtif, GTIFReadMethod scan, object aux) { if(scan==null) scan=DefaultRead; if(aux==null) aux=Console.In; string message=scan(aux); if(message==null||message.Length<20) return false; if(message.ToLower().Substring(0, 20)!=FMT_GEOTIFF.ToLower().Substring(0, 20)) return false; message=scan(aux); if(message==null||message.Length<10) return false; if(message.ToLower().Substring(0, 8)!=FMT_VERSION.ToLower().Substring(0, 8)) return false; message=message.Substring(9); try { gtif.gt_version=ushort.Parse(message); } catch { return false; } message=scan(aux); if(message==null||message.Length<15) return false; if(message.ToLower().Substring(0, 13)!=FMT_REV.ToLower().Substring(0, 13)) return false; message=message.Substring(14); try { string[] spl=message.Split('.'); if(spl.Length!=2) return false; gtif.gt_rev_major=ushort.Parse(spl[0]); gtif.gt_rev_minor=ushort.Parse(spl[1]); } catch { return false; } message=scan(aux); if(message==null||message.Length<19) return false; if(message.ToLower().Substring(0, 19)!=FMT_TAGS.ToLower().Substring(0, 19)) return false; int status; while((status=ReadTag(gtif, scan, aux))>0) ; if(status<0) return false; message=scan(aux); if(message==null||message.Length<18) return false; if(message.ToLower().Substring(0, 18)!=FMT_KEYS.ToLower().Substring(0, 18)) return false; while((status=ReadKey(gtif, scan, aux))>0) ; return (status==0); // success }
//*********************************************************************** // GTIFSetFromProj4() //*********************************************************************** static bool GTIFSetFromProj4(GTIF gtif, string proj4) { Dictionary<string, string> papszNV=OSRProj4Tokenize(proj4); short nSpheroid=KvUserDefined; double dfSemiMajor=0.0, dfSemiMinor=0.0, dfInvFlattening=0.0; int nDatum=KvUserDefined; int nGCS=KvUserDefined; string value; // -------------------------------------------------------------------- // Get the ellipsoid definition. // -------------------------------------------------------------------- value=OSR_GSV(papszNV, "ellps"); if(value!=null) value=value.ToLower(); if(value==null) { } else if(value=="WGS84") nSpheroid=(short)ellipsoid_t.Ellipse_WGS_84; else if(value=="clrk66") nSpheroid=(short)ellipsoid_t.Ellipse_Clarke_1866; else if(value=="clrk80") nSpheroid=(short)ellipsoid_t.Ellipse_Clarke_1880; else if(value=="GRS80") nSpheroid=(short)ellipsoid_t.Ellipse_GRS_1980; if(nSpheroid==KvUserDefined) { dfSemiMajor=OSR_GDV(papszNV, "a", 0.0); dfSemiMinor=OSR_GDV(papszNV, "b", 0.0); dfInvFlattening=OSR_GDV(papszNV, "rf", 0.0); if(dfSemiMinor!=0.0&&dfInvFlattening==0.0) dfInvFlattening=-1.0/(dfSemiMinor/dfSemiMajor-1.0); } // -------------------------------------------------------------------- // Get the GCS/Datum code. // -------------------------------------------------------------------- value=OSR_GSV(papszNV, "datum"); if(value!=null) value=value.ToLower(); if(value==null) { } else if(value=="WGS84") { nGCS=(int)geographic_t.GCS_WGS_84; nDatum=(int)geodeticdatum_t.Datum_WGS84; } else if(value=="NAD83") { nGCS=(int)geographic_t.GCS_NAD83; nDatum=(int)geodeticdatum_t.Datum_North_American_Datum_1983; } else if(value=="NAD27") { nGCS=(int)geographic_t.GCS_NAD27; nDatum=(int)geodeticdatum_t.Datum_North_American_Datum_1927; } // -------------------------------------------------------------------- // Operate on the basis of the projection name. // -------------------------------------------------------------------- value=OSR_GSV(papszNV, "proj"); if(value!=null) value=value.ToLower(); if(value==null) { OSRFreeStringList(papszNV); return false; } else if(value=="longlat"||value=="latlong") { } else if(value=="tmerc") { GTIFKeySet(gtif, geokey_t.GTModelTypeGeoKey, (ushort)modeltype_t.ModelTypeProjected); GTIFKeySet(gtif, geokey_t.ProjectedCSTypeGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjectionGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjCoordTransGeoKey, (ushort)coordtrans_t.CT_TransverseMercator); GTIFKeySet(gtif, geokey_t.ProjNatOriginLatGeoKey, OSR_GDV(papszNV, "lat_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjNatOriginLongGeoKey, OSR_GDV(papszNV, "lon_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, OSR_GDV(papszNV, "k", 1.0)); GTIFKeySet(gtif, geokey_t.ProjFalseEastingGeoKey, OSR_GDV(papszNV, "x_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjFalseNorthingGeoKey, OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="utm") { int nZone=(int)OSR_GDV(papszNV, "zone", 0); string south=OSR_GSV(papszNV, "south"); GTIFKeySet(gtif, geokey_t.GTModelTypeGeoKey, (ushort)modeltype_t.ModelTypeProjected); GTIFKeySet(gtif, geokey_t.ProjectedCSTypeGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjectionGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjCoordTransGeoKey, (ushort)coordtrans_t.CT_TransverseMercator); GTIFKeySet(gtif, geokey_t.ProjNatOriginLatGeoKey, 0.0); GTIFKeySet(gtif, geokey_t.ProjNatOriginLongGeoKey, nZone*6-183.0); GTIFKeySet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, 0.9996); GTIFKeySet(gtif, geokey_t.ProjFalseEastingGeoKey, 500000.0); if(south!=null) GTIFKeySet(gtif, geokey_t.ProjFalseNorthingGeoKey, (south!=null)?10000000.0:0.0); } else if(value=="lcc"&&OSR_GDV(papszNV, "lat_0", 0.0)==OSR_GDV(papszNV, "lat_1", 0.0)) { GTIFKeySet(gtif, geokey_t.GTModelTypeGeoKey, (ushort)modeltype_t.ModelTypeProjected); GTIFKeySet(gtif, geokey_t.ProjectedCSTypeGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjectionGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjCoordTransGeoKey, (ushort)coordtrans_t.CT_LambertConfConic_1SP); GTIFKeySet(gtif, geokey_t.ProjNatOriginLatGeoKey, OSR_GDV(papszNV, "lat_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjNatOriginLongGeoKey, OSR_GDV(papszNV, "lon_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, OSR_GDV(papszNV, "k", 1.0)); GTIFKeySet(gtif, geokey_t.ProjFalseEastingGeoKey, OSR_GDV(papszNV, "x_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjFalseNorthingGeoKey, OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="lcc") { GTIFKeySet(gtif, geokey_t.GTModelTypeGeoKey, (ushort)modeltype_t.ModelTypeProjected); GTIFKeySet(gtif, geokey_t.ProjectedCSTypeGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjectionGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjCoordTransGeoKey, (ushort)coordtrans_t.CT_LambertConfConic_2SP); GTIFKeySet(gtif, geokey_t.ProjFalseOriginLatGeoKey, OSR_GDV(papszNV, "lat_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjFalseOriginLongGeoKey, OSR_GDV(papszNV, "lon_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjStdParallel1GeoKey, OSR_GDV(papszNV, "lat_1", 0.0)); GTIFKeySet(gtif, geokey_t.ProjStdParallel2GeoKey, OSR_GDV(papszNV, "lat_2", 0.0)); GTIFKeySet(gtif, geokey_t.ProjFalseOriginEastingGeoKey, OSR_GDV(papszNV, "x_0", 0.0)); GTIFKeySet(gtif, geokey_t.ProjFalseOriginNorthingGeoKey, OSR_GDV(papszNV, "y_0", 0.0)); } #if notdef else if(value=="bonne") { SetBonne(OSR_GDV(papszNV, "lat_1", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="cass") { SetCS(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="nzmg") { SetNZMG(OSR_GDV(papszNV, "lat_0", -41.0), OSR_GDV(papszNV, "lon_0", 173.0), OSR_GDV(papszNV, "x_0", 2510000.0), OSR_GDV(papszNV, "y_0", 6023150.0)); } else if(value=="cea") { SetCEA(OSR_GDV(papszNV, "lat_ts", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="merc"&&OSR_GDV(papszNV, "lat_ts", 1000.0)<999.0) // 2SP form { SetMercator2SP(OSR_GDV(papszNV, "lat_ts", 0.0), 0.0, OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="merc") // 1SP form { SetMercator(0.0, OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="stere"&&Math.Abs(OSR_GDV(papszNV, "lat_0", 0.0)-90)<0.001) { SetPS(OSR_GDV(papszNV, "lat_ts", 90.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="stere"&&Math.Abs(OSR_GDV(papszNV, "lat_0", 0.0)+90)<0.001) { SetPS(OSR_GDV(papszNV, "lat_ts", -90.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value.StartsWith("stere")&&OSR_GSV(papszNV, "k")!=null) // mostly sterea { SetOS(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="stere") { SetStereographic(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), 1.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="eqc") { if(OSR_GDV(papszNV, "lat_0", 0.0)!=OSR_GDV(papszNV, "lat_ts", 0.0)) SetEquirectangular2(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0)+dfFromGreenwich, OSR_GDV(papszNV, "lat_ts", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); else SetEquirectangular(OSR_GDV(papszNV, "lat_ts", 0.0), OSR_GDV(papszNV, "lon_0", 0.0)+dfFromGreenwich, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="glabsgm") { SetGaussLabordeReunion(OSR_GDV(papszNV, "lat_0", -21.116666667), OSR_GDV(papszNV, "lon_0", 55.53333333309)+dfFromGreenwich, OSR_GDV(papszNV, "k_0", 1.0), OSR_GDV(papszNV, "x_0", 160000.000), OSR_GDV(papszNV, "y_0", 50000.000)); } else if(value=="gnom") { SetGnomonic(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="ortho") { SetOrthographic(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="laea") { SetLAEA(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="aeqd") { SetAE(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="eqdc") { SetEC(OSR_GDV(papszNV, "lat_1", 0.0), OSR_GDV(papszNV, "lat_2", 0.0), OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="mill") { SetMC(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="moll") { SetMollweide(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="eck4") { SetEckertIV(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="eck6") { SetEckertVI(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="poly") { SetPolyconic(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="aea") { SetACEA(OSR_GDV(papszNV, "lat_1", 0.0), OSR_GDV(papszNV, "lat_2", 0.0), OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="robin") { SetRobinson(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="vandg") { SetVDG(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="sinu") { SetSinusoidal(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="gall") { SetGS(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="goode") { SetGH(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="geos") { SetGEOS(OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "h", 35785831.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="lcc") { if(OSR_GDV(papszNV, "lat_0", 0.0)==OSR_GDV(papszNV, "lat_1", 0.0)) { // 1SP form SetLCC1SP(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "k_0", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else { // 2SP form SetLCC(OSR_GDV(papszNV, "lat_1", 0.0), OSR_GDV(papszNV, "lat_2", 0.0), OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } } else if(value=="omerc") { SetHOM(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lonc", 0.0), OSR_GDV(papszNV, "alpha", 0.0), 0.0, // ??? OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="somerc") { SetHOM(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), 90.0, 90.0, OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="krovak") { SetKrovak(OSR_GDV(papszNV, "lat_0", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "alpha", 0.0), 0.0, // pseudo_standard_parallel_1 OSR_GDV(papszNV, "k", 1.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="iwm_p") { SetIWMPolyconic(OSR_GDV(papszNV, "lat_1", 0.0), OSR_GDV(papszNV, "lat_2", 0.0), OSR_GDV(papszNV, "lon_0", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag1") { SetWagner(1, 0.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag2") { SetWagner(2, 0.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag3") { SetWagner(3, OSR_GDV(papszNV, "lat_ts", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag1") { SetWagner(4, 0.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag1") { SetWagner(5, 0.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag1") { SetWagner(6, 0.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="wag1") { SetWagner(7, 0.0, OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } else if(value=="tpeqd") { SetTPED(OSR_GDV(papszNV, "lat_1", 0.0), OSR_GDV(papszNV, "lon_1", 0.0), OSR_GDV(papszNV, "lat_2", 0.0), OSR_GDV(papszNV, "lon_2", 0.0), OSR_GDV(papszNV, "x_0", 0.0), OSR_GDV(papszNV, "y_0", 0.0)); } #endif else { // unsupported coordinate system OSRFreeStringList(papszNV); return false; } // -------------------------------------------------------------------- // Write the GCS if we have it, otherwise write the datum. // -------------------------------------------------------------------- if(nGCS!=KvUserDefined) { GTIFKeySet(gtif, geokey_t.GeographicTypeGeoKey, (ushort)nGCS); } else { GTIFKeySet(gtif, geokey_t.GeographicTypeGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.GeogGeodeticDatumGeoKey, (ushort)nDatum); } // -------------------------------------------------------------------- // Write the ellipsoid if we don't know the GCS. // -------------------------------------------------------------------- if(nGCS==KvUserDefined) { if(nSpheroid!=KvUserDefined) GTIFKeySet(gtif, geokey_t.GeogEllipsoidGeoKey, (ushort)nSpheroid); else { GTIFKeySet(gtif, geokey_t.GeogEllipsoidGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.GeogSemiMajorAxisGeoKey, dfSemiMajor); if(dfInvFlattening==0.0) GTIFKeySet(gtif, geokey_t.GeogSemiMinorAxisGeoKey, dfSemiMajor); else GTIFKeySet(gtif, geokey_t.GeogInvFlatteningGeoKey, dfInvFlattening); } } // -------------------------------------------------------------------- // Linear units translation // -------------------------------------------------------------------- value=OSR_GSV(papszNV, "units"); if(value!=null) value=value.ToLower(); if(value==null) { value=OSR_GSV(papszNV, "to_meter"); if(value!=null) { GTIFKeySet(gtif, geokey_t.ProjLinearUnitsGeoKey, (ushort)KvUserDefined); GTIFKeySet(gtif, geokey_t.ProjLinearUnitSizeGeoKey, GTIFAtof(value)); } } else if(value=="meter"||value=="m") { GTIFKeySet(gtif, geokey_t.ProjLinearUnitsGeoKey, (ushort)geounits_t.Linear_Meter); } else if(value=="us-ft") { GTIFKeySet(gtif, geokey_t.ProjLinearUnitsGeoKey, (ushort)geounits_t.Linear_Foot_US_Survey); } else if(value=="ft") { GTIFKeySet(gtif, geokey_t.ProjLinearUnitsGeoKey, (ushort)geounits_t.Linear_Foot); } OSRFreeStringList(papszNV); return true; }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out primemeridian_t val, int index) { return(GTIFKeyGet(gtif, thekey, out val, index, 0)); }
// This function flushes all the GeoTIFF keys that have been set with the // GTIFKeySet() function into the associated // TIFF file. // // @param gt The GeoTIFF handle returned by GTIFNew. // // GTIFWriteKeys() should be called before // GTIFFree() is used to deallocate a GeoTIFF access handle. public static bool GTIFWriteKeys(GTIF gt) { if((gt.gt_flags>iff_flags.FLAG_FILE_MODIFIED)==0) return true; if(gt.gt_tif==null) return false; List<geokey_t> keys=new List<geokey_t>(gt.gt_keys.Keys); keys.Sort(); List<ushort> shorts=new List<ushort>(); List<ushort> shortsValues=new List<ushort>(); List<double> doubles=new List<double>(); string strings=""; // Set up header of ProjectionInfo tag shorts.Add((ushort)GvCurrentVersion); shorts.Add((ushort)GvCurrentRevision); shorts.Add((ushort)GvCurrentMinorRev); shorts.Add((ushort)keys.Count); int shortOffset=4+keys.Count*4; foreach(geokey_t key in keys) { GeoKey keyptr=gt.gt_keys[key]; if(keyptr.gk_type==tagtype_t.TYPE_ASCII) { string str=keyptr.gk_data as string; if(str==null) str=""; str=str.Trim('\0'); str+="|"; str=str.Replace('\0', '|'); shorts.Add((ushort)key); shorts.Add((ushort)GTIFF_ASCIIPARAMS); shorts.Add((ushort)str.Length); shorts.Add((ushort)strings.Length); strings+=str; continue; } if(keyptr.gk_type==tagtype_t.TYPE_DOUBLE) { double[] dbl=keyptr.gk_data as double[]; if(dbl==null) { shorts.Add((ushort)key); shorts.Add((ushort)GTIFF_DOUBLEPARAMS); shorts.Add((ushort)0); shorts.Add((ushort)0); } else { shorts.Add((ushort)key); shorts.Add((ushort)GTIFF_DOUBLEPARAMS); shorts.Add((ushort)dbl.Length); shorts.Add((ushort)doubles.Count); doubles.AddRange(dbl); } continue; } ushort[] sht=keyptr.gk_data as ushort[]; if(sht==null) { shorts.Add((ushort)key); shorts.Add((ushort)GTIFF_LOCAL); shorts.Add((ushort)0); shorts.Add((ushort)0); } else { if(sht.Length<2) { shorts.Add((ushort)key); shorts.Add((ushort)GTIFF_LOCAL); shorts.Add((ushort)sht.Length); if(sht.Length==1) shorts.Add(sht[0]); else shorts.Add(0); } else { shorts.Add((ushort)key); shorts.Add((ushort)GTIFF_GEOKEYDIRECTORY); shorts.Add((ushort)sht.Length); shorts.Add((ushort)(shortOffset+shortsValues.Count)); shortsValues.AddRange(sht); } } } if(shorts.Count!=shortOffset) return false; shorts.AddRange(shortsValues); // Write out the Key Directory gt.gt_methods.set(gt.gt_tif, (ushort)GTIFF_GEOKEYDIRECTORY, shorts.Count, shorts.ToArray()); // Write out the params directories if(doubles.Count>0) gt.gt_methods.set(gt.gt_tif, (ushort)GTIFF_DOUBLEPARAMS, doubles.Count, doubles.ToArray()); if(strings.Length>0) gt.gt_methods.set(gt.gt_tif, (ushort)GTIFF_ASCIIPARAMS, strings.Length, strings); gt.gt_flags&=~gtiff_flags.FLAG_FILE_MODIFIED; return true; }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, rastertype_t val) { ushort[] val1=new ushort[] { (ushort)val }; return GTIFKeySet(gtif, keyID, val1); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, coordtrans_t val) { ushort[] val1=new ushort[] { (ushort)val }; return GTIFKeySet(gtif, keyID, val1); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, projection_t val) { ushort[] val1=new ushort[] { (ushort)val }; return GTIFKeySet(gtif, keyID, val1); }
// This function writes a geokey_t value to a GeoTIFF file. // // @param gtif The geotiff information handle from GTIFNew(). // // @param keyID The geokey_t name (such as ProjectedCSTypeGeoKey). // This must come from the list of legal geokey_t values // (an enumeration) listed below. // // Note that key values aren't actually flushed to the file until // GTIFWriteKeys() is called. Till then // the new values are just kept with the GTIF structure. // // Example: // // GTIFKeySet(gtif, GTRasterTypeGeoKey, RasterPixelIsArea); // GTIFKeySet(gtif, GTCitationGeoKey, "UTM 11 North / NAD27"); public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, geodeticdatum_t val) { ushort[] val1=new ushort[] { (ushort)val }; return GTIFKeySet(gtif, keyID, val1); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, rastertype_t val) { ushort[] val1 = new ushort[] { (ushort)val }; return(GTIFKeySet(gtif, keyID, val1)); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out coordtrans_t val, int index) { return(GTIFKeyGet(gtif, thekey, out val, index, 0)); }
static int ReadKey(GTIF gt, GTIFReadMethod scan, object aux) { string message=scan(aux); if(message==null) return -1; if(message.Length>=12) if(message.ToLower().Substring(0, 12)==FMT_KEYEND.ToLower().Substring(0, 12)) return 0; try { int firstp=message.IndexOfAny(new char[] { '(', ' ', '\t' }); if(firstp<0) return StringError(message); string name=message.Substring(0, firstp).Trim(); string message1=message.Substring(firstp); int colon=message1.IndexOf(':'); if(colon<0) return StringError(message1); string head=message1.Substring(0, colon); head=head.Trim(' ', '\t', '(', ')'); string[] spl=head.Split(','); if(spl.Length!=2) return StringError(head); string type=spl[0]; int count=int.Parse(spl[1]); // skip white space string data=message1.Substring(colon+1).Trim(); if(data.Length==0) return StringError(message); if(GTIFKeyCode(name)<0) return StringError(name); geokey_t key=(geokey_t)GTIFKeyCode(name); if(GTIFTypeCode(type)<0) return StringError(type); tagtype_t ktype=(tagtype_t)GTIFTypeCode(type); switch(ktype) { case tagtype_t.TYPE_ASCII: { string cdata=""; int firstDoubleQuote=data.IndexOf('"'); if(firstDoubleQuote<0) return StringError(data); data=data.Substring(firstDoubleQuote+1); bool wasesc=false; char c='\0'; for(int i=0; i<data.Length; i++) { c=data[i]; if(wasesc) { if(c=='\\') cdata+='\\'; else if(c=='"') cdata+='"'; else if(c=='n') cdata+='\n'; else if(c=='t') cdata+='\t'; else if(c=='b') cdata+='\b'; else if(c=='r') cdata+='\r'; else if(c=='0') cdata+='\0'; wasesc=false; continue; } if(c=='\\') { wasesc=true; continue; } if(c=='\0') break; if(c=='"') break; cdata+=c; if(cdata.Length==count) { c=data[i+1]; break; } } if(cdata.Length<count) return StringError(message); if(c!='"') return StringError(message); GTIFKeySet(gt, key, cdata); } break; case tagtype_t.TYPE_DOUBLE: { double[] dptr=new double[count]; int i=0; for(; count>0; count-=3) { spl=data.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if(spl.Length!=Math.Min(3, count)) return StringError(data); foreach(string part in spl) { message=part; dptr[i++]=GTIFAtof(part); } if(count>3) message=data=scan(aux); } GTIFKeySet(gt, key, dptr); } break; case tagtype_t.TYPE_SHORT: if(count==1) { int icode=GTIFValueCode(key, data); if(icode<0) return StringError(data); ushort code=(ushort)icode; GTIFKeySet(gt, key, code); } else // multi-valued short - no such thing yet { ushort[] sptr=new ushort[count]; int i=0; for(; count>0; count-=3) { spl=data.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if(spl.Length!=Math.Min(3, count)) return StringError(data); foreach(string part in spl) { message=part; sptr[i++]=ushort.Parse(part); } if(count>3) message=data=scan(aux); } GTIFKeySet(gt, key, sptr); } break; default: return -1; } } catch { return StringError(message); } return 1; }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out rastertype_t val, int index) { return(GTIFKeyGet(gtif, thekey, out val, index, 0)); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, double val) { double[] val1=new double[] { val }; return GTIFKeySet(gtif, keyID, val1); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out string val, int index, int count) { val=null; if(count<0) return 0; if(!gtif.gt_keys.ContainsKey(thekey)) return 0; GeoKey key=gtif.gt_keys[thekey]; if(key.gk_type!=tagtype_t.TYPE_ASCII) return 0; string val_=(string)key.gk_data; if(count==0||(count+index)>val_.Length) val=val_.Substring(index); else val=val_.Substring(index, count); return val.Length; }
static int ReadKey(GTIF gt, GTIFReadMethod scan, object aux) { string message = scan(aux); if (message == null) { return(-1); } if (message.Length >= 12) { if (message.ToLower().Substring(0, 12) == FMT_KEYEND.ToLower().Substring(0, 12)) { return(0); } } try { int firstp = message.IndexOfAny(new char[] { '(', ' ', '\t' }); if (firstp < 0) { return(StringError(message)); } string name = message.Substring(0, firstp).Trim(); string message1 = message.Substring(firstp); int colon = message1.IndexOf(':'); if (colon < 0) { return(StringError(message1)); } string head = message1.Substring(0, colon); head = head.Trim(' ', '\t', '(', ')'); string[] spl = head.Split(','); if (spl.Length != 2) { return(StringError(head)); } string type = spl[0]; int count = int.Parse(spl[1]); // skip white space string data = message1.Substring(colon + 1).Trim(); if (data.Length == 0) { return(StringError(message)); } if (GTIFKeyCode(name) < 0) { return(StringError(name)); } geokey_t key = (geokey_t)GTIFKeyCode(name); if (GTIFTypeCode(type) < 0) { return(StringError(type)); } tagtype_t ktype = (tagtype_t)GTIFTypeCode(type); switch (ktype) { case tagtype_t.TYPE_ASCII: { string cdata = ""; int firstDoubleQuote = data.IndexOf('"'); if (firstDoubleQuote < 0) { return(StringError(data)); } data = data.Substring(firstDoubleQuote + 1); bool wasesc = false; char c = '\0'; for (int i = 0; i < data.Length; i++) { c = data[i]; if (wasesc) { if (c == '\\') { cdata += '\\'; } else if (c == '"') { cdata += '"'; } else if (c == 'n') { cdata += '\n'; } else if (c == 't') { cdata += '\t'; } else if (c == 'b') { cdata += '\b'; } else if (c == 'r') { cdata += '\r'; } else if (c == '0') { cdata += '\0'; } wasesc = false; continue; } if (c == '\\') { wasesc = true; continue; } if (c == '\0') { break; } if (c == '"') { break; } cdata += c; if (cdata.Length == count) { c = data[i + 1]; break; } } if (cdata.Length < count) { return(StringError(message)); } if (c != '"') { return(StringError(message)); } GTIFKeySet(gt, key, cdata); } break; case tagtype_t.TYPE_DOUBLE: { double[] dptr = new double[count]; int i = 0; for (; count > 0; count -= 3) { spl = data.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (spl.Length != Math.Min(3, count)) { return(StringError(data)); } foreach (string part in spl) { message = part; dptr[i++] = GTIFAtof(part); } if (count > 3) { message = data = scan(aux); } } GTIFKeySet(gt, key, dptr); } break; case tagtype_t.TYPE_SHORT: if (count == 1) { int icode = GTIFValueCode(key, data); if (icode < 0) { return(StringError(data)); } ushort code = (ushort)icode; GTIFKeySet(gt, key, code); } else // multi-valued short - no such thing yet { ushort[] sptr = new ushort[count]; int i = 0; for (; count > 0; count -= 3) { spl = data.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (spl.Length != Math.Min(3, count)) { return(StringError(data)); } foreach (string part in spl) { message = part; sptr[i++] = ushort.Parse(part); } if (count > 3) { message = data = scan(aux); } } GTIFKeySet(gt, key, sptr); } break; default: return(-1); } } catch { return(StringError(message)); } return(1); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out string val) { val=null; if(!gtif.gt_keys.ContainsKey(thekey)) return 0; GeoKey key=gtif.gt_keys[thekey]; if(key.gk_type!=tagtype_t.TYPE_ASCII) return 0; val=(string)key.gk_data; return val.Length; }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out double val, int index, int count) { // ignore count val=0; double[] vals; if(GTIFKeyGet(gtif, thekey, out vals, index, 1)==0) return 0; val=vals[0]; return 1; }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out double[] val, int index, int count) { val=null; if(!gtif.gt_keys.ContainsKey(thekey)) return 0; GeoKey key=gtif.gt_keys[thekey]; if(key.gk_type!=tagtype_t.TYPE_DOUBLE) return 0; double[] val_=(double[])key.gk_data; if(count==0||(count+index)>val_.Length) count=val_.Length-index; if(count<=0) return 0; val=new double[count]; Array.Copy(val_, index, val, 0, count); return count; }
//***********************************************************************/ //* GTIFImageToPCS() */ //***********************************************************************/ // Translate a pixel/line coordinate to projection coordinates. // // At this time this function does not support image to PCS translations for // tiepoints-only definitions, only pixelscale and transformation matrix // formulations. // // @param gtif The handle from GTIFNew() indicating the target file. // @param x A reference to the double containing the pixel offset on input, // and into which the easting/longitude will be put on completion. // @param y A reference to the double containing the line offset on input, // and into which the northing/latitude will be put on completion. // // @return true if the transformation succeeds, or false if it fails. It may // fail if the file doesn't have properly setup transformation information, // or it is in a form unsupported by this function. public static bool GTIFImageToPCS(GTIF gtif, ref double x, ref double y) { bool res = false; int tiepoint_count, count, transform_count; TIFF tif = gtif.gt_tif; double[] tiepoints = null; double[] pixel_scale = null; double[] transform = null; // -------------------------------------------------------------------- // Fetch tiepoints and pixel scale. // -------------------------------------------------------------------- object ap; if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out tiepoint_count, out ap)) { tiepoint_count = 0; } else if (ap is double[]) { tiepoints = (double[])ap; } if (!gtif.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out ap)) { count = 0; } else if (ap is double[]) { pixel_scale = (double[])ap; } if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out transform_count, out ap)) { transform_count = 0; } else if (ap is double[]) { transform = (double[])ap; } // -------------------------------------------------------------------- // If we have a transformation matrix, use it. // -------------------------------------------------------------------- if (transform_count == 16) { double x_in = x, y_in = y; x = x_in * transform[0] + y_in * transform[1] + transform[3]; y = x_in * transform[4] + y_in * transform[5] + transform[7]; res = true; } // -------------------------------------------------------------------- // If the pixelscale count is zero, but we have tiepoints use // the tiepoint based approach. // -------------------------------------------------------------------- else if (tiepoint_count > 6 && count == 0) { res = GTIFTiepointTranslate(tiepoint_count / 6, tiepoints, 0, tiepoints, 3, ref x, ref y); } // -------------------------------------------------------------------- // For now we require one tie point, and a valid pixel scale. // -------------------------------------------------------------------- else if (count >= 3 && tiepoint_count >= 6) { x = (x - tiepoints[0]) * pixel_scale[0] + tiepoints[3]; y = (y - tiepoints[1]) * (-1 * pixel_scale[1]) + tiepoints[4]; res = true; } return(res); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out double val, int index) { return(GTIFKeyGet(gtif, thekey, out val, index, 0)); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, ushort val) { ushort[] val1 = new ushort[] { val }; return(GTIFKeySet(gtif, keyID, val1)); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, projection_t val) { ushort[] val1 = new ushort[] { (ushort)val }; return(GTIFKeySet(gtif, keyID, val1)); }
//********************************************************************** // GTIFFetchProjParms() // // Fetch the projection parameters for a particular projection // from a GeoTIFF file, and fill the GTIFDefn structure out // with them. //********************************************************************** static void GTIFFetchProjParms(GTIF gtif, GTIFDefn defn) { double NatOriginLong=0.0, NatOriginLat=0.0, RectGridAngle=0.0; double FalseEasting=0.0, FalseNorthing=0.0, NatOriginScale=1.0; double StdParallel1=0.0, StdParallel2=0.0, Azimuth=0.0; // -------------------------------------------------------------------- // Get the false easting, and northing if available. // -------------------------------------------------------------------- if(GTIFKeyGet(gtif, geokey_t.ProjFalseEastingGeoKey, out FalseEasting, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterEastingGeoKey, out FalseEasting, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginEastingGeoKey, out FalseEasting, 0, 1)==0) FalseEasting=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjFalseNorthingGeoKey, out FalseNorthing, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterNorthingGeoKey, out FalseNorthing, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginNorthingGeoKey, out FalseNorthing, 0, 1)==0) FalseNorthing=0.0; switch(defn.CTProjection) { case coordtrans_t.CT_Stereographic: if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, out NatOriginScale, 0, 1)==0) NatOriginScale=1.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjCenterLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjCenterLongGeoKey; defn.ProjParm[4]=NatOriginScale; defn.ProjParmId[4]=geokey_t.ProjScaleAtNatOriginGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_LambertConfConic_1SP: case coordtrans_t.CT_Mercator: case coordtrans_t.CT_ObliqueStereographic: case coordtrans_t.CT_TransverseMercator: case coordtrans_t.CT_TransvMercator_SouthOriented: if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, out NatOriginScale, 0, 1)==0) NatOriginScale=1.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjNatOriginLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjNatOriginLongGeoKey; defn.ProjParm[4]=NatOriginScale; defn.ProjParmId[4]=geokey_t.ProjScaleAtNatOriginGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_ObliqueMercator: // hotine if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjAzimuthAngleGeoKey, out Azimuth, 0, 1)==0) Azimuth=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjRectifiedGridAngleGeoKey, out RectGridAngle, 0, 1)==0) RectGridAngle=90.0; if(GTIFKeyGet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, out NatOriginScale, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjScaleAtCenterGeoKey, out NatOriginScale, 0, 1)==0) NatOriginScale=1.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjCenterLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjCenterLongGeoKey; defn.ProjParm[2]=Azimuth; defn.ProjParmId[2]=geokey_t.ProjAzimuthAngleGeoKey; defn.ProjParm[3]=RectGridAngle; defn.ProjParmId[3]=geokey_t.ProjRectifiedGridAngleGeoKey; defn.ProjParm[4]=NatOriginScale; defn.ProjParmId[4]=geokey_t.ProjScaleAtCenterGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_CassiniSoldner: case coordtrans_t.CT_Polyconic: if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, out NatOriginScale, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjScaleAtCenterGeoKey, out NatOriginScale, 0, 1)==0) NatOriginScale=1.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjNatOriginLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjNatOriginLongGeoKey; defn.ProjParm[4]=NatOriginScale; defn.ProjParmId[4]=geokey_t.ProjScaleAtNatOriginGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_AzimuthalEquidistant: case coordtrans_t.CT_MillerCylindrical: case coordtrans_t.CT_Gnomonic: case coordtrans_t.CT_LambertAzimEqualArea: case coordtrans_t.CT_Orthographic: case coordtrans_t.CT_NewZealandMapGrid: if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjCenterLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjCenterLongGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_Equirectangular: if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjStdParallel1GeoKey, out StdParallel1, 0, 1)==0) StdParallel1=0.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjCenterLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjCenterLongGeoKey; defn.ProjParm[2]=StdParallel1; defn.ProjParmId[2]=geokey_t.ProjStdParallel1GeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_Robinson: case coordtrans_t.CT_Sinusoidal: case coordtrans_t.CT_VanDerGrinten: if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjCenterLongGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_PolarStereographic: if(GTIFKeyGet(gtif, geokey_t.ProjStraightVertPoleLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjScaleAtNatOriginGeoKey, out NatOriginScale, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjScaleAtCenterGeoKey, out NatOriginScale, 0, 1)==0) NatOriginScale=1.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjNatOriginLatGeoKey; ; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjStraightVertPoleLongGeoKey; defn.ProjParm[4]=NatOriginScale; defn.ProjParmId[4]=geokey_t.ProjScaleAtNatOriginGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_LambertConfConic_2SP: if(GTIFKeyGet(gtif, geokey_t.ProjStdParallel1GeoKey, out StdParallel1, 0, 1)==0) StdParallel1=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjStdParallel2GeoKey, out StdParallel2, 0, 1)==0) StdParallel1=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=NatOriginLat; defn.ProjParmId[0]=geokey_t.ProjFalseOriginLatGeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjFalseOriginLongGeoKey; defn.ProjParm[2]=StdParallel1; defn.ProjParmId[2]=geokey_t.ProjStdParallel1GeoKey; defn.ProjParm[3]=StdParallel2; defn.ProjParmId[3]=geokey_t.ProjStdParallel2GeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_AlbersEqualArea: case coordtrans_t.CT_EquidistantConic: if(GTIFKeyGet(gtif, geokey_t.ProjStdParallel1GeoKey, out StdParallel1, 0, 1)==0) StdParallel1=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjStdParallel2GeoKey, out StdParallel2, 0, 1)==0) StdParallel2=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLatGeoKey, out NatOriginLat, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLatGeoKey, out NatOriginLat, 0, 1)==0) NatOriginLat=0.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=StdParallel1; defn.ProjParmId[0]=geokey_t.ProjStdParallel1GeoKey; defn.ProjParm[1]=StdParallel2; defn.ProjParmId[1]=geokey_t.ProjStdParallel2GeoKey; defn.ProjParm[2]=NatOriginLat; defn.ProjParmId[2]=geokey_t.ProjNatOriginLatGeoKey; defn.ProjParm[3]=NatOriginLong; defn.ProjParmId[3]=geokey_t.ProjNatOriginLongGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; case coordtrans_t.CT_CylindricalEqualArea: if(GTIFKeyGet(gtif, geokey_t.ProjStdParallel1GeoKey, out StdParallel1, 0, 1)==0) StdParallel1=0.0; if(GTIFKeyGet(gtif, geokey_t.ProjNatOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjFalseOriginLongGeoKey, out NatOriginLong, 0, 1)==0&& GTIFKeyGet(gtif, geokey_t.ProjCenterLongGeoKey, out NatOriginLong, 0, 1)==0) NatOriginLong=0.0; // notdef: should transform to decimal degrees at this point defn.ProjParm[0]=StdParallel1; defn.ProjParmId[0]=geokey_t.ProjStdParallel1GeoKey; defn.ProjParm[1]=NatOriginLong; defn.ProjParmId[1]=geokey_t.ProjNatOriginLongGeoKey; defn.ProjParm[5]=FalseEasting; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[6]=FalseNorthing; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; defn.nParms=7; break; } // -------------------------------------------------------------------- // Normalize any linear parameters into meters. In GeoTIFF // the linear projection parameter tags are normally in the // units of the coordinate system described. // -------------------------------------------------------------------- for(int iParm=0; iParm<defn.nParms; iParm++) { switch(defn.ProjParmId[iParm]) { case geokey_t.ProjFalseEastingGeoKey: case geokey_t.ProjFalseNorthingGeoKey: case geokey_t.ProjFalseOriginEastingGeoKey: case geokey_t.ProjFalseOriginNorthingGeoKey: case geokey_t.ProjCenterEastingGeoKey: case geokey_t.ProjCenterNorthingGeoKey: if(defn.UOMLengthInMeters!=0&&defn.UOMLengthInMeters!=1.0) defn.ProjParm[iParm]*=defn.UOMLengthInMeters; break; } } }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, string val) { if(val==null) // delete the indicated tag { if(!gtif.gt_keys.ContainsKey(keyID)) return false; gtif.gt_keys.Remove(keyID); gtif.gt_flags|=gtiff_flags.FLAG_FILE_MODIFIED; return true; } if(gtif.gt_keys.ContainsKey(keyID)) { gtif.gt_keys.Remove(keyID); gtif.gt_flags|=gtiff_flags.FLAG_FILE_MODIFIED; } val=val.Trim('\0'); // We need to create the key try { GeoKey key=new GeoKey(); key.gk_key=keyID; key.gk_type=tagtype_t.TYPE_ASCII; key.gk_count=val.Length; key.gk_data=val.Substring(0, val.Length); gtif.gt_keys.Add(keyID, key); gtif.gt_flags|=gtiff_flags.FLAG_FILE_MODIFIED; return true; } catch { return false; } }
// This function writes a geokey_t value to a GeoTIFF file. // // @param gtif The geotiff information handle from GTIFNew(). // // @param keyID The geokey_t name (such as ProjectedCSTypeGeoKey). // This must come from the list of legal geokey_t values // (an enumeration) listed below. // // Note that key values aren't actually flushed to the file until // GTIFWriteKeys() is called. Till then // the new values are just kept with the GTIF structure. // // Example: // // GTIFKeySet(gtif, GTRasterTypeGeoKey, RasterPixelIsArea); // GTIFKeySet(gtif, GTCitationGeoKey, "UTM 11 North / NAD27"); public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, geodeticdatum_t val) { ushort[] val1 = new ushort[] { (ushort)val }; return(GTIFKeySet(gtif, keyID, val1)); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out rastertype_t val, int index) { return GTIFKeyGet(gtif, thekey, out val, index, 0); }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, coordtrans_t val) { ushort[] val1 = new ushort[] { (ushort)val }; return(GTIFKeySet(gtif, keyID, val1)); }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out double val, int index) { return GTIFKeyGet(gtif, thekey, out val, index, 0); }
// Importing metadata file // Import the directory info, using whatever method is specified // (defaults to fscanf if null). The "aux" parameter is provided for user // defined method for passing file or whatever. // // The input format is a "GeoTIFF meta-data" file, which may be // generated by the GTIFFPrint() routine. public static bool GTIFImport(GTIF gtif) { return GTIFImport(gtif, null, null); }
// ************************************************************************** // * GTIFNewWithMethods() * // * * // * Create a new geotiff, passing in the methods structure to * // * support not libtiff implementations without replacing the * // * default methods. * // ************************************************************************** public static GTIF GTIFNewWithMethods(TIFF tif, TIFFMethod methods) { GTIF gt = null; try { gt = new GTIF(); gt.gt_methods = new TIFFMethod(); gt.gt_keys = new Dictionary <geokey_t, GeoKey>(); } catch { return(null); } // install TIFF file and I/O methods gt.gt_tif = tif; gt.gt_methods.get = methods.get; gt.gt_methods.set = methods.set; gt.gt_methods.type = methods.type; gt.gt_rev_major = GvCurrentRevision; gt.gt_rev_minor = GvCurrentMinorRev; gt.gt_version = GvCurrentVersion; if (tif == null) { return(gt); } object data; int nshorts; // since this is an array, GTIF will allocate the memory if (!gt.gt_methods.get(tif, (ushort)GTIFF_GEOKEYDIRECTORY, out nshorts, out data)) { return(gt); } if (nshorts < 4) { return(null); } ushort[] shorts = data as ushort[]; if (shorts == null || shorts.Length < 4) { return(null); } if (shorts[0] > GvCurrentVersion) { return(null); } gt.gt_version = shorts[0]; if (shorts[1] > GvCurrentRevision) { // issue warning } gt.gt_rev_major = shorts[1]; gt.gt_rev_minor = shorts[2]; int count = shorts[3]; if (count == 0) { return(gt); } if (shorts.Length < (count * 4 + 4)) { return(null); } // If we got here, then the geokey can be parsed // Get the PARAMS Tags, if any int ndoubles; double[] doubles; if (!gt.gt_methods.get(tif, (ushort)GTIFF_DOUBLEPARAMS, out ndoubles, out data)) { try { doubles = new double[MAX_VALUES]; } catch { return(null); } } else { doubles = data as double[]; if (doubles == null) { return(null); } } int stringsLength = 0; string strings = null; if (gt.gt_methods.get(tif, (ushort)GTIFF_ASCIIPARAMS, out stringsLength, out data)) { strings = data as string; if (strings == null) { return(null); } strings = strings.TrimEnd('\0'); // last NULL doesn't count; "|" used for delimiter stringsLength = strings.Length; } for (int i = 0; i < count; i++) { ushort KeyID = shorts[i * 4 + 4]; ushort TIFFTagLocation = shorts[i * 4 + 5]; ushort Count = shorts[i * 4 + 6]; ushort Value_Offset = shorts[i * 4 + 7]; GeoKey keyptr; try { keyptr = new GeoKey(); keyptr.gk_key = (geokey_t)KeyID; if (TIFFTagLocation != 0) { keyptr.gk_type = gt.gt_methods.type(gt.gt_tif, TIFFTagLocation); } else { keyptr.gk_type = tagtype_t.TYPE_SHORT; //gt.gt_methods.type(gt.gt_tif, (ushort)GTIFF_GEOKEYDIRECTORY); } switch (TIFFTagLocation) { case (ushort)GTIFF_LOCAL: // store value into data value keyptr.gk_data = new ushort[] { Value_Offset }; keyptr.gk_count = 1; break; case (ushort)GTIFF_GEOKEYDIRECTORY: ushort[] s = new ushort[Count]; keyptr.gk_data = s; Array.Copy(shorts, Value_Offset, s, 0, Count); keyptr.gk_count = Count; break; case (ushort)GTIFF_DOUBLEPARAMS: double[] d = new double[Count]; keyptr.gk_data = d; Array.Copy(doubles, Value_Offset, d, 0, Count); keyptr.gk_count = Count; break; case (ushort)GTIFF_ASCIIPARAMS: string str = strings.Substring(Value_Offset, Count); str = str.Replace('|', '\0'); str = str.Trim('\0'); keyptr.gk_count = str.Length; keyptr.gk_data = str; break; default: return(null); // failure } } catch { return(null); } gt.gt_keys.Add(keyptr.gk_key, keyptr); } return(gt); }
static int ReadTag(GTIF gt, GTIFReadMethod scan, object aux) { string message=scan(aux); if(message==null) return -1; if(message.Length>=12) if(message.ToLower().Substring(0, 12)==FMT_TAGEND.ToLower().Substring(0, 12)) return 0; try { int firstp=message.IndexOfAny(new char[] { '(', ' ', '\t' }); if(firstp<0) return StringError(message); string tagname=message.Substring(0, firstp).Trim(); message=message.Substring(firstp); int colon=message.IndexOf(':'); if(colon<0) return StringError(message); message=message.Substring(0, colon); message=message.Trim(' ', '\t', '(', ')'); string[] spl=message.Split(','); if(spl.Length!=2) return StringError(message); int nrows=int.Parse(spl[0]); int ncols=int.Parse(spl[1]); int tag=GTIFTagCode(tagname); if(tag<0) return StringError(tagname); int count=nrows*ncols; double[] dptr=new double[count]; for(int i=0; i<nrows; i++) { message=scan(aux); if(message==null) return -1; spl=message.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if(spl.Length!=ncols) StringError(message); for(int j=0; j<ncols; j++) { message=spl[j]; dptr[i*ncols+j]=GTIFAtof(message); } } gt.gt_methods.set(gt.gt_tif, (ushort)tag, count, dptr); } catch { return StringError(message); } return 1; }
//********************************************************************* // // Public Routines // //********************************************************************* // This function deallocates an existing GeoTIFF access handle previously // created with GTIFNew(). If the handle was // used to write GeoTIFF keys to the TIFF file, the // GTIFWriteKeys() function should be used // to flush results to the file before calling GTIFFree(). GTIFFree() // should be called before XTIFFClose() is // called on the corresponding TIFF file handle. public static void GTIFFree(GTIF gtif) { if(gtif==null) return; gtif.gt_keys.Clear(); }
// Importing metadata file // Import the directory info, using whatever method is specified // (defaults to fscanf if null). The "aux" parameter is provided for user // defined method for passing file or whatever. // // The input format is a "GeoTIFF meta-data" file, which may be // generated by the GTIFFPrint() routine. public static bool GTIFImport(GTIF gtif) { return(GTIFImport(gtif, null, null)); }
public static bool GTIFImport(GTIF gtif, GTIFReadMethod scan, object aux) { if (scan == null) { scan = DefaultRead; } if (aux == null) { aux = Console.In; } string message = scan(aux); if (message == null || message.Length < 20) { return(false); } if (message.ToLower().Substring(0, 20) != FMT_GEOTIFF.ToLower().Substring(0, 20)) { return(false); } message = scan(aux); if (message == null || message.Length < 10) { return(false); } if (message.ToLower().Substring(0, 8) != FMT_VERSION.ToLower().Substring(0, 8)) { return(false); } message = message.Substring(9); try { gtif.gt_version = ushort.Parse(message); } catch { return(false); } message = scan(aux); if (message == null || message.Length < 15) { return(false); } if (message.ToLower().Substring(0, 13) != FMT_REV.ToLower().Substring(0, 13)) { return(false); } message = message.Substring(14); try { string[] spl = message.Split('.'); if (spl.Length != 2) { return(false); } gtif.gt_rev_major = ushort.Parse(spl[0]); gtif.gt_rev_minor = ushort.Parse(spl[1]); } catch { return(false); } message = scan(aux); if (message == null || message.Length < 19) { return(false); } if (message.ToLower().Substring(0, 19) != FMT_TAGS.ToLower().Substring(0, 19)) { return(false); } int status; while ((status = ReadTag(gtif, scan, aux)) > 0) { ; } if (status < 0) { return(false); } message = scan(aux); if (message == null || message.Length < 18) { return(false); } if (message.ToLower().Substring(0, 18) != FMT_KEYS.ToLower().Substring(0, 18)) { return(false); } while ((status = ReadKey(gtif, scan, aux)) > 0) { ; } return(status == 0); // success }
public static bool GTIFKeySet(GTIF gtif, geokey_t keyID, ushort val) { ushort[] val1=new ushort[] { val }; return GTIFKeySet(gtif, keyID, val1); }
//********************************************************************** // GTIFGetDefn() //********************************************************************** // // @param psGTIF GeoTIFF information handle as returned by GTIFNew. // @param psDefn Pointer to an existing GTIFDefn structure. This structure // does not need to have been pre-initialized at all. // // @return true if the function has been successful, otherwise false. // // This function reads the coordinate system definition from a GeoTIFF file, // and normalizes it into a set of component information using // definitions from CSV (Comma Seperated Value ASCII) files derived from // EPSG tables. This function is intended to simplify correct support for // reading files with defined PCS (Projected Coordinate System) codes that // wouldn't otherwise be directly known by application software by reducing // it to the underlying projection method, parameters, datum, ellipsoid, // prime meridian and units. // // The application should pass a pointer to an existing uninitialized // GTIFDefn structure, and GTIFGetDefn() will fill it in. The fuction // currently always returns TRUE but in the future will return FALSE if // CSV files are not found. In any event, all geokeys actually found in the // file will be copied into the GTIFDefn. However, if the CSV files aren't // found codes implied by other codes will not be set properly. // // GTIFGetDefn() will not generally work if the EPSG derived CSV files cannot // be found. By default a modest attempt will be made to find them, but // in general it is necessary for the calling application to override the // logic to find them. This can be done by calling the SetCSVFilenameHook() // function to override the search method based on application knowledge of // where they are found. // // The normalization methodology operates by fetching tags from the GeoTIFF // file, and then setting all other tags implied by them in the structure. The // implied relationships are worked out by reading definitions from the // various EPSG derived CSV tables. // // For instance, if a PCS (ProjectedCSTypeGeoKey) is found in the GeoTIFF file // this code is used to lookup a record in the horiz_cs.csv CSV // file. For example given the PCS 26746 we can find the name // (NAD27 / California zone VI), the GCS 4257 (NAD27), and the ProjectionCode // 10406 (California CS27 zone VI). The GCS, and ProjectionCode can in turn // be looked up in other tables until all the details of units, ellipsoid, // prime meridian, datum, projection (LambertConfConic_2SP) and projection // parameters are established. A full listgeo dump of a file // for this result might look like the following, all based on a single PCS // value: // // %listgeo -norm ~/data/geotiff/pci_eg/spaf27.tif // Geotiff_Information: // Version: 1 // Key_Revision: 1.0 // Tagged_Information: // ModelTiepointTag (2,3): // 0 0 0 // 1577139.71 634349.176 0 // ModelPixelScaleTag (1,3): // 195.509321 198.32184 0 // End_Of_Tags. // Keyed_Information: // GTModelTypeGeoKey (Short,1): ModelTypeProjected // GTRasterTypeGeoKey (Short,1): RasterPixelIsArea // ProjectedCSTypeGeoKey (Short,1): PCS_NAD27_California_VI // End_Of_Keys. // End_Of_Geotiff. // // PCS = 26746 (NAD27 / California zone VI) // Projection = 10406 (California CS27 zone VI) // Projection Method: CT_LambertConfConic_2SP // ProjStdParallel1GeoKey: 33.883333 // ProjStdParallel2GeoKey: 32.766667 // ProjFalseOriginLatGeoKey: 32.166667 // ProjFalseOriginLongGeoKey: -116.233333 // ProjFalseEastingGeoKey: 609601.219202 // ProjFalseNorthingGeoKey: 0.000000 // GCS: 4267/NAD27 // Datum: 6267/North American Datum 1927 // Ellipsoid: 7008/Clarke 1866 (6378206.40,6356583.80) // Prime Meridian: 8901/Greenwich (0.000000) // Projection Linear Units: 9003/US survey foot (0.304801m) // // Note that GTIFGetDefn() does not inspect or return the tiepoints and scale. // This must be handled seperately as it normally would. It is intended to // simplify capture and normalization of the coordinate system definition. // Note that GTIFGetDefn() also does the following things: // // * Convert all angular values to decimal degrees. // * Convert all linear values to meters. // * Return the linear units and conversion to meters for the tiepoints and // scale (though the tiepoints and scale remain in their native units). // * When reading projection parameters a variety of differences between // different GeoTIFF generators are handled, and a normalized set of // parameters for each projection are always returned. // // Code fields in the GTIFDefn are filled with KvUserDefined if there is not value to // assign. The parameter lists for each of the underlying projection transform methods // can be found at the Projections (http://www.remotesensing.org/geotiff/proj_list) page. // Note that nParms will be set based on the maximum parameter used. Some of the // parameters may not be used in which case the GTIFDefn::ProjParmId[] will be zero. // This is done to retain correspondence to the EPSG parameter numbering scheme. // //The geotiff_proj4.cs module distributed with libgeotiff can be used as an example of // code that converts a GTIFDefn into another projection system. // // @see GTIFKeySet(), SetCSVFilenameHook() public static bool GTIFGetDefn(GTIF gtif, GTIFDefn defn) { // -------------------------------------------------------------------- // Initially we default all the information we can. // -------------------------------------------------------------------- defn.DefnSet=true; defn.Model=(modeltype_t)KvUserDefined; defn.PCS=(pcstype_t)KvUserDefined; defn.GCS=(geographic_t)KvUserDefined; defn.UOMLength=(geounits_t)KvUserDefined; defn.UOMLengthInMeters=1.0; defn.UOMAngle=(geounits_t)KvUserDefined; defn.UOMAngleInDegrees=1.0; defn.Datum=(geodeticdatum_t)KvUserDefined; defn.Ellipsoid=(ellipsoid_t)KvUserDefined; defn.SemiMajor=0.0; defn.SemiMinor=0.0; defn.PM=(primemeridian_t)KvUserDefined; defn.PMLongToGreenwich=0.0; defn.TOWGS84Count=0; for(int i=0; i<defn.TOWGS84.Length; i++) defn.TOWGS84[i]=0; defn.ProjCode=(projection_t)KvUserDefined; defn.Projection=KvUserDefined; defn.CTProjection=(coordtrans_t)KvUserDefined; defn.nParms=0; for(int i=0; i<MAX_GTIF_PROJPARMS; i++) { defn.ProjParm[i]=0.0; defn.ProjParmId[i]=0; } defn.MapSys=KvUserDefined; defn.Zone=0; // -------------------------------------------------------------------- // Do we have any geokeys? // -------------------------------------------------------------------- int nKeyCount=0; int[] anVersion=new int[3]; GTIFDirectoryInfo(gtif, anVersion, out nKeyCount); if(nKeyCount==0) { defn.DefnSet=false; return false; } // -------------------------------------------------------------------- // Try to get the overall model type. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GTModelTypeGeoKey, out defn.Model, 0, 1); // -------------------------------------------------------------------- // Extract the Geog units. // -------------------------------------------------------------------- geounits_t nGeogUOMLinear=geounits_t.Linear_Meter; GTIFKeyGet(gtif, geokey_t.GeogLinearUnitsGeoKey, out nGeogUOMLinear, 0, 1); // -------------------------------------------------------------------- // Try to get a PCS. // -------------------------------------------------------------------- string dummy; if(GTIFKeyGet(gtif, geokey_t.ProjectedCSTypeGeoKey, out defn.PCS, 0, 1)==1 &&defn.PCS!=(pcstype_t)KvUserDefined) // Translate this into useful information. GTIFGetPCSInfo(defn.PCS, out dummy, out defn.ProjCode, out defn.UOMLength, out defn.GCS); // -------------------------------------------------------------------- // If we have the PCS code, but didn't find it in the CSV files // (likely because we can't find them) we will try some "jiffy // rules" for UTM and state plane. // -------------------------------------------------------------------- if(defn.PCS!=(pcstype_t)KvUserDefined&&defn.ProjCode==(projection_t)KvUserDefined) { int mapSys, zone; geographic_t GCS=defn.GCS; mapSys=GTIFPCSToMapSys(defn.PCS, out GCS, out zone); if(mapSys!=KvUserDefined) { defn.ProjCode=GTIFMapSysToProj(mapSys, zone); defn.GCS=GCS; } } // -------------------------------------------------------------------- // If the Proj_ code is specified directly, use that. // -------------------------------------------------------------------- if(defn.ProjCode==(projection_t)KvUserDefined) GTIFKeyGet(gtif, geokey_t.ProjectionGeoKey, out defn.ProjCode, 0, 1); if(defn.ProjCode!=(projection_t)KvUserDefined) { // We have an underlying projection transformation value. Look // this up. For a PCS of "WGS 84 / UTM 11" the transformation // would be Transverse Mercator, with a particular set of options. // The nProjTRFCode itself would correspond to the name // "UTM zone 11N", and doesn't include datum info. GTIFGetProjTRFInfo(defn.ProjCode, out dummy, out defn.Projection, defn.ProjParm); // Set the GeoTIFF identity of the parameters. defn.CTProjection=EPSGProjMethodToCTProjMethod(defn.Projection); SetGTParmIds(defn.CTProjection, defn.ProjParmId, null); defn.nParms=7; } // -------------------------------------------------------------------- // Try to get a GCS. If found, it will override any implied by // the PCS. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GeographicTypeGeoKey, out defn.GCS, 0, 1); if(defn.GCS<(geographic_t)1||defn.GCS>=(geographic_t)KvUserDefined) defn.GCS=(geographic_t)KvUserDefined; // -------------------------------------------------------------------- // Derive the datum, and prime meridian from the GCS. // -------------------------------------------------------------------- if(defn.GCS!=(geographic_t)KvUserDefined) GTIFGetGCSInfo(defn.GCS, out dummy, out defn.Datum, out defn.PM, out defn.UOMAngle); // -------------------------------------------------------------------- // Handle the GCS angular units. GeogAngularUnitsGeoKey // overrides the GCS or PCS setting. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GeogAngularUnitsGeoKey, out defn.UOMAngle, 0, 1); if(defn.UOMAngle!=(geounits_t)KvUserDefined) GTIFGetUOMAngleInfo(defn.UOMAngle, out dummy, out defn.UOMAngleInDegrees); // -------------------------------------------------------------------- // Check for a datum setting, and then use the datum to derive // an ellipsoid. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GeogGeodeticDatumGeoKey, out defn.Datum, 0, 1); if(defn.Datum!=(geodeticdatum_t)KvUserDefined) GTIFGetDatumInfo(defn.Datum, out dummy, out defn.Ellipsoid); // -------------------------------------------------------------------- // Check for an explicit ellipsoid. Use the ellipsoid to // derive the ellipsoid characteristics, if possible. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GeogEllipsoidGeoKey, out defn.Ellipsoid, 0, 1); if(defn.Ellipsoid!=(ellipsoid_t)KvUserDefined) GTIFGetEllipsoidInfo(defn.Ellipsoid, out dummy, out defn.SemiMajor, out defn.SemiMinor); // -------------------------------------------------------------------- // Check for overridden ellipsoid parameters. It would be nice // to warn if they conflict with provided information, but for // now we just override. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GeogSemiMajorAxisGeoKey, out defn.SemiMajor, 0, 1); GTIFKeyGet(gtif, geokey_t.GeogSemiMinorAxisGeoKey, out defn.SemiMinor, 0, 1); double invFlattening; if(GTIFKeyGet(gtif, geokey_t.GeogInvFlatteningGeoKey, out invFlattening, 0, 1)==1) { if(invFlattening!=0.0) defn.SemiMinor=defn.SemiMajor*(1-1.0/invFlattening); else defn.SemiMinor=defn.SemiMajor; } // -------------------------------------------------------------------- // Get the prime meridian info. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.GeogPrimeMeridianGeoKey, out defn.PM, 0, 1); if(defn.PM!=(primemeridian_t)KvUserDefined) GTIFGetPMInfo(defn.PM, out dummy, out defn.PMLongToGreenwich); else { GTIFKeyGet(gtif, geokey_t.GeogPrimeMeridianLongGeoKey, out defn.PMLongToGreenwich, 0, 1); defn.PMLongToGreenwich=GTIFAngleToDD(defn.PMLongToGreenwich, defn.UOMAngle); } // -------------------------------------------------------------------- // Get the TOWGS84 parameters. // -------------------------------------------------------------------- defn.TOWGS84Count=GTIFKeyGet(gtif, geokey_t.GeogTOWGS84GeoKey, out defn.TOWGS84, 0, 7); // -------------------------------------------------------------------- // Have the projection units of measure been overridden? We // should likely be doing something about angular units too, // but these are very rarely not decimal degrees for actual // file coordinates. // -------------------------------------------------------------------- GTIFKeyGet(gtif, geokey_t.ProjLinearUnitsGeoKey, out defn.UOMLength, 0, 1); if(defn.UOMLength!=(geounits_t)KvUserDefined) GTIFGetUOMLengthInfo(defn.UOMLength, out dummy, out defn.UOMLengthInMeters); // -------------------------------------------------------------------- // Handle a variety of user defined transform types. // -------------------------------------------------------------------- if(GTIFKeyGet(gtif, geokey_t.ProjCoordTransGeoKey, out defn.CTProjection, 0, 1)==1) GTIFFetchProjParms(gtif, defn); // -------------------------------------------------------------------- // Try to set the zoned map system information. // -------------------------------------------------------------------- defn.MapSys=GTIFProjToMapSys(defn.ProjCode, out defn.Zone); // -------------------------------------------------------------------- // If this is UTM, and we were unable to extract the projection // parameters from the CSV file, just set them directly now, // since it's pretty easy, and a common case. // -------------------------------------------------------------------- if((defn.MapSys==MapSys_UTM_North||defn.MapSys==MapSys_UTM_South)&& defn.CTProjection==(coordtrans_t)KvUserDefined) { defn.CTProjection=coordtrans_t.CT_TransverseMercator; defn.nParms=7; defn.ProjParmId[0]=geokey_t.ProjNatOriginLatGeoKey; defn.ProjParm[0]=0.0; defn.ProjParmId[1]=geokey_t.ProjNatOriginLongGeoKey; defn.ProjParm[1]=defn.Zone*6-183.0; defn.ProjParmId[4]=geokey_t.ProjScaleAtNatOriginGeoKey; defn.ProjParm[4]=0.9996; defn.ProjParmId[5]=geokey_t.ProjFalseEastingGeoKey; defn.ProjParm[5]=500000.0; defn.ProjParmId[6]=geokey_t.ProjFalseNorthingGeoKey; if(defn.MapSys==MapSys_UTM_North) defn.ProjParm[6]=0.0; else defn.ProjParm[6]=10000000.0; } return true; }
public static int GTIFKeyGet(GTIF gtif, geokey_t thekey, out coordtrans_t val, int index) { return GTIFKeyGet(gtif, thekey, out val, index, 0); }