public void MapNewTileAvaliableHandler(TileLayer sender, SharpMap.Geometries.BoundingBox bbox, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes) { if (this.MapNewTileAvaliable != null) { this.MapNewTileAvaliable(sender, bbox, bm, sourceWidth, sourceHeight, imageAttributes); } }
private string GetRequestUrl(SharpMap.Geometries.BoundingBox box, TileSet tileSet) { SharpMap.Web.Wms.Client.WmsOnlineResource resource = GetPreferredMethod(); System.Text.StringBuilder strReq = new StringBuilder(resource.OnlineResource); if (!resource.OnlineResource.Contains("?")) { strReq.Append("?"); } if (!strReq.ToString().EndsWith("&") && !strReq.ToString().EndsWith("?")) { strReq.Append("&"); } strReq.AppendFormat(SharpMap.Map.numberFormat_EnUS, "&REQUEST=GetMap&BBOX={0},{1},{2},{3}", box.Min.X, box.Min.Y, box.Max.X, box.Max.Y); strReq.AppendFormat("&WIDTH={0}&Height={1}", tileSet.Width, tileSet.Height); strReq.Append("&LAYERS="); // LAYERS is set in caps because the current version of tilecache.py does not accept mixed case (a little bug) if (tileSet.Layers != null && tileSet.Layers.Count > 0) { foreach (string layer in tileSet.Layers) { strReq.AppendFormat("{0},", layer); } strReq.Remove(strReq.Length - 1, 1); } strReq.AppendFormat("&FORMAT={0}", tileSet.Format); if (_WmsClient.WmsVersion == "1.3.0") { strReq.AppendFormat("&CRS={0}", tileSet.Srs); } else { strReq.AppendFormat("&SRS={0}", tileSet.Srs); } strReq.AppendFormat("&VERSION={0}", _WmsClient.WmsVersion); if (tileSet.Styles != null && tileSet.Styles.Count > 0) { strReq.Append("&STYLES="); foreach (string style in tileSet.Styles) { strReq.AppendFormat("{0},", style); } strReq.Remove(strReq.Length - 1, 1); } if (_CustomParameters != null && _CustomParameters.Count > 0) { foreach (string name in _CustomParameters.Keys) { string value = _CustomParameters[name]; strReq.AppendFormat("&{0}={1}", name, value); } } return(strReq.ToString()); }
public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds) { if (_LabelInfo == null) { return; } ds.Tables.Add(_LabelInfo); // Destroy internal reference _LabelInfo = null; }
/// <summary> /// Gets the URL for a map request base on current settings, the image size and boundingbox /// </summary> /// <param name="box">Area the WMS request should cover</param> /// <param name="size">Size of image</param> /// <returns>URL for WMS request</returns> public string GetRequestUrl(SharpMap.Geometries.BoundingBox box, System.Drawing.Size size) { SharpMap.Web.Wms.Client.WmsOnlineResource resource = GetPreferredMethod(); System.Text.StringBuilder strReq = new StringBuilder(resource.OnlineResource); if (!resource.OnlineResource.Contains("?")) { strReq.Append("?"); } if (!strReq.ToString().EndsWith("&") && !strReq.ToString().EndsWith("?")) { strReq.Append("&"); } strReq.AppendFormat(SharpMap.Map.numberFormat_EnUS, "REQUEST=GetMap&BBOX={0},{1},{2},{3}", box.Min.X, box.Min.Y, box.Max.X, box.Max.Y); strReq.AppendFormat("&WIDTH={0}&Height={1}", size.Width, size.Height); strReq.Append("&Layers="); if (_LayerList != null && _LayerList.Count > 0) { foreach (string layer in _LayerList) { strReq.AppendFormat("{0},", layer); } strReq.Remove(strReq.Length - 1, 1); } strReq.AppendFormat("&FORMAT={0}", _MimeType); if (_SpatialReferenceSystem == string.Empty) { throw new ApplicationException("Spatial reference system not set"); } if (wmsClient.WmsVersion == "1.3.0") { strReq.AppendFormat("&CRS={0}", _SpatialReferenceSystem); } else { strReq.AppendFormat("&SRS={0}", _SpatialReferenceSystem); } strReq.AppendFormat("&VERSION={0}", wmsClient.WmsVersion); strReq.Append("&Styles="); if (_StylesList != null && _StylesList.Count > 0) { foreach (string style in _StylesList) { strReq.AppendFormat("{0},", style); } strReq.Remove(strReq.Length - 1, 1); } return(strReq.ToString()); }
/// <summary> /// Throws an NotSupportedException. Attribute data is not supported by this datasource /// </summary> /// <param name="box"></param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds) { FeatureDataTable fdt = new FeatureDataTable(); fdt = _features.Clone(); foreach (FeatureDataRow fdr in _features) { if (fdr.Geometry.GetBoundingBox().Intersects(box)) { fdt.LoadDataRow(fdr.ItemArray, false); (fdt.Rows[fdt.Rows.Count - 1] as FeatureDataRow).Geometry = fdr.Geometry; } } ds.Tables.Add(fdt); }
protected void ddlProjection_SelectedIndexChanged(object sender, EventArgs e) { //Transform current view to new coordinate system and zoom to the transformed box string PreviousProj = ViewState["currentProj"].ToString(); string SelectedProj = ddlProjection.SelectedValue; //Points defining the current view SharpMap.Geometries.Point left = new SharpMap.Geometries.Point(myMap.Envelope.Left, myMap.Center.Y); SharpMap.Geometries.Point right = new SharpMap.Geometries.Point(myMap.Envelope.Right, myMap.Center.Y); SharpMap.Geometries.Point center = myMap.Center; if (PreviousProj != "Pseudo") { //Transform current view back to geographic coordinates ICoordinateTransformation trans = GetTransform(PreviousProj); left = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(myMap.Envelope.Left, myMap.Center.Y), trans.MathTransform.Inverse()); right = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(myMap.Envelope.Right, myMap.Center.Y), trans.MathTransform.Inverse()); center = GeometryTransform.TransformPoint(myMap.Center, trans.MathTransform.Inverse()); } //If both PreviousSRID and SelectedSRID are projected coordsys, first transform to geographic if (SelectedProj == "Pseudo") { myMap.Center = center; myMap.Zoom = Math.Abs(right.X - left.X); } else //Project coordinates to new projection { //Transform back to geographic and over to new projection ICoordinateTransformation trans = GetTransform(SelectedProj); left = GeometryTransform.TransformPoint(left, trans.MathTransform); right = GeometryTransform.TransformPoint(right, trans.MathTransform); center = GeometryTransform.TransformPoint(center, trans.MathTransform); myMap.Center = center; myMap.Zoom = Math.Abs(right.X - left.X); SharpMap.Geometries.BoundingBox envelopeGcs = GeometryTransform.TransformBox(myMap.Envelope, trans.MathTransform.Inverse()); litEnvelopeLatLong.Text = envelopeGcs.ToString(); } GenerateMap(); }
public void RenderLayer(ILabelLayer layer, Map map, Graphics g) { if (layer.Style.Enabled && layer.Style.MaxVisible >= map.Zoom && layer.Style.MinVisible < map.Zoom) { if (layer.DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + layer.LayerName + "'")); } g.TextRenderingHint = layer.TextRenderingHint; g.SmoothingMode = layer.SmoothingMode; SharpMap.Geometries.BoundingBox envelope = map.Envelope; //View to render if (layer.CoordinateTransformation != null) { envelope = GeometryTransform.TransformBox(envelope, layer.CoordinateTransformation.MathTransform.Inverse()); } FeatureDataSet ds = new FeatureDataSet(); layer.DataSource.Open(); layer.DataSource.ExecuteIntersectionQuery(envelope, ds); layer.DataSource.Close(); if (ds.Tables.Count == 0) { //base.Render(g, map); return; } FeatureDataTable features = (FeatureDataTable)ds.Tables[0]; //Initialize label collection List <Label> labels = new List <Label>(); LabelLayer.GetLabelMethod lblDelegate = layer.LabelStringDelegate; //List<System.Drawing.Rectangle> LabelBoxes; //Used for collision detection //Render labels for (int i = 0; i < features.Count; i++) { FeatureDataRow feature = features[i]; if (layer.CoordinateTransformation != null) { features[i].Geometry = GeometryTransform.TransformGeometry(features[i].Geometry, layer.CoordinateTransformation.MathTransform); } ILabelStyle style = null; if (layer.Theme != null) //If thematics is enabled, lets override the style { style = layer.Theme.GetStyle(feature); } else { style = layer.Style; } float rotation = 0; if (!String.IsNullOrEmpty(layer.RotationColumn)) { float.TryParse(feature[layer.RotationColumn].ToString(), NumberStyles.Any, Map.numberFormat_EnUS, out rotation); } string text; if (lblDelegate != null) { text = lblDelegate(feature); } else { text = feature[layer.LabelColumn].ToString(); } if (text != null && text != String.Empty) { if (feature.Geometry is GeometryCollection) { if (layer.MultipartGeometryBehaviour == SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.All) { foreach (SharpMap.Geometries.Geometry geom in (feature.Geometry as GeometryCollection)) { SharpMap.Rendering.Label lbl = CreateLabel(layer, geom, text, rotation, style, map, g); if (lbl != null) { labels.Add(lbl); } } } else if (layer.MultipartGeometryBehaviour == SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.CommonCenter) { Label lbl = CreateLabel(layer, feature.Geometry, text, rotation, style, map, g); if (lbl != null) { labels.Add(lbl); } } else if (layer.MultipartGeometryBehaviour == SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.First) { if ((feature.Geometry as GeometryCollection).Collection.Count > 0) { SharpMap.Rendering.Label lbl = CreateLabel(layer, (feature.Geometry as GeometryCollection).Collection[0], text, rotation, style, map, g); if (lbl != null) { labels.Add(lbl); } } } else if (layer.MultipartGeometryBehaviour == SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest) { GeometryCollection coll = (feature.Geometry as GeometryCollection); if (coll.NumGeometries > 0) { double largestVal = 0; int idxOfLargest = 0; for (int j = 0; j < coll.NumGeometries; j++) { SharpMap.Geometries.Geometry geom = coll.Geometry(j); if (geom is Geometries.LineString && ((Geometries.LineString)geom).Length > largestVal) { largestVal = ((Geometries.LineString)geom).Length; idxOfLargest = j; } if (geom is Geometries.MultiLineString && ((Geometries.MultiLineString)geom).Length > largestVal) { largestVal = ((Geometries.LineString)geom).Length; idxOfLargest = j; } if (geom is Geometries.Polygon && ((Geometries.Polygon)geom).Area > largestVal) { largestVal = ((Geometries.Polygon)geom).Area; idxOfLargest = j; } if (geom is Geometries.MultiPolygon && ((Geometries.MultiPolygon)geom).Area > largestVal) { largestVal = ((Geometries.MultiPolygon)geom).Area; idxOfLargest = j; } } SharpMap.Rendering.Label lbl = CreateLabel(layer, coll.Geometry(idxOfLargest), text, rotation, style, map, g); if (lbl != null) { labels.Add(lbl); } } } } else { SharpMap.Rendering.Label lbl = CreateLabel(layer, feature.Geometry, text, rotation, style, map, g); if (lbl != null) { labels.Add(lbl); } } } } if (labels.Count > 0) //We have labels to render... { if (layer.Style.CollisionDetection && layer.LabelFilter != null) { layer.LabelFilter(labels); } for (int i = 0; i < labels.Count; i++) { VectorRenderer.DrawLabel(g, labels[i].LabelPoint, labels[i].Style.Offset, labels[i].Style.Font, labels[i].Style.ForeColor, labels[i].Style.BackColor, layer.Style.Halo, labels[i].Rotation, labels[i].Text, map); } } labels = null; } //base.Render(g, map); }
public System.Collections.ObjectModel.Collection <uint> GetObjectIDsInView(SharpMap.Geometries.BoundingBox bbox) { throw new Exception("The method or operation is not implemented."); }
public System.Collections.ObjectModel.Collection <SharpMap.Geometries.Geometry> GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox) { if (_FeatureTypeInfo == null) { return(null); } System.Collections.ObjectModel.Collection <Geometry> geoms = new System.Collections.ObjectModel.Collection <Geometry>(); string geometryTypeString = _FeatureTypeInfo.Geometry._GeometryType; GeometryFactory geomFactory = null; if (!string.IsNullOrEmpty(_Label)) { _LabelInfo = new FeatureDataTable(); _LabelInfo.Columns.Add(_Label); // Turn off quick geometries, if a label is applied... _QuickGeometries = false; } // Configuration for GetFeature request */ WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_TextResources); config.configureForWfsGetFeatureRequest(_HttpClientUtil, _FeatureTypeInfo, _Label, bbox, _OGCFilter, _GetFeatureGETRequest); try { switch (geometryTypeString) { /* Primitive geometry elements */ // GML2 case "PointPropertyType": geomFactory = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); break; // GML2 case "LineStringPropertyType": geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); break; // GML2 case "PolygonPropertyType": geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); break; // GML3 case "CurvePropertyType": geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); break; // GML3 case "SurfacePropertyType": geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); break; /* Aggregate geometry elements */ // GML2 case "MultiPointPropertyType": if (_MultiGeometries) { geomFactory = new MultiPointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } else { geomFactory = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } break; // GML2 case "MultiLineStringPropertyType": if (_MultiGeometries) { geomFactory = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } else { geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } break; // GML2 case "MultiPolygonPropertyType": if (_MultiGeometries) { geomFactory = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } else { geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } break; // GML3 case "MultiCurvePropertyType": if (_MultiGeometries) { geomFactory = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } else { geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } break; // GML3 case "MultiSurfacePropertyType": if (_MultiGeometries) { geomFactory = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } else { geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo); } break; // .e.g. 'gml:GeometryAssociationType' or 'GeometryPropertyType' //It's better to set the geometry type manually, if it is known... default: geomFactory = new UnspecifiedGeometryFactory_WFS1_0_0_GML2(_HttpClientUtil, _FeatureTypeInfo, _MultiGeometries, _QuickGeometries, _LabelInfo); geoms = geomFactory.createGeometries(); return(geoms); } geoms = _QuickGeometries ? geomFactory.createQuickGeometries(geometryTypeString) : geomFactory.createGeometries(); geomFactory.Dispose(); return(geoms); } // Free resources (net connection of geometry factory) finally { geomFactory.Dispose(); } }
/// <summary> /// Renders the layer to a graphics object /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> public override void Render(System.Drawing.Graphics g, Map map) { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } g.SmoothingMode = this.SmoothingMode; SharpMap.Geometries.BoundingBox envelope = map.Envelope; //View to render if (this.CoordinateTransformation != null) { envelope = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformBox(envelope, this.CoordinateTransformation.MathTransform.Inverse()); } //List<SharpMap.Geometries.Geometry> features = this.DataSource.GetGeometriesInView(map.Envelope); if (this.DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + this.LayerName + "'")); } //If thematics is enabled, we use a slighty different rendering approach if (this.Theme != null) { SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); this.DataSource.Open(); this.DataSource.ExecuteIntersectionQuery(envelope, ds); this.DataSource.Close(); SharpMap.Data.FeatureDataTable features = (SharpMap.Data.FeatureDataTable)ds.Tables[0]; if (this.CoordinateTransformation != null) { for (int i = 0; i < features.Count; i++) { features[i].Geometry = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(features[i].Geometry, this.CoordinateTransformation.MathTransform); } } //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (Style.EnableOutline) { //foreach (SharpMap.Geometries.Geometry feature in features) for (int i = 0; i < features.Count; i++) { SharpMap.Data.FeatureDataRow feature = features[i]; //Draw background of all line-outlines first if (feature.Geometry is SharpMap.Geometries.LineString) { SharpMap.Styles.VectorStyle outlinestyle1 = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle; if (outlinestyle1.Enabled && outlinestyle1.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawLineString(g, feature.Geometry as LineString, outlinestyle1.Outline, map); } } else if (feature.Geometry is SharpMap.Geometries.MultiLineString) { SharpMap.Styles.VectorStyle outlinestyle2 = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle; if (outlinestyle2.Enabled && outlinestyle2.EnableOutline) { SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, feature.Geometry as MultiLineString, outlinestyle2.Outline, map); } } } } for (int i = 0; i < features.Count; i++) { SharpMap.Data.FeatureDataRow feature = features[i]; SharpMap.Styles.VectorStyle style = this.Theme.GetStyle(feature) as SharpMap.Styles.VectorStyle; RenderGeometry(g, map, feature.Geometry, style); } } else { this.DataSource.Open(); Collection <SharpMap.Geometries.Geometry> geoms = this.DataSource.GetGeometriesInView(envelope); this.DataSource.Close(); if (this.CoordinateTransformation != null) { for (int i = 0; i < geoms.Count; i++) { geoms[i] = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformGeometry(geoms[i], this.CoordinateTransformation.MathTransform); } } //Linestring outlines is drawn by drawing the layer once with a thicker line //before drawing the "inline" on top. if (this.Style.EnableOutline) { foreach (SharpMap.Geometries.Geometry geom in geoms) { if (geom != null) { //Draw background of all line-outlines first switch (geom.GetType().FullName) { case "SharpMap.Geometries.LineString": SharpMap.Rendering.VectorRenderer.DrawLineString(g, geom as LineString, this.Style.Outline, map); break; case "SharpMap.Geometries.MultiLineString": SharpMap.Rendering.VectorRenderer.DrawMultiLineString(g, geom as MultiLineString, this.Style.Outline, map); break; default: break; } } } } for (int i = 0; i < geoms.Count; i++) { if (geoms[i] != null) { RenderGeometry(g, map, geoms[i], this.Style); } } } base.Render(g, map); }
/// <summary> /// Throws an NotSupportedException. Attribute data is not supported by this datasource /// </summary> /// <param name="box"></param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(SharpMap.Geometries.BoundingBox box, FeatureDataSet ds) { throw new NotSupportedException("Attribute data is not supported by the GeometryProvider."); }
/// <summary> /// Creates an FDO envelope from a SharpMap bounding box /// </summary> /// <param name="bbox">The SharpMap bounding box.</param> /// <returns></returns> public static Fdo.IEnvelope EnvelopeFromBoundingBox(Sm.BoundingBox bbox) { return(FdoGeometryFactory.Instance.CreateEnvelopeXY(bbox.Left, bbox.Bottom, bbox.Right, bbox.Top)); }
/// <summary> /// Creates an R-Tree query rectangle from a SharpMap bounding box /// </summary> /// <param name="bbox">The SharpMap bounding box</param> /// <returns></returns> public static Rectangle RectFromBoundingBox(Sm.BoundingBox bbox) { return(new Rectangle((float)bbox.Left, (float)bbox.Bottom, (float)bbox.Right, (float)bbox.Top, (float)0.0, (float)0.0)); }
/// <summary> /// Checks whether this point intersects a <see cref="BoundingBox"/> /// </summary> /// <param name="box">Box</param> /// <returns>True if they intersect</returns> public bool Intersects(BoundingBox box) { return(box.Contains(this)); }
/// <summary> /// Checks whether this point touches a <see cref="BoundingBox"/> /// </summary> /// <param name="box">box</param> /// <returns>true if they touch</returns> public bool Touches(BoundingBox box) { return(box.Touches(this)); }
/// <summary> /// Returns the distance between this point and a <see cref="BoundingBox"/> /// </summary> /// <param name="box"></param> /// <returns></returns> public double Distance(BoundingBox box) { return(box.Distance(this)); }