private static ProjectionInfo CreateProjectionInfo(ISpatialReference spatialReference) { var pisr = spatialReference as DotSpatialSpatialReference; if (pisr != null && pisr.ProjectionInfo != null) { return(pisr.ProjectionInfo); } switch (spatialReference.DefinitionType) { case SpatialReferenceDefinitionType.Proj4: return(ProjectionInfo.FromProj4String(spatialReference.Definition)); case SpatialReferenceDefinitionType.AuthorityCode: var ac = spatialReference.Definition.Split(new [] { ':' }); var srid = int.Parse(ac[1]); return(ProjectionInfo.FromEpsgCode(srid)); case SpatialReferenceDefinitionType.WellKnownText: return(ProjectionInfo.FromEsriString(spatialReference.Definition)); default: throw new NotSupportedException(); } }
public override void ParseJson(DbGeographyGeoJsonConverter converter, Newtonsoft.Json.Linq.JArray array) { var targetCoordinateSystem = (converter as EpsgDbGeometryConverter).CoordinateSystem; //Cant convert if source dont have any coordinate system. if (!CoordinateSystem.HasValue || CoordinateSystem == targetCoordinateSystem) { base.ParseJson(converter, array); return; } Rings = new List <List <Position> >(); var rings = array.ToObject <double[][][]>(); var ringSizes = rings.Select(r => r.Length).ToArray(); var coordinateLength = rings.First().GroupBy(c => c.Length).Single().Key; foreach (var ring in rings) { var flat = ring.SelectMany(s => s).ToArray(); Reproject.ReprojectPoints(flat, null, ProjectionInfo.FromEpsgCode(CoordinateSystem.Value), ProjectionInfo.FromEpsgCode(targetCoordinateSystem.Value), 0, ringSizes[0]); var ringList = new List <Position>(); for (int i = 0; i < flat.Length; i += coordinateLength) { ringList.Add(new Position(flat.Skip(i).Take(coordinateLength).ToArray())); } Rings.Add(ringList); } CoordinateSystem = targetCoordinateSystem; }
public Geometry ReprojectGeometry(Geometry geometry, int sourceEpsgCode, int targetEpsgCode) { var sourceProjection = ProjectionInfo.FromEpsgCode(sourceEpsgCode); var targetProjection = ProjectionInfo.FromEpsgCode(targetEpsgCode); return(ReprojectGeometry(geometry, sourceProjection, targetProjection)); }
public float[][] GetPCSAxis() { var XY = new float[2][]; XY[0] = new float[ColumnCount]; XY[1] = new float[RowCount]; var wgs84 = ProjectionInfo.FromEpsgCode(4326); IFeatureSet fs_lon = new FeatureSet(FeatureType.Point); fs_lon.Projection = this.Projection; for (int c = 0; c < ColumnCount; c++) { var vertice = LocateCentroid(c + 1, 1); XY[0][c] = (float)vertice.X; } for (int r = 0; r < RowCount; r++) { var vertice = LocateCentroid(1, r + 1); XY[1][r] = (float)vertice.Y; } return(XY); }
/// <summary> /// Creates a new instance of NationalGridsSweden /// </summary> public NationalGridsSweden() { RT380gon = ProjectionInfo.FromEpsgCode(3028).SetNames("RT38_0_gon", "GCS_RT38", "D_Stockholm_1938"); RT3825gonO = ProjectionInfo.FromEpsgCode(3029).SetNames("RT38_25_gon_O", "GCS_RT38", "D_Stockholm_1938"); RT3825gonV = ProjectionInfo.FromEpsgCode(3027).SetNames("RT38_25_gon_V", "GCS_RT38", "D_Stockholm_1938"); RT385gonO = ProjectionInfo.FromEpsgCode(3030).SetNames("RT38_5_gon_O", "GCS_RT38", "D_Stockholm_1938"); RT385gonV = ProjectionInfo.FromEpsgCode(3026).SetNames("RT38_5_gon_V", "GCS_RT38", "D_Stockholm_1938"); RT3875gonV = ProjectionInfo.FromEpsgCode(3025).SetNames("RT38_75_gon_V", "GCS_RT38", "D_Stockholm_1938"); RT900gon = ProjectionInfo.FromEpsgCode(3022).SetNames("RT90_0_gon", "GCS_RT_1990", "D_RT_1990"); RT9025gonO = ProjectionInfo.FromEpsgCode(3023).SetNames("RT90_25_gon_O", "GCS_RT_1990", "D_RT_1990"); RT9025gonV = ProjectionInfo.FromEpsgCode(3021).SetNames("RT90_25_gon_V", "GCS_RT_1990", "D_RT_1990"); RT905gonO = ProjectionInfo.FromEpsgCode(3024).SetNames("RT90_5_gon_O", "GCS_RT_1990", "D_RT_1990"); RT905gonV = ProjectionInfo.FromEpsgCode(3020).SetNames("RT90_5_gon_V", "GCS_RT_1990", "D_RT_1990"); RT9075gonV = ProjectionInfo.FromEpsgCode(3019).SetNames("RT90_75_gon_V", "GCS_RT_1990", "D_RT_1990"); SWEREF991200 = ProjectionInfo.FromEpsgCode(3007).SetNames("SWEREF99_12_00", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991330 = ProjectionInfo.FromEpsgCode(3008).SetNames("SWEREF99_13_30", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991415 = ProjectionInfo.FromEpsgCode(3012).SetNames("SWEREF99_14_15", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991500 = ProjectionInfo.FromEpsgCode(3009).SetNames("SWEREF99_15_00", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991545 = ProjectionInfo.FromEpsgCode(3013).SetNames("SWEREF99_15_45", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991630 = ProjectionInfo.FromEpsgCode(3010).SetNames("SWEREF99_16_30", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991715 = ProjectionInfo.FromEpsgCode(3014).SetNames("SWEREF99_17_15", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991800 = ProjectionInfo.FromEpsgCode(3011).SetNames("SWEREF99_18_00", "GCS_SWEREF99", "D_SWEREF99"); SWEREF991845 = ProjectionInfo.FromEpsgCode(3015).SetNames("SWEREF99_18_45", "GCS_SWEREF99", "D_SWEREF99"); SWEREF992015 = ProjectionInfo.FromEpsgCode(3016).SetNames("SWEREF99_20_15", "GCS_SWEREF99", "D_SWEREF99"); SWEREF992145 = ProjectionInfo.FromEpsgCode(3017).SetNames("SWEREF99_21_45", "GCS_SWEREF99", "D_SWEREF99"); SWEREF992315 = ProjectionInfo.FromEpsgCode(3018).SetNames("SWEREF99_23_15", "GCS_SWEREF99", "D_SWEREF99"); SWEREF99TM = ProjectionInfo.FromEpsgCode(3006).SetNames("SWEREF99_TM", "GCS_SWEREF99", "D_SWEREF99"); }
public static void CentroidToShapefile() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "文本文件|*.txt;*.csv"; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { StreamReader sr = new StreamReader(ofd.FileName); //string[] header = sr.ReadLine().Split(','); IFeatureSet oFS = new FeatureSet(FeatureType.Point); oFS.Projection = ProjectionInfo.FromEpsgCode(4326); oFS.Name = "BusStop"; oFS.DataTable.Columns.Add("Name", typeof(string)); while (!sr.EndOfStream) { string[] line = sr.ReadLine().Split(','); double x = double.Parse(line[2]); double y = double.Parse(line[3]); var xyCorrection = CoordinateTransformUtil.bd09towgs84(x, y); var fe = oFS.AddFeature(new Point(xyCorrection[0], xyCorrection[1])); fe.DataRow.BeginEdit(); fe.DataRow["Name"] = line[0]; fe.DataRow.EndEdit(); } oFS.SaveAs("BusStop.shp", true); sr.Close(); Console.WriteLine("Shapefile转换成功!"); Console.ReadKey(); } }
public void Reproject_DifferentCoordinateSystems_ReprojectImageAndMetaData() { // Setup var mapArgs = new MapArgs(new Rectangle(0, 0, 722, 349), new Extent(520981.864447542, 6853700.54100246, 709995.365081098, 6945065.79269375)); ProjectionInfo sourceProjection = ProjectionInfo.FromEpsgCode(25831); ProjectionInfo targetProjection = KnownCoordinateSystems.Projected.World.WebMercator; var projector = new TileReprojector(mapArgs, sourceProjection, targetProjection); var sourceReference = new WorldFile(140, 0.0, 0.0, -140, 641716.59261121, 5825498); Bitmap sourceTile = Resources.source; WorldFile targetReference; Bitmap targetTile; // Call projector.Reproject(sourceReference, sourceTile, out targetReference, out targetTile); // Assert // Note: These ground truth values have been defined using https://github.com/FObermaier/DotSpatial.Plugins/blob/master/DotSpatial.Plugins.BruTileLayer/Reprojection/TileReprojector.cs Assert.AreEqual(261.791552124038, targetReference.A11, 1e-8); Assert.AreEqual(0.0, targetReference.A21); Assert.AreEqual(0.0, targetReference.A12); Assert.AreEqual(-261.79155212403651, targetReference.A22, 1e-8); Assert.AreEqual(564962.84520438069, targetReference.B1, 1e-8); Assert.AreEqual(6902131.9781454066, targetReference.B2, 1e-8); TestHelper.AssertImagesAreEqual(Resources.target, targetTile); }
private Dictionary <string, List <Point> > GetTilesFromShapeFile() { var tilesToDownload = new Dictionary <string, List <Point> >(); var indexMapFile = Shapefile.OpenFile(this.options.ShapeFile); indexMapFile.Reproject(ProjectionInfo.FromEpsgCode(4326)); // Get the map index from the Feature data for (int i = 0; i < indexMapFile.DataTable.Rows.Count; i++) { // Get the feature DotSpatial.Data.IFeature feature = indexMapFile.Features.ElementAt(i); var polygon = feature.BasicGeometry as Polygon; var name = (string)feature.DataRow[1]; if (!string.IsNullOrWhiteSpace(this.options.FeaturePropertyValue)) { if (this.options.FeaturePropertyValue != name) { continue; } } tilesToDownload[name] = polygon.GetTiles(name, this.options.MinZoom, this.options.MaxZoom); // Now it's very quick to iterate through and work with the feature. } return(tilesToDownload); }
public bool IsInsideBounds(SqlGeometry sqlGeometry) { var currentProjection = ProjectionInfo.FromEpsgCode(sqlGeometry.STSrid.Value); double[] xy = new double[sqlGeometry.STNumPoints().Value * 2]; double[] z = new double[sqlGeometry.STNumPoints().Value]; for (int i = 0; i < sqlGeometry.STNumPoints(); ++i) { var point = sqlGeometry.STPointN(i + 1); xy[i * 2] = point.STX.Value; xy[i * 2 + 1] = point.STY.Value; } DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, currentProjection, GetTargetProjection(), 0, sqlGeometry.STNumPoints().Value); foreach (var d in xy) { if (double.IsInfinity(d)) { return(false); } if (double.IsNaN(d)) { return(false); } } return(true); }
public static ProjectionInfo ToProjectionInfo(this string crs) { ProjectionInfo projectionInfo = null; try { if (!string.IsNullOrEmpty(crs)) { var supportedCRS = crs.Replace("urn:ogc:def:crs:", ""); string[] array = supportedCRS.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries); if (array.Length == 2 && array[0] == "EPSG") { if (int.TryParse(array[1], out int epsg)) { projectionInfo = ProjectionInfo.FromEpsgCode(epsg); } } } } catch (Exception e) { Trace.WriteLine(e); } return(projectionInfo); }
public static void CorrectionCentroid() { //中心点数据 List <Coordinate> centroidPoints = new List <Coordinate>(80); StreamReader sr = new StreamReader(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\中心点80.txt"); sr.ReadLine();//读取标题行 while (!sr.EndOfStream) { string[] line = sr.ReadLine().Split(','); centroidPoints.Add(new Coordinate(double.Parse(line[1]), double.Parse(line[2]))); } sr.Close(); //Bus数据,并且构造KD树 KdTree myKdtree = new KdTree(2); IFeatureSet busFS = FeatureSet.Open(@"D:\OneDrive\2017研究生毕业设计\数据\项目用数据\BusStopGauss.shp"); List <Coordinate> busStopPoints = new List <Coordinate>(busFS.NumRows()); HashSet <int> checkDuplicate = new HashSet <int>(); foreach (var item in busFS.Features) { var c = item.Coordinates[0]; busStopPoints.Add(c); myKdtree.Insert(new double[] { c.X, c.Y }, item); } Console.WriteLine("数据读取完毕,开始纠正数据"); IFeatureSet newCentroid = new FeatureSet(FeatureType.Point); newCentroid.Name = "优化过的中心点"; newCentroid.Projection = ProjectionInfo.FromEpsgCode(GAUSS_EPSG); int count = 0; foreach (var item in centroidPoints) { var nearsestBus = myKdtree.Nearest(new double[] { item.X, item.Y }, 3); bool addSuccess = false; IFeature addFeature = null; for (int i = 0; i < 3; i++) { IFeature f = nearsestBus[i] as IFeature; if (f.Coordinates[0].Distance(item) < 100) { if (checkDuplicate.Add(f.Fid)) { addFeature = newCentroid.AddFeature(f.BasicGeometry); addSuccess = true; } } } if (!addSuccess) { addFeature = newCentroid.AddFeature(new Point(item)); count++; } } Console.WriteLine("数据优化结束,共有{0}个数据没有优化", count); newCentroid.SaveAs("newCentroid2.shp", true); Console.ReadKey(); }
public FeatureCollection GetCombinedBoundariesAndRates(int year, int quarter, int outSR = _defaultSrid) { ProjectionInfo targetProjection = outSR == _defaultSrid ? null : ProjectionInfo.FromEpsgCode(outSR); var boundaries = DorTaxRateReader.EnumerateLocationCodeBoundariesWithTaxRates(new QuarterYear(year, quarter), targetProjection); var featureCollection = boundaries.ToNtsFeatureCollection(outSR, _omittedFields); return(featureCollection); }
private void BtnOkClick(object sender, EventArgs e) { if (_wmsCapabilities == null) { MessageBox.Show(Resources.SelectServerToView, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tvLayers.SelectedNode == null) { MessageBox.Show(Resources.SelectLayerToView, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (lbCRS.SelectedItem == null) { MessageBox.Show(Resources.SelectCrsToView, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ProjectionInfo projectionInfo; try { var crs = ((string)lbCRS.SelectedItem).ToUpper(); if (string.Equals(crs, "CRS:84")) { crs = "EPSG:4326"; } var epsgCode = Convert.ToInt32(crs.Replace("EPSG:", string.Empty)); switch (epsgCode) { case 3857: projectionInfo = KnownCoordinateSystems.Projected.World.WebMercator; break; case 4326: projectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984; break; default: projectionInfo = ProjectionInfo.FromEpsgCode(epsgCode); break; } } catch (Exception) { MessageBox.Show(Resources.UnsupportedCrs, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Parse custom parameters var cs = string.IsNullOrWhiteSpace(tbCustomParameters.Text) ? new Dictionary <string, string>() : tbCustomParameters.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(d => d.Split('=')).ToDictionary(d => d[0], d => d[1]); WmsInfo = new WmsInfo(tbServerUrl.Text, _wmsCapabilities, (Layer)tvLayers.SelectedNode.Tag, cs, (string)lbCRS.SelectedItem, projectionInfo, ((StyleWrapper)lbStyles.SelectedItem)?.Style.Name, GetUserCredentials()); DialogResult = DialogResult.OK; }
public FromNetCDF2TIF() { Name = "Convert from NetCDF to TIF"; Category = "Conversion"; Description = "Convert nc file to tif files"; Version = "1.0.0.0"; this.Author = "Yong Tian"; OutputFolder = Environment.SpecialFolder.MyDocuments.ToString(); Projection = ProjectionInfo.FromEpsgCode(4326); }
public void Test_WSG84_To_MGI_Austria(int epsgCodeTo, double[] xy, double[] expected) { ProjectionInfo wgs84 = ProjectionInfo.FromEpsgCode(4326); ProjectionInfo MGI_Austria_GK_ = ProjectionInfo.FromEpsgCode(epsgCodeTo); double tolerance = 0.08d; Reproject.ReprojectPoints(xy, null, wgs84, MGI_Austria_GK_, 0, 1); Assert.AreEqual(expected[0], xy[0], tolerance); Assert.AreEqual(expected[1], xy[1], tolerance); }
private static bool IsLatitudeLongitude(int epsgCode) { try { return(ProjectionInfo.FromEpsgCode(epsgCode).IsLatLon); } catch (ArgumentOutOfRangeException) { throw new DataDeliveryParseException("Unknown EPSG code: " + epsgCode); } }
public FeatureCollection GetSalesTaxJursitictionBoundaries(int year, int quarter, int outSR = _defaultSrid) { ProjectionInfo targetProjection = outSR == _defaultSrid ? null : ProjectionInfo.FromEpsgCode(outSR); var boundaries = DorTaxRateReader.EnumerateLocationCodeBoundaries(new QuarterYear(year, quarter), targetProjection); var aliases = new Dictionary <string, string>(); aliases.Add("LOCCODE", "LocationCode"); var featureCollection = boundaries.ToNtsFeatureCollection(outSR, _omittedFields, aliases); return(featureCollection); }
private void ProxyParseSelectedDatabase() { try { ExtFunctions.ParseSelectedDatabase(theMap, ProjectionInfo.FromEpsgCode(32640)); Log("Operation completed"); } catch (Exception ex) { Log("Operation aborted: " + ex.Message); } }
/// <summary> /// Returns fieldAttributes projection info object for the specified EPSG code /// </summary> /// <param name="pEPSGCode">EPSG code</param> /// <returns>DotSpatial ProjectionInfo object</returns> public static ProjectionInfo GetProjByEPSG(int pEPSGCode) { if (pEPSGCode == 0) { pEPSGCode = 4326; } var mProjInfo = ProjectionInfo.FromEpsgCode(pEPSGCode); mProjInfo.Authority = "EPSG"; mProjInfo.AuthorityCode = pEPSGCode; return(mProjInfo); }
public static MemoryStream GenerateShapeFile(Collection <NatureArea> natureAreas, int epsgCode) { // Return empty memory stream if there are no nature areas or no epsg code: if (natureAreas.Count == 0 || epsgCode < 0) { return(new MemoryStream()); } // Define a new set of features and set projection: FeatureSet featureSets = new FeatureSet { Projection = ProjectionInfo.FromEpsgCode(epsgCode) }; // Add data columns featureSets.DataTable.Columns.Add(new DataColumn("LocalId", typeof(string))); featureSets.DataTable.Columns.Add(new DataColumn("Nivå", typeof(string))); featureSets.DataTable.Columns.Add(new DataColumn("NiN", typeof(string))); // Create geometry objects: foreach (var natureArea in natureAreas) { if (natureArea.Area == null) { continue; } IFeature feature = featureSets.AddFeature(DotSpatialGeometry.GetGeometry(natureArea.Area)); // Adding values for the data columns feature.DataRow.BeginEdit(); feature.DataRow["LocalId"] = natureArea.UniqueId.LocalId.ToString(); feature.DataRow["Nivå"] = Naturnivå.TilNavn(natureArea.Nivå); feature.DataRow["NiN"] = FormatNatureAreaTypes(natureArea.Parameters); feature.DataRow.EndEdit(); } // Create temporary directory: string tempDirectoryPath = GetTempDirectoryPath(); // Save the feature set: featureSets.SaveAs(tempDirectoryPath + "\\TempShapeFiles\\data.shp", true); // Zip all shape files: ZipFile.CreateFromDirectory(tempDirectoryPath + "\\TempShapeFiles", tempDirectoryPath + "\\data.zip"); // Read the zip file: var bytes = File.ReadAllBytes(tempDirectoryPath + "\\data.zip"); // Delete the temporary directory: Directory.Delete(tempDirectoryPath, true); return(new MemoryStream(bytes)); }
public void Belge1972_EPSG31370() { // see https://dotspatial.codeplex.com/discussions/548133 var source = ProjectionInfo.FromEpsgCode(31370); var dest = KnownCoordinateSystems.Geographic.World.WGS1984; double[] vertices = { 156117.21, 133860.06 }; Reproject.ReprojectPoints(vertices, null, source, dest, 0, 1); Assert.IsTrue(Math.Abs(vertices[0] - 4.455) < 1e-7); Assert.IsTrue(Math.Abs(vertices[1] - 50.515485) < 1e-7); }
private void CalcXYButton_Click(object sender, EventArgs e) { var xy = new[] { _xYTransformViewModel.XSourceCoordinates, _xYTransformViewModel.YSourceCoordinates }; var z = new[] { 0.0 }; Reproject.ReprojectPoints(xy, z, ProjectionInfo.FromEpsgCode(_xYTransformViewModel.SourceProjection), ProjectionInfo.FromEpsgCode(_xYTransformViewModel.TargetProjection), 0, 1); _xYTransformViewModel.XTargetCoordinates = xy[0]; _xYTransformViewModel.YTargetCoordinates = xy[1]; }
private static ProjectionInfo GetProjectionInfo(int epsgCode) { ProjectionInfo newProjection; try { newProjection = ProjectionInfo.FromEpsgCode(epsgCode); } catch (ArgumentOutOfRangeException) { throw new CoordinateSystemConverterException("Converting coordinates failed. Unknown EPSG code: " + epsgCode); } return(newProjection); }
/// <summary> /// Get X,Y axis expressed by longitude and latitude /// </summary> /// <returns>mat[2][], mat[0] is longitude, mat[1] is latitude </returns> public float[][] GetLonLatAxis() { var lonlat = new float[2][]; lonlat[0] = new float[ColumnCount]; lonlat[1] = new float[RowCount]; var wgs84 = ProjectionInfo.FromEpsgCode(4326); IFeatureSet fs_lon = new FeatureSet(FeatureType.Point); fs_lon.Projection = this.Projection; for (int c = 0; c < ColumnCount; c++) { var vertice = LocateCentroid(c + 1, 1); Point pt = new Point(vertice); fs_lon.AddFeature(pt); } if (fs_lon.Projection != null) { fs_lon.Reproject(wgs84); } for (int c = 0; c < ColumnCount; c++) { var fea = fs_lon.GetFeature(c).Geometry.Coordinate; lonlat[0][c] = (float)fea.X; } IFeatureSet fs_lat = new FeatureSet(FeatureType.Point); fs_lat.Projection = this.Projection; for (int r = 0; r < RowCount; r++) { var vertice = LocateCentroid(1, r + 1); Point pt = new Point(vertice); fs_lat.AddFeature(pt); } if (fs_lat.Projection != null) { fs_lat.Reproject(wgs84); } for (int r = 0; r < RowCount; r++) { var fea = fs_lat.GetFeature(r).Geometry.Coordinate; lonlat[1][r] = (float)fea.Y; } return(lonlat); }
/// <summary> /// Reads the complete feature set from the database /// </summary> /// <param name="connString">sqlite db connection string</param> /// <param name="featureSetInfo">information about the table</param> /// <param name="sql">the sql query</param> /// <returns>the resulting feature set</returns> public IFeatureSet ReadFeatureSet(string connString, GeometryColumnInfo featureSetInfo, string sql) { DataTable tab = new DataTable(); FeatureType fType = GetGeometryType(featureSetInfo.GeometryType); FeatureSet fs = new FeatureSet(fType); fs.IndexMode = false; //setting the initial index mode.. using (SQLiteCommand cmd = CreateCommand(connString, sql)) { cmd.Connection.Open(); RunInitialCommands(cmd.Connection); //DotSpatial.Topology.Utilities.WkbReader wkbr = new DotSpatial.Topology.Utilities.WkbReader(); SpatiaLiteWkbReader wkbr = new SpatiaLiteWkbReader(); SQLiteDataReader rdr = cmd.ExecuteReader(); string[] columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr); int numColumns = fs.DataTable.Columns.Count; while (rdr.Read()) { byte[] wkb = rdr[featureSetInfo.GeometryColumnName] as byte[]; IGeometry geom = wkbr.Read(wkb); IFeature newFeature = fs.AddFeature(geom); //populate the attributes foreach (string colName in columnNames) { newFeature.DataRow[colName] = rdr[colName]; } } cmd.Connection.Close(); fs.Name = featureSetInfo.TableName; //HACK required for selection to work properly fs.IndexMode = true; //assign projection ProjectionInfo proj = ProjectionInfo.FromEpsgCode(featureSetInfo.SRID); fs.Projection = proj; return(fs); } }
public BackgroundLayer(ITileSource tileSource, ITileCache <byte[]> tileCache) { TileSource = tileSource; TileCache = tileCache ?? new MemoryCache <byte[]>(200, 300); if (int.TryParse(TileSource.Schema.Srs.Substring(5), out int epsgCode)) { _projection = new ProjectionInfo(); _projection = ProjectionInfo.FromEpsgCode(epsgCode); } else { _projection = KnownCoordinateSystems.Projected.World.WebMercator; } LegendItemVisible = true; }
public static SqlGeometry ReprojectTo(this SqlGeometry geom, ProjectionInfo destination) { Func <double[], double[]> reprojectionFunc = SqlGeometryReprojection.Identity; // Defines the starting coordiante system ProjectionInfo pStart = ProjectionInfo.FromEpsgCode(geom.STSrid.Value); // Defines the starting coordiante system ProjectionInfo pEnd = destination; reprojectionFunc = pts => SqlGeometryReprojection.ReprojectPoint(pts, 0, pStart, pEnd); GeometryToGeometrySink sink = new GeometryToGeometrySink(destination.AuthorityCode, pts => reprojectionFunc(pts)); geom.Populate(sink); return(sink.ConstructedGeometry); }
/// <summary> /// Reads the complete feature set from the database /// </summary> /// <param name="featureSetInfo">information about the table</param> /// <param name="sql">the sql query</param> /// <returns>the resulting feature set</returns> public IFeatureSet ReadFeatureSet(GeometryColumnInfo featureSetInfo, string sql) { var fType = GetGeometryType(featureSetInfo.GeometryType); SpatiaLiteFeatureSet fs = new SpatiaLiteFeatureSet(fType) { IndexMode = true, // setting the initial index mode.. Name = featureSetInfo.TableName, Filename = SqLiteHelper.GetSqLiteFileName(ConnectionString), LayerName = featureSetInfo.TableName }; using (var cmd = CreateCommand(ConnectionString, sql)) { cmd.Connection.Open(); var wkbr = new SpatiaLiteWkbReader(); var rdr = cmd.ExecuteReader(); var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr); while (rdr.Read()) { var wkb = rdr[featureSetInfo.GeometryColumnName] as byte[]; var geom = wkbr.Read(wkb); var newFeature = fs.AddFeature(geom); // populate the attributes foreach (var colName in columnNames) { newFeature.DataRow[colName] = rdr[colName]; } } cmd.Connection.Close(); // assign projection if (featureSetInfo.Srid > 0) { var proj = ProjectionInfo.FromEpsgCode(featureSetInfo.Srid); fs.Projection = proj; } return(fs); } }
private void CalcWktButton_Click(object sender, EventArgs e) { string wkt = _wktTransformViewModel.WktSource; WKTReader reader = new WKTReader(); Geometry geom = (Geometry)reader.Read(wkt); double[] pointArray = new double[geom.Coordinates.Count() * 2]; double[] zArray = new double[1]; zArray[0] = 1; int counterX = 0; int counterY = 1; foreach (var coordinate in geom.Coordinates) { pointArray[counterX] = coordinate.X; pointArray[counterY] = coordinate.Y; counterX = counterX + 2; counterY = counterY + 2; } var sourceProjection = ProjectionInfo.FromEpsgCode(_wktTransformViewModel.SourceProjection); var targetProjection = ProjectionInfo.FromEpsgCode(_wktTransformViewModel.TargetProjection); Reproject.ReprojectPoints(pointArray, zArray, sourceProjection, targetProjection, 0, (pointArray.Length / 2)); counterX = 0; counterY = 1; foreach (var coordinate in geom.Coordinates) { coordinate.X = pointArray[counterX]; coordinate.Y = pointArray[counterY]; counterX = counterX + 2; counterY = counterY + 2; } geom.GeometryChanged(); var wktwriter = new WKTWriter(); var wktResult = wktwriter.Write(geom); _wktTransformViewModel.WktTarget = wktResult; }
/// <summary> /// Reads the complete feature set from the database /// </summary> /// <param name="connString">sqlite db connection string</param> /// <param name="featureSetInfo">information about the table</param> /// <param name="sql">the sql query</param> /// <returns>the resulting feature set</returns> public IFeatureSet ReadFeatureSet(string connString, GeometryColumnInfo featureSetInfo, string sql) { FeatureSet fs = new SpatiaLiteFeatureSet(featureSetInfo.GeometryType); fs.IndexMode = false; //setting the initial index mode.. using (var cmd = CreateCommand(connString, sql)) { cmd.Connection.Open(); RunInitialCommands(cmd.Connection); //DotSpatial.Topology.Utilities.WkbReader wkbr = new DotSpatial.Topology.Utilities.WkbReader(); var wkbr = new SpatiaLiteWkbReader(); var rdr = cmd.ExecuteReader(); var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr); while (rdr.Read()) { var wkb = rdr[featureSetInfo.GeometryColumnName] as byte[]; var geom = wkbr.Read(wkb); var newFeature = fs.AddFeature(geom); //populate the attributes foreach (var colName in columnNames) { newFeature.DataRow[colName] = rdr[colName]; } } cmd.Connection.Close(); fs.Name = featureSetInfo.TableName; //TODO: look into this more //HACK required for selection to work properly fs.IndexMode = true; //assign projection var proj = ProjectionInfo.FromEpsgCode(featureSetInfo.SRID); fs.Projection = proj; return(fs); } }