/// <summary> /// Method to query the feature's ids /// </summary> /// <param name="envelope">The extent in which to look for features</param> /// <returns>An enumeration of feature ids</returns> public IEnumerable <uint> QueryFids(Envelope envelope) { if (envelope == null || envelope.IsNull) { return(null); } envelope = envelope.Intersection(_sbnHeader.Extent); var res = new List <uint>(); if (envelope.IsNull) { return(res); } byte minx, miny, maxx, maxy; ClampUtility.Clamp(_sbnHeader.Extent, envelope, out minx, out miny, out maxx, out maxy); var nodes = new List <SbnQueryOnlyNode>(); Root.QueryNodes(minx, miny, maxx, maxy, nodes); nodes.Sort(); foreach (var node in nodes) { node.QueryFids(minx, miny, maxx, maxy, res, false); } //Root.QueryFids(minx, miny, maxx, maxy, res); res.Sort(); return(res); }
public static SharpMap.Data.FeatureDataRow FindGeoNearPoint( GeoAPI.Geometries.IPoint point, SharpMap.Layers.VectorLayer layer, double amountGrow) { var box = new GeoAPI.Geometries.Envelope(point.Coordinate); box.ExpandBy(amountGrow); var fds = new SharpMap.Data.FeatureDataSet(); layer.DataSource.ExecuteIntersectionQuery(box, fds); SharpMap.Data.FeatureDataRow result = null; var minDistance = double.MaxValue; foreach (SharpMap.Data.FeatureDataTable fdt in fds.Tables) { foreach (SharpMap.Data.FeatureDataRow fdr in fdt.Rows) { if (fdr.Geometry != null) { var distance = point.Distance(fdr.Geometry); if (distance < minDistance) { result = fdr; minDistance = distance; } } } } return result; }
public override BoundingBox GetExtents() { BoundingBox box = null; using (var conn = new SQLiteConnection(ConnectionString)) { string strSQL = "SELECT Min(minx) AS MinX, Min(miny) AS MinY, Max(maxx) AS MaxX, Max(maxy) AS MaxY FROM " + Table; if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += " WHERE " + DefinitionQuery; } using (var command = new SQLiteCommand(strSQL, conn)) { conn.Open(); using (SQLiteDataReader dr = command.ExecuteReader()) if (dr.Read()) { box = new BoundingBox((double)dr[0], (double)dr[2], (double)dr[1], (double)dr[3]); } conn.Close(); } return(box); } }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox) { var geoms = new Collection <Geometry>(); _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); _ogrLayer.ResetReading(); try { OgrFeature ogrFeature; while ((ogrFeature = _ogrLayer.GetNextFeature()) != null) { using (var gr = ogrFeature.GetGeometryRef()) { var geom = ParseOgrGeometry(gr, Factory); if (geom != null) { geoms.Add(geom); } } ogrFeature.Dispose(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(geoms); }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = String.Format( "SELECT g.* FROM {0} g {1} WHERE ", Table, BuildTableHints()); if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strBbox; using (var adapter = new SqlDataAdapter(strSql, conn)) { conn.Open(); var ds2 = new System.Data.DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (System.Data.DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdr[col.ColumnName] = dr[col]; } } var geom = dr[GeometryColumn]; Geometry sqlGeometry = null; if (geom != null && geom != DBNull.Value) { sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom); } fdr.Geometry = sqlGeometry; fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
public MapDescription NewMapDescription(GeoAPI.Geometries.Envelope envelope) { MapDescription mapDesc = DefaultMapDescription.Copy(); mapDesc.MapArea.Extent = Envelope.FromCommon(envelope); return(mapDesc); }
/// <summary> /// Returns the bounding box around this route. /// </summary> public static GeoAPI.Geometries.Envelope GetBox(this Route route) { if (route == null) { throw new ArgumentNullException("route"); } if (route.Shape == null) { return(null); } if (route.Shape.Length == 1) { return(new GeoAPI.Geometries.Envelope( route.Shape[0].ToCoordinate(), route.Shape[0].ToCoordinate())); } var envelope = new GeoAPI.Geometries.Envelope( route.Shape[0].ToCoordinate(), route.Shape[1].ToCoordinate()); for (var i = 2; i < route.Shape.Length; i++) { envelope.ExpandToInclude(route.Shape[i].ToCoordinate()); } return(envelope); }
public static SharpMap.Data.FeatureDataRow FindGeoNearPoint( GeoAPI.Geometries.IPoint point, SharpMap.Layers.VectorLayer layer, double amountGrow) { var box = new GeoAPI.Geometries.Envelope(point.Coordinate); box.ExpandBy(amountGrow); var fds = new SharpMap.Data.FeatureDataSet(); layer.DataSource.ExecuteIntersectionQuery(box, fds); SharpMap.Data.FeatureDataRow result = null; var minDistance = double.MaxValue; foreach (SharpMap.Data.FeatureDataTable fdt in fds.Tables) { foreach (SharpMap.Data.FeatureDataRow fdr in fdt.Rows) { if (fdr.Geometry != null) { var distance = point.Distance(fdr.Geometry); if (distance < minDistance) { result = fdr; minDistance = distance; } } } } return(result); }
private static IEnumerable <GeoJSON> QueryData(BoundingBox bbox, ICanQueryLayer layer) { if (layer == null) { throw new ArgumentNullException("layer"); } // Query for data FeatureDataSet ds = new FeatureDataSet(); layer.ExecuteIntersectionQuery(bbox, ds); IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(ds); // Reproject geometries if needed IMathTransform transform = null; if (layer is VectorLayer) { ICoordinateTransformation transformation = (layer as VectorLayer).CoordinateTransformation; transform = transformation == null ? null : transformation.MathTransform; } if (transform != null) { GeometryFactory gf = new GeometryFactory(); data = data.Select(d => { Geometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, gf); d.SetGeometry(converted); return(d); }); } return(data); }
public override Collection <uint> GetObjectIDsInView(BoundingBox bbox) { var objectlist = new Collection <uint>(); using (var conn = new SQLiteConnection(ConnectionID)) { var strSQL = "SELECT " + ObjectIdColumn + " "; strSQL += "FROM " + Table + " WHERE "; strSQL += GetBoxClause(bbox); if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += " AND " + DefinitionQuery + " AND "; } using (var command = new SQLiteCommand(strSQL, conn)) { conn.Open(); using (var dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { var id = (uint)(int)dr[0]; objectlist.Add(id); } } } conn.Close(); } } return(objectlist); }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="fcs">FeatureDataSet to fill data into</param> /// <param name="cancellationToken">A cancellation token</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null) { using (SqlConnection conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSQL = String.Format( "SELECT g.* FROM {0} g {1} WHERE ", Table, BuildTableHints()); if (!String.IsNullOrEmpty(DefinitionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strBbox; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSQL += " " + extraOptions; } using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn)) { conn.Open(); System.Data.DataSet ds2 = new System.Data.DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } var geometryReader = CreateReader(); foreach (System.Data.DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = geometryReader.Read(dr[GeometryColumn]); fdt.AddRow(fdr); } fcs.Add(fdt); } } } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="fid">The feature's id</param> /// <param name="geometry">The features geometry</param> /// <param name="zRange">An optional value for the z-Range</param> /// <param name="mRange">An optional value for the m-Range</param> #pragma warning disable 3001 public SbnTreeRebuildRequiredEventArgs(uint fid, Envelope geometry, Interval?zRange, Interval?mRange) #pragma warning restore 3001 { Fid = fid; Geometry = geometry; ZRange = zRange; MRange = mRange; }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="numRecords">The number of features</param> /// <param name="extent">The extent</param> public SbnHeader(int numRecords, Envelope extent) { NumRecords = numRecords; XRange = Interval.Create(extent.MinX, extent.MaxX); YRange = Interval.Create(extent.MinY, extent.MaxY); ZRange = Interval.Create(); MRange = Interval.Create(); }
internal void AddFeature(uint id, Envelope geometry, Interval?zRange, Interval?mRange) { NumRecords++; XRange = XRange.ExpandedByInterval(Interval.Create(geometry.MinX, geometry.MaxX)); YRange = YRange.ExpandedByInterval(Interval.Create(geometry.MinY, geometry.MaxY)); ZRange = ZRange.ExpandedByInterval(zRange ?? Interval.Create()); MRange = MRange.ExpandedByInterval(mRange ?? Interval.Create()); }
public void TestGetExtents() { using (var sq = GetTestProvider()) { GeoAPI.Geometries.Envelope extents = sq.GetExtents(); Assert.IsNotNull(extents); } }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new OracleConnection(ConnectionString)) { //Get bounding box string var strBbox = GetBoxFilterStr(bbox); var strSql = "SELECT * "; strSql += "FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strBbox; using (var adapter = new OracleDataAdapter(strSql, conn)) { conn.Open(); var ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) { if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) { if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) { fdr[col.ColumnName] = dr[col]; } } var sdoGeom = dr[GeometryColumn] as SdoGeometry; if (sdoGeom != null) { fdr.Geometry = sdoGeom.AsGeometry(); } fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
public void TestGetExtentsQueryIndividualFeatures(SharpMap.Data.Providers.SqlServerSpatialObjectType spatialType) { SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(spatialType); sq.ExtentsMode = SharpMap.Data.Providers.SqlServer2008ExtentsMode.QueryIndividualFeatures; GeoAPI.Geometries.Envelope extents = sq.GetExtents(); NUnit.Framework.Assert.IsNotNull(extents); }
public void TestGetExtentsQueryIndividualFeatures() { SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(); sq.ExtentsMode = SharpMap.Data.Providers.SqlServer2008ExtentsMode.QueryIndividualFeatures; GeoAPI.Geometries.Envelope extents = sq.GetExtents(); Assert.IsNotNull(extents); }
public void TestGetExtentsSpatialIndex() { SharpMap.Data.Providers.SqlServer2008 sq = GetTestProvider(); sq.ExtentsMode = SharpMap.Data.Providers.SqlServer2008ExtentsMode.SpatialIndex; GeoAPI.Geometries.Envelope extents = sq.GetExtents(); Assert.IsNotNull(extents); }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="bbox">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, IFeatureCollectionSet fcs, CancellationToken?ct = null) { _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); var fds = new FeatureDataSet(); ExecuteIntersectionQuery(fds); foreach (var fd in fds) { fcs.Add(fd); } }
public static EnvelopeN FromCommon(GeoAPI.Geometries.Envelope commonEnvelope) { EnvelopeN agsEnvelope = new EnvelopeN(); agsEnvelope.XMin = commonEnvelope.MinX; agsEnvelope.YMin = commonEnvelope.MinY; agsEnvelope.XMax = commonEnvelope.MaxX; agsEnvelope.YMax = commonEnvelope.MaxY; return(agsEnvelope); }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox) { var features = new Collection <Geometry>(); using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = "SELECT g." + GeometryColumn + GetMakeValidString(); strSql += " FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } if (!ValidateGeometries || (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex)))) { // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr strSql += $"{GeometryColumn}.STIsValid() = 1 AND "; } strSql += strBbox; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSql += " " + extraOptions; } using (var command = new SqlCommand(strSql, conn)) { conn.Open(); using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != null && dr[0] != DBNull.Value) { Geometry geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]); if (geom != null) { features.Add(geom); } } } } conn.Close(); } } return(features); }
internal static void Clamp(Envelope scale, Envelope envelope, out byte minx, out byte miny, out byte maxx, out byte maxy) { var xrange = Interval.Create(scale.MinX, scale.MaxX); var yrange = Interval.Create(scale.MinY, scale.MaxY); minx = ScaleLower(envelope.MinX, xrange); maxx = ScaleUpper(envelope.MaxX, xrange); miny = ScaleLower(envelope.MinY, yrange); maxy = ScaleUpper(envelope.MaxY, yrange); }
public override void ProcessRequest(HttpContext context) { try { string s = context.Request.Params["BBOX"]; if (String.IsNullOrEmpty(s)) { WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified", context); return; } Map map = this.GetMap(context.Request); bool flip = map.Layers[0].TargetSRID == 4326; BoundingBox bbox = WmsServer.ParseBBOX(s, flip); if (bbox == null) { WmsException.ThrowWmsException("Invalid parameter BBOX", context); return; } string ls = context.Request.Params["LAYERS"]; if (!String.IsNullOrEmpty(ls)) { string[] layers = ls.Split(','); foreach (ILayer layer in map.Layers) { if (!layers.Contains(layer.LayerName)) { layer.Enabled = false; } } } IEnumerable <GeoJSON> items = GetData(map, bbox); StringWriter writer = new StringWriter(); GeoJSONWriter.Write(items, writer); string buffer = writer.ToString(); context.Response.Clear(); context.Response.ContentType = "text/json"; context.Response.BufferOutput = true; context.Response.Write(buffer); context.Response.Flush(); context.Response.SuppressContent = true; context.ApplicationInstance.CompleteRequest(); //context.Response.End(); } catch (Exception ex) { Trace.WriteLine(ex); throw; } }
public override void ExecuteIntersectionQuery(BoundingBox box, FeatureDataSet ds) { using (var conn = new SQLiteConnection(ConnectionID)) { string strSQL = "SELECT *, " + GeometryColumn + " AS sharpmap_tempgeometry "; strSQL += "FROM " + Table + " WHERE "; strSQL += GetBoxClause(box); if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += " AND " + DefinitionQuery; } using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(strSQL, conn)) { conn.Open(); DataSet ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_")) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_")) { fdr[col.ColumnName] = dr[col]; } } if (dr["sharpmap_tempgeometry"] != DBNull.Value) { fdr.Geometry = GeometryFromWKT.Parse((string)dr["sharpmap_tempgeometry"]); } fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
public void HeightWidth() { var rnd = new Random(); var x1 = ((rnd.NextDouble() * 360) - 180); var x2 = ((rnd.NextDouble() * 360) - 180); var y1 = ((rnd.NextDouble() * 360) - 180); var y2 = ((rnd.NextDouble() * 360) - 180); var ev = new Envelope(x1, x2, y1, y2); var evcheck = new GeoAPI.Geometries.Envelope(x1, x2, y1, y2); AssertExt.AreEqual15(ev.Height, evcheck.Height); AssertExt.AreEqual15(ev.Width, evcheck.Width); }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new OracleConnection(ConnectionString)) { //Get bounding box string var strBbox = GetBoxFilterStr(bbox); var strSQL = "SELECT g.*, g." + GeometryColumn + ".Get_WKB() AS sharpmap_tempgeometry "; strSQL += "FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strBbox; using (var adapter = new OracleDataAdapter(strSQL, conn)) { conn.Open(); var ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
public void EnvelopeCoordinate() { var rnd = new Random(); var c = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var ev = new Envelope(c); var x = c.X; var y = c.Y; var ccheck = new GeoAPI.Geometries.Coordinate(x, y); var evcheck = new GeoAPI.Geometries.Envelope(ccheck); AssertExt.AreEqual15(ev.Maximum.Y, evcheck.MaxY); AssertExt.AreEqual15(ev.Maximum.X, evcheck.MaxX); AssertExt.AreEqual15(ev.Minimum.Y, evcheck.MinY); AssertExt.AreEqual15(ev.Minimum.X, evcheck.MinX); }
/// <summary> /// Returns the box filter string needed in SQL query /// </summary> /// <param name="bbox"></param> /// <returns></returns> protected string GetBoxFilterStr(BoundingBox bbox) { string strBbox = "SDO_FILTER(g." + GeometryColumn + ", mdsys.sdo_geometry(2003,#SRID#,NULL," + "mdsys.sdo_elem_info_array(1,1003,3)," + "mdsys.sdo_ordinate_array(" + bbox.MinX.ToString(Map.NumberFormatEnUs) + ", " + bbox.MinY.ToString(Map.NumberFormatEnUs) + ", " + bbox.MaxX.ToString(Map.NumberFormatEnUs) + ", " + bbox.MaxY.ToString(Map.NumberFormatEnUs) + ")), " + "'querytype=window') = 'TRUE'"; strBbox = strBbox.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL"); return(strBbox); }
/// <summary> /// Returns geometry Object IDs whose bounding box intersects 'bbox' /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override IEnumerable <object> GetOidsInView(BoundingBox bbox, CancellationToken?ct = null) { _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); _ogrLayer.ResetReading(); OgrFeature ogrFeature; while ((ogrFeature = _ogrLayer.GetNextFeature()) != null) { yield return(ogrFeature.GetFID()); ogrFeature.Dispose(); } }
//private const string SpatialObject = "geometry"; /// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <param name="cancellationToken">A cancellation token</param> /// <returns></returns> public override IEnumerable <Geometry> GetGeometriesInView(BoundingBox bbox, CancellationToken?cancellationToken = null) { var features = new Collection <Geometry>(); using (SqlConnection conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSQL = "SELECT g." + GeometryColumn; strSQL += " FROM " + Table + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strBbox; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSQL += " " + extraOptions; } using (SqlCommand command = new SqlCommand(strSQL, conn)) { conn.Open(); using (SqlDataReader dr = command.ExecuteReader()) { var spatialReader = CreateReader(); while (dr.Read()) { if (dr[0] != DBNull.Value) { var geom = spatialReader.Read(dr[0]); if (geom != null) { features.Add(geom); } } } } conn.Close(); } } return(features); }
public void TransformBoxTest() { var from = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; var to = DotSpatial.Projections.KnownCoordinateSystems.Projected.NationalGrids.GermanyZone2; var env0 = new GeoAPI.Geometries.Envelope(5, 5.1, 52, 52.1); System.Console.WriteLine(env0); var env1 = DotSpatial.Projections.GeometryTransform.TransformBox(env0, from, to); System.Console.WriteLine(env1); var env2 = DotSpatial.Projections.GeometryTransform.TransformBox(env1, to, from); System.Console.WriteLine(env2); NUnit.Framework.Assert.AreEqual(env0.MinX, env2.MinX, 0.01d); NUnit.Framework.Assert.AreEqual(env0.MaxX, env2.MaxX, 0.01d); NUnit.Framework.Assert.AreEqual(env0.MinY, env2.MinY, 0.01d); NUnit.Framework.Assert.AreEqual(env0.MaxY, env2.MaxY, 0.01d); }
private void DoExecuteIntersectionQuery(int obj) { var ext = _provider.GetExtents(); var minX = _rnd.Next((int)ext.MinX, (int)ext.MaxX); var maxX = _rnd.Next((int)minX, (int)ext.MaxX); var minY = _rnd.Next((int)ext.MinY, (int)ext.MaxY); var maxY = _rnd.Next((int)minY, (int)ext.MaxY); var box = new GeoAPI.Geometries.Envelope(minX, maxX, minY, maxY); Console.WriteLine(@"{0:000}/{2:00}: Executing intersection query agains {1}", obj, box, Thread.CurrentThread.ManagedThreadId); var fds = new SharpMap.Data.FeatureDataSet(); _provider.ExecuteIntersectionQuery(box, fds); var table = fds.Tables[0]; var count = table != null ? table.Rows.Count : 0; Console.WriteLine(@"{0:000}/{3:00}: Executed intersection query agains {1} returned {2} features", obj, box, count, Thread.CurrentThread.ManagedThreadId); }
public void TwoCoordinates() { var rnd = new Random(); var c1 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var c2 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var ev = new Envelope(c1, c2); var x1 = c1.X; var y1 = c1.Y; var x2 = c2.X; var y2 = c2.Y; var c1Check = new GeoAPI.Geometries.Coordinate(x1, y1); var c2Check = new GeoAPI.Geometries.Coordinate(x2, y2); var evcheck = new GeoAPI.Geometries.Envelope(c1Check, c2Check); AssertExt.AreEqual15(ev.Maximum.Y, evcheck.MaxY); AssertExt.AreEqual15(ev.Maximum.X, evcheck.MaxX); AssertExt.AreEqual15(ev.Minimum.Y, evcheck.MinY); AssertExt.AreEqual15(ev.Minimum.X, evcheck.MinX); }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (SqlConnection conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSQL = String.Format( "SELECT g.* FROM {0} g {1} WHERE ", Table, BuildTableHints()); if (!String.IsNullOrEmpty(DefinitionQuery)) strSQL += DefinitionQuery + " AND "; strSQL += strBbox; using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn)) { conn.Open(); System.Data.DataSet ds2 = new System.Data.DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) if (col.ColumnName != GeometryColumn) fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); foreach (System.Data.DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) if (col.ColumnName != GeometryColumn) fdr[col.ColumnName] = dr[col]; fdr.Geometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[GeometryColumn]); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
private static IEnumerable<GeoJSON> GetData(Map map, BoundingBox bbox) { if (map == null) throw new ArgumentNullException("map"); // Only queryable data! IQueryable<ICanQueryLayer> coll = map.Layers .AsQueryable() .Where(l => l.Enabled) .OfType<ICanQueryLayer>() .Where(l => l.IsQueryEnabled); List<GeoJSON> items = new List<GeoJSON>(); foreach (ICanQueryLayer layer in coll) { IEnumerable<GeoJSON> data = QueryData(bbox, layer); items.AddRange(data); } return items; }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection<Geometry> GetGeometriesInView(BoundingBox bbox) { var features = new Collection<Geometry>(); using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = "SELECT g." + GeometryColumn; strSql += " FROM " + Table + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) strSql += DefinitionQuery + " AND "; strSql += strBbox; using (var command = new SqlCommand(strSql, conn)) { conn.Open(); using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != null && dr[0] != DBNull.Value) { Geometry geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry) dr[0]); if (geom != null) features.Add(geom); } } } conn.Close(); } } return features; }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection<Geometry> GetGeometriesInView(BoundingBox bbox) { var features = new Collection<Geometry>(); using (var conn = new OracleConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); //string strSQL = "SELECT AsBinary(" + this.GeometryColumn + ") AS Geom "; string strSQL = "SELECT g." + GeometryColumn + ".Get_WKB() "; strSQL += " FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) strSQL += DefinitionQuery + " AND "; strSQL += strBbox; using (OracleCommand command = new OracleCommand(strSQL, conn)) { conn.Open(); using (OracleDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { Geometry geom = GeometryFromWKB.Parse((byte[]) dr[0], Factory); if (geom != null) features.Add(geom); } } } conn.Close(); } } return features; }
private static string GetBoxClause(BoundingBox bbox) { return String.Format(Map.NumberFormatEnUs, "(minx < {0} AND maxx > {1} AND miny < {2} AND maxy > {3})", bbox.MaxX, bbox.MinX, bbox.MaxY, bbox.MinY); }
private static IEnumerable<GeoJSON> QueryData(BoundingBox bbox, ICanQueryLayer layer) { if (layer == null) throw new ArgumentNullException("layer"); // Query for data FeatureDataSet ds = new FeatureDataSet(); layer.ExecuteIntersectionQuery(bbox, ds); IEnumerable<GeoJSON> data = GeoJSONHelper.GetData(ds); // Reproject geometries if needed IMathTransform transform = null; if (layer is VectorLayer) { ICoordinateTransformation transformation = (layer as VectorLayer).CoordinateTransformation; transform = transformation == null ? null : transformation.MathTransform; } if (transform != null) { GeometryFactory gf = new GeometryFactory(); data = data.Select(d => { Geometry converted = GeometryTransform.TransformGeometry(d.Geometry, transform, gf); d.SetGeometry(converted); return d; }); } return data; }
public void Center() { var rnd = new Random(); var c1 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var c2 = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90); var ev = new Envelope(c1, c2); var x1 = c1.X; var y1 = c1.Y; var x2 = c2.X; var y2 = c2.Y; var c1Check = new GeoAPI.Geometries.Coordinate(x1, y1); var c2Check = new GeoAPI.Geometries.Coordinate(x2, y2); var evcheck = new GeoAPI.Geometries.Envelope(c1Check, c2Check); var center = new Coordinate(ev.Center()); var centercheck = new GeoAPI.Geometries.Coordinate(evcheck.Centre); AssertExt.AreEqual15(center.X, centercheck.X); AssertExt.AreEqual15(center.Y, centercheck.Y); }
public void GetFeaturesInView(BoundingBox bbox, FeatureDataSet ds) { ExecuteIntersectionQuery(bbox, ds); }
public override Collection<uint> GetObjectIDsInView(BoundingBox bbox) { var objectlist = new Collection<uint>(); using (var conn = new SQLiteConnection(ConnectionID)) { var strSQL = "SELECT " + ObjectIdColumn + " "; strSQL += "FROM " + Table + " WHERE "; strSQL += GetBoxClause(bbox); if (!String.IsNullOrEmpty(_definitionQuery)) strSQL += " AND " + DefinitionQuery + " AND "; using (var command = new SQLiteCommand(strSQL, conn)) { conn.Open(); using (var dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { var id = (uint) (int) dr[0]; objectlist.Add(id); } } } conn.Close(); } } return objectlist; }
/// <summary> /// Returns the box filter string needed in SQL query /// </summary> /// <param name="bbox"></param> /// <returns></returns> protected string GetBoxFilterStr(BoundingBox bbox) { string strBbox = "SDO_FILTER(g." + GeometryColumn + ", mdsys.sdo_geometry(2003,#SRID#,NULL," + "mdsys.sdo_elem_info_array(1,1003,3)," + "mdsys.sdo_ordinate_array(" + bbox.MinX.ToString(Map.NumberFormatEnUs) + ", " + bbox.MinY.ToString(Map.NumberFormatEnUs) + ", " + bbox.MaxX.ToString(Map.NumberFormatEnUs) + ", " + bbox.MaxY.ToString(Map.NumberFormatEnUs) + ")), " + "'querytype=window') = 'TRUE'"; if (SRID > 0) { strBbox = strBbox.Replace("#SRID#", SRID.ToString(Map.NumberFormatEnUs)); } else { strBbox = strBbox.Replace("#SRID#", "NULL"); } return strBbox; }
/// <summary> /// Returns geometry Object IDs whose bounding box intersects 'bbox' /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection<uint> GetObjectIDsInView(BoundingBox bbox) { var objectlist = new Collection<uint>(); using (var conn = new OracleConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSQL = "SELECT g." + ObjectIdColumn + " "; strSQL += "FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) strSQL += DefinitionQuery + " AND "; strSQL += strBbox; using (OracleCommand command = new OracleCommand(strSQL, conn)) { conn.Open(); using (OracleDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { var id = (uint) (decimal) dr[0]; objectlist.Add(id); } } } conn.Close(); } } return objectlist; }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="bbox">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, IFeatureCollectionSet fcs, CancellationToken? ct = null) { _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); var fds = new FeatureDataSet(); ExecuteIntersectionQuery(fds); foreach (var fd in fds) fcs.Add(fd); }
/// <summary> /// Returns geometry Object IDs whose bounding box intersects 'bbox' /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override IEnumerable<object> GetOidsInView(BoundingBox bbox, CancellationToken? ct = null) { _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); _ogrLayer.ResetReading(); OgrFeature ogrFeature; while ((ogrFeature = _ogrLayer.GetNextFeature()) != null) { yield return ogrFeature.GetFID(); ogrFeature.Dispose(); } }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new OracleConnection(ConnectionString)) { //Get bounding box string var strBbox = GetBoxFilterStr(bbox); var strSQL = "SELECT g.*, g." + GeometryColumn + ".Get_WKB() AS sharpmap_tempgeometry "; strSQL += "FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) strSQL += DefinitionQuery + " AND "; strSQL += strBbox; using (var adapter = new OracleDataAdapter(strSQL, conn)) { conn.Open(); var ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") fdr[col.ColumnName] = dr[col]; fdr.Geometry = GeometryFromWKB.Parse((byte[]) dr["sharpmap_tempgeometry"], Factory); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
public void TestTransformation() { var m = new SharpMap.Map(new System.Drawing.Size(640, 320)); var l = new SharpMap.Layers.Symbolizer.PuntalVectorLayer("l", new SharpMap.Data.Providers.GeometryProvider(m.Factory.CreatePoint(new GeoAPI.Geometries.Coordinate(0, 51.478885))), SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(System.Drawing.Pens.Aquamarine, System.Drawing.Brushes.BurlyWood, 24)); var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory(); l.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); l.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84); m.Layers.Add(new SharpMap.Layers.TileLayer(new BruTile.Web.OsmTileSource(),"b")); m.Layers.Add(l); var e = new GeoAPI.Geometries.Envelope(-0.02, 0.02, 51.478885 - 0.01, 51.478885 + 0.01); e = GeoAPI.CoordinateSystems.Transformations.GeometryTransform.TransformBox(e, l.CoordinateTransformation.MathTransform); m.ZoomToBox(e); m.GetMap().Save("Greenwich.png", System.Drawing.Imaging.ImageFormat.Png); }
public void GetFeaturesInView(BoundingBox bbox, FeatureDataSet ds) { GetFeaturesInView(bbox, ds); }
/// <summary> /// Returns the data associated with all the geometries that are intersected by 'geom' /// </summary> /// <param name="bbox">Geometry to intersect with</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); ExecuteIntersectionQuery(ds); }
public override Collection<Geometry> GetGeometriesInView(BoundingBox bbox) { var features = new Collection<Geometry>(); using (var conn = new SQLiteConnection(ConnectionID)) { var boxIntersect = GetBoxClause(bbox); var strSQL = "SELECT " + GeometryColumn + " AS Geom "; strSQL += "FROM " + Table + " WHERE "; strSQL += boxIntersect; if (!String.IsNullOrEmpty(_definitionQuery)) strSQL += " AND " + DefinitionQuery; using (var command = new SQLiteCommand(strSQL, conn)) { conn.Open(); using (var dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { var geom = GeometryFromWKT.Parse((string) dr[0]); if (geom != null) features.Add(geom); } } } conn.Close(); } } return features; }
public override BoundingBox GetExtents() { BoundingBox box = null; using (var conn = new SQLiteConnection(ConnectionString)) { string strSQL = "SELECT Min(minx) AS MinX, Min(miny) AS MinY, Max(maxx) AS MaxX, Max(maxy) AS MaxY FROM " + Table; if (!String.IsNullOrEmpty(_definitionQuery)) strSQL += " WHERE " + DefinitionQuery; using (var command = new SQLiteCommand(strSQL, conn)) { conn.Open(); using (SQLiteDataReader dr = command.ExecuteReader()) if (dr.Read()) { box = new BoundingBox((double) dr[0], (double) dr[2], (double) dr[1], (double) dr[3]); } conn.Close(); } return box; } }
/// <summary> /// Boundingbox of the dataset /// </summary> /// <returns>boundingbox</returns> public override BoundingBox GetExtents() { if (_bbox == null) { OgrEnvelope ogrEnvelope = new OgrEnvelope(); if (_ogrLayer != null) _ogrLayer.GetExtent(ogrEnvelope, 1); _bbox = new BoundingBox(ogrEnvelope.MinX, ogrEnvelope.MaxX, ogrEnvelope.MinY, ogrEnvelope.MaxY); } return _bbox; }
private static Map InitializeMapOsm(float angle) { //Transparent style VectorStyle transparentStyle = new VectorStyle(); transparentStyle.Fill = Brushes.Transparent; transparentStyle.EnableOutline = true; //otherwise all the fancy theming stuff won't work! transparentStyle.Line.Brush = Brushes.Transparent; transparentStyle.Outline.Brush = Brushes.Transparent; transparentStyle.Symbol = null; VectorStyle transparentStyle2 = new VectorStyle(); transparentStyle2.Fill = Brushes.Transparent; transparentStyle2.EnableOutline = true; //otherwise all the fancy theming stuff won't work! transparentStyle2.Line.Brush = Brushes.Transparent; transparentStyle2.Outline.Brush = Brushes.Transparent; transparentStyle2.Symbol = null; //Initialize a new map Map map = new Map(); map.BackColor = Color.Cornsilk; var encoding = System.Text.Encoding.UTF8; //Set up the countries layer VectorLayer layNatural = new VectorLayer("Natural"); //Set the datasource to a shapefile in the App_data folder layNatural.DataSource = new ShapeFile(string.Format("{0}/natural.shp", PathOsm), true) { Encoding = encoding }; //Set default style to draw nothing layNatural.Style = transparentStyle; //Set theme ThemeViaDelegate theme = new ThemeViaDelegate(layNatural.Style, "type"); theme.GetStyleFunction = delegate(FeatureDataRow row) { string caseVal = (String) row["type"]; caseVal = caseVal.ToLowerInvariant(); VectorStyle returnStyle = new VectorStyle(); switch (caseVal) { case "forest": returnStyle.Fill = Brushes.ForestGreen; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.DarkGreen; break; case "water": returnStyle.Fill = Brushes.Aqua; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.DarkBlue; break; case "riverbank": returnStyle.Fill = Brushes.Peru; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.OrangeRed; break; case "park": returnStyle.Fill = Brushes.PaleGreen; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.DarkGreen; break; default: returnStyle = null; break; } return returnStyle; }; layNatural.Theme = theme; layNatural.SRID = 31466; VectorLayer layRoads = new VectorLayer("Roads"); layRoads.DataSource = new ShapeFile(string.Format("{0}/roads.shp", PathOsm)) { Encoding = encoding }; layRoads.DataSource.Open(); _roadsExtents = layRoads.DataSource.GetExtents(); //layRoads.DataSource.Close(); layRoads.Style = transparentStyle; ThemeViaDelegate themeRoads = new ThemeViaDelegate(transparentStyle, "type"); themeRoads.GetStyleFunction = delegate(FeatureDataRow row) { VectorStyle returnStyle = new VectorStyle(); switch ((String)row["type"]) { case "rail": returnStyle.Fill = Brushes.White; returnStyle.Line.DashPattern = new float[] { 4f, 4f };//;System.Drawing.Drawing2D.DashStyle.Dash; returnStyle.Line.Width = 4; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.Black; returnStyle.Outline.Width = 6; break; case "canal": returnStyle.Fill = Brushes.Aqua; returnStyle.Outline.Brush = Brushes.DarkBlue; returnStyle.Outline.Width = 5; break; case "cycleway": case "footway": case "pedestrian": returnStyle.Line.Brush = Brushes.DarkGray; returnStyle.Line.DashStyle = DashStyle.Dot; returnStyle.Line.Width = 1; returnStyle.MaxVisible = _roadsExtents.Width * 0.05d; break; case "living_street": case "residential": returnStyle.Line.Brush = Brushes.LightGoldenrodYellow; returnStyle.Line.Width = 2; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.DarkGray; returnStyle.Outline.Width = 4; returnStyle.MaxVisible = _roadsExtents.Width * 0.15d; break; case "primary": returnStyle.Line.Brush = Brushes.LightGoldenrodYellow; returnStyle.Line.Width = 7; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.Black; returnStyle.Outline.Width = 11; break; case "secondary": returnStyle.Line.Brush = Brushes.LightGoldenrodYellow; returnStyle.Line.Width = 6; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.Black; returnStyle.MaxVisible = _roadsExtents.Width * 0.3d; returnStyle.Outline.Width = 10; break; case "tertiary": returnStyle.Line.Brush = Brushes.LightGoldenrodYellow; returnStyle.Line.Width = 5; returnStyle.EnableOutline = true; returnStyle.Outline.Brush = Brushes.Black; returnStyle.MaxVisible = _roadsExtents.Width * 0.6d; returnStyle.Outline.Width = 9; break; case "path": case "track": case "unclassified": returnStyle.Line.Brush = Brushes.DarkGray; returnStyle.Line.DashStyle = DashStyle.DashDotDot; returnStyle.Line.Width = 1; returnStyle.MaxVisible = _roadsExtents.Width * 0.025d; break; default: returnStyle = null; break; } return returnStyle; }; layRoads.Theme = themeRoads; layRoads.SRID = 31466; VectorLayer layRail = new VectorLayer("Railways"); layRail.DataSource = new ShapeFile(string.Format("{0}/railways.shp", PathOsm)) { Encoding = encoding }; layRail.Style.Line.Brush = Brushes.White; layRail.Style.Line.DashPattern = new float[] {4f, 4f};//;System.Drawing.Drawing2D.DashStyle.Dash; layRail.Style.Line.Width = 4; layRail.Style.EnableOutline = true; layRail.Style.Outline.Brush = Brushes.Black; layRail.Style.Outline.Width = 6; VectorLayer layWaterways = new VectorLayer("Waterways"); layWaterways.Style = transparentStyle; layWaterways.DataSource = new ShapeFile(string.Format("{0}/waterways.shp", PathOsm)) { Encoding = encoding }; layRoads.Style = transparentStyle; ThemeViaDelegate themeWater = new ThemeViaDelegate(transparentStyle, "type"); themeWater.GetStyleFunction = delegate(FeatureDataRow row) { VectorStyle returnStyle = new VectorStyle(); returnStyle.Line.Brush = Brushes.Aqua; returnStyle.EnableOutline = true; Int32 lineWidth = 1; switch ((String)row["type"]) { case "canal": case "derelict_canal": lineWidth = 2; break; case "drain": returnStyle.EnableOutline = false; break; case "stream": lineWidth = 2; break; default: //returnStyle = null; break; } returnStyle.Line.Width = lineWidth; returnStyle.Outline.Brush = Brushes.DarkBlue; returnStyle.Outline.Width = lineWidth + 1; return returnStyle; }; layWaterways.Theme = themeWater; layWaterways.SRID = 31466; VectorLayer layPoints = new VectorLayer("Points"); layPoints.DataSource = new ShapeFile(string.Format("{0}/points.shp", PathOsm)) { Encoding = encoding }; layPoints.Style = transparentStyle2; ThemeViaDelegate themePoints = new ThemeViaDelegate(transparentStyle2, "type"); themePoints.GetStyleFunction = delegate(FeatureDataRow row) { VectorStyle returnStyle = new VectorStyle(); switch ((String)row["type"]) { case "bank": returnStyle.Symbol = new Bitmap("Images/Bank.gif"); break; case "hospital": returnStyle.Symbol = new Bitmap("Images/medical-facility.gif"); break; case "hotel": returnStyle.Symbol = new Bitmap("Images/hotel.gif"); break; case "restaurant": case "fast-food": returnStyle.Symbol = new Bitmap("Images/restaurant.gif"); break; case "parking": returnStyle.Symbol = new Bitmap("Images/car.gif"); break; default: Bitmap tmp = new Bitmap(1,1); tmp.SetPixel(0,0, Color.Transparent); returnStyle.Symbol = tmp; break; } return returnStyle; }; layPoints.Theme = themePoints; layWaterways.SRID = 31466; var layLabel = new LabelLayer("Road Labels"); layLabel.DataSource = layRoads.DataSource; layLabel.LabelColumn = "Name"; //Add layers to Map map.Layers.Add(layNatural); map.Layers.Add(layWaterways); map.Layers.Add(layRail); map.Layers.Add(layRoads); map.Layers.Add(layPoints); map.Layers.Add(layLabel); ShapeProvider sp = new ShapeProvider(string.Format("{0}/obepath.shp", PathOsm)) { Encoding = encoding }; VectorLayer vl = new VectorLayer("obepath", sp); vl.SRID = 31466; vl.Style.Symbol = new Bitmap("Images/car.gif"); VariableLayerCollection.Interval = 500; map.VariableLayers.Add(vl); //Restrict zoom map.MaximumZoom = layRoads.Envelope.Width * 0.75d; map.Zoom = layRoads.Envelope.Width * 0.2d; ; map.Center = layRoads.Envelope.Centre; var disclaimer = new Disclaimer { Font = new Font("Arial", 7f, FontStyle.Italic), Text = "Geodata from OpenStreetMap (CC-by-SA)\nTransformed to Shapefile by geofabrik.de", Anchor = MapDecorationAnchor.CenterBottom }; map.Decorations.Add(disclaimer); transparentStyle2.MaxVisible = map.MaximumZoom*0.3; Matrix mat = new Matrix(); mat.RotateAt(angle, map.WorldToImage(map.Center)); map.MapTransform = mat; return map; }
/// <summary> /// Returns geometry Object IDs whose bounding box intersects 'bbox' /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection<uint> GetObjectIDsInView(BoundingBox bbox) { _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); _ogrLayer.ResetReading(); var objectIDs = new Collection<uint>(); OgrFeature ogrFeature; while ((ogrFeature = _ogrLayer.GetNextFeature()) != null) { objectIDs.Add((uint)ogrFeature.GetFID()); ogrFeature.Dispose(); } return objectIDs; }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection<Geometry> GetGeometriesInView(BoundingBox bbox) { var geoms = new Collection<Geometry>(); _ogrLayer.SetSpatialFilterRect(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY); _ogrLayer.ResetReading(); try { OgrFeature ogrFeature; while ((ogrFeature = _ogrLayer.GetNextFeature()) != null) { using (var gr = ogrFeature.GetGeometryRef()) { var geom = ParseOgrGeometry(gr, Factory); if (geom != null) geoms.Add(geom); } ogrFeature.Dispose(); } } catch(Exception ex) { Debug.WriteLine(ex.Message); } return geoms; }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new OracleConnection(ConnectionString)) { //Get bounding box string var strBbox = GetBoxFilterStr(bbox); var strSql = "SELECT * "; strSql += "FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) strSql += DefinitionQuery + " AND "; strSql += strBbox; using (var adapter = new OracleDataAdapter(strSql, conn)) { conn.Open(); var ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) fdr[col.ColumnName] = dr[col]; var sdoGeom = dr[GeometryColumn] as SdoGeometry; if (sdoGeom != null) fdr.Geometry = sdoGeom.AsGeometry(); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }