public void ShowMapWithPointLayerBasedOnFeatureDataTable() { var table = new FeatureDataTable(); table.Columns.Add("X", typeof(double)); table.Columns.Add("Y", typeof(double)); table.Columns.Add("Category", typeof(string)); DataRow row = table.NewRow(); table.Rows.Add(row); row.ItemArray = new object[] { 100000, 400000, "testCategory" }; row = table.NewRow(); table.Rows.Add(row); row.ItemArray = new object[] { 200000, 400000, "TestCategory" }; var dataTablePoint = new DataTablePoint(table, "Category", "X", "Y"); var vectorLayer = new VectorLayer("test", dataTablePoint); vectorLayer.Theme =ThemeFactory.CreateSingleFeatureTheme(vectorLayer.Style.GeometryType, Color.Blue, 10); var map = new Map { Name = "testmap" }; map.Layers.Add(vectorLayer); map.Center = new Coordinate(150000, 400000); map.Zoom = 200000; //map.ZoomToExtents(); //map.ZoomToBox(map.Envelope); MapTestHelper.Show(map); }
public void CreateDataTablePoints() { DataTable source = CreateDataTableSource(); DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y"); Assert.IsNotNull(provider); Assert.AreSame(source, provider.Table); Assert.AreEqual("oid", provider.ObjectIdColumn); Assert.AreEqual("x", provider.XColumn); Assert.AreEqual("y", provider.YColumn); }
public void OpenAndCloseUpdatesIsOpenPropertyCorrectly() { DataTable source = createDataTableSource(); DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y"); Assert.AreEqual(false, provider.IsOpen); provider.Open(); Assert.AreEqual(true, provider.IsOpen); provider.Close(); Assert.AreEqual(false, provider.IsOpen); }
public void GetGeometryByIDReturnsExpectedGeometry() { DataTable source = createDataTableSource(); DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y"); DataRow row = source.Select("oid = 43")[0]; Point expected = new Point((double)row["x"], (double)row["y"]); Geometry actual = provider.GetGeometryByID(43); Assert.IsNotNull(actual); Assert.IsInstanceOfType(typeof(Point), actual); Assert.AreEqual(expected, actual); }
public void ExecuteIntersectionQueryReturnsExpectedFeatures() { DataTable source = CreateDataTableSource(); DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y"); var query = new Envelope(400, 600, 400, 600); FeatureDataTable expected = new FeatureDataTable(); expected.TableName = "PointSource"; foreach (DataColumn column in source.Columns) { expected.Columns.Add(column.ColumnName, column.DataType); } foreach (DataRowView rowView in source.DefaultView) { if (query.Contains(new Coordinate((double) rowView["x"], (double) rowView["y"]))) { expected.ImportRow(rowView.Row); } } FeatureDataSet dataSet = new FeatureDataSet(); provider.ExecuteIntersectionQuery(query, dataSet); Assert.IsNotNull(dataSet); Assert.IsNotNull(dataSet.Tables); Assert.AreEqual(1, dataSet.Tables.Count); FeatureDataTable actual = dataSet.Tables[0]; Assert.AreEqual(expected.Rows.Count, actual.Rows.Count); foreach (DataRowView expectedRowView in expected.DefaultView) { DataRow[] actualRows = actual.Select("oid = " + expectedRowView["oid"]); Assert.AreEqual(1, actualRows.Length); Assert.AreEqual(expectedRowView["oid"], actualRows[0]["oid"]); Assert.AreEqual(expectedRowView["x"], actualRows[0]["x"]); Assert.AreEqual(expectedRowView["y"], actualRows[0]["y"]); } }
public void GetExtentsComputation() { DataTable source = createDataTableSource(); DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y"); double minX = Double.PositiveInfinity, minY = Double.PositiveInfinity, maxX = Double.NegativeInfinity, maxY = Double.NegativeInfinity; foreach (DataRowView rowView in source.DefaultView) { if (minX > (double)rowView["x"]) minX = (double)rowView["x"]; if (minY > (double)rowView["y"]) minY = (double)rowView["y"]; if (maxX < (double)rowView["x"]) maxX = (double)rowView["x"]; if (maxY < (double)rowView["y"]) maxY = (double)rowView["y"]; } Envelope expectedBounds = new Envelope(minX, minY, maxX, maxY); IEnvelope actualBounds = provider.GetExtents(); Assert.AreEqual(expectedBounds, actualBounds); }
private static Map InitializeMapOsmWithXls(float angle) { Map map = new Map(); TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS"); map.Layers.Add(tileLayer); //Get data from excel var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls"); var ds = new System.Data.DataSet("XLS"); using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath)) { cn.Open(); using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn))) da.Fill(ds); } #if !DotSpatialProjections //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var epsg4326 = cf.CreateFromWkt("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 epsg3785 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; coords = ct.MathTransform.Transform(coords); row["X"] = coords[0]; row["Y"] = coords[1]; } #else var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; var epsg3785 = new DotSpatial.Projections.ProjectionInfo(); epsg3785.ReadEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue; double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])}; DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 0, 1); row["X"] = coords[0]; row["Y"] = coords[1]; } #endif //Add Rotation Column ds.Tables[0].Columns.Add("Rotation", typeof (float)); foreach (System.Data.DataRow row in ds.Tables[0].Rows) row["Rotation"] = -angle; //Set up provider var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y"); var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider); xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol; //Add layer to map map.Layers.Add(xlsLayer); var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel"); xlsLabelLayer.DataSource = xlsProvider; xlsLabelLayer.LabelColumn = "Name"; xlsLabelLayer.PriorityColumn = "Population"; xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f); xlsLabelLayer.Style.CollisionDetection = true; xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; map.Layers.Add(xlsLabelLayer); map.ZoomToBox(tileLayer.Envelope); return map; }
public void GetGeometryByOidReturnsExpectedGeometry() { DataTable source = CreateDataTableSource(); DataTablePoint provider = new DataTablePoint(source, "oid", "x", "y"); DataRow row = source.Select("oid = 43")[0]; Point expected = new Point((double) row["x"], (double) row["y"]); IGeometry actual = provider.GetGeometryByOid(43); Assert.IsNotNull(actual); Assert.IsTrue(actual is Point); Assert.AreEqual(expected, actual); }
private static Map InitializeMapOsmWithXls(float angle) { Map map = new Map(); TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS"); map.Layers.Add(tileLayer); //Get data from excel var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls"); var ds = new System.Data.DataSet("XLS"); using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath)) { cn.Open(); using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn))) da.Fill(ds); } #if !DotSpatialProjections //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); var epsg4326 = cf.CreateFromWkt("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 epsg3785 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]"); var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) { continue; } double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) }; coords = ct.MathTransform.Transform(coords); row["X"] = coords[0]; row["Y"] = coords[1]; } #else var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; var epsg3785 = new DotSpatial.Projections.ProjectionInfo(); epsg3785.ReadEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) { continue; } double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) }; DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 0, 1); row["X"] = coords[0]; row["Y"] = coords[1]; } #endif //Add Rotation Column ds.Tables[0].Columns.Add("Rotation", typeof(float)); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { row["Rotation"] = -angle; } //Set up provider var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y"); var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider); xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol; //Add layer to map map.Layers.Add(xlsLayer); var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel"); xlsLabelLayer.DataSource = xlsProvider; xlsLabelLayer.LabelColumn = "Name"; xlsLabelLayer.PriorityColumn = "Population"; xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f); xlsLabelLayer.Style.CollisionDetection = true; xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection; map.Layers.Add(xlsLabelLayer); map.ZoomToBox(tileLayer.Envelope); return(map); }
public void ClonePerformanceTest() { var table = new FeatureDataTable(); table.Columns.Add("Id", typeof(int)); table.Columns.Add("X", typeof(double)); table.Columns.Add("Y", typeof(double)); table.Columns.Add("Value", typeof(double)); AddRow(table, new object[] { 0, 5.0, 5.0, 0.0 }); AddRow(table, new object[] { 1, 10.0, 10.0, 10.0 }); var dataSource = new DataTablePoint(table, "Id", "X", "Y"); var basicTheme = ThemeFactory.CreateGradientTheme("Value", null, ColorBlend.Rainbow7, 0.0, 5.0, 3, 3, false, true, 8); var layer = new VectorLayer { AutoUpdateThemeOnDataSourceChanged = true, Theme = basicTheme, DataSource = dataSource }; TestHelper.AssertIsFasterThan(230, () => layer.Clone()); }
public void LayersWithThemeGroupShareMinMax() { var table = new FeatureDataTable(); table.Columns.Add("Id", typeof(int)); table.Columns.Add("X", typeof(double)); table.Columns.Add("Y", typeof(double)); table.Columns.Add("Value", typeof(double)); AddRow(table, new object[] {0, 5.0, 5.0, 0.0}); AddRow(table, new object[] { 1, 10.0, 10.0, 10.0 }); var dataSource = new DataTablePoint(table, "Id", "X", "Y"); var table2 = new FeatureDataTable(); table2.Columns.Add("Id", typeof(int)); table2.Columns.Add("X", typeof(double)); table2.Columns.Add("Y", typeof(double)); table2.Columns.Add("Value", typeof(double)); AddRow(table2, new object[] { 0, 5.0, 2.0, 0.0 }); AddRow(table2, new object[] { 1, 10.0, 4.0, 10.0 }); AddRow(table2, new object[] { 2, 7.0, 10.0, 20.0 }); var dataSource2 = new DataTablePoint(table2, "Id", "X", "Y"); var basicTheme = ThemeFactory.CreateGradientTheme("Value", null, ColorBlend.Rainbow7, 0.0, 5.0, 3, 3, false, true, 3); var layer = new VectorLayer { AutoUpdateThemeOnDataSourceChanged = true, ThemeGroup = "group1", DataSource = dataSource, Theme = basicTheme }; var layer2 = new VectorLayer { AutoUpdateThemeOnDataSourceChanged = true, ThemeGroup = "group1", DataSource = dataSource2, Theme = basicTheme }; var map = new Map(); map.Layers.Add(layer); Assert.AreEqual(10.0, ((GradientTheme)layer.Theme).Max); // refresh on add map.Layers.Add(layer2); Assert.AreEqual(20.0, ((GradientTheme)layer.Theme).Max); // both to max of the group Assert.AreEqual(20.0, ((GradientTheme)layer2.Theme).Max); map.Layers.Remove(layer2); Assert.AreEqual(10.0, ((GradientTheme)layer.Theme).Max); // refresh on remove }