public void Proj4EsriComparisonTest() { var infoBuiltIn = KnownCoordinateSystems.Geographic.World.WGS1984; const string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; var infoFromEsri = ProjectionInfo.FromEsriString(esri); var expected = infoFromEsri.ToProj4String(); var actual = infoBuiltIn.ToProj4String(); Assert.AreEqual(expected, actual); }
public void ToEsriStringNorthAmericanDatum1983Test() { ProjectionInfo p1 = KnownCoordinateSystems.Geographic.NorthAmerica.NorthAmericanDatum1983; const string esri = "GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101004]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo p2 = ProjectionInfo.FromEsriString(esri); string expected = p2.ToEsriString(); string actual = p1.ToEsriString(); Assert.AreEqual(expected, actual); Assert.IsTrue(p1.Equals(p2)); }
public void ToEsriStringWGS1984Test() { ProjectionInfo p1 = KnownCoordinateSystems.Geographic.World.WGS1984; const string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo p2 = ProjectionInfo.FromEsriString(esri); string expected = p2.ToEsriString(); string actual = p1.ToEsriString(); Assert.AreEqual(expected, actual); Assert.IsTrue(p1.Equals(p2)); }
/// <summary> /// Restores the 'search area rectangle' in the map /// </summary> public void RestoreSearchRectangle(double minLon, double minLat, double maxLon, double maxLat) { AddRectangleLayer(); if (_rectangleLayer != null) { _rectangleLayer.DataSet.Features.Clear(); double maxLat1 = Math.Max(minLat, maxLat); double minLat1 = Math.Min(minLat, maxLat); double maxLon1 = Math.Max(minLon, maxLon); double minLon1 = Math.Min(minLon, maxLon); //reproject the points int numPoints = 4; double[] array = new double[8]; array[0] = minLon1; array[1] = minLat1; array[2] = minLon1; array[3] = maxLat1; array[4] = maxLon1; array[5] = maxLat1; array[6] = maxLon1; array[7] = minLat1; ProjectionInfo wgs84 = ProjectionInfo.FromEsriString(KnownCoordinateSystems.Geographic.World.WGS1984.ToEsriString()); Reproject.ReprojectPoints(array, new double[] { 0, 0, 0, 0 }, wgs84, _mainMap.Projection, 0, numPoints); //form the coordinate array and add rectangle feature Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(array[0], array[1]); coords[1] = new Coordinate(array[2], array[3]); coords[2] = new Coordinate(array[4], array[5]); coords[3] = new Coordinate(array[6], array[7]); //add the closing point of the rectangle - same as first point coords[4] = new Coordinate(array[0], array[1]); //create a polygon feature from the coordinate array LinearRing shell = new LinearRing(coords); Polygon poly = new Polygon(shell); IFeature newF = _rectangleLayer.DataSet.AddFeature(poly); newF.DataRow["ID"] = 1; _numClicks = 0; _mainMap.ResetBuffer(); //Deactivate(); OnRectangleCreated(); } }
/// <summary> /// Restores the 'search area rectangle' in the map /// </summary> public void RestoreSearchRectangle(double minLon, double minLat, double maxLon, double maxLat) { AddRectangleLayer(); if (_rectangleLayer != null) { _rectangleLayer.DataSet.Features.Clear(); double maxLat1 = Math.Max(minLat, maxLat); double minLat1 = Math.Min(minLat, maxLat); double maxLon1 = Math.Max(minLon, maxLon); double minLon1 = Math.Min(minLon, maxLon); //reproject the points const int numPoints = 4; var array = new double[8]; array[0] = minLon1; array[1] = minLat1; array[2] = minLon1; array[3] = maxLat1; array[4] = maxLon1; array[5] = maxLat1; array[6] = maxLon1; array[7] = minLat1; ProjectionInfo wgs84 = ProjectionInfo.FromEsriString(Properties.Resources.wgs_84_esri_string); Reproject.ReprojectPoints(array, new double[] { 0, 0, 0, 0 }, wgs84, _mainMap.Projection, 0, numPoints); //form the coordinate array and add rectangle feature var coords = new Coordinate[5]; coords[0] = new Coordinate(array[0], array[1]); coords[1] = new Coordinate(array[2], array[3]); coords[2] = new Coordinate(array[4], array[5]); coords[3] = new Coordinate(array[6], array[7]); //add the closing point of the rectangle - same as first point coords[4] = new Coordinate(array[0], array[1]); //create a polygon feature from the coordinate array var shell = new LinearRing(coords); var poly = new Polygon(shell); var newF = _rectangleLayer.DataSet.AddFeature(poly); newF.DataRow["ID"] = 1; _numClicks = 0; _mainMap.ResetBuffer(); //Deactivate(); OnRectangleCreated(); } }
private static void SetMapExtent(Map map) { Extent defaultMapExtent = new Extent(-130, 5, -70, 60); double[] xy = new double[4]; xy[0] = defaultMapExtent.MinX; xy[1] = defaultMapExtent.MinY; xy[2] = defaultMapExtent.MaxX; xy[3] = defaultMapExtent.MaxY; double[] z = new double[] { 0, 0 }; ProjectionInfo wgs84 = ProjectionInfo.FromEsriString(Properties.Resources.wgs_84_esri_string); Reproject.ReprojectPoints(xy, z, wgs84, projWorld.WebMercator, 0, 2); map.ViewExtents = new Extent(xy); map.MapFrame.ResetExtents(); }
/// <summary> /// Reprojects all layers in the map frame so that they use the new /// projection Esri string /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjEsriString">The Esri WKT string of the new projection</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, string newProjEsriString) { if (mapFrame == null) { throw new ArgumentNullException("mapFrame"); } if (newProjEsriString == null) { throw new ArgumentNullException("newProjEsriString"); } // parse the projection var newProjection = ProjectionInfo.FromEsriString(newProjEsriString); mapFrame.ReprojectMapFrame(newProjection); }
//Code that allows the user to input a Proj4 string and reproject a WGS 1984 GCS to a Proj4 PCS public static void ReadingProj4Settings() { //Declares a new ProjectionInfo and sets it to GCS_WGS_1984 ProjectionInfo pStart = new ProjectionInfo(); pStart = KnownCoordinateSystems.Geographic.World.WGS1984; //Declares a new ProjectionInfo and allows the user to directly input a Proj4 string ProjectionInfo pEnd = ProjectionInfo.FromEsriString("+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs "); //Declares the point to be projected, starts out as 0,0 double[] xy = new double[2]; double[] z = new double[1]; //calls the reproject function and reprojects the points Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1); Console.WriteLine("Reprojection is complete."); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="oid"></param> /// <param name="definition"></param> public DotSpatialSpatialReference(string oid, string definition) { _oid = oid; Definition = definition; if (definition.StartsWith("EPSG:")) { ProjectionInfo = ProjectionInfo.FromEpsgCode(int.Parse(definition.Substring(5))); } else if (definition.StartsWith("+proj")) { ProjectionInfo = ProjectionInfo.FromProj4String(definition); } else { ProjectionInfo = ProjectionInfo.FromEsriString(definition); } }
public void GeometryTransformTest() { #region Init ICoordinateTransformation // RGF93_Lambert_93 const string coordSysRGF93_Lambert_93 = "PROJCS[\"RGF93_Lambert_93\",GEOGCS[\"GCS_RGF_1993\",DATUM[\"D_RGF_1993\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",700000.0],PARAMETER[\"False_Northing\",6600000.0],PARAMETER[\"Central_Meridian\",3.0],PARAMETER[\"Standard_Parallel_1\",44.0],PARAMETER[\"Standard_Parallel_2\",49.0],PARAMETER[\"Latitude_Of_Origin\",46.5],UNIT[\"Meter\",1.0]]"; // SRID 4326 const string coordSys4326 = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"; var csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(coordSysRGF93_Lambert_93) as GeoAPI.CoordinateSystems.ICoordinateSystem; var csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(coordSys4326) as GeoAPI.CoordinateSystems.ICoordinateSystem; var transform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(csSource, csTarget); var piSource = ProjectionInfo.FromEsriString(coordSysRGF93_Lambert_93); var piTarget = ProjectionInfo.FromEsriString(coordSys4326); var dsTransform = new DotSpatialMathTransform(piSource, piTarget); #endregion Init ICoordinateTransformation using (var shapeDataReader = new ShapefileDataReader(@"..\..\..\NetTopologySuite.Samples.Shapefiles\DEPARTEMENT.SHP", GeometryFactory.Default)) { while (shapeDataReader.Read()) { var outGeomDotSpatial = CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, shapeDataReader.Geometry, dsTransform); Assert.IsFalse(outGeomDotSpatial.IsEmpty); Console.WriteLine(outGeomDotSpatial.AsText()); var outGeomProjNet = CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(GeometryFactory.Default, shapeDataReader.Geometry, transform.MathTransform); Assert.IsFalse(outGeomProjNet.IsEmpty); Console.WriteLine(outGeomProjNet.AsText()); var hd = Algorithm.Distance.DiscreteHausdorffDistance.Distance(outGeomProjNet, outGeomDotSpatial); Console.WriteLine(string.Format("\nHaussdorffDistance: {0}", hd)); Console.WriteLine(); } } }
public static GeometryTransform GetTransform(string shapefile, string targetWKT) { string prjPath = Path.ChangeExtension(shapefile, ".prj"); if (targetWKT != null && File.Exists(prjPath)) { string sourceWKT = File.ReadAllText(prjPath); ProjectionInfo source = ProjectionInfo.FromEsriString(sourceWKT); ProjectionInfo target = ProjectionInfo.FromEsriString(targetWKT); if (source != null && !source.Matches(target)) { return(new GeometryTransform(source, target)); } } return(null); }
public void KrovakToWgs84_EsriString() { double[] myOut = new double[2]; myOut[0] = -868208.52; myOut[1] = -1095793.96; double[] myZ = new double[1]; myZ[0] = 0; string jtskEsriString = @"PROJCS[""S-JTSK_Krovak_East_North"",GEOGCS[""GCS_S_JTSK"",DATUM[""D_S_JTSK"",SPHEROID[""Bessel_1841"",6377397.155,299.1528128]],PRIMEM[""Greenwich"",0.0],UNIT[""Degree"",0.0174532925199433]],PROJECTION[""Krovak""],PARAMETER[""False_Easting"",0.0],PARAMETER[""False_Northing"",0.0],PARAMETER[""Pseudo_Standard_Parallel_1"",78.5],PARAMETER[""Scale_Factor"",0.9999],PARAMETER[""Azimuth"",30.28813975277778],PARAMETER[""Longitude_Of_Center"",24.83333333333333],PARAMETER[""Latitude_Of_Center"",49.5],PARAMETER[""X_Scale"",-1.0],PARAMETER[""Y_Scale"",1.0],PARAMETER[""XY_Plane_Rotation"",90.0],UNIT[""Meter"",1.0]]"; ProjectionInfo projWGS84 = KnownCoordinateSystems.Geographic.World.WGS1984; ProjectionInfo myJTSKPI = ProjectionInfo.FromEsriString(jtskEsriString); Reproject.ReprojectPoints(myOut, myZ, myJTSKPI, projWGS84, 0, myZ.Length); Assert.AreEqual(myOut[0], 12.8069888666667, 1.0); Assert.AreEqual(myOut[1], 49.4522626972222, 1.0); }
private void BtnUseEsriClick(object sender, EventArgs e) { ProjectionInfo proj; try { proj = chbEsri.Checked ? ProjectionInfo.FromEsriString(tbEsriProj4.Text) : ProjectionInfo.FromProj4String(tbEsriProj4.Text); } catch (Exception) { MessageBox.Show(this, ProjectionStrings.UnknownEsriOrProj4String, ProjectionStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); proj = null; } if (proj != null) { SelectedCoordinateSystem = proj; } }
public CoordinateDisplay(AppManager app) { latLonStatusPanel = new StatusPanel(); latLonStatusPanel.Width = 400; app.ProgressHandler.Add(latLonStatusPanel); mainMap = app.Map as Map; if (mainMap == null) { return; } string mapProjEsriString = mainMap.Projection.ToEsriString(); isWgs84 = (mapProjEsriString == Properties.Resources.wgs_84_esri_string); currentMapProjection = ProjectionInfo.FromEsriString(mapProjEsriString); mainMap.MouseMove += new MouseEventHandler(mainMap_MouseMove); mainMap.ProjectionChanged += new EventHandler(mainMap_ProjectionChanged); }
/// <summary> /// Creates a spatial reference object given its Well-known text representation. /// The output object may be either a <see cref="T:GeoAPI.CoordinateSystems.IGeographicCoordinateSystem" /> or /// a <see cref="T:GeoAPI.CoordinateSystems.IProjectedCoordinateSystem" />. /// </summary> /// <param name="wkt">The Well-known text representation for the spatial reference</param> /// <returns>The resulting spatial reference object</returns> public ICoordinateSystem CreateFromWkt(string wkt) { //Hack: DotSpatial.Projections does not handle Authority and AuthorityCode var pos1 = 10 + wkt.LastIndexOf("AUTHORITY[", StringComparison.InvariantCulture); var pos2 = wkt.IndexOf("]", pos1, StringComparison.InvariantCulture) - 1; var parts = wkt.Substring(pos1, pos2 - pos1 + 1).Split(','); var auth = parts[0].Replace("\"", "").Trim(); var code = int.Parse(parts[1].Replace("\"", ""), NumberStyles.Integer, NumberFormatInfo.InvariantInfo); ProjectionInfo pi = null; try { pi = ProjectionInfo.FromEsriString(wkt); } catch (Exception) { try { pi = ProjectionInfo.FromAuthorityCode(auth, code); } catch (Exception) { } } if (pi == null) { return(null); } pi.Authority = auth; pi.AuthorityCode = code; return(new DotSpatialCoordinateSystem(pi)); }
/// <summary> /// This function gets the site information. /// </summary> private Site getSitesParameters(PolygonData polygon) { IFeature centroid = polygon.polygon.Centroid(); var newpoint = sitesPoints.AddFeature(centroid); Site site = new Site(); var xy = new[] { centroid.Coordinates.First().X, centroid.Coordinates.First().Y }; String projectionString = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[" + "\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; var _wgs84Projection = ProjectionInfo.FromEsriString(projectionString); Reproject.ReprojectPoints(xy, new double[] { 0, 0 }, App.Map.Projection, _wgs84Projection, 0, 1); int indexNumber = (polygonData.IndexOf(polygon) + 1); site.Code = "CrwrAggregation:" + OutputResultName.Text + indexNumber.ToString(); newpoint.DataRow.BeginEdit(); newpoint.DataRow["SiteCode"] = site.Code.ToString(); newpoint.DataRow.EndEdit(); site.Name = OutputResultName.Text + indexNumber.ToString(); site.Latitude = xy[1]; site.Longitude = xy[0]; //site.Elevation_m = 12; site.VerticalDatum = "Unkown"; //site.LocalX = 12; //site.LocalY = 12; //site.PosAccuracy_m = 12; site.State = ""; site.County = ""; //site.Comments = "testing"; //site.Country = "Mexico"; //site.SiteType = "Type"; return(site); }
private double[] LatLonReproject(double x, double y) { double[] xy = new double[2] { x, y }; //Change y coordinate to be less than 90 degrees to prevent a bug. if (xy[1] >= 90) { xy[1] = 89.9; } if (xy[1] <= -90) { xy[1] = -89.9; } //Need to convert points to proper projection. Currently describe WGS84 points which may or may not be accurate. bool isWgs84; String wgs84String = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; String mapProjEsriString = App.Map.Projection.ToEsriString(); isWgs84 = (mapProjEsriString.Equals(wgs84String)); //If the projection is not WGS84, then convert points to properly describe desired location. if (!isWgs84) { double[] z = new double[1]; ProjectionInfo wgs84Projection = ProjectionInfo.FromEsriString(wgs84String); ProjectionInfo currentMapProjection = ProjectionInfo.FromEsriString(mapProjEsriString); Reproject.ReprojectPoints(xy, z, wgs84Projection, currentMapProjection, 0, 1); } //Return array with 1 x and 1 y value. return(xy); }
/// <summary> /// Creates a new ThemeManager /// </summary> public ThemeManager() { _wgs84Projection = ProjectionInfo.FromEsriString(Properties.Resources.Wgs84ProjectionString); }
private void btn_Ok_Click(object sender, EventArgs e) { string outputDir = tbx_Dir.Text.Trim(); if (!Directory.Exists(outputDir)) { if (string.IsNullOrWhiteSpace(outputDir)) { MessageBox.Show("请选择Shapefile文件保存文件夹"); return; } Directory.CreateDirectory(outputDir); } List <FeatureClass> pOutputFeatureClasses = GetCheckedFeatureClass(); foreach (FeatureClass feaClass in pOutputFeatureClasses) { DataTable pDT = feaClass.GetDataTable(); if (pDT == null) { //表格不存在 MessageBox.Show(feaClass.Name + "表格不存在。"); continue; } if (pDT.Rows.Count == 0) { //MessageCenterMgr.MessageCenter.AddInfoMsg(feaClass.Name + "表格中要素个数为0。"); MessageBox.Show(feaClass.Name + "表格中要素个数为0。"); continue; } List <IFeatureSet> feaSets = new List <IFeatureSet>(); IFeatureSet feaSet = null; switch (feaClass.GeometryType) { case EsriGeometryType.Point: feaSet = new FeatureSet(FeatureType.Point); break; case EsriGeometryType.MultiPoint: feaSet = new FeatureSet(FeatureType.MultiPoint); break; case EsriGeometryType.Line: feaSet = new FeatureSet(FeatureType.Line); break; case EsriGeometryType.Polygon: feaSet = new FeatureSet(FeatureType.Polygon); break; } if (feaSet == null) { MessageBox.Show(feaClass + "表格中几何类型不被支持,请联系开发者处理。"); continue; } Table2ShapeFile(feaSet, pDT, feaClass.GeomShapeFieldName); //设置坐标系并保存 feaSet.Projection = ProjectionInfo.FromEsriString(feaClass.ProjectionString); feaSet.Filename = Path.Combine(tbx_Dir.Text, feaClass.Name + ".shp"); feaSet.Save(); MessageBox.Show(feaClass.Name + "表格向Shapefile转换成功。"); } MessageBox.Show("转换完毕"); pGeoMDBReader.CloseMDB(); this.Close(); }
static ServiceProviderFactory() { WebMercProj = new Lazy <ProjectionInfo>(() => ProjectionInfo.FromEsriString(KnownCoordinateSystems.Projected.World.WebMercator.ToEsriString())); Wgs84Proj = new Lazy <ProjectionInfo>(() => ProjectionInfo.FromEsriString(KnownCoordinateSystems.Geographic.World.WGS1984.ToEsriString())); }
public void PlateCarreeFromEsriString() { ProjectionInfo pStart = ProjectionInfo.FromEsriString("PROJCS[\"WGS_1984_Plate_Carree\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Plate_Carree\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],UNIT[\"Meter\",1.0]]"); Tester.TestProjection(pStart); }
/// <summary> /// Load base maps for World template project. The base shapefiles /// are loaded from the [Program Files]\[Cuahsi HIS]\HydroDesktop\maps\BaseData folder. /// </summary> public static Boolean LoadBaseMaps(AppManager applicationManager1, Map mainMap) { //set the projection of main map mainMap.Projection = projWorld.WebMercator; Extent defaultMapExtent = new Extent(-170, -50, 170, 50); string baseMapFolder = Settings.Instance.DefaultBaseMapDirectory; //MapGroup baseGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler); //baseGroup.LegendText = "Base Map Data"; //baseGroup.ParentMapFrame = mainMap.MapFrame; //baseGroup.MapFrame = mainMap.MapFrame; //baseGroup.IsVisible = true; //load the 'Countries of the world' layer try { mainMap.BackColor = Color.LightBlue; string fileName = Path.Combine(baseMapFolder, "world_countries.shp"); if (File.Exists(fileName)) { IFeatureSet fsCountries = FeatureSet.OpenFile(fileName); MapPolygonLayer layCountries = new MapPolygonLayer(fsCountries); layCountries.LegendText = "Countries"; layCountries.Symbolizer = new PolygonSymbolizer(Color.FromArgb(255, 239, 213), Color.LightGray); //PolygonScheme schmCountries = new PolygonScheme(); //schmCountries.EditorSettings.StartColor = Color.Orange; //schmCountries.EditorSettings.EndColor = Color.Silver; //schmCountries.EditorSettings.ClassificationType = // ClassificationType.UniqueValues; //schmCountries.EditorSettings.FieldName = "NAME"; //schmCountries.EditorSettings.UseGradient = true; //schmCountries.CreateCategories(layCountries.DataSet.DataTable); //layCountries.Symbology = schmCountries; //baseGroup.Layers.Add(layCountries); mainMap.Layers.Add(layCountries); layCountries.MapFrame = mainMap.MapFrame; layCountries.ProgressReportingEnabled = false; } } catch { } //load a rivers layer try { var fileName = Path.Combine(baseMapFolder, "world_rivers.shp"); if (File.Exists(fileName)) { IFeatureSet fsRivers = FeatureSet.OpenFile(fileName); //fsRivers.Reproject(mainMap.Projection); MapLineLayer layRivers = new MapLineLayer(fsRivers); layRivers.LegendText = "rivers"; LineSymbolizer symRivers = new LineSymbolizer(Color.Blue, 1.0); layRivers.Symbolizer = symRivers; mainMap.Layers.Add(layRivers); layRivers.MapFrame = mainMap.MapFrame; } } catch { } //load a lakes layer try { var fileName = Path.Combine(baseMapFolder, "world_lakes.shp"); if (File.Exists(fileName)) { IFeatureSet fsLakes = FeatureSet.OpenFile(fileName); //fsLakes.Reproject(mainMap.Projection); MapPolygonLayer layLakes = new MapPolygonLayer(fsLakes); layLakes.LegendText = "lakes"; PolygonSymbolizer symLakes = new PolygonSymbolizer(Color.Blue, Color.Blue); layLakes.Symbolizer = symLakes; mainMap.Layers.Add(layLakes); layLakes.MapFrame = mainMap.MapFrame; layLakes.ProgressReportingEnabled = false; } } catch { } double[] xy = new double[4]; xy[0] = defaultMapExtent.MinX; xy[1] = defaultMapExtent.MinY; xy[2] = defaultMapExtent.MaxX; xy[3] = defaultMapExtent.MaxY; double[] z = new double[] { 0, 0 }; var wgs84 = ProjectionInfo.FromEsriString(Properties.Resources.wgs_84_esri_string); Reproject.ReprojectPoints(xy, z, wgs84, mainMap.Projection, 0, 2); mainMap.ViewExtents = new Extent(xy); return(true); }
public static void Reproject(string destinationFolder, string projection, params ReprojectShapefile[] shapes) { ProjectionInfo targetProjection = ProjectionInfo.FromEsriString(projection); foreach (ReprojectShapefile shape in shapes) { string shapePath = Path.Combine(destinationFolder, shape.DestinationName); ShapefileHeader shapeHeader = ShapefileHeader.CreateEmpty(ShapefileGeometryType.Polygon); DbfHeader dbfHeader = new DbfHeader(); dbfHeader.AddCharacter("Label", 80); GeometryFactory gf = new GeometryFactory(); using (ShapefileDataWriter writer = ShapefileDataWriter.Create(shapePath + ".shp", dbfHeader, shapeHeader)) { GeometryTransform transform = null; if (File.Exists(Path.ChangeExtension(shape.Source, ".prj"))) { transform = GeometryTransform.GetTransform(shape.Source, projection); if (transform != null) { File.WriteAllText(shapePath + ".prj", projection); } else { File.Copy(Path.ChangeExtension(shape.Source, ".prj"), shapePath + ".prj"); } } using (ShapefileIndexReader index = new ShapefileIndexReader(Path.ChangeExtension(shape.Source, ".shx"))) { if (transform != null) { writer.Header.Bounds.ExpandToInclude(transform.Apply(index.Header.Bounds)); } else { writer.Header.Bounds.ExpandToInclude(index.Header.Bounds); } Task[] tasks = new Task[Environment.ProcessorCount]; for (int i = 0; i < tasks.Length; i++) { tasks[i] = Task.Factory.StartNew(() => { using (ShapefileBlockReader reader = new ShapefileBlockReader(shape.Source, index, gf, transform)) { while (reader.Read()) { writer.Write(reader.Geometry, reader.Record.GetString(shape.Label)); } } }); } Task.WaitAll(tasks); writer.Flush(); } } } }
public void TestSetViewExtents() { Map mainMap = new Map(); mainMap.Projection = KnownCoordinateSystems.Projected.World.WebMercator; Extent defaultMapExtent = new Extent(-130, 5, -70, 60); string baseMapFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles"); //SetDefaultMapExtents(mainMap); MapPolygonLayer layStates; MapGroup baseGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler); baseGroup.LegendText = "Base Map Data"; baseGroup.ParentMapFrame = mainMap.MapFrame; baseGroup.MapFrame = mainMap.MapFrame; baseGroup.IsVisible = true; //load the 'Countries of the world' layer try { string fileName = Path.Combine(baseMapFolder, "50m_admin_0_countries.shp"); IFeatureSet fsCountries = FeatureSet.OpenFile(fileName); fsCountries.Reproject(mainMap.Projection); MapPolygonLayer layCountries = new MapPolygonLayer(fsCountries); layCountries.LegendText = "Countries"; PolygonScheme schmCountries = new PolygonScheme(); schmCountries.EditorSettings.StartColor = Color.Orange; schmCountries.EditorSettings.EndColor = Color.Silver; schmCountries.EditorSettings.ClassificationType = ClassificationType.UniqueValues; schmCountries.EditorSettings.FieldName = "NAME"; schmCountries.EditorSettings.UseGradient = true; schmCountries.CreateCategories(layCountries.DataSet.DataTable); layCountries.Symbology = schmCountries; baseGroup.Layers.Add(layCountries); layCountries.MapFrame = mainMap.MapFrame; } catch { } //load U.S. states layer try { string fileName = Path.Combine(baseMapFolder, "50mil_us_states.shp"); IFeatureSet fsStates = FeatureSet.OpenFile(fileName); fsStates.Reproject(mainMap.Projection); layStates = new MapPolygonLayer(fsStates); PolygonScheme schmStates = new PolygonScheme(); layStates.IsVisible = true; layStates.LegendText = "U.S. States"; schmStates.EditorSettings.StartColor = Color.LemonChiffon; schmStates.EditorSettings.EndColor = Color.LightPink; schmStates.EditorSettings.ClassificationType = ClassificationType.UniqueValues; schmStates.EditorSettings.FieldName = "NAME"; schmStates.EditorSettings.UseGradient = true; schmStates.CreateCategories(layStates.DataSet.DataTable); layStates.Symbology = schmStates; baseGroup.Layers.Add(layStates); layStates.MapFrame = mainMap.MapFrame; } catch { } //load Canada Provinces layer try { string fileName = Path.Combine(baseMapFolder, "50mil_canada_provinces.shp"); IFeatureSet fsProvince = FeatureSet.OpenFile(fileName); fsProvince.Reproject(mainMap.Projection); MapPolygonLayer layProvince = new MapPolygonLayer(fsProvince); PolygonScheme schmProvince = new PolygonScheme(); layProvince.IsVisible = true; layProvince.LegendText = "Canada Provinces"; schmProvince.EditorSettings.StartColor = Color.Green; schmProvince.EditorSettings.EndColor = Color.Yellow; schmProvince.EditorSettings.ClassificationType = ClassificationType.UniqueValues; schmProvince.EditorSettings.FieldName = "NAME"; schmProvince.EditorSettings.UseGradient = true; schmProvince.CreateCategories(layProvince.DataSet.DataTable); layProvince.Symbology = schmProvince; baseGroup.Layers.Add(layProvince); layProvince.MapFrame = mainMap.MapFrame; } catch { } //theme data group //create a new empty 'themes' data group try { MapGroup themeGroup = new MapGroup(mainMap.Layers, mainMap.MapFrame, mainMap.ProgressHandler); themeGroup.ParentMapFrame = mainMap.MapFrame; themeGroup.MapFrame = mainMap.MapFrame; themeGroup.LegendText = "Themes"; } catch { } double[] xy = new double[4]; xy[0] = defaultMapExtent.MinX; xy[1] = defaultMapExtent.MinY; xy[2] = defaultMapExtent.MaxX; xy[3] = defaultMapExtent.MaxY; double[] z = new double[] { 0, 0 }; string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]"; ProjectionInfo wgs84 = ProjectionInfo.FromEsriString(esri); Reproject.ReprojectPoints(xy, z, wgs84, mainMap.Projection, 0, 2); xy[0] = 1000000000000000; xy[1] = 2000000000000000; xy[2] = 3000000000000000; xy[3] = 4000000000000000; Extent ext = new Extent(xy); mainMap.ViewExtents = ext; }
/// <summary> /// Opens the specified file /// </summary> /// <param name="fileName">Path to file.</param> /// <returns>Feature set from file data.</returns> /// <exception cref="Exception">Throws if no sheets in the file, or /// Latitude or Longitude column not found.</exception> public IDataSet Open(string fileName) { var fs = new FeatureSet { Name = Path.GetFileNameWithoutExtension(fileName), Filename = fileName }; var extension = Path.GetExtension(fileName); IExcelDataReader reader = null; var stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); try { switch (extension) { case ".xls": reader = ExcelReaderFactory.CreateBinaryReader(stream); break; case ".xlsx": reader = ExcelReaderFactory.CreateOpenXmlReader(stream); break; default: goto case ".xls"; } reader.IsFirstRowAsColumnNames = true; var ds = reader.AsDataSet(); if (ds.Tables.Count == 0) { throw new Exception("There is no sheets in the file"); } // Find first table (sheet) with Latitude/Longitude columns. DataTable table = null; int latColumnIndex = -1; int lngColumnIndex = -1; for (int i = 0; i < ds.Tables.Count; i++) { table = ds.Tables[i]; latColumnIndex = table.Columns.IndexOf("Latitude"); lngColumnIndex = table.Columns.IndexOf("Longitude"); if (latColumnIndex >= 0 && lngColumnIndex >= 0) { break; } } if (latColumnIndex == -1 || lngColumnIndex == -1) { throw new Exception("Latitude or Longitude column not found"); } Debug.Assert(table != null); for (int i = 0; i < table.Columns.Count; i++) { string sFieldName = table.Columns[i].ColumnName; Type type = table.Columns[i].DataType; int uniqueNumber = 1; string uniqueName = sFieldName; while (fs.DataTable.Columns.Contains(uniqueName)) { uniqueName = sFieldName + uniqueNumber; uniqueNumber++; } fs.DataTable.Columns.Add(new DataColumn(uniqueName, type)); } reader.Read(); while (reader.Read()) { var lat = reader.GetDouble(latColumnIndex); var lng = reader.GetDouble(lngColumnIndex); IGeometry geometry = new Point(lng, lat); IFeature feature = new Feature(geometry); feature.DataRow = fs.DataTable.NewRow(); for (int j = 0; j < reader.FieldCount; j++) { object value = reader.GetValue(j) ?? DBNull.Value; feature.DataRow[j] = value; } fs.Features.Add(feature); } }finally { if (reader != null) { reader.Close(); } stream.Close(); } fs.Projection = ProjectionInfo.FromEsriString(Resources.wgs_84_esri_string); return(fs); }
/// <summary> /// Creates a new ThemeManager /// </summary> public ThemeManager(ISearchPlugin searchPlugin) { _searchPlugin = searchPlugin; _wgs84Projection = ProjectionInfo.FromEsriString(Properties.Resources.Wgs84ProjectionString); }
public bool LoadFile(string filename) { FileName = filename; log.InfoFormat("GeoTiff {0}", filename); using (Tiff tiff = Tiff.Open(filename, "r")) { width = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt(); height = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt(); bits = tiff.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt(); //https://www.awaresystems.be/imaging/tiff/tifftags/sampleformat.html type = tiff.GetField(TiffTag.SAMPLEFORMAT)[0].ToInt(); modelscale = tiff.GetField(TiffTag.GEOTIFF_MODELPIXELSCALETAG); tiepoint = tiff.GetField(TiffTag.GEOTIFF_MODELTIEPOINTTAG); for (int i = 0; i < tiff.GetTagListCount(); i += 1) { var tagno = tiff.GetTagListEntry(i); var tag = (TiffTag)tagno; var info = tiff.GetField((TiffTag)tagno); log.InfoFormat("tiff ID={0} ? {1} len={2}", tag, (GKID)tagno, info.Length); } var GeoKeyDirectoryTag = tiff.GetField((TiffTag)34735); var KeyDirectoryVersion = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), 0); var KeyRevision = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), 2); var MinorRevision = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), 4); var NumberOfKeys = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), 6); ProjectedCSTypeGeoKey = 0; for (int i = 8; i < 8 + NumberOfKeys * 8; i += 8) { var KeyID = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), i); var TIFFTagLocation = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), i + 2); var Count = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), i + 4); var Value_Offset = BitConverter.ToUInt16(GeoKeyDirectoryTag[1].ToByteArray(), i + 6); log.InfoFormat("GeoKeyDirectoryTag ID={0} TagLoc={1} Count={2} Value/offset={3}", (GKID)KeyID, TIFFTagLocation, Count, Value_Offset); // save it if (TIFFTagLocation == 0) { GeoKeys[(GKID)KeyID] = Value_Offset; } else if (TIFFTagLocation == 34737) { GeoKeys[(GKID)KeyID] = Encoding.ASCII.GetString(tiff.GetField((TiffTag)TIFFTagLocation)[1].ToByteArray().Skip(Value_Offset).Take(Count).ToArray()); } else if (TIFFTagLocation == 34736) { GeoKeys[(GKID)KeyID] = BitConverter.ToDouble(tiff.GetField((TiffTag)TIFFTagLocation)[1].ToByteArray().Skip(Value_Offset * 8).Take(Count * 8).ToArray(), 0); } else { GeoKeys[(GKID)KeyID] = Value_Offset; } if (KeyID == (int)GKID.ProjectedCSTypeGeoKey) { ProjectedCSTypeGeoKey = Value_Offset; } if (KeyID == (int)GKID.GTRasterTypeGeoKey) { GTRasterTypeGeoKey = Value_Offset; } if (KeyID == (int)GKID.ProjCoordTransGeoKey) { ProjCoordTransGeoKey = Value_Offset; } if (TIFFTagLocation != 0) { if (TIFFTagLocation == 34737) //ascii { var value = tiff.GetField((TiffTag)TIFFTagLocation)[1].ToByteArray().Skip(Value_Offset) .Take(Count); log.InfoFormat("GeoKeyDirectoryTag ID={0} Value={1}", (GKID)KeyID, Encoding.ASCII.GetString(value.ToArray())); } if (TIFFTagLocation == 34736) // double { var value = tiff.GetField((TiffTag)TIFFTagLocation)[1].ToByteArray().Skip(Value_Offset * 8).Take(Count * 8); log.InfoFormat("GeoKeyDirectoryTag ID={0} Value={1}", (GKID)KeyID, BitConverter.ToDouble(value.ToArray(), 0)); } if (KeyID == (int)GKID.PCSCitationGeoKey) { var value = tiff.GetField((TiffTag)TIFFTagLocation)[1].ToByteArray().Skip(Value_Offset).Take(Count); PCSCitationGeoKey = Encoding.ASCII.GetString(value.ToArray()); log.InfoFormat("GeoKeyDirectoryTag ID={0} Value={1}", (GKID)KeyID, Encoding.ASCII.GetString(value.ToArray())); } } } GeoAsciiParamsTag = tiff.GetField((TiffTag)34737); if (GeoAsciiParamsTag != null && GeoAsciiParamsTag.Length == 2) { log.InfoFormat("GeoAsciiParamsTag 34737 {0}", GeoAsciiParamsTag[1]); } i = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0); j = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 8); k = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 16); x = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 24); y = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 32); z = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 40); log.InfoFormat("Tie Point ({0},{1},{2}) --> ({3},{4},{5})", i, j, k, x, y, z); xscale = BitConverter.ToDouble(modelscale[1].ToByteArray(), 0); yscale = BitConverter.ToDouble(modelscale[1].ToByteArray(), 0 + 8); zscale = BitConverter.ToDouble(modelscale[1].ToByteArray(), 0 + 16); log.InfoFormat("Scale ({0},{1},{2})", xscale, yscale, zscale); if (GTRasterTypeGeoKey == 1) { // starts from top left so x + y - x += xscale / 2.0; y -= yscale / 2.0; } if (ProjectedCSTypeGeoKey == 32767 && ProjCoordTransGeoKey == 15) { // user-defined ProjectionInfo pStart = ProjectionInfo.FromProj4String($"+proj=stere +lat_ts={GeoKeys[GKID.ProjOriginLatGeoKey].ToString()} +lat_0=90 +lon_0={GeoKeys[GKID.ProjStraightVertPoleLongGeoKey].ToString()} +x_0=0 +y_0=0 +ellps={GeoKeys[GKID.GeogCitationGeoKey].ToString().Replace(" ", "").Replace("|", "")} +datum={GeoKeys[GKID.GeogCitationGeoKey].ToString().Replace(" ", "").Replace("|", "")} +units=m +no_defs "); ProjectionInfo pESRIEnd = KnownCoordinateSystems.Geographic.World.WGS1984; srcProjection = pStart; double[] xyarray = { x, y, x + width * xscale, y - height * yscale, x + width * xscale, y, x, y - height * yscale }; Reproject.ReprojectPoints(xyarray, null, pStart, pESRIEnd, 0, xyarray.Length / 2); ymin = Math.Min(Math.Min(Math.Min(xyarray[1], xyarray[3]), xyarray[5]), xyarray[7]); xmin = Math.Min(Math.Min(Math.Min(xyarray[0], xyarray[2]), xyarray[4]), xyarray[6]); ymax = Math.Max(Math.Max(Math.Max(xyarray[1], xyarray[3]), xyarray[5]), xyarray[7]); xmax = Math.Max(Math.Max(Math.Max(xyarray[0], xyarray[2]), xyarray[4]), xyarray[6]); } else if (ProjectedCSTypeGeoKey != 32767 && ProjectedCSTypeGeoKey != 0) { try { srcProjection = ProjectionInfo.FromEpsgCode(ProjectedCSTypeGeoKey); ProjectionInfo pESRIEnd = KnownCoordinateSystems.Geographic.World.WGS1984; double[] xyarray = { x, y, x + width * xscale, y - height * yscale, x + width * xscale, y, x, y - height * yscale }; Reproject.ReprojectPoints(xyarray, null, srcProjection, pESRIEnd, 0, xyarray.Length / 2); ymin = Math.Min(Math.Min(Math.Min(xyarray[1], xyarray[3]), xyarray[5]), xyarray[7]); xmin = Math.Min(Math.Min(Math.Min(xyarray[0], xyarray[2]), xyarray[4]), xyarray[6]); ymax = Math.Max(Math.Max(Math.Max(xyarray[1], xyarray[3]), xyarray[5]), xyarray[7]); xmax = Math.Max(Math.Max(Math.Max(xyarray[0], xyarray[2]), xyarray[4]), xyarray[6]); } catch (Exception ex) { log.Error(ex); srcProjection = null; } } else { try { srcProjection = ProjectionInfo.FromEsriString(GeoKeys[GKID.PCSCitationGeoKey].ToString()); ProjectionInfo pESRIEnd = KnownCoordinateSystems.Geographic.World.WGS1984; double[] xyarray = { x, y, x + width * xscale, y - height * yscale, x + width * xscale, y, x, y - height * yscale }; Reproject.ReprojectPoints(xyarray, null, srcProjection, pESRIEnd, 0, xyarray.Length / 2); ymin = Math.Min(Math.Min(Math.Min(xyarray[1], xyarray[3]), xyarray[5]), xyarray[7]); xmin = Math.Min(Math.Min(Math.Min(xyarray[0], xyarray[2]), xyarray[4]), xyarray[6]); ymax = Math.Max(Math.Max(Math.Max(xyarray[1], xyarray[3]), xyarray[5]), xyarray[7]); xmax = Math.Max(Math.Max(Math.Max(xyarray[0], xyarray[2]), xyarray[4]), xyarray[6]); } catch (Exception ex) { log.Error(ex); srcProjection = null; } } if (srcProjection != null) { } else // wgs84 utm if (ProjectedCSTypeGeoKey >= 32601 && ProjectedCSTypeGeoKey <= 32760) { if (ProjectedCSTypeGeoKey > 32700) { UTMZone = (ProjectedCSTypeGeoKey - 32700) * -1; srcProjection = ProjectionInfo.FromProj4String($"+proj=utm +zone={UTMZone} +ellps=WGS84 +datum=WGS84 +units=m +no_defs "); //tl var pnt = PointLatLngAlt.FromUTM(UTMZone, x, y); //br var pnt2 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y - height * yscale); //tr var pnt3 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y); //bl var pnt4 = PointLatLngAlt.FromUTM(UTMZone, x, y - height * yscale); ymin = Math.Min(Math.Min(Math.Min(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmin = Math.Min(Math.Min(Math.Min(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); ymax = Math.Max(Math.Max(Math.Max(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmax = Math.Max(Math.Max(Math.Max(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); } if (ProjectedCSTypeGeoKey < 32700) { UTMZone = ProjectedCSTypeGeoKey - 32600; srcProjection = ProjectionInfo.FromProj4String($"+proj=utm +zone={UTMZone} +ellps=WGS84 +datum=WGS84 +units=m +no_defs "); var pnt = PointLatLngAlt.FromUTM(UTMZone, x, y); var pnt2 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y - height * yscale); var pnt3 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y); var pnt4 = PointLatLngAlt.FromUTM(UTMZone, x, y - height * yscale); ymin = Math.Min(Math.Min(Math.Min(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmin = Math.Min(Math.Min(Math.Min(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); ymax = Math.Max(Math.Max(Math.Max(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmax = Math.Max(Math.Max(Math.Max(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); } } else // etrs89 utm if (ProjectedCSTypeGeoKey >= 3038 && ProjectedCSTypeGeoKey <= 3051) { UTMZone = ProjectedCSTypeGeoKey - 3012; srcProjection = ProjectionInfo.FromProj4String($"+proj=utm +zone={UTMZone} +ellps=GRS80 +units=m +no_defs "); // 3038 - 26 var pnt = PointLatLngAlt.FromUTM(UTMZone, x, y); var pnt2 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y - height * yscale); var pnt3 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y); var pnt4 = PointLatLngAlt.FromUTM(UTMZone, x, y - height * yscale); ymin = Math.Min(Math.Min(Math.Min(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmin = Math.Min(Math.Min(Math.Min(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); ymax = Math.Max(Math.Max(Math.Max(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmax = Math.Max(Math.Max(Math.Max(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); } else if (ProjectedCSTypeGeoKey >= 25828 && ProjectedCSTypeGeoKey <= 25838) { UTMZone = ProjectedCSTypeGeoKey - 25800; // 3038 - 26 var pnt = PointLatLngAlt.FromUTM(UTMZone, x, y); var pnt2 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y - height * yscale); var pnt3 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y); var pnt4 = PointLatLngAlt.FromUTM(UTMZone, x, y - height * yscale); ymin = Math.Min(Math.Min(Math.Min(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmin = Math.Min(Math.Min(Math.Min(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); ymax = Math.Max(Math.Max(Math.Max(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmax = Math.Max(Math.Max(Math.Max(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); } else /// gda94 if (ProjectedCSTypeGeoKey >= 28348 && ProjectedCSTypeGeoKey <= 28358) { UTMZone = (ProjectedCSTypeGeoKey - 28300) * -1; var pnt = PointLatLngAlt.FromUTM(UTMZone, x, y); var pnt2 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y - height * yscale); var pnt3 = PointLatLngAlt.FromUTM(UTMZone, x + width * xscale, y); var pnt4 = PointLatLngAlt.FromUTM(UTMZone, x, y - height * yscale); ymin = Math.Min(Math.Min(Math.Min(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmin = Math.Min(Math.Min(Math.Min(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); ymax = Math.Max(Math.Max(Math.Max(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmax = Math.Max(Math.Max(Math.Max(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); } else // geo lat/lng if (ProjectedCSTypeGeoKey == 0 || ProjectedCSTypeGeoKey == 4326) { var pnt = new PointLatLngAlt(y, x); var pnt2 = new PointLatLngAlt(y - height * yscale, x + width * xscale); var pnt3 = new PointLatLngAlt(y, x + width * xscale); var pnt4 = new PointLatLngAlt(y - height * yscale, x); ymin = Math.Min(Math.Min(Math.Min(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmin = Math.Min(Math.Min(Math.Min(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); ymax = Math.Max(Math.Max(Math.Max(pnt.Lat, pnt2.Lat), pnt3.Lat), pnt4.Lat); xmax = Math.Max(Math.Max(Math.Max(pnt.Lng, pnt2.Lng), pnt3.Lng), pnt4.Lng); } Area = new RectLatLng(ymax, xmin, xmax - xmin, ymax - ymin); log.InfoFormat("Coverage {0}", Area.ToString()); log.InfoFormat("Start Point ({0},{1},{2}) --> ({3},{4},{5})", i, j, k, x, y, z); lock (index) GeoTiff.index.Add(this); /* * * short numberOfDirectories = tiff.NumberOfDirectories(); * for (short d = 0; d < numberOfDirectories; ++d) * { * tiff.SetDirectory((short)d); * * for (ushort t = ushort.MinValue; t < ushort.MaxValue; ++t) * { * TiffTag tag = (TiffTag)t; * FieldValue[] value = tiff.GetField(tag); * if (value != null) * { * for (int j2 = 0; j2 < value.Length; j2++) * { * Console.WriteLine("{0} : {1} : {2}", tag.ToString(), value[j2].Value.GetType().ToString(), value[j2].ToString()); * } * } * } * } */ } return(true); }